Lusheng Ji | 5e11184 | 2017-09-11 23:01:37 +0000 | [diff] [blame] | 1 | #!/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 | |
Lusheng Ji | d92d448 | 2017-09-21 05:42:28 +0000 | [diff] [blame] | 22 | #MVN_PROJECT_MODULEID="$1" |
| 23 | #MVN_PHASE="$2" |
| 24 | #PROJECT_ROOT=$(dirname $0) |
| 25 | |
| 26 | FQDN="${MVN_PROJECT_GROUPID}" |
| 27 | if [ "$MVN_PROJECT_MODULEID" == "__" ]; then |
| 28 | MVN_PROJECT_MODULEID="" |
| 29 | fi |
| 30 | |
| 31 | if [[ "$MVN_PROJECT_VERSION" == *SNAPSHOT ]]; then |
| 32 | echo "=> for SNAPSHOT artifact build" |
| 33 | MVN_DEPLOYMENT_TYPE='SNAPSHOT' |
| 34 | else |
| 35 | echo "=> for STAGING/RELEASE artifact build" |
| 36 | MVN_DEPLOYMENT_TYPE='STAGING' |
| 37 | fi |
| 38 | echo "MVN_DEPLOYMENT_TYPE is [$MVN_DEPLOYMENT_TYPE]" |
| 39 | |
| 40 | |
| 41 | TIMESTAMP=$(date +%C%y%m%dT%H%M%S) |
| 42 | |
| 43 | # expected environment variables |
| 44 | if [ -z "${MVN_NEXUSPROXY}" ]; then |
| 45 | echo "MVN_NEXUSPROXY environment variable not set. Cannot proceed" |
| 46 | exit |
| 47 | fi |
| 48 | MVN_NEXUSPROXY_HOST=$(echo "$MVN_NEXUSPROXY" |cut -f3 -d'/' | cut -f1 -d':') |
| 49 | echo "=> Nexus Proxy at $MVN_NEXUSPROXY_HOST, $MVN_NEXUSPROXY" |
| 50 | |
| 51 | if [ -z "$WORKSPACE" ]; then |
| 52 | WORKSPACE=$(pwd) |
| 53 | fi |
| 54 | |
| 55 | if [ -z "$SETTINGS_FILE" ]; then |
| 56 | echo "SETTINGS_FILE environment variable not set. Cannot proceed" |
| 57 | exit |
| 58 | fi |
| 59 | |
| 60 | |
| 61 | |
| 62 | # mvn phase in life cycle |
| 63 | MVN_PHASE="$2" |
| 64 | |
| 65 | echo "MVN_PROJECT_MODULEID is [$MVN_PROJECT_MODULEID]" |
| 66 | echo "MVN_PHASE is [$MVN_PHASE]" |
| 67 | echo "MVN_PROJECT_GROUPID is [$MVN_PROJECT_GROUPID]" |
| 68 | echo "MVN_PROJECT_ARTIFACTID is [$MVN_PROJECT_ARTIFACTID]" |
| 69 | echo "MVN_PROJECT_VERSION is [$MVN_PROJECT_VERSION]" |
| 70 | echo "MVN_NEXUSPROXY is [$MVN_NEXUSPROXY]" |
| 71 | echo "MVN_RAWREPO_BASEURL_UPLOAD is [$MVN_RAWREPO_BASEURL_UPLOAD]" |
| 72 | echo "MVN_RAWREPO_BASEURL_DOWNLOAD is [$MVN_RAWREPO_BASEURL_DOWNLOAD]" |
| 73 | MVN_RAWREPO_HOST=$(echo "$MVN_RAWREPO_BASEURL_UPLOAD" | cut -f3 -d'/' |cut -f1 -d':') |
| 74 | echo "MVN_RAWREPO_HOST is [$MVN_RAWREPO_HOST]" |
| 75 | echo "MVN_RAWREPO_SERVERID is [$MVN_RAWREPO_SERVERID]" |
| 76 | echo "MVN_DOCKERREGISTRY_SNAOSHOT is [$MVN_DOCKERREGISTRY_SNAPSHOT]" |
| 77 | echo "MVN_DOCKERREGISTRY_RELEASE is [$MVN_DOCKERREGISTRY_RELEASE]" |
| 78 | echo "MVN_DOCKERREGISTRY_SNAPSHOT_SERVERID is [$MVN_DOCKERREGISTRY_SNAPSHOT_SERVERID]" |
| 79 | echo "MVN_DOCKERREGISTRY_RELEASE_SERVERID is [$MVN_DOCKERREGISTRY_RELEASE_SERVERID]" |
| 80 | |
| 81 | echo "MVN_PYPISERVER_SERVERID [$MVN_PYPISERVER_SERVERID]" |
| 82 | echo "MVN_PYPISERVER_BASEURL is [$MVN_PYPISERVER_BASEURL]" |
| 83 | |
| 84 | |
| 85 | |
Lusheng Ji | 5e11184 | 2017-09-11 23:01:37 +0000 | [diff] [blame] | 86 | clean_templated_files() |
| 87 | { |
| 88 | TEMPLATE_FILES=$(find . -name "*-template") |
| 89 | for F in $TEMPLATE_FILES; do |
| 90 | F2=$(echo "$F" | sed 's/-template$//') |
| 91 | rm -f "$F2" |
| 92 | done |
| 93 | } |
| 94 | clean_tox_files() |
| 95 | { |
| 96 | TOX_FILES=$(find . -name ".tox") |
| 97 | TOX_FILES="$TOX_FILES $(find . -name 'venv-tox')" |
| 98 | for F in $TOX_FILES; do |
| 99 | rm -rf "$F" |
| 100 | done |
| 101 | } |
| 102 | |
| 103 | expand_templates() |
| 104 | { |
| 105 | # set up env variables, get ready for template resolution |
| 106 | # NOTE: CCSDK artifacts do not distinguish REALESE vs SNAPSHOTs |
| 107 | export ONAPTEMPLATE_RAWREPOURL_org_onap_ccsdk_platform_plugins_releases="$MVN_RAWREPO_BASEURL_DOWNLOAD/org.onap.ccsdk.platform.plugins" |
| 108 | export ONAPTEMPLATE_RAWREPOURL_org_onap_ccsdk_platform_plugins_snapshots="$MVN_RAWREPO_BASEURL_DOWNLOAD/org.onap.ccsdk.platform.plugins" |
| 109 | export ONAPTEMPLATE_RAWREPOURL_org_onap_ccsdk_platform_blueprints_releases="$MVN_RAWREPO_BASEURL_DOWNLOAD/org.onap.ccsdk.platform.blueprints" |
| 110 | export ONAPTEMPLATE_RAWREPOURL_org_onap_ccsdk_platform_blueprints_snapshots="$MVN_RAWREPO_BASEURL_DOWNLOAD/org.onap.ccsdk.platform.blueprints" |
| 111 | |
| 112 | export ONAPTEMPLATE_RAWREPOURL_org_onap_dcaegen2_releases="$MVN_RAWREPO_BASEURL_DOWNLOAD/org.onap.dcaegen2/releases" |
| 113 | export ONAPTEMPLATE_RAWREPOURL_org_onap_dcaegen2_snapshots="$MVN_RAWREPO_BASEURL_DOWNLOAD/org.onap.dcaegen2/snapshots" |
| 114 | export ONAPTEMPLATE_RAWREPOURL_org_onap_dcaegen2_platform_plugins_releases="$MVN_RAWREPO_BASEURL_DOWNLOAD/org.onap.dcaegen2.platform.plugins/releases" |
| 115 | export ONAPTEMPLATE_RAWREPOURL_org_onap_dcaegen2_platform_plugins_snapshots="$MVN_RAWREPO_BASEURL_DOWNLOAD/org.onap.dcaegen2.platform.plugins/snapshots" |
| 116 | export ONAPTEMPLATE_RAWREPOURL_org_onap_dcaegen2_platform_blueprints_releases="$MVN_RAWREPO_BASEURL_DOWNLOAD/org.onap.dcaegen2.platform.blueprints/releases" |
| 117 | export ONAPTEMPLATE_RAWREPOURL_org_onap_dcaegen2_platform_blueprints_snapshots="$MVN_RAWREPO_BASEURL_DOWNLOAD/org.onap.dcaegen2.platform.blueprints/snapshots" |
| 118 | |
Lusheng Ji | d92d448 | 2017-09-21 05:42:28 +0000 | [diff] [blame] | 119 | export ONAPTEMPLATE_PYPIURL_org_onap_dcaegen2="$MVN_PYPISERVER_BASEURL" |
Lusheng Ji | 5e11184 | 2017-09-11 23:01:37 +0000 | [diff] [blame] | 120 | |
| 121 | export ONAPTEMPLATE_DOCKERREGURL_org_onap_dcaegen2_releases="$MVN_DOCKERREGISTRY_DAILY" |
| 122 | export ONAPTEMPLATE_DOCKERREGURL_org_onap_dcaegen2_snapshots="$MVN_DOCKERREGISTRY_DAILY/snapshots" |
| 123 | |
| 124 | |
| 125 | TEMPLATE_FILES=$(find . -name "*-template") |
| 126 | for F in $TEMPLATE_FILES; do |
| 127 | F2=$(echo "$F" | sed 's/-template$//') |
| 128 | cp "$F" "$F2" |
| 129 | MOD=$(stat --format '%a' "$F") |
| 130 | chmod "$MOD" "$F2" |
| 131 | done |
| 132 | |
| 133 | |
| 134 | TEMPLATES=$(env |grep ONAPTEMPLATE) |
| 135 | if [ -z "$TEMPLATES" ]; then |
| 136 | return 0 |
| 137 | fi |
| 138 | |
| 139 | echo "====> Resolving the following temaplate from environment variables " |
| 140 | echo "[$TEMPLATES]" |
| 141 | SELFFILE=$(echo "$0" | rev | cut -f1 -d '/' | rev) |
| 142 | for TEMPLATE in $TEMPLATES; do |
| 143 | KEY=$(echo "$TEMPLATE" | cut -f1 -d'=') |
| 144 | VALUE=$(echo "$TEMPLATE" | cut -f2 -d'=') |
| 145 | VALUE2=$(echo "$TEMPLATE" | cut -f2 -d'=' |sed 's/\//\\\//g') |
| 146 | set +e |
| 147 | FILES=$(grep -rl "$KEY") |
| 148 | set -e |
| 149 | |
| 150 | if [ -z "$FILES" ]; then |
| 151 | continue |
| 152 | fi |
| 153 | |
| 154 | # assuming FILES is not longer than 2M bytes, the limit for variable value max size on this VM |
| 155 | for F in $FILES; do |
| 156 | if [[ $F == *"$SELFFILE" ]]; then |
| 157 | continue |
| 158 | fi |
| 159 | if [[ "$F" == *-template ]]; then |
| 160 | continue |
| 161 | fi |
| 162 | |
| 163 | echo "======> Resolving template $KEY to value $VALUE for file $F" |
| 164 | sed -i "s/{{[[:space:]]*$KEY[[:space:]]*}}/$VALUE2/g" "$F" |
| 165 | #cat "$F" |
| 166 | done |
| 167 | |
| 168 | #if [ ! -z "$FILES" ]; then |
| 169 | # echo "====> Resolving template $VALUE to value $VALUE" |
| 170 | # #CMD="grep -rl \"$VALUE\" | tr '\n' '\0' | xargs -0 sed -i \"s/{{[[:space:]]*$VALUE[[:space:]]*}}/$VALUE/g\"" |
| 171 | # grep -rl "$KEY" | tr '\n' '\0' | xargs -0 sed -i 's/$KEY/$VALUE2/g' |
| 172 | # #echo $CMD |
| 173 | # #eval $CMD |
| 174 | #fi |
| 175 | done |
| 176 | echo "====> Done template reolving" |
| 177 | } |
| 178 | |
| 179 | |
| 180 | run_tox_test() |
| 181 | { |
| 182 | set -x |
| 183 | CURDIR=$(pwd) |
| 184 | TOXINIS=$(find . -name "tox.ini") |
| 185 | for TOXINI in "${TOXINIS[@]}"; do |
| 186 | DIR=$(echo "$TOXINI" | rev | cut -f2- -d'/' | rev) |
| 187 | cd "${CURDIR}/${DIR}" |
| 188 | rm -rf ./venv-tox ./.tox |
| 189 | virtualenv ./venv-tox |
| 190 | source ./venv-tox/bin/activate |
| 191 | pip install --upgrade pip |
| 192 | pip install --upgrade tox argparse |
| 193 | pip freeze |
| 194 | tox |
| 195 | deactivate |
| 196 | rm -rf ./venv-tox ./.tox |
| 197 | done |
| 198 | } |
| 199 | |
| 200 | build_wagons() |
| 201 | { |
| 202 | rm -rf ./*.wgn venv-pkg |
| 203 | |
| 204 | SETUPFILES=$(find . -name "setup.py") |
| 205 | for SETUPFILE in $SETUPFILES; do |
| 206 | PLUGIN_DIR=$(echo "$SETUPFILE" |rev | cut -f 2- -d '/' |rev) |
| 207 | PLUGIN_NAME=$(grep 'name' "$SETUPFILE" | cut -f2 -d'=' | sed 's/[^0-9a-zA-Z\.]*//g') |
| 208 | PLUGIN_VERSION=$(grep 'version' "$SETUPFILE" | cut -f2 -d'=' | sed 's/[^0-9\.]*//g') |
| 209 | |
| 210 | echo "In $PLUGIN_DIR, $PLUGIN_NAME, $PLUGIN_VERSION" |
| 211 | |
| 212 | virtualenv ./venv-pkg |
| 213 | source ./venv-pkg/bin/activate |
| 214 | pip install --upgrade pip |
| 215 | pip install wagon |
| 216 | wagon create --format tar.gz "$PLUGIN_DIR" |
| 217 | deactivate |
| 218 | rm -rf venv-pkg |
| 219 | |
| 220 | PKG_FILE_NAMES=( "${PLUGIN_NAME}-${PLUGIN_VERSION}"*.wgn ) |
| 221 | echo Built package: "${PKG_FILE_NAMES[@]}" |
| 222 | done |
| 223 | } |
| 224 | |
| 225 | |
| 226 | upload_raw_file() |
| 227 | { |
| 228 | # Extract the username and password to the nexus repo from the settings file |
| 229 | USER=$(xpath -q -e "//servers/server[id='$MVN_RAWREPO_SERVERID']/username/text()" "$SETTINGS_FILE") |
| 230 | PASS=$(xpath -q -e "//servers/server[id='$MVN_RAWREPO_SERVERID']/password/text()" "$SETTINGS_FILE") |
| 231 | NETRC=$(mktemp) |
| 232 | echo "machine $MVN_RAWREPO_HOST login $USER password $PASS" > "$NETRC" |
| 233 | |
| 234 | REPO="$MVN_RAWREPO_BASEURL_UPLOAD" |
| 235 | |
Lusheng Ji | d92d448 | 2017-09-21 05:42:28 +0000 | [diff] [blame] | 236 | OUTPUT_FILE=$(echo "$1" | sed -e "s/^.\///") |
Lusheng Ji | 5e11184 | 2017-09-11 23:01:37 +0000 | [diff] [blame] | 237 | EXT=$(echo "$OUTPUT_FILE" | rev |cut -f1 -d '.' |rev) |
| 238 | if [ "$EXT" == 'yaml' ]; then |
| 239 | OUTPUT_FILE_TYPE='text/x-yaml' |
Lusheng Ji | d92d448 | 2017-09-21 05:42:28 +0000 | [diff] [blame] | 240 | elif [ "$EXT" == 'json' ]; then |
| 241 | OUTPUT_FILE_TYPE='application/json' |
Lusheng Ji | 5e11184 | 2017-09-11 23:01:37 +0000 | [diff] [blame] | 242 | elif [ "$EXT" == 'sh' ]; then |
| 243 | OUTPUT_FILE_TYPE='text/x-shellscript' |
Lusheng Ji | 94a4ef6 | 2017-10-16 22:14:08 -0400 | [diff] [blame] | 244 | elif [ "$EXT" == 'py' ]; then |
| 245 | OUTPUT_FILE_TYPE='text/x-python' |
Lusheng Ji | 5e11184 | 2017-09-11 23:01:37 +0000 | [diff] [blame] | 246 | elif [ "$EXT" == 'gz' ]; then |
| 247 | OUTPUT_FILE_TYPE='application/gzip' |
| 248 | elif [ "$EXT" == 'wgn' ]; then |
| 249 | OUTPUT_FILE_TYPE='application/gzip' |
| 250 | else |
| 251 | OUTPUT_FILE_TYPE='application/octet-stream' |
| 252 | fi |
| 253 | |
| 254 | |
| 255 | if [ "$MVN_DEPLOYMENT_TYPE" == 'SNAPSHOT' ]; then |
Lusheng Ji | d92d448 | 2017-09-21 05:42:28 +0000 | [diff] [blame] | 256 | SEND_TO="${REPO}/${MVN_PROJECT_GROUPID}/snapshots" |
Lusheng Ji | 5e11184 | 2017-09-11 23:01:37 +0000 | [diff] [blame] | 257 | elif [ "$MVN_DEPLOYMENT_TYPE" == 'STAGING' ]; then |
Lusheng Ji | d92d448 | 2017-09-21 05:42:28 +0000 | [diff] [blame] | 258 | SEND_TO="${REPO}/{$MVN_PROJECT_GROUPID}/releases" |
Lusheng Ji | 5e11184 | 2017-09-11 23:01:37 +0000 | [diff] [blame] | 259 | else |
| 260 | echo "Unreconfnized deployment type, quit" |
| 261 | exit |
| 262 | fi |
| 263 | if [ ! -z "$MVN_PROJECT_MODULEID" ]; then |
| 264 | SEND_TO="$SEND_TO/$MVN_PROJECT_MODULEID" |
| 265 | fi |
| 266 | |
| 267 | echo "Sending ${OUTPUT_FILE} to Nexus: ${SEND_TO}" |
Lusheng Ji | 97112db | 2017-10-16 22:43:03 -0400 | [diff] [blame] | 268 | curl -vkn --netrc-file "${NETRC}" --upload-file "${OUTPUT_FILE}" -X PUT -H "Content-Type: $OUTPUT_FILE_TYPE" "${SEND_TO}/${OUTPUT_FILE}-${MVN_PROJECT_VERSION}-${TIMESTAMP}" |
Lusheng Ji | 5e11184 | 2017-09-11 23:01:37 +0000 | [diff] [blame] | 269 | curl -vkn --netrc-file "${NETRC}" --upload-file "${OUTPUT_FILE}" -X PUT -H "Content-Type: $OUTPUT_FILE_TYPE" "${SEND_TO}/${OUTPUT_FILE}-${MVN_PROJECT_VERSION}" |
| 270 | curl -vkn --netrc-file "${NETRC}" --upload-file "${OUTPUT_FILE}" -X PUT -H "Content-Type: $OUTPUT_FILE_TYPE" "${SEND_TO}/${OUTPUT_FILE}" |
| 271 | } |
| 272 | |
| 273 | |
| 274 | |
| 275 | upload_wagons_and_type_yamls() |
| 276 | { |
| 277 | WAGONS=$(ls -1 ./*.wgn) |
| 278 | for WAGON in $WAGONS ; do |
| 279 | WAGON_NAME=$(echo "$WAGON" | cut -f1 -d '-') |
| 280 | WAGON_VERSION=$(echo "$WAGON" | cut -f2 -d '-') |
| 281 | WAGON_TYPEFILE=$(grep -rl "$WAGON_NAME" | grep yaml | head -1) |
| 282 | |
| 283 | upload_raw_file "$WAGON" |
| 284 | upload_raw_file "$WAGON_TYPEFILE" |
| 285 | done |
| 286 | } |
| 287 | |
| 288 | upload_files_of_extension() |
| 289 | { |
| 290 | FILES=$(ls -1 ./*."$1") |
| 291 | for F in $FILES ; do |
| 292 | upload_raw_file "$F" |
| 293 | done |
| 294 | } |
Lusheng Ji | 94a4ef6 | 2017-10-16 22:14:08 -0400 | [diff] [blame] | 295 | upload_files_of_extension_recursively() |
| 296 | { |
| 297 | FILES=$(find . -name "*.$1") |
| 298 | for F in $FILES ; do |
| 299 | upload_raw_file "$F" |
| 300 | done |
| 301 | } |
Lusheng Ji | 5e11184 | 2017-09-11 23:01:37 +0000 | [diff] [blame] | 302 | |
| 303 | |
Lusheng Ji | d92d448 | 2017-09-21 05:42:28 +0000 | [diff] [blame] | 304 | generate_pypirc_then_publish() |
| 305 | { |
| 306 | set +x |
| 307 | USER=$(xpath -e "//servers/server[id='$MVN_PYPISERVER_SERVERID']/username/text()" "$SETTINGS_FILE") |
| 308 | PASS=$(xpath -e "//servers/server[id='$MVN_PYPISERVER_SERVERID']/password/text()" "$SETTINGS_FILE") |
| 309 | |
| 310 | if [[ "$MVN_PYPISERVER_BASEURL" != */ ]]; then |
| 311 | MVN_PYPISERVER_BASEURL="${MVN_PYPISERVER_BASEURL}/" |
| 312 | fi |
| 313 | |
| 314 | |
| 315 | cat > ~/.pypirc <<EOL |
| 316 | [distutils] |
| 317 | index-servers = |
| 318 | $MVN_PYPISERVER_SERVERID |
| 319 | |
| 320 | [$MVN_PYPISERVER_SERVERID] |
| 321 | repository: $MVN_PYPISERVER_BASEURL |
| 322 | username: $USER |
| 323 | password: $PASS |
| 324 | EOL |
| 325 | |
| 326 | # this may fail if a package of same version exists |
| 327 | python setup.py sdist register -r "$MVN_PYPISERVER_SERVERID" upload -r "$MVN_PYPISERVER_SERVERID" |
| 328 | set -x |
| 329 | } |
| 330 | |
| 331 | |
Lusheng Ji | 5e11184 | 2017-09-11 23:01:37 +0000 | [diff] [blame] | 332 | |
| 333 | build_and_push_docker() |
| 334 | { |
Lusheng Ji | d92d448 | 2017-09-21 05:42:28 +0000 | [diff] [blame] | 335 | IMAGENAME="onap/${MVN_PROJECT_GROUPID}.${MVN_PROJECT_MODULEID}" |
Lusheng Ji | 5e11184 | 2017-09-11 23:01:37 +0000 | [diff] [blame] | 336 | IMAGENAME=$(echo "$IMAGENAME" | sed -e 's/_*$//g' -e 's/\.*$//g') |
Lusheng Ji | d92d448 | 2017-09-21 05:42:28 +0000 | [diff] [blame] | 337 | IMAGENAME=$(echo "$IMAGENAME" | tr '[:upper:]' '[:lower:]') |
Lusheng Ji | 5e11184 | 2017-09-11 23:01:37 +0000 | [diff] [blame] | 338 | |
| 339 | # use the major and minor version of the MVN artifact version as docker image version |
| 340 | VERSION="${MVN_PROJECT_VERSION//[^0-9.]/}" |
| 341 | VERSION2=$(echo "$VERSION" | cut -f1-2 -d'.') |
| 342 | |
| 343 | LFQI="${IMAGENAME}:${VERSION}-${TIMESTAMP}" |
Lusheng Ji | 5e11184 | 2017-09-11 23:01:37 +0000 | [diff] [blame] | 344 | # build a docker image |
Lusheng Ji | 39932a1 | 2017-09-12 03:41:15 +0000 | [diff] [blame] | 345 | docker build --rm -f ./Dockerfile -t "${LFQI}" ./ |
Lusheng Ji | 5e11184 | 2017-09-11 23:01:37 +0000 | [diff] [blame] | 346 | |
| 347 | REPO="" |
| 348 | if [ $MVN_DEPLOYMENT_TYPE == "SNAPSHOT" ]; then |
Lusheng Ji | d92d448 | 2017-09-21 05:42:28 +0000 | [diff] [blame] | 349 | REPO=$MVN_DOCKERREGISTRY_SNAPSHOT |
| 350 | SERVERID=$MVN_DOCKERREGISTRY_SNAPSHOT_SERVERID |
Lusheng Ji | 5e11184 | 2017-09-11 23:01:37 +0000 | [diff] [blame] | 351 | elif [ $MVN_DEPLOYMENT_TYPE == "STAGING" ]; then |
| 352 | # there seems to be no staging docker registry? set to use SNAPSHOT also |
| 353 | #REPO=$MVN_DOCKERREGISTRY_RELEASE |
Lusheng Ji | d92d448 | 2017-09-21 05:42:28 +0000 | [diff] [blame] | 354 | REPO=$MVN_DOCKERREGISTRY_SNAPSHOT |
| 355 | SERVERID=$MVN_DOCKERREGISTRY_SNAPSHOT_SERVERID |
Lusheng Ji | 5e11184 | 2017-09-11 23:01:37 +0000 | [diff] [blame] | 356 | else |
| 357 | echo "Fail to determine DEPLOYMENT_TYPE" |
Lusheng Ji | d92d448 | 2017-09-21 05:42:28 +0000 | [diff] [blame] | 358 | REPO=$MVN_DOCKERREGISTRY_SNAPSHOT |
| 359 | SERVERID=$MVN_DOCKERREGISTRY_SNAPSHOT_SERVERID |
Lusheng Ji | 5e11184 | 2017-09-11 23:01:37 +0000 | [diff] [blame] | 360 | fi |
| 361 | echo "DEPLOYMENT_TYPE is: $MVN_DEPLOYMENT_TYPE, repo is $REPO" |
| 362 | |
| 363 | if [ ! -z "$REPO" ]; then |
Lusheng Ji | d92d448 | 2017-09-21 05:42:28 +0000 | [diff] [blame] | 364 | USER=$(xpath -e "//servers/server[id='$SERVERID']/username/text()" "$SETTINGS_FILE") |
| 365 | PASS=$(xpath -e "//servers/server[id='$SERVERID']/password/text()" "$SETTINGS_FILE") |
Lusheng Ji | 5e11184 | 2017-09-11 23:01:37 +0000 | [diff] [blame] | 366 | if [ -z "$USER" ]; then |
| 367 | echo "Error: no user provided" |
| 368 | fi |
| 369 | if [ -z "$PASS" ]; then |
| 370 | echo "Error: no password provided" |
| 371 | fi |
| 372 | [ -z "$PASS" ] && PASS_PROVIDED="<empty>" || PASS_PROVIDED="<password>" |
| 373 | echo docker login "$REPO" -u "$USER" -p "$PASS_PROVIDED" |
| 374 | docker login "$REPO" -u "$USER" -p "$PASS" |
| 375 | |
| 376 | if [ $MVN_DEPLOYMENT_TYPE == "SNAPSHOT" ]; then |
| 377 | REPO="$REPO/snapshots" |
| 378 | elif [ $MVN_DEPLOYMENT_TYPE == "STAGING" ]; then |
| 379 | # there seems to be no staging docker registry? set to use SNAPSHOT also |
| 380 | #REPO=$MVN_DOCKERREGISTRY_RELEASE |
| 381 | REPO="$REPO" |
| 382 | else |
| 383 | echo "Fail to determine DEPLOYMENT_TYPE" |
| 384 | REPO="$REPO/unknown" |
| 385 | fi |
| 386 | |
| 387 | OLDTAG="${LFQI}" |
| 388 | PUSHTAGS="${REPO}/${IMAGENAME}:${VERSION2}-${TIMESTAMP} ${REPO}/${IMAGENAME}:${VERSION2} ${REPO}/${IMAGENAME}:${VERSION2}-latest" |
| 389 | for NEWTAG in ${PUSHTAGS} |
| 390 | do |
| 391 | echo "tagging ${OLDTAG} to ${NEWTAG}" |
| 392 | docker tag "${OLDTAG}" "${NEWTAG}" |
| 393 | echo "pushing ${NEWTAG}" |
| 394 | docker push "${NEWTAG}" |
| 395 | OLDTAG="${NEWTAG}" |
| 396 | done |
| 397 | fi |
| 398 | |
| 399 | } |
| 400 | |
| 401 | |
| 402 | |