blob: bc1b2377e2be4d9ab84f91437917f5e4e37fbde1 [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, password for the nexus repo from the maven settings file
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")
11OPENECOMP_NEXUS_REPO="${NEXUSPROXY}/content/sites/raw"
12
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'
54cp ${WORKSPACE}/dcae-analytics-tca/target/dcae-analytics-tca-${POM_VERSION}.jar \
55 ${STAGE_DIR}/stage/opt/app/cdap-apps
56
57echo 'Copying json file to stage'
58cp ${WORKSPACE}/dcae-apod-buildtools/configs/package-dcae-analytics-tca.json \
59 ${STAGE_DIR}/package.json
60
61echo 'Contents of stage directory'
62ls -lR ${STAGE_DIR}
63
64echo 'Creating debian package'
65${WORKSPACE}/dcae-apod-buildtools/scripts/package -b debian -d ${STAGE_DIR} \
66 -o ${OUTPUT_DIR} -y package.json -B ${PACKAGE_BUILD_NUMBER} -v
67
68# The controller needs the debian packaged named
69# dcae-analytics-tca_17.01.0-LATEST.deb so it can find and deploy it.
70# In order to have a copy of each file built a copy of
71# dcae-analytics-tca_17.01.0-LATEST.deb will be made and it will have a
72# date stamp and build number on it.
73# For example: dcae-analytics-tca_17.01.0-YYYYMMDDHHMMSS-XXX.deb
74# Both files will then be uploaded to the repository.
75
76cp ${OUTPUT_DIR}/${OUTPUT_FILE_DATE_STAMPED} ${OUTPUT_DIR}/${OUTPUT_FILE}
77
78echo 'Contents of output directory'
79ls -lR ${OUTPUT_DIR}
80
81SEND_TO="${OPENECOMP_NEXUS_REPO}/org.openecomp.dcae/deb-snapshots/${PACKAGE_GROUP_ID}/${OUTPUT_FILE}"
82echo "Sending ${OUTPUT_DIR}/${OUTPUT_FILE} to Nexus Repo: ${SEND_TO}"
83curl -vkn --netrc-file "${NETRC}" --upload-file ${OUTPUT_DIR}/${OUTPUT_FILE} ${SEND_TO}
84
85SEND_TO="${OPENECOMP_NEXUS_REPO}/org.openecomp.dcae/deb-snapshots/${PACKAGE_GROUP_ID}/${OUTPUT_FILE_DATE_STAMPED}"
86
87echo "Sending ${OUTPUT_DIR}/${OUTPUT_FILE_DATE_STAMPED} to Nexus Repo: ${SEND_TO}"
88curl -vkn --netrc-file "${NETRC}" --upload-file ${OUTPUT_DIR}/${OUTPUT_FILE_DATE_STAMPED} ${SEND_TO}
89
90echo '================== ENDING SCRIPT TO CREATE DEBIAN FILE ==================='