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 and URL 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") |
| 11 | OPENECOMP_NEXUS_REPO="${NEXUSPROXY}/content/sites/raw" |
| 12 | |
| 13 | #Create a netrc file for use with curl |
| 14 | NETRC=$(mktemp) |
| 15 | echo "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 |
| 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' |
| 54 | cp ${WORKSPACE}/dcae-analytics-tca/target/dcae-analytics-tca-${POM_VERSION}.jar \ |
| 55 | ${STAGE_DIR}/stage/opt/app/cdap-apps |
| 56 | |
| 57 | echo 'Copying json file to stage' |
| 58 | cp ${WORKSPACE}/dcae-apod-buildtools/configs/package-dcae-analytics-tca.json \ |
| 59 | ${STAGE_DIR}/package.json |
| 60 | |
| 61 | echo 'Contents of stage directory' |
| 62 | ls -lR ${STAGE_DIR} |
| 63 | |
| 64 | echo '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 | |
| 76 | cp ${OUTPUT_DIR}/${OUTPUT_FILE_DATE_STAMPED} ${OUTPUT_DIR}/${OUTPUT_FILE} |
| 77 | |
| 78 | echo 'Contents of output directory' |
| 79 | ls -lR ${OUTPUT_DIR} |
| 80 | |
| 81 | SEND_TO="${OPENECOMP_NEXUS_REPO}/org.openecomp.dcae/deb-snapshots/${PACKAGE_GROUP_ID}/${OUTPUT_FILE}" |
| 82 | echo "Sending ${OUTPUT_DIR}/${OUTPUT_FILE} to Nexus Repo: ${SEND_TO}" |
| 83 | curl -vkn --netrc-file "${NETRC}" --upload-file ${OUTPUT_DIR}/${OUTPUT_FILE} ${SEND_TO} |
| 84 | |
| 85 | SEND_TO="${OPENECOMP_NEXUS_REPO}/org.openecomp.dcae/deb-snapshots/${PACKAGE_GROUP_ID}/${OUTPUT_FILE_DATE_STAMPED}" |
| 86 | |
| 87 | echo "Sending ${OUTPUT_DIR}/${OUTPUT_FILE_DATE_STAMPED} to Nexus Repo: ${SEND_TO}" |
| 88 | curl -vkn --netrc-file "${NETRC}" --upload-file ${OUTPUT_DIR}/${OUTPUT_FILE_DATE_STAMPED} ${SEND_TO} |
| 89 | |
| 90 | echo '================ ENDING SCRIPT TO CREATE DEBIAN FILE ====================' |