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