Lusheng Ji | 88648fc | 2017-09-20 02:18:20 +0000 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | # ================================================================================ |
Lusheng Ji | 7ed3376 | 2018-03-05 08:10:18 -0500 | [diff] [blame] | 4 | # Copyright (c) 2017-2018 AT&T Intellectual Property. All rights reserved. |
Lusheng Ji | 88648fc | 2017-09-20 02:18:20 +0000 | [diff] [blame] | 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========================================================= |
Lusheng Ji | 88648fc | 2017-09-20 02:18:20 +0000 | [diff] [blame] | 18 | |
| 19 | |
| 20 | #MVN_PROJECT_MODULEID="$1" |
| 21 | #MVN_PHASE="$2" |
| 22 | #PROJECT_ROOT=$(dirname $0) |
| 23 | |
| 24 | FQDN="${MVN_PROJECT_GROUPID}.${MVN_PROJECT_ARTIFACTID}" |
| 25 | if [ "$MVN_PROJECT_MODULEID" == "__" ]; then |
| 26 | MVN_PROJECT_MODULEID="" |
| 27 | fi |
| 28 | |
| 29 | if [[ "$MVN_PROJECT_VERSION" == *SNAPSHOT ]]; then |
| 30 | echo "=> for SNAPSHOT artifact build" |
| 31 | MVN_DEPLOYMENT_TYPE='SNAPSHOT' |
| 32 | else |
| 33 | echo "=> for STAGING/RELEASE artifact build" |
| 34 | MVN_DEPLOYMENT_TYPE='STAGING' |
| 35 | fi |
| 36 | echo "MVN_DEPLOYMENT_TYPE is [$MVN_DEPLOYMENT_TYPE]" |
| 37 | |
| 38 | |
| 39 | TIMESTAMP=$(date +%C%y%m%dT%H%M%S) |
| 40 | |
| 41 | # expected environment variables |
| 42 | if [ -z "${MVN_NEXUSPROXY}" ]; then |
| 43 | echo "MVN_NEXUSPROXY environment variable not set. Cannot proceed" |
| 44 | exit |
| 45 | fi |
| 46 | MVN_NEXUSPROXY_HOST=$(echo "$MVN_NEXUSPROXY" |cut -f3 -d'/' | cut -f1 -d':') |
| 47 | echo "=> Nexus Proxy at $MVN_NEXUSPROXY_HOST, $MVN_NEXUSPROXY" |
| 48 | |
| 49 | if [ -z "$WORKSPACE" ]; then |
| 50 | WORKSPACE=$(pwd) |
| 51 | fi |
| 52 | |
Andrew Gauld | 373f0f3 | 2018-02-21 11:14:46 -0500 | [diff] [blame] | 53 | export SETTINGS_FILE=${SETTINGS_FILE:-$HOME/.m2/settings.xml} |
Lusheng Ji | 88648fc | 2017-09-20 02:18:20 +0000 | [diff] [blame] | 54 | |
Lusheng Ji | 5a3dbbb | 2018-03-14 22:44:45 -0400 | [diff] [blame] | 55 | RELEASE_TAG=${MVN_RELEASE_TAG:-R2} |
| 56 | if [ "$RELEASE_TAG" == "R1" ]; then |
| 57 | unset RELEASE_TAG |
| 58 | fi |
Lusheng Ji | 88648fc | 2017-09-20 02:18:20 +0000 | [diff] [blame] | 59 | |
| 60 | |
| 61 | # mvn phase in life cycle |
| 62 | MVN_PHASE="$2" |
| 63 | |
Lusheng Ji | 5a3dbbb | 2018-03-14 22:44:45 -0400 | [diff] [blame] | 64 | echo "MVN_RELEASE_TAG is [$MVN_RELEASE_TAG]" |
Lusheng Ji | 88648fc | 2017-09-20 02:18:20 +0000 | [diff] [blame] | 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]" |
Lusheng Ji | 00444ab | 2017-10-13 17:39:45 +0000 | [diff] [blame] | 76 | echo "MVN_DOCKERREGISTRY_SNAPSHOT is [$MVN_DOCKERREGISTRY_SNAPSHOT]" |
| 77 | echo "MVN_DOCKERREGISTRY_PUBLIC is [$MVN_DOCKERREGISTRY_PUBLIC]" |
Lusheng Ji | 88648fc | 2017-09-20 02:18:20 +0000 | [diff] [blame] | 78 | echo "MVN_DOCKERREGISTRY_RELEASE is [$MVN_DOCKERREGISTRY_RELEASE]" |
Lusheng Ji | 88648fc | 2017-09-20 02:18:20 +0000 | [diff] [blame] | 79 | echo "MVN_PYPISERVER_SERVERID [$MVN_PYPISERVER_SERVERID]" |
| 80 | echo "MVN_PYPISERVER_BASEURL is [$MVN_PYPISERVER_BASEURL]" |
| 81 | |
| 82 | |
| 83 | |
| 84 | clean_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 | } |
| 92 | clean_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 | |
| 101 | expand_templates() |
| 102 | { |
Lusheng Ji | 00444ab | 2017-10-13 17:39:45 +0000 | [diff] [blame] | 103 | set +x |
Lusheng Ji | 88648fc | 2017-09-20 02:18:20 +0000 | [diff] [blame] | 104 | # 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 Ji | 5a3dbbb | 2018-03-14 22:44:45 -0400 | [diff] [blame] | 110 | |
| 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 Ji | 88648fc | 2017-09-20 02:18:20 +0000 | [diff] [blame] | 128 | |
Lusheng Ji | 00444ab | 2017-10-13 17:39:45 +0000 | [diff] [blame] | 129 | export ONAPTEMPLATE_PYPIURL_org_onap_dcaegen2="${MVN_PYPISERVER_BASEURL}" |
Lusheng Ji | 88648fc | 2017-09-20 02:18:20 +0000 | [diff] [blame] | 130 | |
Lusheng Ji | 00444ab | 2017-10-13 17:39:45 +0000 | [diff] [blame] | 131 | # docker registry templates are for poll, so use PUBLIC registry |
Lusheng Ji | 5a3dbbb | 2018-03-14 22:44:45 -0400 | [diff] [blame] | 132 | export ONAPTEMPLATE_DOCKERREGURL_org_onap_dcaegen2_releases="${MVN_DOCKERREGISTRY_PUBLIC}" |
| 133 | export ONAPTEMPLATE_DOCKERREGURL_org_onap_dcaegen2_snapshots="${MVN_DOCKERREGISTRY_PUBLIC}" |
Lusheng Ji | 88648fc | 2017-09-20 02:18:20 +0000 | [diff] [blame] | 134 | |
Lusheng Ji | 00444ab | 2017-10-13 17:39:45 +0000 | [diff] [blame] | 135 | # 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 Ji | 88648fc | 2017-09-20 02:18:20 +0000 | [diff] [blame] | 174 | |
| 175 | TEMPLATE_FILES=$(find . -name "*-template") |
| 176 | for F in $TEMPLATE_FILES; do |
| 177 | F2=$(echo "$F" | sed 's/-template$//') |
Lusheng Ji | 00444ab | 2017-10-13 17:39:45 +0000 | [diff] [blame] | 178 | cp -p "$F" "$F2" |
| 179 | chmod u+w "$F2" |
Lusheng Ji | 88648fc | 2017-09-20 02:18:20 +0000 | [diff] [blame] | 180 | |
Lusheng Ji | 00444ab | 2017-10-13 17:39:45 +0000 | [diff] [blame] | 181 | 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 Ji | 88648fc | 2017-09-20 02:18:20 +0000 | [diff] [blame] | 186 | |
Lusheng Ji | 00444ab | 2017-10-13 17:39:45 +0000 | [diff] [blame] | 187 | 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 Ji | 88648fc | 2017-09-20 02:18:20 +0000 | [diff] [blame] | 193 | |
Lusheng Ji | 00444ab | 2017-10-13 17:39:45 +0000 | [diff] [blame] | 194 | test_templates() |
| 195 | { |
| 196 | # make certain that the type references exist |
| 197 | TMP=$(mktemp) |
| 198 | trap 'rm -f $TMP' 0 1 2 3 15 |
Lusheng Ji | 88648fc | 2017-09-20 02:18:20 +0000 | [diff] [blame] | 199 | |
Lusheng Ji | 00444ab | 2017-10-13 17:39:45 +0000 | [diff] [blame] | 200 | 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 Ji | 5a3dbbb | 2018-03-14 22:44:45 -0400 | [diff] [blame] | 204 | egrep '^ - .?https?://' < "$file" |
Lusheng Ji | 00444ab | 2017-10-13 17:39:45 +0000 | [diff] [blame] | 205 | done | awk '{print $2}' | sed -e 's/"//g' | sort -u | |
| 206 | while read url |
| 207 | do |
Lusheng Ji | 5a3dbbb | 2018-03-14 22:44:45 -0400 | [diff] [blame] | 208 | curl -L -w '%{http_code}' -s -o /dev/null "$url" > "$TMP" |
| 209 | case $(< "$TMP") in |
Lusheng Ji | 00444ab | 2017-10-13 17:39:45 +0000 | [diff] [blame] | 210 | 2* ) ;; |
| 211 | * ) echo ">>>>>>>>>>>>>>>> $url not found <<<<<<<<<<<<<<<<" ;; |
| 212 | esac |
Lusheng Ji | 88648fc | 2017-09-20 02:18:20 +0000 | [diff] [blame] | 213 | done |
| 214 | |
Lusheng Ji | 00444ab | 2017-10-13 17:39:45 +0000 | [diff] [blame] | 215 | 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 Ji | 5a3dbbb | 2018-03-14 22:44:45 -0400 | [diff] [blame] | 220 | check-blueprint-vs-input -b "$blueprint" -i check-blueprint-vs-input/lib/sample-inputs.yaml || true |
Lusheng Ji | 00444ab | 2017-10-13 17:39:45 +0000 | [diff] [blame] | 221 | done |
Lusheng Ji | 88648fc | 2017-09-20 02:18:20 +0000 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | |
| 225 | run_tox_test() |
| 226 | { |
Andrew Gauld | 373f0f3 | 2018-02-21 11:14:46 -0500 | [diff] [blame] | 227 | set -e -x |
Lusheng Ji | 88648fc | 2017-09-20 02:18:20 +0000 | [diff] [blame] | 228 | 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 | |
| 245 | build_wagons() |
| 246 | { |
| 247 | rm -rf ./*.wgn venv-pkg |
Lusheng Ji | 88648fc | 2017-09-20 02:18:20 +0000 | [diff] [blame] | 248 | SETUPFILES=$(find . -name "setup.py") |
Lusheng Ji | 00444ab | 2017-10-13 17:39:45 +0000 | [diff] [blame] | 249 | |
| 250 | virtualenv ./venv-pkg |
| 251 | source ./venv-pkg/bin/activate |
| 252 | pip install --upgrade pip |
| 253 | pip install wagon |
| 254 | |
| 255 | CURDIR=$(pwd) |
Lusheng Ji | 88648fc | 2017-09-20 02:18:20 +0000 | [diff] [blame] | 256 | for SETUPFILE in $SETUPFILES; do |
Lusheng Ji | 00444ab | 2017-10-13 17:39:45 +0000 | [diff] [blame] | 257 | PLUGIN_DIR=$(dirname "$SETUPFILE") |
Lusheng Ji | 88648fc | 2017-09-20 02:18:20 +0000 | [diff] [blame] | 258 | 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 Ji | 00444ab | 2017-10-13 17:39:45 +0000 | [diff] [blame] | 261 | echo "In $PLUGIN_DIR, build plugin $PLUGIN_NAME, version $PLUGIN_VERSION" |
Lusheng Ji | 88648fc | 2017-09-20 02:18:20 +0000 | [diff] [blame] | 262 | |
Lusheng Ji | 7ed3376 | 2018-03-05 08:10:18 -0500 | [diff] [blame] | 263 | wagon create -r "${PLUGIN_DIR}/requirements.txt" --format tar.gz "${PLUGIN_DIR}" |
Lusheng Ji | 88648fc | 2017-09-20 02:18:20 +0000 | [diff] [blame] | 264 | |
| 265 | PKG_FILE_NAMES=( "${PLUGIN_NAME}-${PLUGIN_VERSION}"*.wgn ) |
| 266 | echo Built package: "${PKG_FILE_NAMES[@]}" |
Lusheng Ji | 5a3dbbb | 2018-03-14 22:44:45 -0400 | [diff] [blame] | 267 | cd "$CURDIR" |
Lusheng Ji | 88648fc | 2017-09-20 02:18:20 +0000 | [diff] [blame] | 268 | done |
Lusheng Ji | 00444ab | 2017-10-13 17:39:45 +0000 | [diff] [blame] | 269 | |
| 270 | deactivate |
| 271 | rm -rf venv-pkg |
Lusheng Ji | 88648fc | 2017-09-20 02:18:20 +0000 | [diff] [blame] | 272 | } |
| 273 | |
Lusheng Ji | a1e8332 | 2018-03-18 22:23:18 -0400 | [diff] [blame] | 274 | build_archives_for_wagons() |
| 275 | { |
Lusheng Ji | a3361d3 | 2018-03-19 13:40:31 -0400 | [diff] [blame] | 276 | rm -rf ./*.tgz ./*.zip venv-pkg |
Lusheng Ji | a1e8332 | 2018-03-18 22:23:18 -0400 | [diff] [blame] | 277 | |
Lusheng Ji | 0ce8925 | 2018-03-20 10:12:41 -0400 | [diff] [blame^] | 278 | SETUPFILES=$(find "$(pwd)" -name "setup.py") |
Lusheng Ji | a1e8332 | 2018-03-18 22:23:18 -0400 | [diff] [blame] | 279 | CURDIR=$(pwd) |
| 280 | for SETUPFILE in $SETUPFILES; do |
Lusheng Ji | b99b3c8 | 2018-03-19 22:38:58 -0400 | [diff] [blame] | 281 | PLUGIN_FULL_DIR=$(dirname "$SETUPFILE") |
Lusheng Ji | 0ce8925 | 2018-03-20 10:12:41 -0400 | [diff] [blame^] | 282 | PLUGIN_BASE_DIR=$(basename "$PLUGIN_FULL_DIR") |
Lusheng Ji | a1e8332 | 2018-03-18 22:23:18 -0400 | [diff] [blame] | 283 | 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 Ji | 0ce8925 | 2018-03-20 10:12:41 -0400 | [diff] [blame^] | 286 | cd "${PLUGIN_FULL_DIR}"/.. |
Lusheng Ji | a1e8332 | 2018-03-18 22:23:18 -0400 | [diff] [blame] | 287 | echo "In $(pwd), build plugin zip $PLUGIN_NAME, version $PLUGIN_VERSION" |
| 288 | |
Lusheng Ji | 32433a5 | 2018-03-20 08:55:50 -0400 | [diff] [blame] | 289 | zip -r "${PLUGIN_NAME}-${PLUGIN_VERSION}.zip" "./${PLUGIN_BASE_DIR}" |
Lusheng Ji | b99b3c8 | 2018-03-19 22:38:58 -0400 | [diff] [blame] | 290 | tar -czvf "${PLUGIN_NAME}-${PLUGIN_VERSION}.tgz" "./${PLUGIN_BASE_DIR}" |
Lusheng Ji | a1e8332 | 2018-03-18 22:23:18 -0400 | [diff] [blame] | 291 | |
Lusheng Ji | b99b3c8 | 2018-03-19 22:38:58 -0400 | [diff] [blame] | 292 | echo "Built archives for package ${PLUGIN_NAME}-${PLUGIN_VERSION} at $(pwd)" |
Lusheng Ji | a1e8332 | 2018-03-18 22:23:18 -0400 | [diff] [blame] | 293 | cd "$CURDIR" |
| 294 | done |
Lusheng Ji | a1e8332 | 2018-03-18 22:23:18 -0400 | [diff] [blame] | 295 | } |
| 296 | |
Lusheng Ji | 88648fc | 2017-09-20 02:18:20 +0000 | [diff] [blame] | 297 | |
| 298 | upload_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 Ji | a3361d3 | 2018-03-19 13:40:31 -0400 | [diff] [blame] | 316 | elif [ "$EXT" == 'tgz' ]; then |
| 317 | OUTPUT_FILE_TYPE='application/gzip' |
| 318 | elif [ "$EXT" == 'zip' ]; then |
| 319 | OUTPUT_FILE_TYPE='application/zip' |
Lusheng Ji | 88648fc | 2017-09-20 02:18:20 +0000 | [diff] [blame] | 320 | elif [ "$EXT" == 'wgn' ]; then |
| 321 | OUTPUT_FILE_TYPE='application/gzip' |
| 322 | else |
| 323 | OUTPUT_FILE_TYPE='application/octet-stream' |
| 324 | fi |
| 325 | |
Lusheng Ji | 00444ab | 2017-10-13 17:39:45 +0000 | [diff] [blame] | 326 | # 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 Ji | 7ed3376 | 2018-03-05 08:10:18 -0500 | [diff] [blame] | 334 | |
Lusheng Ji | 5a3dbbb | 2018-03-14 22:44:45 -0400 | [diff] [blame] | 335 | if [ -z "$RELEASE_TAG" ]; then |
| 336 | SEND_TO="${REPO}/${PROJECT_NAME}" |
| 337 | else |
| 338 | SEND_TO="${REPO}/${PROJECT_NAME}/${RELEASE_TAG}" |
| 339 | fi |
Lusheng Ji | 7ed3376 | 2018-03-05 08:10:18 -0500 | [diff] [blame] | 340 | |
Lusheng Ji | 00444ab | 2017-10-13 17:39:45 +0000 | [diff] [blame] | 341 | if [ ! -z "$2" ]; then |
| 342 | SEND_TO="$SEND_TO/$2" |
Lusheng Ji | d4c05d0 | 2017-09-21 03:22:18 +0000 | [diff] [blame] | 343 | fi |
Lusheng Ji | 88648fc | 2017-09-20 02:18:20 +0000 | [diff] [blame] | 344 | |
| 345 | echo "Sending ${OUTPUT_FILE} to Nexus: ${SEND_TO}" |
Lusheng Ji | 00444ab | 2017-10-13 17:39:45 +0000 | [diff] [blame] | 346 | curl -vkn --netrc-file "${NETRC}" --upload-file "${OUTPUT_FILE}" -X PUT -H "Content-Type: $OUTPUT_FILE_TYPE" "${SEND_TO}/${OUTPUT_FILE}-${TIMESTAMP}" |
Lusheng Ji | 88648fc | 2017-09-20 02:18:20 +0000 | [diff] [blame] | 347 | curl -vkn --netrc-file "${NETRC}" --upload-file "${OUTPUT_FILE}" -X PUT -H "Content-Type: $OUTPUT_FILE_TYPE" "${SEND_TO}/${OUTPUT_FILE}" |
| 348 | } |
| 349 | |
Lusheng Ji | a1e8332 | 2018-03-18 22:23:18 -0400 | [diff] [blame] | 350 | upload_wagon_archives() |
| 351 | { |
Lusheng Ji | 0ce8925 | 2018-03-20 10:12:41 -0400 | [diff] [blame^] | 352 | SETUPFILES=$(find "$(pwd)" -name "setup.py") |
Lusheng Ji | a1e8332 | 2018-03-18 22:23:18 -0400 | [diff] [blame] | 353 | CURDIR=$(pwd) |
| 354 | for SETUPFILE in $SETUPFILES; do |
Lusheng Ji | b99b3c8 | 2018-03-19 22:38:58 -0400 | [diff] [blame] | 355 | PLUGIN_FULL_DIR=$(dirname "$SETUPFILE") |
Lusheng Ji | 0ce8925 | 2018-03-20 10:12:41 -0400 | [diff] [blame^] | 356 | PLUGIN_BASE_DIR=$(basename "$PLUGIN_FULL_DIR") |
Lusheng Ji | a1e8332 | 2018-03-18 22:23:18 -0400 | [diff] [blame] | 357 | 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 Ji | 88648fc | 2017-09-20 02:18:20 +0000 | [diff] [blame] | 359 | |
Lusheng Ji | 0ce8925 | 2018-03-20 10:12:41 -0400 | [diff] [blame^] | 360 | cd "${PLUGIN_FULL_DIR}"/.. |
Lusheng Ji | a1e8332 | 2018-03-18 22:23:18 -0400 | [diff] [blame] | 361 | 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 Ji | 0ce8925 | 2018-03-20 10:12:41 -0400 | [diff] [blame^] | 377 | cd "${CURDIR}" |
Lusheng Ji | a1e8332 | 2018-03-18 22:23:18 -0400 | [diff] [blame] | 378 | done |
| 379 | } |
Lusheng Ji | 88648fc | 2017-09-20 02:18:20 +0000 | [diff] [blame] | 380 | |
| 381 | upload_wagons_and_type_yamls() |
| 382 | { |
Lusheng Ji | 00444ab | 2017-10-13 17:39:45 +0000 | [diff] [blame] | 383 | 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 Ji | 5a3dbbb | 2018-03-14 22:44:45 -0400 | [diff] [blame] | 406 | 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 Ji | 00444ab | 2017-10-13 17:39:45 +0000 | [diff] [blame] | 408 | 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 Ji | 7ed3376 | 2018-03-05 08:10:18 -0500 | [diff] [blame] | 414 | upload_raw_file "${NEWFILENAME}" "${PLUGIN_NAME}/${PLUGIN_VERSION}" |
| 415 | upload_raw_file "${WAGONFILE_NAME}" "${PLUGIN_NAME}/${PLUGIN_VERSION}" |
Lusheng Ji | 88648fc | 2017-09-20 02:18:20 +0000 | [diff] [blame] | 416 | |
Lusheng Ji | 5a3dbbb | 2018-03-14 22:44:45 -0400 | [diff] [blame] | 417 | rm -r "$WAGONFILE_NAME" |
Lusheng Ji | 00444ab | 2017-10-13 17:39:45 +0000 | [diff] [blame] | 418 | if [ "$TYPEFILE_NAME" != "$NEWFILENAME" ]; then |
| 419 | rm -f "$NEWFILENAME" |
| 420 | fi |
Lusheng Ji | 88648fc | 2017-09-20 02:18:20 +0000 | [diff] [blame] | 421 | done |
| 422 | } |
| 423 | |
| 424 | upload_files_of_extension() |
| 425 | { |
| 426 | FILES=$(ls -1 ./*."$1") |
| 427 | for F in $FILES ; do |
Lusheng Ji | 00444ab | 2017-10-13 17:39:45 +0000 | [diff] [blame] | 428 | upload_raw_file "$F" "$2" |
Lusheng Ji | 88648fc | 2017-09-20 02:18:20 +0000 | [diff] [blame] | 429 | done |
| 430 | } |
| 431 | |
| 432 | |
| 433 | generate_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] |
| 446 | index-servers = |
| 447 | $MVN_PYPISERVER_SERVERID |
| 448 | |
| 449 | [$MVN_PYPISERVER_SERVERID] |
| 450 | repository: $MVN_PYPISERVER_BASEURL |
| 451 | username: $USER |
| 452 | password: $PASS |
| 453 | EOL |
| 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 Ji | 5a3dbbb | 2018-03-14 22:44:45 -0400 | [diff] [blame] | 462 | # following the https://wiki.onap.org/display/DW/Independent+Versioning+and+Release+Process |
| 463 | #IndependentVersioningandReleaseProcess-StandardizedDockerTagging |
Lusheng Ji | 88648fc | 2017-09-20 02:18:20 +0000 | [diff] [blame] | 464 | build_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 Ji | 5a3dbbb | 2018-03-14 22:44:45 -0400 | [diff] [blame] | 478 | # all local builds push to SNAPSHOT repo |
Lusheng Ji | 88648fc | 2017-09-20 02:18:20 +0000 | [diff] [blame] | 479 | REPO="" |
| 480 | if [ $MVN_DEPLOYMENT_TYPE == "SNAPSHOT" ]; then |
Lusheng Ji | 5a3dbbb | 2018-03-14 22:44:45 -0400 | [diff] [blame] | 481 | REPO=$MVN_DOCKERREGISTRY_SNAPSHOT |
Lusheng Ji | 88648fc | 2017-09-20 02:18:20 +0000 | [diff] [blame] | 482 | elif [ $MVN_DEPLOYMENT_TYPE == "STAGING" ]; then |
Lusheng Ji | 5a3dbbb | 2018-03-14 22:44:45 -0400 | [diff] [blame] | 483 | REPO=$MVN_DOCKERREGISTRY_SNAPSHOT |
Lusheng Ji | 88648fc | 2017-09-20 02:18:20 +0000 | [diff] [blame] | 484 | else |
| 485 | echo "Fail to determine DEPLOYMENT_TYPE" |
Lusheng Ji | 00444ab | 2017-10-13 17:39:45 +0000 | [diff] [blame] | 486 | REPO=$MVN_DOCKERREGISTRY_SNAPSHOT |
Lusheng Ji | 88648fc | 2017-09-20 02:18:20 +0000 | [diff] [blame] | 487 | 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 Ji | 5a3dbbb | 2018-03-14 22:44:45 -0400 | [diff] [blame] | 503 | # local tag is imagename:version-timestamp |
Lusheng Ji | 88648fc | 2017-09-20 02:18:20 +0000 | [diff] [blame] | 504 | OLDTAG="${LFQI}" |
Lusheng Ji | 5a3dbbb | 2018-03-14 22:44:45 -0400 | [diff] [blame] | 505 | #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 Ji | 88648fc | 2017-09-20 02:18:20 +0000 | [diff] [blame] | 511 | 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 Ji | 88648fc | 2017-09-20 02:18:20 +0000 | [diff] [blame] | 520 | } |