blob: 0094fd6ac7e3062dd00c530c6e2703e6a1f6ebc0 [file] [log] [blame]
Lisa Revel22a0a332017-02-16 20:14:52 +00001#!/bin/bash
2# Create a debian package and push to remote repo
3#
Lisa Reveldae96392017-02-17 16:29:33 +00004set -x
Lisa Revel22a0a332017-02-16 20:14:52 +00005echo '===================== STARTING SCRIPT TO CREATE DEBIAN FILE ======================='
6# Extract the username, password and path to the nexus repo from the maven settings file
7USER=$(xpath -q -e "//servers/server[id='ecomp-raw']/username/text()" "$SETTINGS_FILE")
8PASS=$(xpath -q -e "//servers/server[id='ecomp-raw']/password/text()" "$SETTINGS_FILE")
9OPENECOMP_NEXUS_REPO="${NEXUSPROXY}/content/sites/raw"
10
11#Create a netrc file for use with curl
12NETRC=$(mktemp)
13echo "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
17echo "NETRC=$NETRC" > "$WORKSPACE/netrc_env.txt"
18
19STAGE_DIR=${WORKSPACE}/package
20OUTPUT_DIR=${WORKSPACE}/package/output
21
22DATE_STAMP="$(date +"%Y%m%d%H%M%S")"
23PACKAGE_BUILD_NUMBER=${DATE_STAMP}
24PACKAGE_NAME_APPLICATION=$( \
25 cat ${WORKSPACE}/dcae-apod-buildtools/configs/package-cdap3vm.json | \
26 python -c 'import json,sys;print json.load(sys.stdin)["applicationName"]')
27PACKAGE_NAME_VERSION=$( \
28 cat ${WORKSPACE}/dcae-apod-buildtools/configs/package-cdap3vm.json | \
29 python -c 'import json,sys;print json.load(sys.stdin)["version"]')
30PACKAGE_GROUP_ID=$( \
31 cat ${WORKSPACE}/dcae-apod-buildtools/configs/package-cdap3vm.json | \
32 python -c 'import json,sys;print json.load(sys.stdin)["groupId"]')
33OUTPUT_FILE="${PACKAGE_NAME_APPLICATION}_${PACKAGE_NAME_VERSION}.deb"
Lisa Reveldae96392017-02-17 16:29:33 +000034OUTPUT_FILE_DATE_STAMPED="${PACKAGE_NAME_APPLICATION}_${PACKAGE_NAME_VERSION}-${DATE_STAMP}.deb"
Lisa Revel22a0a332017-02-16 20:14:52 +000035
Lisa Revel409c7362017-02-17 00:31:49 +000036echo 'Package variables:'
Lisa Reveldae96392017-02-17 16:29:33 +000037echo " STAGE_DIR = ${STAGE_DIR}"
Lisa Revel409c7362017-02-17 00:31:49 +000038echo " OUTPUT_DIR = ${OUTPUT_DIR}"
39echo " PACKAGE_BUILD_NUMBER = ${PACKAGE_BUILD_NUMBER}"
40echo " PACKAGE_NAME_APPLICATION = ${PACKAGE_NAME_APPLICATION}"
41echo " PACKAGE_NAME_VERSION = ${PACKAGE_NAME_VERSION}"
42echo " PACKAGE_GROUP_ID = ${PACKAGE_GROUP_ID}"
43echo " OUTPUT_FILE = ${OUTPUT_FILE}"
44echo " OUTPUT_FILE_DATE_STAMPED = ${OUTPUT_FILE_DATE_STAMPED}"
Lisa Revel22a0a332017-02-16 20:14:52 +000045
Lisa Revel409c7362017-02-17 00:31:49 +000046echo 'Creating Staging and Output directories'
Lisa Revel22a0a332017-02-16 20:14:52 +000047rm -rf ${STAGE_DIR}
48rm -rf ${OUTPUT_DIR}
49mkdir -p ${STAGE_DIR}/stage/opt/app/dcae-cdap-small-hadoop
50mkdir -p ${OUTPUT_DIR}
51
52echo 'Copying files to stage'
53cp -R ${WORKSPACE}/cdap3vm/* ${STAGE_DIR}/stage/opt/app/dcae-cdap-small-hadoop
54
55echo 'Copying json file to stage'
56cp ${WORKSPACE}/dcae-apod-buildtools/configs/package-cdap3vm.json ${STAGE_DIR}/package.json
57
Lisa Revel409c7362017-02-17 00:31:49 +000058echo 'Contents of stage directory'
59ls -lR ${STAGE_DIR}
60
Lisa Revel22a0a332017-02-16 20:14:52 +000061echo "Creating debian package"
62${WORKSPACE}/dcae-apod-buildtools/scripts/package -b debian -d ${STAGE_DIR} \
63 -o ${OUTPUT_DIR} -y package.json -B ${PACKAGE_BUILD_NUMBER} -v
64
Lisa Revel22a0a332017-02-16 20:14:52 +000065# The controller needs the debian packaged named
66# dcae-cdap-small-hadoop_17.01.0-LATEST.deb so it can find and deploy it.
67# In order to have a copy of each file built a copy of
68# dcae-cdap-small-hadoop_17.01.0-LATEST.deb will be made and it will have a
69# date stamp and build number on it.
70# For example: dcae-cda-small-hadoop_17.01.0-YYYYMMDDHHMMSS-XXX.deb
71# Both files will then be uploaded to the repository.
72
73cp ${OUTPUT_DIR}/${OUTPUT_FILE_DATE_STAMPED} ${OUTPUT_DIR}/${OUTPUT_FILE}
74
Lisa Reveldae96392017-02-17 16:29:33 +000075echo "Contents of output directory"
76ls -lR ${OUTPUT_DIR}
77
78SEND_TO="${OPENECOMP_NEXUS_REPO}/org.openecomp.dcae.apod.cdap/deb-snapshots/${PACKAGE_GROUP_ID}/${OUTPUT_FILE}"
Lisa Revel409c7362017-02-17 00:31:49 +000079echo "Sending ${OUTPUT_DIR}/${OUTPUT_FILE} to Nexus Repo: ${SEND_TO}"
Lisa Revel22a0a332017-02-16 20:14:52 +000080curl -vkn --netrc-file "${NETRC}" --upload-file ${OUTPUT_DIR}/${OUTPUT_FILE} ${SEND_TO}
81
Lisa Reveldae96392017-02-17 16:29:33 +000082SEND_TO="${OPENECOMP_NEXUS_REPO}/org.openecomp.dcae.apod.cdap/deb-snapshots/${PACKAGE_GROUP_ID}/${OUTPUT_FILE_DATE_STAMPED}"
Lisa Revel409c7362017-02-17 00:31:49 +000083
84echo "Sending ${OUTPUT_DIR}/${OUTPUT_FILE_DATE_STAMPED} to Nexus Repo: ${SEND_TO}"
Lisa Revel22a0a332017-02-16 20:14:52 +000085curl -vkn --netrc-file "${NETRC}" --upload-file ${OUTPUT_DIR}/${OUTPUT_FILE_DATE_STAMPED} ${SEND_TO}
86
87echo '===================== ENDING SCRIPT TO CREATE DEBIAN FILE ======================='