blob: 7a15c2f07a7c379446ea69821f769f81d5b376b9 [file] [log] [blame]
Lisa Revelcaf95792017-02-18 20:48:00 +00001#!/bin/bash
2#
3# Create a debian package and push to remote repo
4#
5set -x
6echo '================= STARTING SCRIPT TO CREATE DEBIAN FILE ================='
7
8# Extract the username and password for the nexus repo
9USER=$(xpath -q -e "//servers/server[id='ecomp-raw']/username/text()" "$SETTINGS_FILE")
10PASS=$(xpath -q -e "//servers/server[id='ecomp-raw']/password/text()" "$SETTINGS_FILE")
Lisa Revel824b7cb2017-02-20 01:56:48 +000011REPO="${NEXUSPROXY}/content/sites/raw"
Lisa Revelcaf95792017-02-18 20:48:00 +000012
13#Create a netrc file for use with curl
14NETRC=$(mktemp)
15echo "machine nexus.dcaeapod.org login $USER password $PASS" > "$NETRC"
16
17#Write an envionment var for the netrc location since it's a temp file
18echo "NETRC=$NETRC" > "$WORKSPACE/netrc_env.txt"
19
20STAGE_DIR=${WORKSPACE}/package
21OUTPUT_DIR=${WORKSPACE}/package/output
22
23DATE_STAMP="$(date +"%Y%m%d%H%M%S")"
24PACKAGE_BUILD_NUMBER=${DATE_STAMP}
25PACKAGE_NAME_APPLICATION=$( \
26 cat ${WORKSPACE}/dcae-apod-buildtools/configs/package-dcae-analytics-tca.json | \
27 python -c 'import json,sys;print json.load(sys.stdin)["applicationName"]')
28PACKAGE_NAME_VERSION=$( \
29 cat ${WORKSPACE}/dcae-apod-buildtools/configs/package-dcae-analytics-tca.json | \
30 python -c 'import json,sys;print json.load(sys.stdin)["version"]')
31PACKAGE_GROUP_ID=$( \
32 cat ${WORKSPACE}/dcae-apod-buildtools/configs/package-dcae-analytics-tca.json | \
33 python -c 'import json,sys;print json.load(sys.stdin)["groupId"]')
34OUTPUT_FILE="${PACKAGE_NAME_APPLICATION}_${PACKAGE_NAME_VERSION}.deb"
35OUTPUT_FILE_DATE_STAMPED="${PACKAGE_NAME_APPLICATION}_${PACKAGE_NAME_VERSION}-${DATE_STAMP}.deb"
36
37echo 'Package variables:'
38echo " STAGE_DIR = ${STAGE_DIR}"
39echo " OUTPUT_DIR = ${OUTPUT_DIR}"
40echo " PACKAGE_BUILD_NUMBER = ${PACKAGE_BUILD_NUMBER}"
41echo " PACKAGE_NAME_APPLICATION = ${PACKAGE_NAME_APPLICATION}"
42echo " PACKAGE_NAME_VERSION = ${PACKAGE_NAME_VERSION}"
43echo " PACKAGE_GROUP_ID = ${PACKAGE_GROUP_ID}"
44echo " OUTPUT_FILE = ${OUTPUT_FILE}"
45echo " OUTPUT_FILE_DATE_STAMPED = ${OUTPUT_FILE_DATE_STAMPED}"
46
47echo 'Creating Staging and Output directories'
48rm -rf ${STAGE_DIR}
49rm -rf ${OUTPUT_DIR}
50mkdir -p ${STAGE_DIR}/stage/opt/app/cdap-apps
51mkdir -p ${OUTPUT_DIR}
52
53echo 'Copying jar file to stage'
Lisa Revel824b7cb2017-02-20 01:56:48 +000054JAR_FILE=$(ls ${WORKSPACE}/dcae-analytics-tca/target/ | \
55 grep dcae-analytics-tca- | grep -v javadoc | grep -v sources)
56
57cp ${WORKSPACE}/dcae-analytics-tca/target/${JAR_FILE} \
Lisa Revelcaf95792017-02-18 20:48:00 +000058 ${STAGE_DIR}/stage/opt/app/cdap-apps
59
60echo 'Copying json file to stage'
61cp ${WORKSPACE}/dcae-apod-buildtools/configs/package-dcae-analytics-tca.json \
62 ${STAGE_DIR}/package.json
63
64echo 'Contents of stage directory'
65ls -lR ${STAGE_DIR}
66
67echo 'Creating debian package'
68${WORKSPACE}/dcae-apod-buildtools/scripts/package -b debian -d ${STAGE_DIR} \
69 -o ${OUTPUT_DIR} -y package.json -B ${PACKAGE_BUILD_NUMBER} -v
70
71# The controller needs the debian packaged named
72# dcae-analytics-tca_17.01.0-LATEST.deb so it can find and deploy it.
73# In order to have a copy of each file built a copy of
74# dcae-analytics-tca_17.01.0-LATEST.deb will be made and it will have a
75# date stamp and build number on it.
76# For example: dcae-analytics-tca_17.01.0-YYYYMMDDHHMMSS-XXX.deb
77# Both files will then be uploaded to the repository.
78
79cp ${OUTPUT_DIR}/${OUTPUT_FILE_DATE_STAMPED} ${OUTPUT_DIR}/${OUTPUT_FILE}
80
81echo 'Contents of output directory'
82ls -lR ${OUTPUT_DIR}
83
Lisa Revel824b7cb2017-02-20 01:56:48 +000084SEND_TO="${REPO}/org.openecomp.dcae.apod.analytics/deb-snapshots/${OUTPUT_FILE}"
Lisa Revelcaf95792017-02-18 20:48:00 +000085echo "Sending ${OUTPUT_DIR}/${OUTPUT_FILE} to Nexus Repo: ${SEND_TO}"
86curl -vkn --netrc-file "${NETRC}" --upload-file ${OUTPUT_DIR}/${OUTPUT_FILE} ${SEND_TO}
87
Lisa Revel824b7cb2017-02-20 01:56:48 +000088SEND_TO="${REPO}/org.openecomp.dcae.apod.analytics/deb-snapshots/${OUTPUT_FILE_DATE_STAMPED}"
Lisa Revelcaf95792017-02-18 20:48:00 +000089
90echo "Sending ${OUTPUT_DIR}/${OUTPUT_FILE_DATE_STAMPED} to Nexus Repo: ${SEND_TO}"
91curl -vkn --netrc-file "${NETRC}" --upload-file ${OUTPUT_DIR}/${OUTPUT_FILE_DATE_STAMPED} ${SEND_TO}
92
93echo '================ ENDING SCRIPT TO CREATE DEBIAN FILE ===================='