blob: 6f6805848c2ebb25a6971d2d67589a573edf8f7b [file] [log] [blame]
mmis824a75e2018-03-02 18:04:48 +00001#!/bin/bash
Pamela Dragosh7bfe2222018-04-16 09:40:04 -04002# 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
mmis824a75e2018-03-02 18:04:48 +000016#
17echo '============== STARTING SCRIPT TO BUILD DOCKER IMAGES ================='
18DOCKER_REPOSITORY=nexus3.onap.org:10003
19MVN_VERSION=$(cat packages/docker/target/version)
20MVN_MAJMIN_VERSION=$(cut -f 1,2 -d . packages/docker/target/version)
21TIMESTAMP=$(date -u +%Y%m%dT%H%M%S)
Jorge Hernandez3ad27752018-04-30 17:24:44 -050022BUILD_ARGS="--build-arg BUILD_VERSION=${MVN_VERSION}"
mmis824a75e2018-03-02 18:04:48 +000023IMAGE=policy-drools
24
25if [ $HTTP_PROXY ]; then
Jorge Hernandez3ad27752018-04-30 17:24:44 -050026 BUILD_ARGS+=" --build-arg HTTP_PROXY=${HTTP_PROXY}"
mmis824a75e2018-03-02 18:04:48 +000027fi
Jorge Hernandez3ad27752018-04-30 17:24:44 -050028
mmis824a75e2018-03-02 18:04:48 +000029if [ $HTTPS_PROXY ]; then
Jorge Hernandez3ad27752018-04-30 17:24:44 -050030 BUILD_ARGS+=" --build-arg HTTPS_PROXY=${HTTPS_PROXY}"
mmis824a75e2018-03-02 18:04:48 +000031fi
32
33echo $DOCKER_REPOSITORY
34echo $MVN_VERSION
35echo $MVN_MAJMIN_VERSION
36echo $TIMESTAMP
37
38if [[ -z $MVN_VERSION ]]
39then
40 echo "MVN_VERSION is empty"
41 exit 1
42fi
43
44if [[ -z $MVN_MAJMIN_VERSION ]]
45then
46 echo "MVN_MAJMIN_VERSION is empty"
47 exit 1
48fi
49
50if [[ $MVN_VERSION == *"SNAPSHOT"* ]]
51then
52 MVN_MAJMIN_VERSION="${MVN_MAJMIN_VERSION}-SNAPSHOT"
53else
54 MVN_MAJMIN_VERSION="${MVN_MAJMIN_VERSION}-STAGING"
55fi
56
57echo $MVN_MAJMIN_VERSION
58
59echo "Building $IMAGE"
mmis824a75e2018-03-02 18:04:48 +000060
61#
62# This is the local latest tagged image. The Dockerfile's need this to build images
63#
mmisac6780a2018-03-14 12:10:52 +000064TAGS="--tag onap/${IMAGE}:latest"
mmis824a75e2018-03-02 18:04:48 +000065#
66# This is the nexus repo prepended for latest tagged image.
67#
mmisac6780a2018-03-14 12:10:52 +000068TAGS="${TAGS} --tag ${DOCKER_REPOSITORY}/onap/${IMAGE}:latest"
mmis824a75e2018-03-02 18:04:48 +000069#
70# This has the nexus repo prepended and only major/minor version with latest
71#
mmisac6780a2018-03-14 12:10:52 +000072TAGS="${TAGS} --tag ${DOCKER_REPOSITORY}/onap/${IMAGE}:${MVN_MAJMIN_VERSION}-latest"
mmis824a75e2018-03-02 18:04:48 +000073#
74# This has the nexus repo prepended and major/minor/patch version with timestamp
75#
mmis43380df2018-03-29 09:47:04 +010076TAGS="${TAGS} --tag ${DOCKER_REPOSITORY}/onap/${IMAGE}:${MVN_VERSION}-STAGING-${TIMESTAMP}Z"
mmis824a75e2018-03-02 18:04:48 +000077
78echo $TAGS
79
Jorge Hernandez3ad27752018-04-30 17:24:44 -050080docker build --quiet ${BUILD_ARGS} $TAGS packages/docker/target/$IMAGE
mmis824a75e2018-03-02 18:04:48 +000081
82if [ $? -ne 0 ]
83then
84 echo "Docker build failed"
85 docker images
86 exit 1
87fi
88
89docker images
90
91echo "Pushing $IMAGE"
92
mmisac6780a2018-03-14 12:10:52 +000093docker push ${DOCKER_REPOSITORY}/onap/${IMAGE}:latest
mmis824a75e2018-03-02 18:04:48 +000094
95if [ $? -ne 0 ]
96then
97 echo "Docker push failed"
98 exit 1
99
100fi
101
mmisac6780a2018-03-14 12:10:52 +0000102docker push ${DOCKER_REPOSITORY}/onap/${IMAGE}:${MVN_MAJMIN_VERSION}-latest
mmis824a75e2018-03-02 18:04:48 +0000103
104if [ $? -ne 0 ]
105then
106 echo "Docker push failed"
107 exit 1
108
109fi
mmis43380df2018-03-29 09:47:04 +0100110docker push ${DOCKER_REPOSITORY}/onap/${IMAGE}:${MVN_VERSION}-STAGING-${TIMESTAMP}Z
mmis824a75e2018-03-02 18:04:48 +0000111
112if [ $? -ne 0 ]
113then
114 echo "Docker push failed"
115 exit 1
116
117fi
118