blob: ac755e0310428084311228b37abc57cb5b91e85c [file] [log] [blame]
Lusheng Ji88648fc2017-09-20 02:18:20 +00001#!/bin/bash
2
3# ================================================================================
4# Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
5# ================================================================================
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=========================================================
18#
19# ECOMP is a trademark and service mark of AT&T Intellectual Property.
20
21
22#MVN_PROJECT_MODULEID="$1"
23#MVN_PHASE="$2"
24#PROJECT_ROOT=$(dirname $0)
25
26FQDN="${MVN_PROJECT_GROUPID}.${MVN_PROJECT_ARTIFACTID}"
27if [ "$MVN_PROJECT_MODULEID" == "__" ]; then
28 MVN_PROJECT_MODULEID=""
29fi
30
31if [[ "$MVN_PROJECT_VERSION" == *SNAPSHOT ]]; then
32 echo "=> for SNAPSHOT artifact build"
33 MVN_DEPLOYMENT_TYPE='SNAPSHOT'
34else
35 echo "=> for STAGING/RELEASE artifact build"
36 MVN_DEPLOYMENT_TYPE='STAGING'
37fi
38echo "MVN_DEPLOYMENT_TYPE is [$MVN_DEPLOYMENT_TYPE]"
39
40
41TIMESTAMP=$(date +%C%y%m%dT%H%M%S)
42
43# expected environment variables
44if [ -z "${MVN_NEXUSPROXY}" ]; then
45 echo "MVN_NEXUSPROXY environment variable not set. Cannot proceed"
46 exit
47fi
48MVN_NEXUSPROXY_HOST=$(echo "$MVN_NEXUSPROXY" |cut -f3 -d'/' | cut -f1 -d':')
49echo "=> Nexus Proxy at $MVN_NEXUSPROXY_HOST, $MVN_NEXUSPROXY"
50
51if [ -z "$WORKSPACE" ]; then
52 WORKSPACE=$(pwd)
53fi
54
Andrew Gauld373f0f32018-02-21 11:14:46 -050055export SETTINGS_FILE=${SETTINGS_FILE:-$HOME/.m2/settings.xml}
Lusheng Ji88648fc2017-09-20 02:18:20 +000056
57
58
59# mvn phase in life cycle
60MVN_PHASE="$2"
61
62echo "MVN_PROJECT_MODULEID is [$MVN_PROJECT_MODULEID]"
63echo "MVN_PHASE is [$MVN_PHASE]"
64echo "MVN_PROJECT_GROUPID is [$MVN_PROJECT_GROUPID]"
65echo "MVN_PROJECT_ARTIFACTID is [$MVN_PROJECT_ARTIFACTID]"
66echo "MVN_PROJECT_VERSION is [$MVN_PROJECT_VERSION]"
67echo "MVN_NEXUSPROXY is [$MVN_NEXUSPROXY]"
68echo "MVN_RAWREPO_BASEURL_UPLOAD is [$MVN_RAWREPO_BASEURL_UPLOAD]"
69echo "MVN_RAWREPO_BASEURL_DOWNLOAD is [$MVN_RAWREPO_BASEURL_DOWNLOAD]"
70MVN_RAWREPO_HOST=$(echo "$MVN_RAWREPO_BASEURL_UPLOAD" | cut -f3 -d'/' |cut -f1 -d':')
71echo "MVN_RAWREPO_HOST is [$MVN_RAWREPO_HOST]"
72echo "MVN_RAWREPO_SERVERID is [$MVN_RAWREPO_SERVERID]"
Lusheng Ji00444ab2017-10-13 17:39:45 +000073echo "MVN_DOCKERREGISTRY_SNAPSHOT is [$MVN_DOCKERREGISTRY_SNAPSHOT]"
74echo "MVN_DOCKERREGISTRY_PUBLIC is [$MVN_DOCKERREGISTRY_PUBLIC]"
Lusheng Ji88648fc2017-09-20 02:18:20 +000075echo "MVN_DOCKERREGISTRY_RELEASE is [$MVN_DOCKERREGISTRY_RELEASE]"
76
77echo "MVN_PYPISERVER_SERVERID [$MVN_PYPISERVER_SERVERID]"
78echo "MVN_PYPISERVER_BASEURL is [$MVN_PYPISERVER_BASEURL]"
79
80
81
82clean_templated_files()
83{
84 TEMPLATE_FILES=$(find . -name "*-template")
85 for F in $TEMPLATE_FILES; do
86 F2=$(echo "$F" | sed 's/-template$//')
87 rm -f "$F2"
88 done
89}
90clean_tox_files()
91{
92 TOX_FILES=$(find . -name ".tox")
93 TOX_FILES="$TOX_FILES $(find . -name 'venv-tox')"
94 for F in $TOX_FILES; do
95 rm -rf "$F"
96 done
97}
98
99expand_templates()
100{
Lusheng Ji00444ab2017-10-13 17:39:45 +0000101 set +x
Lusheng Ji88648fc2017-09-20 02:18:20 +0000102 # set up env variables, get ready for template resolution
103 # NOTE: CCSDK artifacts do not distinguish REALESE vs SNAPSHOTs
104 export ONAPTEMPLATE_RAWREPOURL_org_onap_ccsdk_platform_plugins_releases="$MVN_RAWREPO_BASEURL_DOWNLOAD/org.onap.ccsdk.platform.plugins"
105 export ONAPTEMPLATE_RAWREPOURL_org_onap_ccsdk_platform_plugins_snapshots="$MVN_RAWREPO_BASEURL_DOWNLOAD/org.onap.ccsdk.platform.plugins"
106 export ONAPTEMPLATE_RAWREPOURL_org_onap_ccsdk_platform_blueprints_releases="$MVN_RAWREPO_BASEURL_DOWNLOAD/org.onap.ccsdk.platform.blueprints"
107 export ONAPTEMPLATE_RAWREPOURL_org_onap_ccsdk_platform_blueprints_snapshots="$MVN_RAWREPO_BASEURL_DOWNLOAD/org.onap.ccsdk.platform.blueprints"
108
109 export ONAPTEMPLATE_RAWREPOURL_org_onap_dcaegen2_releases="$MVN_RAWREPO_BASEURL_DOWNLOAD/org.onap.dcaegen2/releases"
110 export ONAPTEMPLATE_RAWREPOURL_org_onap_dcaegen2_snapshots="$MVN_RAWREPO_BASEURL_DOWNLOAD/org.onap.dcaegen2/snapshots"
111 export ONAPTEMPLATE_RAWREPOURL_org_onap_dcaegen2_platform_plugins_releases="$MVN_RAWREPO_BASEURL_DOWNLOAD/org.onap.dcaegen2.platform.plugins/releases"
112 export ONAPTEMPLATE_RAWREPOURL_org_onap_dcaegen2_platform_plugins_snapshots="$MVN_RAWREPO_BASEURL_DOWNLOAD/org.onap.dcaegen2.platform.plugins/snapshots"
113 export ONAPTEMPLATE_RAWREPOURL_org_onap_dcaegen2_platform_blueprints_releases="$MVN_RAWREPO_BASEURL_DOWNLOAD/org.onap.dcaegen2.platform.blueprints/releases"
114 export ONAPTEMPLATE_RAWREPOURL_org_onap_dcaegen2_platform_blueprints_snapshots="$MVN_RAWREPO_BASEURL_DOWNLOAD/org.onap.dcaegen2.platform.blueprints/snapshots"
115
Lusheng Ji00444ab2017-10-13 17:39:45 +0000116 export ONAPTEMPLATE_PYPIURL_org_onap_dcaegen2="${MVN_PYPISERVER_BASEURL}"
Lusheng Ji88648fc2017-09-20 02:18:20 +0000117
Lusheng Ji00444ab2017-10-13 17:39:45 +0000118 # docker registry templates are for poll, so use PUBLIC registry
119 export ONAPTEMPLATE_DOCKERREGURL_org_onap_dcaegen2_releases="$MVN_DOCKERREGISTRY_PUBLIC"
120 export ONAPTEMPLATE_DOCKERREGURL_org_onap_dcaegen2_snapshots="${MVN_DOCKERREGISTRY_PUBLIC}/snapshots"
Lusheng Ji88648fc2017-09-20 02:18:20 +0000121
Lusheng Ji00444ab2017-10-13 17:39:45 +0000122 # Mvn repo
123 export ONAPTEMPLATE_MVN_org_onap_dcaegen2_analytics_tca_snapshots="${MVN_NEXUSPROXY}/service/local/repositories/snapshots/content/org/onap/dcaegen2/analytics/tca"
124 export ONAPTEMPLATE_MVN_org_onap_dcaegen2_analytics_tca_staging="${MVN_NEXUSPROXY}/service/local/repositories/staging/content/org/onap/dcaegen2/analytics/tca"
125 export ONAPTEMPLATE_MVN_org_onap_dcaegen2_analytics_tca_releases="${MVN_NEXUSPROXY}/service/local/repositories/releases/content/org/onap/dcaegen2/analytics/tca"
126
127
128 export ONAPTEMPLATE_STANDARD_INPUTS_TYPES=" # standard inputs list
129 centos7image_id:
130 type: string
131 ubuntu1604image_id:
132 type: string
133 flavor_id:
134 type: string
135 security_group:
136 type: string
137 public_net:
138 type: string
139 private_net:
140 type: string
141 openstack: {}
142 keypair:
143 type: string
144 key_filename:
145 type: string
146 location_prefix:
147 type: string
148 location_domain:
149 type: string
150 codesource_url:
151 type: string
152 codesource_version:
153 type: string"
154
155
156 TEMPLATES=$(env |grep ONAPTEMPLATE | sed 's/=.*//' | sort -u)
157 if [ -z "$TEMPLATES" ]; then
158 echo "No template variables found!"
159 return 0
160 fi
Lusheng Ji88648fc2017-09-20 02:18:20 +0000161
162 TEMPLATE_FILES=$(find . -name "*-template")
163 for F in $TEMPLATE_FILES; do
164 F2=$(echo "$F" | sed 's/-template$//')
Lusheng Ji00444ab2017-10-13 17:39:45 +0000165 cp -p "$F" "$F2"
166 chmod u+w "$F2"
Lusheng Ji88648fc2017-09-20 02:18:20 +0000167
Lusheng Ji00444ab2017-10-13 17:39:45 +0000168 echo "====> Resolving the following template from environment variables "
169 echo "$TEMPLATES"
170 for KEY in $TEMPLATES; do
171 VALUE1=$(eval 'echo "$"'"$KEY"'"' | sed 1q)
172 VALUE2=$(eval 'echo "$'"$KEY"'"' | sed -e 's/\//\\\//g' -e 's/$/\\/' -e '$s/\\$//')
Lusheng Ji88648fc2017-09-20 02:18:20 +0000173
Lusheng Ji00444ab2017-10-13 17:39:45 +0000174 echo "======> Resolving template $KEY to value $VALUE1 for file $F2"
175 sed -i "s/{{[[:space:]]*$KEY[[:space:]]*}}/$VALUE2/g" "$F2"
176 done
177 done
178 echo "====> Done template resolving"
179}
Lusheng Ji88648fc2017-09-20 02:18:20 +0000180
Lusheng Ji00444ab2017-10-13 17:39:45 +0000181test_templates()
182{
183 # make certain that the type references exist
184 TMP=$(mktemp)
185 trap 'rm -f $TMP' 0 1 2 3 15
Lusheng Ji88648fc2017-09-20 02:18:20 +0000186
Lusheng Ji00444ab2017-10-13 17:39:45 +0000187 echo Verify that all of the import URLs are correct
188 find . -name '*-template' | sed -e 's/-template$//' |
189 while read file
190 do
191 egrep '^ - .?https?://' < $file
192 done | awk '{print $2}' | sed -e 's/"//g' | sort -u |
193 while read url
194 do
195 curl -L -w '%{http_code}' -s -o /dev/null "$url" > $TMP
196 case $(< $TMP) in
197 2* ) ;;
198 * ) echo ">>>>>>>>>>>>>>>> $url not found <<<<<<<<<<<<<<<<" ;;
199 esac
Lusheng Ji88648fc2017-09-20 02:18:20 +0000200 done
201
Lusheng Ji00444ab2017-10-13 17:39:45 +0000202 echo Verify that the inputs are correct
203 PATH=$PATH:$PWD/check-blueprint-vs-input/bin
204 find . -name '*-template' | sed -e 's/-template$//' |
205 while read blueprint
206 do
207 check-blueprint-vs-input -b $blueprint -i check-blueprint-vs-input/lib/sample-inputs.yaml || true
208 done
Lusheng Ji88648fc2017-09-20 02:18:20 +0000209}
210
211
212run_tox_test()
213{
Andrew Gauld373f0f32018-02-21 11:14:46 -0500214 set -e -x
Lusheng Ji88648fc2017-09-20 02:18:20 +0000215 CURDIR=$(pwd)
216 TOXINIS=$(find . -name "tox.ini")
217 for TOXINI in "${TOXINIS[@]}"; do
218 DIR=$(echo "$TOXINI" | rev | cut -f2- -d'/' | rev)
219 cd "${CURDIR}/${DIR}"
220 rm -rf ./venv-tox ./.tox
221 virtualenv ./venv-tox
222 source ./venv-tox/bin/activate
223 pip install --upgrade pip
224 pip install --upgrade tox argparse
225 pip freeze
226 tox
227 deactivate
228 rm -rf ./venv-tox ./.tox
229 done
230}
231
232build_wagons()
233{
234 rm -rf ./*.wgn venv-pkg
Lusheng Ji88648fc2017-09-20 02:18:20 +0000235 SETUPFILES=$(find . -name "setup.py")
Lusheng Ji00444ab2017-10-13 17:39:45 +0000236
237 virtualenv ./venv-pkg
238 source ./venv-pkg/bin/activate
239 pip install --upgrade pip
240 pip install wagon
241
242 CURDIR=$(pwd)
Lusheng Ji88648fc2017-09-20 02:18:20 +0000243 for SETUPFILE in $SETUPFILES; do
Lusheng Ji00444ab2017-10-13 17:39:45 +0000244 PLUGIN_DIR=$(dirname "$SETUPFILE")
Lusheng Ji88648fc2017-09-20 02:18:20 +0000245 PLUGIN_NAME=$(grep 'name' "$SETUPFILE" | cut -f2 -d'=' | sed 's/[^0-9a-zA-Z\.]*//g')
246 PLUGIN_VERSION=$(grep 'version' "$SETUPFILE" | cut -f2 -d'=' | sed 's/[^0-9\.]*//g')
247
Lusheng Ji00444ab2017-10-13 17:39:45 +0000248 echo "In $PLUGIN_DIR, build plugin $PLUGIN_NAME, version $PLUGIN_VERSION"
Lusheng Ji88648fc2017-09-20 02:18:20 +0000249
Lusheng Ji00444ab2017-10-13 17:39:45 +0000250 wagon create --format tar.gz "${PLUGIN_DIR}"
Lusheng Ji88648fc2017-09-20 02:18:20 +0000251
252 PKG_FILE_NAMES=( "${PLUGIN_NAME}-${PLUGIN_VERSION}"*.wgn )
253 echo Built package: "${PKG_FILE_NAMES[@]}"
Lusheng Ji00444ab2017-10-13 17:39:45 +0000254 cd $CURDIR
Lusheng Ji88648fc2017-09-20 02:18:20 +0000255 done
Lusheng Ji00444ab2017-10-13 17:39:45 +0000256
257 deactivate
258 rm -rf venv-pkg
Lusheng Ji88648fc2017-09-20 02:18:20 +0000259}
260
261
262upload_raw_file()
263{
264 # Extract the username and password to the nexus repo from the settings file
265 USER=$(xpath -q -e "//servers/server[id='$MVN_RAWREPO_SERVERID']/username/text()" "$SETTINGS_FILE")
266 PASS=$(xpath -q -e "//servers/server[id='$MVN_RAWREPO_SERVERID']/password/text()" "$SETTINGS_FILE")
267 NETRC=$(mktemp)
268 echo "machine $MVN_RAWREPO_HOST login $USER password $PASS" > "$NETRC"
269
270 REPO="$MVN_RAWREPO_BASEURL_UPLOAD"
271
272 OUTPUT_FILE=$1
273 EXT=$(echo "$OUTPUT_FILE" | rev |cut -f1 -d '.' |rev)
274 if [ "$EXT" == 'yaml' ]; then
275 OUTPUT_FILE_TYPE='text/x-yaml'
276 elif [ "$EXT" == 'sh' ]; then
277 OUTPUT_FILE_TYPE='text/x-shellscript'
278 elif [ "$EXT" == 'gz' ]; then
279 OUTPUT_FILE_TYPE='application/gzip'
280 elif [ "$EXT" == 'wgn' ]; then
281 OUTPUT_FILE_TYPE='application/gzip'
282 else
283 OUTPUT_FILE_TYPE='application/octet-stream'
284 fi
285
Lusheng Ji00444ab2017-10-13 17:39:45 +0000286 # for multi module projects, the raw repo path must match with project name, not project + module
287 # FQDN is project + module
288 # GROUPID is project name
289 if [ "$MVN_PROJECT_ARTIFACTID" == "$MVN_PROJECT_MODULEID" ]; then
290 PROJECT_NAME=${MVN_PROJECT_GROUPID}
291 else
292 PROJECT_NAME=${FQDN}
293 fi
Lusheng Ji88648fc2017-09-20 02:18:20 +0000294 if [ "$MVN_DEPLOYMENT_TYPE" == 'SNAPSHOT' ]; then
Lusheng Ji00444ab2017-10-13 17:39:45 +0000295 SEND_TO="${REPO}/${PROJECT_NAME}/snapshots"
Lusheng Ji88648fc2017-09-20 02:18:20 +0000296 elif [ "$MVN_DEPLOYMENT_TYPE" == 'STAGING' ]; then
Lusheng Ji00444ab2017-10-13 17:39:45 +0000297 SEND_TO="${REPO}/${PROJECT_NAME}/releases"
Lusheng Ji88648fc2017-09-20 02:18:20 +0000298 else
299 echo "Unreconfnized deployment type, quit"
300 exit
301 fi
Lusheng Ji00444ab2017-10-13 17:39:45 +0000302 #if [ ! -z "$MVN_PROJECT_MODULEID" ]; then
303 # SEND_TO="$SEND_TO/$MVN_PROJECT_MODULEID"
304 #fi
305 if [ ! -z "$2" ]; then
306 SEND_TO="$SEND_TO/$2"
Lusheng Jid4c05d02017-09-21 03:22:18 +0000307 fi
Lusheng Ji88648fc2017-09-20 02:18:20 +0000308
309 echo "Sending ${OUTPUT_FILE} to Nexus: ${SEND_TO}"
Lusheng Ji00444ab2017-10-13 17:39:45 +0000310 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 +0000311 curl -vkn --netrc-file "${NETRC}" --upload-file "${OUTPUT_FILE}" -X PUT -H "Content-Type: $OUTPUT_FILE_TYPE" "${SEND_TO}/${OUTPUT_FILE}"
312}
313
314
315
316upload_wagons_and_type_yamls()
317{
Lusheng Ji00444ab2017-10-13 17:39:45 +0000318 SETUPFILES=$(find . -name "setup.py")
319
320 CURDIR=$(pwd)
321 for SETUPFILE in $SETUPFILES; do
322 PLUGIN_DIR=$(dirname "$SETUPFILE")
323 PLUGIN_NAME=$(grep 'name' "$SETUPFILE" | cut -f2 -d'=' | sed 's/[^0-9a-zA-Z\.]*//g')
324 PLUGIN_VERSION=$(grep 'version' "$SETUPFILE" | cut -f2 -d'=' | sed 's/[^0-9\.]*//g')
325 PLUGIN_VERSION_MAJOR=$(echo "$PLUGIN_VERSION" | cut -f1 -d'.')
326 PLUGIN_VERSION_MAJOR_MINOR=$(echo "$PLUGIN_VERSION" | cut -f1-2 -d'.')
327
328 echo "Found setup file in $PLUGIN_DIR, for plugin $PLUGIN_NAME version $PLUGIN_VERSION"
329
330 TYPEFILE_NAME=$(grep -R "package_name:[[:space:]]*${PLUGIN_NAME}" | cut -f1 -d ':')
331 if [ -z "$TYPEFILE_NAME" ]; then
332 echo "!!! No typefile found with matching package name $PLUGIN_NAME"
333 exit -1
334 fi
335 NEWFILENAME="${PLUGIN_NAME}"_types.yaml
336 if [ "$TYPEFILE_NAME" != "$NEWFILENAME" ]; then
337 echo "copy typefile to standard naming"
338 cp -f "$TYPEFILE_NAME" "$NEWFILENAME"
339 fi
340
341 TYPEFILE_PACKAGE_VERSION=$(grep -R 'package_version' $TYPEFILE_NAME |cut -f2 -d ':' |sed -r 's/\s+//g')
342 WAGONFILE_NAME=$(ls -1 $PLUGIN_NAME-$TYPEFILE_PACKAGE_VERSION-*.wgn)
343 if [ -z "$WAGONFILE_NAME" ]; then
344 echo "!!! No wagonfile found with matching package name and version as required in typefile: "
345 echo " $TYPEFILE_NAME plugin $PLUGIN_NAME package version ${TYPEFILE_PACKAGE_VERSION}"
346 exit -1
347 fi
348
349 upload_raw_file "$NEWFILENAME" type_files/${PLUGIN_NAME}/${PLUGIN_VERSION_MAJOR}
350 upload_raw_file "$NEWFILENAME" type_files/${PLUGIN_NAME}/${PLUGIN_VERSION_MAJOR_MINOR}
351 upload_raw_file "${WAGONFILE_NAME}" "plugins/${PLUGIN_NAME}"
Lusheng Ji88648fc2017-09-20 02:18:20 +0000352
Lusheng Ji00444ab2017-10-13 17:39:45 +0000353 rm -r $WAGONFILE_NAME
354 if [ "$TYPEFILE_NAME" != "$NEWFILENAME" ]; then
355 rm -f "$NEWFILENAME"
356 fi
Lusheng Ji88648fc2017-09-20 02:18:20 +0000357 done
358}
359
360upload_files_of_extension()
361{
362 FILES=$(ls -1 ./*."$1")
363 for F in $FILES ; do
Lusheng Ji00444ab2017-10-13 17:39:45 +0000364 upload_raw_file "$F" "$2"
Lusheng Ji88648fc2017-09-20 02:18:20 +0000365 done
366}
367
368
369generate_pypirc_then_publish()
370{
371 set +x
372 USER=$(xpath -e "//servers/server[id='$MVN_PYPISERVER_SERVERID']/username/text()" "$SETTINGS_FILE")
373 PASS=$(xpath -e "//servers/server[id='$MVN_PYPISERVER_SERVERID']/password/text()" "$SETTINGS_FILE")
374
375 if [[ "$MVN_PYPISERVER_BASEURL" != */ ]]; then
376 MVN_PYPISERVER_BASEURL="${MVN_PYPISERVER_BASEURL}/"
377 fi
378
379
380 cat > ~/.pypirc <<EOL
381[distutils]
382index-servers =
383 $MVN_PYPISERVER_SERVERID
384
385[$MVN_PYPISERVER_SERVERID]
386repository: $MVN_PYPISERVER_BASEURL
387username: $USER
388password: $PASS
389EOL
390
391 # this may fail if a package of same version exists
392 python setup.py sdist register -r "$MVN_PYPISERVER_SERVERID" upload -r "$MVN_PYPISERVER_SERVERID"
393 set -x
394}
395
396
397
398build_and_push_docker()
399{
400 IMAGENAME="onap/${FQDN}.${MVN_PROJECT_MODULEID}"
401 IMAGENAME=$(echo "$IMAGENAME" | sed -e 's/_*$//g' -e 's/\.*$//g')
402 IMAGENAME=$(echo "$IMAGENAME" | tr '[:upper:]' '[:lower:]')
403
404 # use the major and minor version of the MVN artifact version as docker image version
405 VERSION="${MVN_PROJECT_VERSION//[^0-9.]/}"
406 VERSION2=$(echo "$VERSION" | cut -f1-2 -d'.')
407
408 LFQI="${IMAGENAME}:${VERSION}-${TIMESTAMP}"
409 # build a docker image
410 docker build --rm -f ./Dockerfile -t "${LFQI}" ./
411
412 REPO=""
413 if [ $MVN_DEPLOYMENT_TYPE == "SNAPSHOT" ]; then
Lusheng Ji00444ab2017-10-13 17:39:45 +0000414 REPO=$MVN_DOCKERREGISTRY_SNASHOT
Lusheng Ji88648fc2017-09-20 02:18:20 +0000415 elif [ $MVN_DEPLOYMENT_TYPE == "STAGING" ]; then
416 # there seems to be no staging docker registry? set to use SNAPSHOT also
Lusheng Ji00444ab2017-10-13 17:39:45 +0000417 REPO=$MVN_DOCKERREGISTRY_RELEASE
Lusheng Ji88648fc2017-09-20 02:18:20 +0000418 else
419 echo "Fail to determine DEPLOYMENT_TYPE"
Lusheng Ji00444ab2017-10-13 17:39:45 +0000420 REPO=$MVN_DOCKERREGISTRY_SNAPSHOT
Lusheng Ji88648fc2017-09-20 02:18:20 +0000421 fi
422 echo "DEPLOYMENT_TYPE is: $MVN_DEPLOYMENT_TYPE, repo is $REPO"
423
424 if [ ! -z "$REPO" ]; then
425 USER=$(xpath -e "//servers/server[id='$REPO']/username/text()" "$SETTINGS_FILE")
426 PASS=$(xpath -e "//servers/server[id='$REPO']/password/text()" "$SETTINGS_FILE")
427 if [ -z "$USER" ]; then
428 echo "Error: no user provided"
429 fi
430 if [ -z "$PASS" ]; then
431 echo "Error: no password provided"
432 fi
433 [ -z "$PASS" ] && PASS_PROVIDED="<empty>" || PASS_PROVIDED="<password>"
434 echo docker login "$REPO" -u "$USER" -p "$PASS_PROVIDED"
435 docker login "$REPO" -u "$USER" -p "$PASS"
436
437 if [ $MVN_DEPLOYMENT_TYPE == "SNAPSHOT" ]; then
438 REPO="$REPO/snapshots"
439 elif [ $MVN_DEPLOYMENT_TYPE == "STAGING" ]; then
440 # there seems to be no staging docker registry? set to use SNAPSHOT also
441 #REPO=$MVN_DOCKERREGISTRY_RELEASE
442 REPO="$REPO"
443 else
444 echo "Fail to determine DEPLOYMENT_TYPE"
445 REPO="$REPO/unknown"
446 fi
447
448 OLDTAG="${LFQI}"
449 PUSHTAGS="${REPO}/${IMAGENAME}:${VERSION2}-${TIMESTAMP} ${REPO}/${IMAGENAME}:${VERSION2} ${REPO}/${IMAGENAME}:${VERSION2}-latest"
450 for NEWTAG in ${PUSHTAGS}
451 do
452 echo "tagging ${OLDTAG} to ${NEWTAG}"
453 docker tag "${OLDTAG}" "${NEWTAG}"
454 echo "pushing ${NEWTAG}"
455 docker push "${NEWTAG}"
456 OLDTAG="${NEWTAG}"
457 done
458 fi
459
460}
461
462
463