Lisa Revel | caf9579 | 2017-02-18 20:48:00 +0000 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # Create a debian package and push to remote repo |
| 4 | # |
| 5 | set -x |
| 6 | echo '================= STARTING SCRIPT TO CREATE DEBIAN FILE =================' |
| 7 | |
| 8 | # Extract the username and password for the nexus repo |
| 9 | USER=$(xpath -q -e "//servers/server[id='ecomp-raw']/username/text()" "$SETTINGS_FILE") |
| 10 | PASS=$(xpath -q -e "//servers/server[id='ecomp-raw']/password/text()" "$SETTINGS_FILE") |
Lisa Revel | 824b7cb | 2017-02-20 01:56:48 +0000 | [diff] [blame] | 11 | REPO="${NEXUSPROXY}/content/sites/raw" |
Lisa Revel | caf9579 | 2017-02-18 20:48:00 +0000 | [diff] [blame] | 12 | |
| 13 | #Create a netrc file for use with curl |
| 14 | NETRC=$(mktemp) |
Lisa Revel | 6e0428d | 2017-02-20 21:52:10 +0000 | [diff] [blame^] | 15 | echo "machine nexus.openecomp.org login $USER password $PASS" > "$NETRC" |
Lisa Revel | caf9579 | 2017-02-18 20:48:00 +0000 | [diff] [blame] | 16 | |
| 17 | #Write an envionment var for the netrc location since it's a temp file |
| 18 | echo "NETRC=$NETRC" > "$WORKSPACE/netrc_env.txt" |
| 19 | |
| 20 | STAGE_DIR=${WORKSPACE}/package |
| 21 | OUTPUT_DIR=${WORKSPACE}/package/output |
| 22 | |
| 23 | DATE_STAMP="$(date +"%Y%m%d%H%M%S")" |
| 24 | PACKAGE_BUILD_NUMBER=${DATE_STAMP} |
| 25 | PACKAGE_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"]') |
| 28 | PACKAGE_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"]') |
| 31 | PACKAGE_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"]') |
| 34 | OUTPUT_FILE="${PACKAGE_NAME_APPLICATION}_${PACKAGE_NAME_VERSION}.deb" |
| 35 | OUTPUT_FILE_DATE_STAMPED="${PACKAGE_NAME_APPLICATION}_${PACKAGE_NAME_VERSION}-${DATE_STAMP}.deb" |
| 36 | |
| 37 | echo 'Package variables:' |
| 38 | echo " STAGE_DIR = ${STAGE_DIR}" |
| 39 | echo " OUTPUT_DIR = ${OUTPUT_DIR}" |
| 40 | echo " PACKAGE_BUILD_NUMBER = ${PACKAGE_BUILD_NUMBER}" |
| 41 | echo " PACKAGE_NAME_APPLICATION = ${PACKAGE_NAME_APPLICATION}" |
| 42 | echo " PACKAGE_NAME_VERSION = ${PACKAGE_NAME_VERSION}" |
| 43 | echo " PACKAGE_GROUP_ID = ${PACKAGE_GROUP_ID}" |
| 44 | echo " OUTPUT_FILE = ${OUTPUT_FILE}" |
| 45 | echo " OUTPUT_FILE_DATE_STAMPED = ${OUTPUT_FILE_DATE_STAMPED}" |
| 46 | |
| 47 | echo 'Creating Staging and Output directories' |
| 48 | rm -rf ${STAGE_DIR} |
| 49 | rm -rf ${OUTPUT_DIR} |
| 50 | mkdir -p ${STAGE_DIR}/stage/opt/app/cdap-apps |
| 51 | mkdir -p ${OUTPUT_DIR} |
| 52 | |
| 53 | echo 'Copying jar file to stage' |
Lisa Revel | 824b7cb | 2017-02-20 01:56:48 +0000 | [diff] [blame] | 54 | JAR_FILE=$(ls ${WORKSPACE}/dcae-analytics-tca/target/ | \ |
| 55 | grep dcae-analytics-tca- | grep -v javadoc | grep -v sources) |
| 56 | |
| 57 | cp ${WORKSPACE}/dcae-analytics-tca/target/${JAR_FILE} \ |
Lisa Revel | caf9579 | 2017-02-18 20:48:00 +0000 | [diff] [blame] | 58 | ${STAGE_DIR}/stage/opt/app/cdap-apps |
| 59 | |
| 60 | echo 'Copying json file to stage' |
| 61 | cp ${WORKSPACE}/dcae-apod-buildtools/configs/package-dcae-analytics-tca.json \ |
| 62 | ${STAGE_DIR}/package.json |
| 63 | |
| 64 | echo 'Contents of stage directory' |
| 65 | ls -lR ${STAGE_DIR} |
| 66 | |
| 67 | echo '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 | |
| 79 | cp ${OUTPUT_DIR}/${OUTPUT_FILE_DATE_STAMPED} ${OUTPUT_DIR}/${OUTPUT_FILE} |
| 80 | |
| 81 | echo 'Contents of output directory' |
| 82 | ls -lR ${OUTPUT_DIR} |
| 83 | |
Lisa Revel | 824b7cb | 2017-02-20 01:56:48 +0000 | [diff] [blame] | 84 | SEND_TO="${REPO}/org.openecomp.dcae.apod.analytics/deb-snapshots/${OUTPUT_FILE}" |
Lisa Revel | caf9579 | 2017-02-18 20:48:00 +0000 | [diff] [blame] | 85 | echo "Sending ${OUTPUT_DIR}/${OUTPUT_FILE} to Nexus Repo: ${SEND_TO}" |
| 86 | curl -vkn --netrc-file "${NETRC}" --upload-file ${OUTPUT_DIR}/${OUTPUT_FILE} ${SEND_TO} |
| 87 | |
Lisa Revel | 824b7cb | 2017-02-20 01:56:48 +0000 | [diff] [blame] | 88 | SEND_TO="${REPO}/org.openecomp.dcae.apod.analytics/deb-snapshots/${OUTPUT_FILE_DATE_STAMPED}" |
Lisa Revel | caf9579 | 2017-02-18 20:48:00 +0000 | [diff] [blame] | 89 | |
| 90 | echo "Sending ${OUTPUT_DIR}/${OUTPUT_FILE_DATE_STAMPED} to Nexus Repo: ${SEND_TO}" |
| 91 | curl -vkn --netrc-file "${NETRC}" --upload-file ${OUTPUT_DIR}/${OUTPUT_FILE_DATE_STAMPED} ${SEND_TO} |
| 92 | |
| 93 | echo '================ ENDING SCRIPT TO CREATE DEBIAN FILE ====================' |