blob: aa3f6379d2cd656088c20894f2921423cf3956f7 [file] [log] [blame]
Lusheng Ji88648fc2017-09-20 02:18:20 +00001#!/bin/bash
2
3# ================================================================================
Lusheng Ji7ed33762018-03-05 08:10:18 -05004# Copyright (c) 2017-2018 AT&T Intellectual Property. All rights reserved.
Lusheng Ji88648fc2017-09-20 02:18:20 +00005# ================================================================================
6# Licensed under the Apache License, Version 2.0 (the "License");
7# you may not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17# ============LICENSE_END=========================================================
Lusheng Ji88648fc2017-09-20 02:18:20 +000018
19
20#MVN_PROJECT_MODULEID="$1"
21#MVN_PHASE="$2"
22#PROJECT_ROOT=$(dirname $0)
23
24FQDN="${MVN_PROJECT_GROUPID}.${MVN_PROJECT_ARTIFACTID}"
25if [ "$MVN_PROJECT_MODULEID" == "__" ]; then
26 MVN_PROJECT_MODULEID=""
27fi
28
29if [[ "$MVN_PROJECT_VERSION" == *SNAPSHOT ]]; then
30 echo "=> for SNAPSHOT artifact build"
31 MVN_DEPLOYMENT_TYPE='SNAPSHOT'
32else
33 echo "=> for STAGING/RELEASE artifact build"
34 MVN_DEPLOYMENT_TYPE='STAGING'
35fi
36echo "MVN_DEPLOYMENT_TYPE is [$MVN_DEPLOYMENT_TYPE]"
37
38
39TIMESTAMP=$(date +%C%y%m%dT%H%M%S)
40
41# expected environment variables
42if [ -z "${MVN_NEXUSPROXY}" ]; then
43 echo "MVN_NEXUSPROXY environment variable not set. Cannot proceed"
44 exit
45fi
46MVN_NEXUSPROXY_HOST=$(echo "$MVN_NEXUSPROXY" |cut -f3 -d'/' | cut -f1 -d':')
47echo "=> Nexus Proxy at $MVN_NEXUSPROXY_HOST, $MVN_NEXUSPROXY"
48
49if [ -z "$WORKSPACE" ]; then
50 WORKSPACE=$(pwd)
51fi
52
Andrew Gauld373f0f32018-02-21 11:14:46 -050053export SETTINGS_FILE=${SETTINGS_FILE:-$HOME/.m2/settings.xml}
Lusheng Ji88648fc2017-09-20 02:18:20 +000054
Lusheng Ji5a3dbbb2018-03-14 22:44:45 -040055RELEASE_TAG=${MVN_RELEASE_TAG:-R2}
56if [ "$RELEASE_TAG" == "R1" ]; then
57 unset RELEASE_TAG
58fi
Lusheng Ji88648fc2017-09-20 02:18:20 +000059
60
61# mvn phase in life cycle
62MVN_PHASE="$2"
63
Lusheng Ji5a3dbbb2018-03-14 22:44:45 -040064echo "MVN_RELEASE_TAG is [$MVN_RELEASE_TAG]"
Lusheng Ji88648fc2017-09-20 02:18:20 +000065echo "MVN_PROJECT_MODULEID is [$MVN_PROJECT_MODULEID]"
66echo "MVN_PHASE is [$MVN_PHASE]"
67echo "MVN_PROJECT_GROUPID is [$MVN_PROJECT_GROUPID]"
68echo "MVN_PROJECT_ARTIFACTID is [$MVN_PROJECT_ARTIFACTID]"
69echo "MVN_PROJECT_VERSION is [$MVN_PROJECT_VERSION]"
70echo "MVN_NEXUSPROXY is [$MVN_NEXUSPROXY]"
71echo "MVN_RAWREPO_BASEURL_UPLOAD is [$MVN_RAWREPO_BASEURL_UPLOAD]"
72echo "MVN_RAWREPO_BASEURL_DOWNLOAD is [$MVN_RAWREPO_BASEURL_DOWNLOAD]"
73MVN_RAWREPO_HOST=$(echo "$MVN_RAWREPO_BASEURL_UPLOAD" | cut -f3 -d'/' |cut -f1 -d':')
74echo "MVN_RAWREPO_HOST is [$MVN_RAWREPO_HOST]"
75echo "MVN_RAWREPO_SERVERID is [$MVN_RAWREPO_SERVERID]"
Lusheng Ji00444ab2017-10-13 17:39:45 +000076echo "MVN_DOCKERREGISTRY_SNAPSHOT is [$MVN_DOCKERREGISTRY_SNAPSHOT]"
77echo "MVN_DOCKERREGISTRY_PUBLIC is [$MVN_DOCKERREGISTRY_PUBLIC]"
Lusheng Ji88648fc2017-09-20 02:18:20 +000078echo "MVN_DOCKERREGISTRY_RELEASE is [$MVN_DOCKERREGISTRY_RELEASE]"
Lusheng Ji88648fc2017-09-20 02:18:20 +000079echo "MVN_PYPISERVER_SERVERID [$MVN_PYPISERVER_SERVERID]"
80echo "MVN_PYPISERVER_BASEURL is [$MVN_PYPISERVER_BASEURL]"
81
82
83
84clean_templated_files()
85{
86 TEMPLATE_FILES=$(find . -name "*-template")
87 for F in $TEMPLATE_FILES; do
88 F2=$(echo "$F" | sed 's/-template$//')
89 rm -f "$F2"
90 done
91}
92clean_tox_files()
93{
94 TOX_FILES=$(find . -name ".tox")
95 TOX_FILES="$TOX_FILES $(find . -name 'venv-tox')"
96 for F in $TOX_FILES; do
97 rm -rf "$F"
98 done
99}
100
101expand_templates()
102{
Lusheng Ji00444ab2017-10-13 17:39:45 +0000103 set +x
Lusheng Ji88648fc2017-09-20 02:18:20 +0000104 # set up env variables, get ready for template resolution
105 # NOTE: CCSDK artifacts do not distinguish REALESE vs SNAPSHOTs
106 export ONAPTEMPLATE_RAWREPOURL_org_onap_ccsdk_platform_plugins_releases="$MVN_RAWREPO_BASEURL_DOWNLOAD/org.onap.ccsdk.platform.plugins"
107 export ONAPTEMPLATE_RAWREPOURL_org_onap_ccsdk_platform_plugins_snapshots="$MVN_RAWREPO_BASEURL_DOWNLOAD/org.onap.ccsdk.platform.plugins"
108 export ONAPTEMPLATE_RAWREPOURL_org_onap_ccsdk_platform_blueprints_releases="$MVN_RAWREPO_BASEURL_DOWNLOAD/org.onap.ccsdk.platform.blueprints"
109 export ONAPTEMPLATE_RAWREPOURL_org_onap_ccsdk_platform_blueprints_snapshots="$MVN_RAWREPO_BASEURL_DOWNLOAD/org.onap.ccsdk.platform.blueprints"
Lusheng Ji5a3dbbb2018-03-14 22:44:45 -0400110
111
112 if [ -z "$RELEASE_TAG" ]; then
113 export ONAPTEMPLATE_RAWREPOURL_org_onap_dcaegen2_releases="$MVN_RAWREPO_BASEURL_DOWNLOAD/org.onap.dcaegen2/releases"
114 export ONAPTEMPLATE_RAWREPOURL_org_onap_dcaegen2_snapshots="$MVN_RAWREPO_BASEURL_DOWNLOAD/org.onap.dcaegen2/snapshots"
115 export ONAPTEMPLATE_RAWREPOURL_org_onap_dcaegen2_platform_plugins_releases="$MVN_RAWREPO_BASEURL_DOWNLOAD/org.onap.dcaegen2.platform.plugins/releases"
116 export ONAPTEMPLATE_RAWREPOURL_org_onap_dcaegen2_platform_plugins_snapshots="$MVN_RAWREPO_BASEURL_DOWNLOAD/org.onap.dcaegen2.platform.plugins/snapshots"
117 export ONAPTEMPLATE_RAWREPOURL_org_onap_dcaegen2_platform_blueprints_releases="$MVN_RAWREPO_BASEURL_DOWNLOAD/org.onap.dcaegen2.platform.blueprints/releases"
118 export ONAPTEMPLATE_RAWREPOURL_org_onap_dcaegen2_platform_blueprints_snapshots="$MVN_RAWREPO_BASEURL_DOWNLOAD/org.onap.dcaegen2.platform.blueprints/snapshots"
119 else
120 export ONAPTEMPLATE_RAWREPOURL_org_onap_dcaegen2_releases="$MVN_RAWREPO_BASEURL_DOWNLOAD/org.onap.dcaegen2/$RELEASE_TAG"
121 export ONAPTEMPLATE_RAWREPOURL_org_onap_dcaegen2_snapshots="$MVN_RAWREPO_BASEURL_DOWNLOAD/org.onap.dcaegen2/$RELEASE_TAG"
122 export ONAPTEMPLATE_RAWREPOURL_org_onap_dcaegen2_platform_plugins_releases="$MVN_RAWREPO_BASEURL_DOWNLOAD/org.onap.dcaegen2.platform.plugins/$RELEASE_TAG"
123 export ONAPTEMPLATE_RAWREPOURL_org_onap_dcaegen2_platform_plugins_snapshots="$MVN_RAWREPO_BASEURL_DOWNLOAD/org.onap.dcaegen2.platform.plugins/$RELEASE_TAG"
124 export ONAPTEMPLATE_RAWREPOURL_org_onap_dcaegen2_platform_blueprints_releases="$MVN_RAWREPO_BASEURL_DOWNLOAD/org.onap.dcaegen2.platform.blueprints/$RELEASE_TAG"
125 export ONAPTEMPLATE_RAWREPOURL_org_onap_dcaegen2_platform_blueprints_snapshots="$MVN_RAWREPO_BASEURL_DOWNLOAD/org.onap.dcaegen2.platform.blueprints/$RELEASE_TAG"
126 fi
127
Lusheng Ji88648fc2017-09-20 02:18:20 +0000128
Lusheng Ji00444ab2017-10-13 17:39:45 +0000129 export ONAPTEMPLATE_PYPIURL_org_onap_dcaegen2="${MVN_PYPISERVER_BASEURL}"
Lusheng Ji88648fc2017-09-20 02:18:20 +0000130
Lusheng Ji00444ab2017-10-13 17:39:45 +0000131 # docker registry templates are for poll, so use PUBLIC registry
Lusheng Ji5a3dbbb2018-03-14 22:44:45 -0400132 export ONAPTEMPLATE_DOCKERREGURL_org_onap_dcaegen2_releases="${MVN_DOCKERREGISTRY_PUBLIC}"
133 export ONAPTEMPLATE_DOCKERREGURL_org_onap_dcaegen2_snapshots="${MVN_DOCKERREGISTRY_PUBLIC}"
Lusheng Ji88648fc2017-09-20 02:18:20 +0000134
Lusheng Ji00444ab2017-10-13 17:39:45 +0000135 # Mvn repo
136 export ONAPTEMPLATE_MVN_org_onap_dcaegen2_analytics_tca_snapshots="${MVN_NEXUSPROXY}/service/local/repositories/snapshots/content/org/onap/dcaegen2/analytics/tca"
137 export ONAPTEMPLATE_MVN_org_onap_dcaegen2_analytics_tca_staging="${MVN_NEXUSPROXY}/service/local/repositories/staging/content/org/onap/dcaegen2/analytics/tca"
138 export ONAPTEMPLATE_MVN_org_onap_dcaegen2_analytics_tca_releases="${MVN_NEXUSPROXY}/service/local/repositories/releases/content/org/onap/dcaegen2/analytics/tca"
139
140
141 export ONAPTEMPLATE_STANDARD_INPUTS_TYPES=" # standard inputs list
142 centos7image_id:
143 type: string
144 ubuntu1604image_id:
145 type: string
146 flavor_id:
147 type: string
148 security_group:
149 type: string
150 public_net:
151 type: string
152 private_net:
153 type: string
154 openstack: {}
155 keypair:
156 type: string
157 key_filename:
158 type: string
159 location_prefix:
160 type: string
161 location_domain:
162 type: string
163 codesource_url:
164 type: string
165 codesource_version:
166 type: string"
167
168
169 TEMPLATES=$(env |grep ONAPTEMPLATE | sed 's/=.*//' | sort -u)
170 if [ -z "$TEMPLATES" ]; then
171 echo "No template variables found!"
172 return 0
173 fi
Lusheng Ji88648fc2017-09-20 02:18:20 +0000174
175 TEMPLATE_FILES=$(find . -name "*-template")
176 for F in $TEMPLATE_FILES; do
177 F2=$(echo "$F" | sed 's/-template$//')
Lusheng Ji00444ab2017-10-13 17:39:45 +0000178 cp -p "$F" "$F2"
179 chmod u+w "$F2"
Lusheng Ji88648fc2017-09-20 02:18:20 +0000180
Lusheng Ji00444ab2017-10-13 17:39:45 +0000181 echo "====> Resolving the following template from environment variables "
182 echo "$TEMPLATES"
183 for KEY in $TEMPLATES; do
184 VALUE1=$(eval 'echo "$"'"$KEY"'"' | sed 1q)
185 VALUE2=$(eval 'echo "$'"$KEY"'"' | sed -e 's/\//\\\//g' -e 's/$/\\/' -e '$s/\\$//')
Lusheng Ji88648fc2017-09-20 02:18:20 +0000186
Lusheng Ji00444ab2017-10-13 17:39:45 +0000187 echo "======> Resolving template $KEY to value $VALUE1 for file $F2"
188 sed -i "s/{{[[:space:]]*$KEY[[:space:]]*}}/$VALUE2/g" "$F2"
189 done
190 done
191 echo "====> Done template resolving"
192}
Lusheng Ji88648fc2017-09-20 02:18:20 +0000193
Lusheng Ji00444ab2017-10-13 17:39:45 +0000194test_templates()
195{
196 # make certain that the type references exist
197 TMP=$(mktemp)
198 trap 'rm -f $TMP' 0 1 2 3 15
Lusheng Ji88648fc2017-09-20 02:18:20 +0000199
Lusheng Ji00444ab2017-10-13 17:39:45 +0000200 echo Verify that all of the import URLs are correct
201 find . -name '*-template' | sed -e 's/-template$//' |
202 while read file
203 do
Lusheng Ji5a3dbbb2018-03-14 22:44:45 -0400204 egrep '^ - .?https?://' < "$file"
Lusheng Ji00444ab2017-10-13 17:39:45 +0000205 done | awk '{print $2}' | sed -e 's/"//g' | sort -u |
206 while read url
207 do
Lusheng Ji5a3dbbb2018-03-14 22:44:45 -0400208 curl -L -w '%{http_code}' -s -o /dev/null "$url" > "$TMP"
209 case $(< "$TMP") in
Lusheng Ji00444ab2017-10-13 17:39:45 +0000210 2* ) ;;
211 * ) echo ">>>>>>>>>>>>>>>> $url not found <<<<<<<<<<<<<<<<" ;;
212 esac
Lusheng Ji88648fc2017-09-20 02:18:20 +0000213 done
214
Lusheng Ji00444ab2017-10-13 17:39:45 +0000215 echo Verify that the inputs are correct
216 PATH=$PATH:$PWD/check-blueprint-vs-input/bin
217 find . -name '*-template' | sed -e 's/-template$//' |
218 while read blueprint
219 do
Lusheng Ji5a3dbbb2018-03-14 22:44:45 -0400220 check-blueprint-vs-input -b "$blueprint" -i check-blueprint-vs-input/lib/sample-inputs.yaml || true
Lusheng Ji00444ab2017-10-13 17:39:45 +0000221 done
Lusheng Ji88648fc2017-09-20 02:18:20 +0000222}
223
224
225run_tox_test()
226{
Andrew Gauld373f0f32018-02-21 11:14:46 -0500227 set -e -x
Lusheng Ji88648fc2017-09-20 02:18:20 +0000228 CURDIR=$(pwd)
229 TOXINIS=$(find . -name "tox.ini")
230 for TOXINI in "${TOXINIS[@]}"; do
231 DIR=$(echo "$TOXINI" | rev | cut -f2- -d'/' | rev)
232 cd "${CURDIR}/${DIR}"
233 rm -rf ./venv-tox ./.tox
234 virtualenv ./venv-tox
235 source ./venv-tox/bin/activate
236 pip install --upgrade pip
237 pip install --upgrade tox argparse
238 pip freeze
239 tox
240 deactivate
241 rm -rf ./venv-tox ./.tox
242 done
243}
244
245build_wagons()
246{
247 rm -rf ./*.wgn venv-pkg
Lusheng Ji88648fc2017-09-20 02:18:20 +0000248 SETUPFILES=$(find . -name "setup.py")
Lusheng Ji00444ab2017-10-13 17:39:45 +0000249
250 virtualenv ./venv-pkg
251 source ./venv-pkg/bin/activate
252 pip install --upgrade pip
253 pip install wagon
254
255 CURDIR=$(pwd)
Lusheng Ji88648fc2017-09-20 02:18:20 +0000256 for SETUPFILE in $SETUPFILES; do
Lusheng Ji00444ab2017-10-13 17:39:45 +0000257 PLUGIN_DIR=$(dirname "$SETUPFILE")
Lusheng Ji88648fc2017-09-20 02:18:20 +0000258 PLUGIN_NAME=$(grep 'name' "$SETUPFILE" | cut -f2 -d'=' | sed 's/[^0-9a-zA-Z\.]*//g')
259 PLUGIN_VERSION=$(grep 'version' "$SETUPFILE" | cut -f2 -d'=' | sed 's/[^0-9\.]*//g')
260
Lusheng Ji00444ab2017-10-13 17:39:45 +0000261 echo "In $PLUGIN_DIR, build plugin $PLUGIN_NAME, version $PLUGIN_VERSION"
Lusheng Ji88648fc2017-09-20 02:18:20 +0000262
Lusheng Ji7ed33762018-03-05 08:10:18 -0500263 wagon create -r "${PLUGIN_DIR}/requirements.txt" --format tar.gz "${PLUGIN_DIR}"
Lusheng Ji88648fc2017-09-20 02:18:20 +0000264
265 PKG_FILE_NAMES=( "${PLUGIN_NAME}-${PLUGIN_VERSION}"*.wgn )
266 echo Built package: "${PKG_FILE_NAMES[@]}"
Lusheng Ji5a3dbbb2018-03-14 22:44:45 -0400267 cd "$CURDIR"
Lusheng Ji88648fc2017-09-20 02:18:20 +0000268 done
Lusheng Ji00444ab2017-10-13 17:39:45 +0000269
270 deactivate
271 rm -rf venv-pkg
Lusheng Ji88648fc2017-09-20 02:18:20 +0000272}
273
Lusheng Jia1e83322018-03-18 22:23:18 -0400274build_archives_for_wagons()
275{
Lusheng Jia3361d32018-03-19 13:40:31 -0400276 rm -rf ./*.tgz ./*.zip venv-pkg
Lusheng Jia1e83322018-03-18 22:23:18 -0400277
Lusheng Ji0ce89252018-03-20 10:12:41 -0400278 SETUPFILES=$(find "$(pwd)" -name "setup.py")
Lusheng Jia1e83322018-03-18 22:23:18 -0400279 CURDIR=$(pwd)
280 for SETUPFILE in $SETUPFILES; do
Lusheng Jib99b3c82018-03-19 22:38:58 -0400281 PLUGIN_FULL_DIR=$(dirname "$SETUPFILE")
Lusheng Ji0ce89252018-03-20 10:12:41 -0400282 PLUGIN_BASE_DIR=$(basename "$PLUGIN_FULL_DIR")
Lusheng Jia1e83322018-03-18 22:23:18 -0400283 PLUGIN_NAME=$(grep 'name' "$SETUPFILE" | cut -f2 -d'=' | sed 's/[^0-9a-zA-Z\.]*//g')
284 PLUGIN_VERSION=$(grep 'version' "$SETUPFILE" | cut -f2 -d'=' | sed 's/[^0-9\.]*//g')
285
Lusheng Ji0ce89252018-03-20 10:12:41 -0400286 cd "${PLUGIN_FULL_DIR}"/..
Lusheng Jia1e83322018-03-18 22:23:18 -0400287 echo "In $(pwd), build plugin zip $PLUGIN_NAME, version $PLUGIN_VERSION"
288
Lusheng Ji32433a52018-03-20 08:55:50 -0400289 zip -r "${PLUGIN_NAME}-${PLUGIN_VERSION}.zip" "./${PLUGIN_BASE_DIR}"
Lusheng Jib99b3c82018-03-19 22:38:58 -0400290 tar -czvf "${PLUGIN_NAME}-${PLUGIN_VERSION}.tgz" "./${PLUGIN_BASE_DIR}"
Lusheng Jia1e83322018-03-18 22:23:18 -0400291
Lusheng Jib99b3c82018-03-19 22:38:58 -0400292 echo "Built archives for package ${PLUGIN_NAME}-${PLUGIN_VERSION} at $(pwd)"
Lusheng Jia1e83322018-03-18 22:23:18 -0400293 cd "$CURDIR"
294 done
Lusheng Jia1e83322018-03-18 22:23:18 -0400295}
296
Lusheng Ji88648fc2017-09-20 02:18:20 +0000297
298upload_raw_file()
299{
300 # Extract the username and password to the nexus repo from the settings file
301 USER=$(xpath -q -e "//servers/server[id='$MVN_RAWREPO_SERVERID']/username/text()" "$SETTINGS_FILE")
302 PASS=$(xpath -q -e "//servers/server[id='$MVN_RAWREPO_SERVERID']/password/text()" "$SETTINGS_FILE")
303 NETRC=$(mktemp)
304 echo "machine $MVN_RAWREPO_HOST login $USER password $PASS" > "$NETRC"
305
306 REPO="$MVN_RAWREPO_BASEURL_UPLOAD"
307
308 OUTPUT_FILE=$1
309 EXT=$(echo "$OUTPUT_FILE" | rev |cut -f1 -d '.' |rev)
310 if [ "$EXT" == 'yaml' ]; then
311 OUTPUT_FILE_TYPE='text/x-yaml'
312 elif [ "$EXT" == 'sh' ]; then
313 OUTPUT_FILE_TYPE='text/x-shellscript'
314 elif [ "$EXT" == 'gz' ]; then
315 OUTPUT_FILE_TYPE='application/gzip'
Lusheng Jia3361d32018-03-19 13:40:31 -0400316 elif [ "$EXT" == 'tgz' ]; then
317 OUTPUT_FILE_TYPE='application/gzip'
318 elif [ "$EXT" == 'zip' ]; then
319 OUTPUT_FILE_TYPE='application/zip'
Lusheng Ji88648fc2017-09-20 02:18:20 +0000320 elif [ "$EXT" == 'wgn' ]; then
321 OUTPUT_FILE_TYPE='application/gzip'
322 else
323 OUTPUT_FILE_TYPE='application/octet-stream'
324 fi
325
Lusheng Ji00444ab2017-10-13 17:39:45 +0000326 # for multi module projects, the raw repo path must match with project name, not project + module
327 # FQDN is project + module
328 # GROUPID is project name
329 if [ "$MVN_PROJECT_ARTIFACTID" == "$MVN_PROJECT_MODULEID" ]; then
330 PROJECT_NAME=${MVN_PROJECT_GROUPID}
331 else
332 PROJECT_NAME=${FQDN}
333 fi
Lusheng Ji7ed33762018-03-05 08:10:18 -0500334
Lusheng Ji5a3dbbb2018-03-14 22:44:45 -0400335 if [ -z "$RELEASE_TAG" ]; then
336 SEND_TO="${REPO}/${PROJECT_NAME}"
337 else
338 SEND_TO="${REPO}/${PROJECT_NAME}/${RELEASE_TAG}"
339 fi
Lusheng Ji7ed33762018-03-05 08:10:18 -0500340
Lusheng Ji00444ab2017-10-13 17:39:45 +0000341 if [ ! -z "$2" ]; then
342 SEND_TO="$SEND_TO/$2"
Lusheng Jid4c05d02017-09-21 03:22:18 +0000343 fi
Lusheng Ji88648fc2017-09-20 02:18:20 +0000344
345 echo "Sending ${OUTPUT_FILE} to Nexus: ${SEND_TO}"
Lusheng Ji00444ab2017-10-13 17:39:45 +0000346 curl -vkn --netrc-file "${NETRC}" --upload-file "${OUTPUT_FILE}" -X PUT -H "Content-Type: $OUTPUT_FILE_TYPE" "${SEND_TO}/${OUTPUT_FILE}-${TIMESTAMP}"
Lusheng Ji88648fc2017-09-20 02:18:20 +0000347 curl -vkn --netrc-file "${NETRC}" --upload-file "${OUTPUT_FILE}" -X PUT -H "Content-Type: $OUTPUT_FILE_TYPE" "${SEND_TO}/${OUTPUT_FILE}"
348}
349
Lusheng Jia1e83322018-03-18 22:23:18 -0400350upload_wagon_archives()
351{
Lusheng Ji0ce89252018-03-20 10:12:41 -0400352 SETUPFILES=$(find "$(pwd)" -name "setup.py")
Lusheng Jia1e83322018-03-18 22:23:18 -0400353 CURDIR=$(pwd)
354 for SETUPFILE in $SETUPFILES; do
Lusheng Jib99b3c82018-03-19 22:38:58 -0400355 PLUGIN_FULL_DIR=$(dirname "$SETUPFILE")
Lusheng Ji0ce89252018-03-20 10:12:41 -0400356 PLUGIN_BASE_DIR=$(basename "$PLUGIN_FULL_DIR")
Lusheng Jia1e83322018-03-18 22:23:18 -0400357 PLUGIN_NAME=$(grep 'name' "$SETUPFILE" | cut -f2 -d'=' | sed 's/[^0-9a-zA-Z\.]*//g')
358 PLUGIN_VERSION=$(grep 'version' "$SETUPFILE" | cut -f2 -d'=' | sed 's/[^0-9\.]*//g')
Lusheng Ji88648fc2017-09-20 02:18:20 +0000359
Lusheng Ji0ce89252018-03-20 10:12:41 -0400360 cd "${PLUGIN_FULL_DIR}"/..
Lusheng Jia1e83322018-03-18 22:23:18 -0400361 echo "In $(pwd), upload zip archive for $PLUGIN_NAME, version $PLUGIN_VERSION"
362 ARCHIVE_FILE_NAME="${PLUGIN_NAME}-${PLUGIN_VERSION}.zip"
363 if [ -z "$ARCHIVE_FILE_NAME" ]; then
364 echo "!!! No zip archive file found ${ARCHIVE_FILE_NAME}"
365 exit -1
366 fi
367 upload_raw_file "${ARCHIVE_FILE_NAME}" "${PLUGIN_NAME}/${PLUGIN_VERSION}"
368
369 echo "In $(pwd), upload tgz archive for $PLUGIN_NAME, version $PLUGIN_VERSION"
370 ARCHIVE_FILE_NAME="${PLUGIN_NAME}-${PLUGIN_VERSION}.tgz"
371 if [ -z "$ARCHIVE_FILE_NAME" ]; then
372 echo "!!! No tgz archive file found ${ARCHIVE_FILE_NAME}"
373 exit -1
374 fi
375 upload_raw_file "${ARCHIVE_FILE_NAME}" "${PLUGIN_NAME}/${PLUGIN_VERSION}"
376
Lusheng Ji0ce89252018-03-20 10:12:41 -0400377 cd "${CURDIR}"
Lusheng Jia1e83322018-03-18 22:23:18 -0400378 done
379}
Lusheng Ji88648fc2017-09-20 02:18:20 +0000380
381upload_wagons_and_type_yamls()
382{
Lusheng Ji00444ab2017-10-13 17:39:45 +0000383 SETUPFILES=$(find . -name "setup.py")
384
385 CURDIR=$(pwd)
386 for SETUPFILE in $SETUPFILES; do
387 PLUGIN_DIR=$(dirname "$SETUPFILE")
388 PLUGIN_NAME=$(grep 'name' "$SETUPFILE" | cut -f2 -d'=' | sed 's/[^0-9a-zA-Z\.]*//g')
389 PLUGIN_VERSION=$(grep 'version' "$SETUPFILE" | cut -f2 -d'=' | sed 's/[^0-9\.]*//g')
390 PLUGIN_VERSION_MAJOR=$(echo "$PLUGIN_VERSION" | cut -f1 -d'.')
391 PLUGIN_VERSION_MAJOR_MINOR=$(echo "$PLUGIN_VERSION" | cut -f1-2 -d'.')
392
393 echo "Found setup file in $PLUGIN_DIR, for plugin $PLUGIN_NAME version $PLUGIN_VERSION"
394
395 TYPEFILE_NAME=$(grep -R "package_name:[[:space:]]*${PLUGIN_NAME}" | cut -f1 -d ':')
396 if [ -z "$TYPEFILE_NAME" ]; then
397 echo "!!! No typefile found with matching package name $PLUGIN_NAME"
398 exit -1
399 fi
400 NEWFILENAME="${PLUGIN_NAME}"_types.yaml
401 if [ "$TYPEFILE_NAME" != "$NEWFILENAME" ]; then
402 echo "copy typefile to standard naming"
403 cp -f "$TYPEFILE_NAME" "$NEWFILENAME"
404 fi
405
Lusheng Ji5a3dbbb2018-03-14 22:44:45 -0400406 TYPEFILE_PACKAGE_VERSION=$(grep -R 'package_version' "$TYPEFILE_NAME" |cut -f2 -d ':' |sed -r 's/\s+//g')
407 WAGONFILE_NAME=$(ls -1 "${PLUGIN_NAME}"-"${TYPEFILE_PACKAGE_VERSION}"-*.wgn)
Lusheng Ji00444ab2017-10-13 17:39:45 +0000408 if [ -z "$WAGONFILE_NAME" ]; then
409 echo "!!! No wagonfile found with matching package name and version as required in typefile: "
410 echo " $TYPEFILE_NAME plugin $PLUGIN_NAME package version ${TYPEFILE_PACKAGE_VERSION}"
411 exit -1
412 fi
413
Lusheng Ji7ed33762018-03-05 08:10:18 -0500414 upload_raw_file "${NEWFILENAME}" "${PLUGIN_NAME}/${PLUGIN_VERSION}"
415 upload_raw_file "${WAGONFILE_NAME}" "${PLUGIN_NAME}/${PLUGIN_VERSION}"
Lusheng Ji88648fc2017-09-20 02:18:20 +0000416
Lusheng Ji5a3dbbb2018-03-14 22:44:45 -0400417 rm -r "$WAGONFILE_NAME"
Lusheng Ji00444ab2017-10-13 17:39:45 +0000418 if [ "$TYPEFILE_NAME" != "$NEWFILENAME" ]; then
419 rm -f "$NEWFILENAME"
420 fi
Lusheng Ji88648fc2017-09-20 02:18:20 +0000421 done
422}
423
424upload_files_of_extension()
425{
426 FILES=$(ls -1 ./*."$1")
427 for F in $FILES ; do
Lusheng Ji00444ab2017-10-13 17:39:45 +0000428 upload_raw_file "$F" "$2"
Lusheng Ji88648fc2017-09-20 02:18:20 +0000429 done
430}
431
432
433generate_pypirc_then_publish()
434{
435 set +x
436 USER=$(xpath -e "//servers/server[id='$MVN_PYPISERVER_SERVERID']/username/text()" "$SETTINGS_FILE")
437 PASS=$(xpath -e "//servers/server[id='$MVN_PYPISERVER_SERVERID']/password/text()" "$SETTINGS_FILE")
438
439 if [[ "$MVN_PYPISERVER_BASEURL" != */ ]]; then
440 MVN_PYPISERVER_BASEURL="${MVN_PYPISERVER_BASEURL}/"
441 fi
442
443
444 cat > ~/.pypirc <<EOL
445[distutils]
446index-servers =
447 $MVN_PYPISERVER_SERVERID
448
449[$MVN_PYPISERVER_SERVERID]
450repository: $MVN_PYPISERVER_BASEURL
451username: $USER
452password: $PASS
453EOL
454
455 # this may fail if a package of same version exists
456 python setup.py sdist register -r "$MVN_PYPISERVER_SERVERID" upload -r "$MVN_PYPISERVER_SERVERID"
457 set -x
458}
459
460
461
Lusheng Ji5a3dbbb2018-03-14 22:44:45 -0400462# following the https://wiki.onap.org/display/DW/Independent+Versioning+and+Release+Process
463#IndependentVersioningandReleaseProcess-StandardizedDockerTagging
Lusheng Ji88648fc2017-09-20 02:18:20 +0000464build_and_push_docker()
465{
466 IMAGENAME="onap/${FQDN}.${MVN_PROJECT_MODULEID}"
467 IMAGENAME=$(echo "$IMAGENAME" | sed -e 's/_*$//g' -e 's/\.*$//g')
468 IMAGENAME=$(echo "$IMAGENAME" | tr '[:upper:]' '[:lower:]')
469
470 # use the major and minor version of the MVN artifact version as docker image version
471 VERSION="${MVN_PROJECT_VERSION//[^0-9.]/}"
472 VERSION2=$(echo "$VERSION" | cut -f1-2 -d'.')
473
474 LFQI="${IMAGENAME}:${VERSION}-${TIMESTAMP}"
475 # build a docker image
476 docker build --rm -f ./Dockerfile -t "${LFQI}" ./
477
Lusheng Ji5a3dbbb2018-03-14 22:44:45 -0400478 # all local builds push to SNAPSHOT repo
Lusheng Ji88648fc2017-09-20 02:18:20 +0000479 REPO=""
480 if [ $MVN_DEPLOYMENT_TYPE == "SNAPSHOT" ]; then
Lusheng Ji5a3dbbb2018-03-14 22:44:45 -0400481 REPO=$MVN_DOCKERREGISTRY_SNAPSHOT
Lusheng Ji88648fc2017-09-20 02:18:20 +0000482 elif [ $MVN_DEPLOYMENT_TYPE == "STAGING" ]; then
Lusheng Ji5a3dbbb2018-03-14 22:44:45 -0400483 REPO=$MVN_DOCKERREGISTRY_SNAPSHOT
Lusheng Ji88648fc2017-09-20 02:18:20 +0000484 else
485 echo "Fail to determine DEPLOYMENT_TYPE"
Lusheng Ji00444ab2017-10-13 17:39:45 +0000486 REPO=$MVN_DOCKERREGISTRY_SNAPSHOT
Lusheng Ji88648fc2017-09-20 02:18:20 +0000487 fi
488 echo "DEPLOYMENT_TYPE is: $MVN_DEPLOYMENT_TYPE, repo is $REPO"
489
490 if [ ! -z "$REPO" ]; then
491 USER=$(xpath -e "//servers/server[id='$REPO']/username/text()" "$SETTINGS_FILE")
492 PASS=$(xpath -e "//servers/server[id='$REPO']/password/text()" "$SETTINGS_FILE")
493 if [ -z "$USER" ]; then
494 echo "Error: no user provided"
495 fi
496 if [ -z "$PASS" ]; then
497 echo "Error: no password provided"
498 fi
499 [ -z "$PASS" ] && PASS_PROVIDED="<empty>" || PASS_PROVIDED="<password>"
500 echo docker login "$REPO" -u "$USER" -p "$PASS_PROVIDED"
501 docker login "$REPO" -u "$USER" -p "$PASS"
502
Lusheng Ji5a3dbbb2018-03-14 22:44:45 -0400503 # local tag is imagename:version-timestamp
Lusheng Ji88648fc2017-09-20 02:18:20 +0000504 OLDTAG="${LFQI}"
Lusheng Ji5a3dbbb2018-03-14 22:44:45 -0400505 #PUSHTAGS="${REPO}/${IMAGENAME}:${VERSION2}-${TIMESTAMP} ${REPO}/${IMAGENAME}:${VERSION2} ${REPO}/${IMAGENAME}:${VERSION2}-latest"
506 # four tags are pushed:
507 # imagename:symver-timestamp,
508 # imagename:semver, imagename:symver-snapshot : latest of current version
509 # imagename:latest: latest of all, used mainly by csit
510 PUSHTAGS="${REPO}/${LFQI} ${REPO}/${IMAGENAME}:${VERSION} ${REPO}/${IMAGENAME}:${VERSION}-snapshot ${REPO}/${IMAGENAME}:latest"
Lusheng Ji88648fc2017-09-20 02:18:20 +0000511 for NEWTAG in ${PUSHTAGS}
512 do
513 echo "tagging ${OLDTAG} to ${NEWTAG}"
514 docker tag "${OLDTAG}" "${NEWTAG}"
515 echo "pushing ${NEWTAG}"
516 docker push "${NEWTAG}"
517 OLDTAG="${NEWTAG}"
518 done
519 fi
Lusheng Ji88648fc2017-09-20 02:18:20 +0000520}