mmis | 824a75e | 2018-03-02 18:04:48 +0000 | [diff] [blame] | 1 | #!/bin/bash |
Jorge Hernandez | b001c1a | 2019-02-28 10:10:49 -0600 | [diff] [blame] | 2 | # Copyright 2018-2019 AT&T Intellectual Property. All rights reserved |
Pamela Dragosh | 7bfe222 | 2018-04-16 09:40:04 -0400 | [diff] [blame] | 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) |
jhh | 7df0f4e | 2019-04-26 12:01:14 -0500 | [diff] [blame] | 22 | BUILD_ARGS="--build-arg BUILD_VERSION_DROOLS=${MVN_VERSION}" |
mmis | 824a75e | 2018-03-02 18:04:48 +0000 | [diff] [blame] | 23 | IMAGE=policy-drools |
| 24 | |
mmis | 824a75e | 2018-03-02 18:04:48 +0000 | [diff] [blame] | 25 | echo $DOCKER_REPOSITORY |
| 26 | echo $MVN_VERSION |
| 27 | echo $MVN_MAJMIN_VERSION |
| 28 | echo $TIMESTAMP |
| 29 | |
| 30 | if [[ -z $MVN_VERSION ]] |
| 31 | then |
| 32 | echo "MVN_VERSION is empty" |
| 33 | exit 1 |
| 34 | fi |
| 35 | |
| 36 | if [[ -z $MVN_MAJMIN_VERSION ]] |
| 37 | then |
| 38 | echo "MVN_MAJMIN_VERSION is empty" |
| 39 | exit 1 |
| 40 | fi |
| 41 | |
| 42 | if [[ $MVN_VERSION == *"SNAPSHOT"* ]] |
| 43 | then |
| 44 | MVN_MAJMIN_VERSION="${MVN_MAJMIN_VERSION}-SNAPSHOT" |
| 45 | else |
| 46 | MVN_MAJMIN_VERSION="${MVN_MAJMIN_VERSION}-STAGING" |
| 47 | fi |
| 48 | |
| 49 | echo $MVN_MAJMIN_VERSION |
| 50 | |
jhh | f8b78e9 | 2019-04-25 15:32:13 -0500 | [diff] [blame] | 51 | docker login -u docker -p docker nexus3.onap.org:10001 |
| 52 | docker pull nexus3.onap.org:10001/onap/policy-common-alpine:1.4.0 |
| 53 | docker tag nexus3.onap.org:10001/onap/policy-common-alpine:1.4.0 onap/policy-common-alpine:1.4.0 |
| 54 | |
mmis | 824a75e | 2018-03-02 18:04:48 +0000 | [diff] [blame] | 55 | echo "Building $IMAGE" |
mmis | 824a75e | 2018-03-02 18:04:48 +0000 | [diff] [blame] | 56 | |
| 57 | # |
| 58 | # This is the local latest tagged image. The Dockerfile's need this to build images |
| 59 | # |
mmis | ac6780a | 2018-03-14 12:10:52 +0000 | [diff] [blame] | 60 | TAGS="--tag onap/${IMAGE}:latest" |
mmis | 824a75e | 2018-03-02 18:04:48 +0000 | [diff] [blame] | 61 | # |
| 62 | # This is the nexus repo prepended for latest tagged image. |
| 63 | # |
mmis | ac6780a | 2018-03-14 12:10:52 +0000 | [diff] [blame] | 64 | TAGS="${TAGS} --tag ${DOCKER_REPOSITORY}/onap/${IMAGE}:latest" |
mmis | 824a75e | 2018-03-02 18:04:48 +0000 | [diff] [blame] | 65 | # |
| 66 | # This has the nexus repo prepended and only major/minor version with latest |
| 67 | # |
mmis | ac6780a | 2018-03-14 12:10:52 +0000 | [diff] [blame] | 68 | TAGS="${TAGS} --tag ${DOCKER_REPOSITORY}/onap/${IMAGE}:${MVN_MAJMIN_VERSION}-latest" |
mmis | 824a75e | 2018-03-02 18:04:48 +0000 | [diff] [blame] | 69 | # |
| 70 | # This has the nexus repo prepended and major/minor/patch version with timestamp |
| 71 | # |
mmis | 43380df | 2018-03-29 09:47:04 +0100 | [diff] [blame] | 72 | TAGS="${TAGS} --tag ${DOCKER_REPOSITORY}/onap/${IMAGE}:${MVN_VERSION}-STAGING-${TIMESTAMP}Z" |
mmis | 824a75e | 2018-03-02 18:04:48 +0000 | [diff] [blame] | 73 | |
| 74 | echo $TAGS |
| 75 | |
Jorge Hernandez | 3ad2775 | 2018-04-30 17:24:44 -0500 | [diff] [blame] | 76 | docker build --quiet ${BUILD_ARGS} $TAGS packages/docker/target/$IMAGE |
mmis | 824a75e | 2018-03-02 18:04:48 +0000 | [diff] [blame] | 77 | |
| 78 | if [ $? -ne 0 ] |
| 79 | then |
| 80 | echo "Docker build failed" |
| 81 | docker images |
| 82 | exit 1 |
| 83 | fi |
| 84 | |
| 85 | docker images |
| 86 | |
| 87 | echo "Pushing $IMAGE" |
| 88 | |
mmis | ac6780a | 2018-03-14 12:10:52 +0000 | [diff] [blame] | 89 | docker push ${DOCKER_REPOSITORY}/onap/${IMAGE}:latest |
mmis | 824a75e | 2018-03-02 18:04:48 +0000 | [diff] [blame] | 90 | |
| 91 | if [ $? -ne 0 ] |
| 92 | then |
| 93 | echo "Docker push failed" |
| 94 | exit 1 |
| 95 | |
| 96 | fi |
| 97 | |
mmis | ac6780a | 2018-03-14 12:10:52 +0000 | [diff] [blame] | 98 | docker push ${DOCKER_REPOSITORY}/onap/${IMAGE}:${MVN_MAJMIN_VERSION}-latest |
mmis | 824a75e | 2018-03-02 18:04:48 +0000 | [diff] [blame] | 99 | |
| 100 | if [ $? -ne 0 ] |
| 101 | then |
| 102 | echo "Docker push failed" |
| 103 | exit 1 |
| 104 | |
| 105 | fi |
mmis | 43380df | 2018-03-29 09:47:04 +0100 | [diff] [blame] | 106 | docker push ${DOCKER_REPOSITORY}/onap/${IMAGE}:${MVN_VERSION}-STAGING-${TIMESTAMP}Z |
mmis | 824a75e | 2018-03-02 18:04:48 +0000 | [diff] [blame] | 107 | |
| 108 | if [ $? -ne 0 ] |
| 109 | then |
| 110 | echo "Docker push failed" |
| 111 | exit 1 |
| 112 | |
| 113 | fi |
| 114 | |