Lisa Revel | 22a0a33 | 2017-02-16 20:14:52 +0000 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # Create a debian package and push to remote repo |
| 3 | # |
| 4 | |
| 5 | echo '===================== STARTING SCRIPT TO CREATE DEBIAN FILE =======================' |
| 6 | # Extract the username, password and path to the nexus repo from the maven settings file |
| 7 | USER=$(xpath -q -e "//servers/server[id='ecomp-raw']/username/text()" "$SETTINGS_FILE") |
| 8 | PASS=$(xpath -q -e "//servers/server[id='ecomp-raw']/password/text()" "$SETTINGS_FILE") |
| 9 | OPENECOMP_NEXUS_REPO="${NEXUSPROXY}/content/sites/raw" |
| 10 | |
| 11 | #Create a netrc file for use with curl |
| 12 | NETRC=$(mktemp) |
| 13 | echo "machine nexus.openecomp.org login $USER password $PASS" > "$NETRC" |
| 14 | |
| 15 | |
| 16 | #Write an envionment var for the netrc location since it's a temp file |
| 17 | echo "NETRC=$NETRC" > "$WORKSPACE/netrc_env.txt" |
| 18 | |
| 19 | STAGE_DIR=${WORKSPACE}/package |
| 20 | OUTPUT_DIR=${WORKSPACE}/package/output |
| 21 | |
| 22 | DATE_STAMP="$(date +"%Y%m%d%H%M%S")" |
| 23 | PACKAGE_BUILD_NUMBER=${DATE_STAMP} |
| 24 | PACKAGE_NAME_APPLICATION=$( \ |
| 25 | cat ${WORKSPACE}/dcae-apod-buildtools/configs/package-cdap3vm.json | \ |
| 26 | python -c 'import json,sys;print json.load(sys.stdin)["applicationName"]') |
| 27 | PACKAGE_NAME_VERSION=$( \ |
| 28 | cat ${WORKSPACE}/dcae-apod-buildtools/configs/package-cdap3vm.json | \ |
| 29 | python -c 'import json,sys;print json.load(sys.stdin)["version"]') |
| 30 | PACKAGE_GROUP_ID=$( \ |
| 31 | cat ${WORKSPACE}/dcae-apod-buildtools/configs/package-cdap3vm.json | \ |
| 32 | python -c 'import json,sys;print json.load(sys.stdin)["groupId"]') |
| 33 | OUTPUT_FILE="${PACKAGE_NAME_APPLICATION}_${PACKAGE_NAME_VERSION}.deb" |
| 34 | OUTPUT_FILE_DATE_STAMPED= \ |
| 35 | "${PACKAGE_NAME_APPLICATION}_${PACKAGE_NAME_VERSION}-${DATE_STAMP}.deb" |
| 36 | |
Lisa Revel | 409c736 | 2017-02-17 00:31:49 +0000 | [diff] [blame^] | 37 | echo 'Package variables:' |
| 38 | echo " STAGE_DIR = ${STATE_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}" |
Lisa Revel | 22a0a33 | 2017-02-16 20:14:52 +0000 | [diff] [blame] | 46 | |
Lisa Revel | 409c736 | 2017-02-17 00:31:49 +0000 | [diff] [blame^] | 47 | echo 'Creating Staging and Output directories' |
Lisa Revel | 22a0a33 | 2017-02-16 20:14:52 +0000 | [diff] [blame] | 48 | rm -rf ${STAGE_DIR} |
| 49 | rm -rf ${OUTPUT_DIR} |
| 50 | mkdir -p ${STAGE_DIR}/stage/opt/app/dcae-cdap-small-hadoop |
| 51 | mkdir -p ${OUTPUT_DIR} |
| 52 | |
| 53 | echo 'Copying files to stage' |
| 54 | cp -R ${WORKSPACE}/cdap3vm/* ${STAGE_DIR}/stage/opt/app/dcae-cdap-small-hadoop |
| 55 | |
| 56 | echo 'Copying json file to stage' |
| 57 | cp ${WORKSPACE}/dcae-apod-buildtools/configs/package-cdap3vm.json ${STAGE_DIR}/package.json |
| 58 | |
Lisa Revel | 409c736 | 2017-02-17 00:31:49 +0000 | [diff] [blame^] | 59 | echo 'Contents of stage directory' |
| 60 | ls -lR ${STAGE_DIR} |
| 61 | |
Lisa Revel | 22a0a33 | 2017-02-16 20:14:52 +0000 | [diff] [blame] | 62 | echo "Creating debian package" |
| 63 | ${WORKSPACE}/dcae-apod-buildtools/scripts/package -b debian -d ${STAGE_DIR} \ |
| 64 | -o ${OUTPUT_DIR} -y package.json -B ${PACKAGE_BUILD_NUMBER} -v |
| 65 | |
| 66 | |
Lisa Revel | 409c736 | 2017-02-17 00:31:49 +0000 | [diff] [blame^] | 67 | echo "Contents of output directory" |
| 68 | ls -lR ${OUTPUT_DIR} |
| 69 | |
Lisa Revel | 22a0a33 | 2017-02-16 20:14:52 +0000 | [diff] [blame] | 70 | # The controller needs the debian packaged named |
| 71 | # dcae-cdap-small-hadoop_17.01.0-LATEST.deb so it can find and deploy it. |
| 72 | # In order to have a copy of each file built a copy of |
| 73 | # dcae-cdap-small-hadoop_17.01.0-LATEST.deb will be made and it will have a |
| 74 | # date stamp and build number on it. |
| 75 | # For example: dcae-cda-small-hadoop_17.01.0-YYYYMMDDHHMMSS-XXX.deb |
| 76 | # Both files will then be uploaded to the repository. |
| 77 | |
| 78 | cp ${OUTPUT_DIR}/${OUTPUT_FILE_DATE_STAMPED} ${OUTPUT_DIR}/${OUTPUT_FILE} |
| 79 | |
| 80 | SEND_TO= \ |
| 81 | "${OPENECOMP_NEXUS_REPO}/org.openecomp.dcae.apod.cdap/deb-snapshots/${PACKAGE_GROUP_ID}/${OUTPUT_FILE}" |
Lisa Revel | 409c736 | 2017-02-17 00:31:49 +0000 | [diff] [blame^] | 82 | echo "Sending ${OUTPUT_DIR}/${OUTPUT_FILE} to Nexus Repo: ${SEND_TO}" |
Lisa Revel | 22a0a33 | 2017-02-16 20:14:52 +0000 | [diff] [blame] | 83 | curl -vkn --netrc-file "${NETRC}" --upload-file ${OUTPUT_DIR}/${OUTPUT_FILE} ${SEND_TO} |
| 84 | |
| 85 | SEND_TO= \ |
| 86 | "${OPENECOMP_NEXUS_REPO}/org.openecomp.dcae.apod.cdap/deb-snapshots/${PACKAGE_GROUP_ID}/${OUTPUT_FILE_DATE_STAMPED}" |
Lisa Revel | 409c736 | 2017-02-17 00:31:49 +0000 | [diff] [blame^] | 87 | |
| 88 | echo "Sending ${OUTPUT_DIR}/${OUTPUT_FILE_DATE_STAMPED} to Nexus Repo: ${SEND_TO}" |
Lisa Revel | 22a0a33 | 2017-02-16 20:14:52 +0000 | [diff] [blame] | 89 | curl -vkn --netrc-file "${NETRC}" --upload-file ${OUTPUT_DIR}/${OUTPUT_FILE_DATE_STAMPED} ${SEND_TO} |
| 90 | |
| 91 | echo '===================== ENDING SCRIPT TO CREATE DEBIAN FILE =======================' |