mmis | 1336873 | 2018-03-01 16:50:11 +0000 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
Jim Hahn | daee922 | 2018-04-19 11:28:41 -0400 | [diff] [blame] | 3 | #============LICENSE_START================================================== |
| 4 | # ONAP Policy Engine |
| 5 | #=========================================================================== |
| 6 | # Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. |
| 7 | #=========================================================================== |
| 8 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 9 | # you may not use this file except in compliance with the License. |
| 10 | # You may obtain a copy of the License at |
| 11 | # |
| 12 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 13 | # |
| 14 | # Unless required by applicable law or agreed to in writing, software |
| 15 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 16 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 | # See the License for the specific language governing permissions and |
| 18 | # limitations under the License. |
| 19 | #============LICENSE_END================================================== |
| 20 | # |
| 21 | |
| 22 | # |
mmis | 1336873 | 2018-03-01 16:50:11 +0000 | [diff] [blame] | 23 | echo '============== STARTING SCRIPT TO BUILD DOCKER IMAGES =================' |
| 24 | DOCKER_REPOSITORY=nexus3.onap.org:10003 |
| 25 | MVN_VERSION=$(cat packages/docker/target/version) |
| 26 | MVN_MAJMIN_VERSION=$(cut -f 1,2 -d . packages/docker/target/version) |
| 27 | TIMESTAMP=$(date -u +%Y%m%dT%H%M%S) |
Jorge Hernandez | 973929c | 2018-05-07 18:22:12 -0500 | [diff] [blame] | 28 | BUILD_ARGS="--build-arg BUILD_VERSION=${MVN_VERSION}" |
mmis | 1336873 | 2018-03-01 16:50:11 +0000 | [diff] [blame] | 29 | IMAGE=policy-pe |
| 30 | |
| 31 | if [ $HTTP_PROXY ]; then |
Jorge Hernandez | 973929c | 2018-05-07 18:22:12 -0500 | [diff] [blame] | 32 | BUILD_ARGS+=" --build-arg HTTP_PROXY=${HTTP_PROXY}" |
mmis | 1336873 | 2018-03-01 16:50:11 +0000 | [diff] [blame] | 33 | fi |
| 34 | if [ $HTTPS_PROXY ]; then |
Jorge Hernandez | 973929c | 2018-05-07 18:22:12 -0500 | [diff] [blame] | 35 | BUILD_ARGS+=" --build-arg HTTPS_PROXY=${HTTPS_PROXY}" |
mmis | 1336873 | 2018-03-01 16:50:11 +0000 | [diff] [blame] | 36 | fi |
| 37 | |
| 38 | echo $DOCKER_REPOSITORY |
| 39 | echo $MVN_VERSION |
| 40 | echo $MVN_MAJMIN_VERSION |
| 41 | echo $TIMESTAMP |
| 42 | |
| 43 | if [[ -z $MVN_VERSION ]] |
| 44 | then |
| 45 | echo "MVN_VERSION is empty" |
| 46 | exit 1 |
| 47 | fi |
| 48 | |
| 49 | if [[ -z $MVN_MAJMIN_VERSION ]] |
| 50 | then |
| 51 | echo "MVN_MAJMIN_VERSION is empty" |
| 52 | exit 1 |
| 53 | fi |
| 54 | |
| 55 | if [[ $MVN_VERSION == *"SNAPSHOT"* ]] |
| 56 | then |
| 57 | MVN_MAJMIN_VERSION="${MVN_MAJMIN_VERSION}-SNAPSHOT" |
| 58 | else |
| 59 | MVN_MAJMIN_VERSION="${MVN_MAJMIN_VERSION}-STAGING" |
| 60 | fi |
| 61 | |
| 62 | echo $MVN_MAJMIN_VERSION |
| 63 | |
| 64 | echo "Building $IMAGE" |
mmis | 1336873 | 2018-03-01 16:50:11 +0000 | [diff] [blame] | 65 | |
| 66 | # |
| 67 | # This is the local latest tagged image. The Dockerfile's need this to build images |
| 68 | # |
mmis | 4ea6678 | 2018-03-14 12:03:37 +0000 | [diff] [blame] | 69 | TAGS="--tag onap/${IMAGE}:latest" |
mmis | 1336873 | 2018-03-01 16:50:11 +0000 | [diff] [blame] | 70 | # |
| 71 | # This is the nexus repo prepended for latest tagged image. |
| 72 | # |
mmis | 4ea6678 | 2018-03-14 12:03:37 +0000 | [diff] [blame] | 73 | TAGS="${TAGS} --tag ${DOCKER_REPOSITORY}/onap/${IMAGE}:latest" |
mmis | 1336873 | 2018-03-01 16:50:11 +0000 | [diff] [blame] | 74 | # |
| 75 | # This has the nexus repo prepended and only major/minor version with latest |
| 76 | # |
mmis | 4ea6678 | 2018-03-14 12:03:37 +0000 | [diff] [blame] | 77 | TAGS="${TAGS} --tag ${DOCKER_REPOSITORY}/onap/${IMAGE}:${MVN_MAJMIN_VERSION}-latest" |
mmis | 1336873 | 2018-03-01 16:50:11 +0000 | [diff] [blame] | 78 | # |
| 79 | # This has the nexus repo prepended and major/minor/patch version with timestamp |
| 80 | # |
mmis | d7eac78 | 2018-03-29 09:37:45 +0100 | [diff] [blame] | 81 | TAGS="${TAGS} --tag ${DOCKER_REPOSITORY}/onap/${IMAGE}:${MVN_VERSION}-STAGING-${TIMESTAMP}Z" |
mmis | 1336873 | 2018-03-01 16:50:11 +0000 | [diff] [blame] | 82 | |
| 83 | echo $TAGS |
| 84 | |
Jorge Hernandez | 973929c | 2018-05-07 18:22:12 -0500 | [diff] [blame] | 85 | docker build --quiet ${BUILD_ARGS} $TAGS packages/docker/target/$IMAGE |
mmis | 1336873 | 2018-03-01 16:50:11 +0000 | [diff] [blame] | 86 | |
| 87 | if [ $? -ne 0 ] |
| 88 | then |
| 89 | echo "Docker build failed" |
| 90 | docker images |
| 91 | exit 1 |
| 92 | fi |
| 93 | |
| 94 | docker images |
| 95 | |
| 96 | echo "Pushing $IMAGE" |
| 97 | |
mmis | 4ea6678 | 2018-03-14 12:03:37 +0000 | [diff] [blame] | 98 | docker push ${DOCKER_REPOSITORY}/onap/${IMAGE}:latest |
mmis | 1336873 | 2018-03-01 16:50:11 +0000 | [diff] [blame] | 99 | |
| 100 | if [ $? -ne 0 ] |
| 101 | then |
| 102 | echo "Docker push failed" |
| 103 | exit 1 |
| 104 | |
| 105 | fi |
| 106 | |
mmis | 4ea6678 | 2018-03-14 12:03:37 +0000 | [diff] [blame] | 107 | docker push ${DOCKER_REPOSITORY}/onap/${IMAGE}:${MVN_MAJMIN_VERSION}-latest |
mmis | 1336873 | 2018-03-01 16:50:11 +0000 | [diff] [blame] | 108 | |
| 109 | if [ $? -ne 0 ] |
| 110 | then |
| 111 | echo "Docker push failed" |
| 112 | exit 1 |
| 113 | |
| 114 | fi |
mmis | d7eac78 | 2018-03-29 09:37:45 +0100 | [diff] [blame] | 115 | docker push ${DOCKER_REPOSITORY}/onap/${IMAGE}:${MVN_VERSION}-STAGING-${TIMESTAMP}Z |
mmis | 1336873 | 2018-03-01 16:50:11 +0000 | [diff] [blame] | 116 | |
| 117 | if [ $? -ne 0 ] |
| 118 | then |
| 119 | echo "Docker push failed" |
| 120 | exit 1 |
| 121 | |
| 122 | fi |