blob: 20fa184cfd415944ab09a3768671205c063dcc06 [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
28if [ $HTTPS_PROXY ]; then
Jorge Hernandez3ad27752018-04-30 17:24:44 -050029 BUILD_ARGS+=" --build-arg HTTPS_PROXY=${HTTPS_PROXY}"
mmis824a75e2018-03-02 18:04:48 +000030fi
31
32echo $DOCKER_REPOSITORY
33echo $MVN_VERSION
34echo $MVN_MAJMIN_VERSION
35echo $TIMESTAMP
36
37if [[ -z $MVN_VERSION ]]
38then
39 echo "MVN_VERSION is empty"
40 exit 1
41fi
42
43if [[ -z $MVN_MAJMIN_VERSION ]]
44then
45 echo "MVN_MAJMIN_VERSION is empty"
46 exit 1
47fi
48
49if [[ $MVN_VERSION == *"SNAPSHOT"* ]]
50then
51 MVN_MAJMIN_VERSION="${MVN_MAJMIN_VERSION}-SNAPSHOT"
52else
53 MVN_MAJMIN_VERSION="${MVN_MAJMIN_VERSION}-STAGING"
54fi
55
56echo $MVN_MAJMIN_VERSION
57
58echo "Building $IMAGE"
mmis824a75e2018-03-02 18:04:48 +000059
60#
61# This is the local latest tagged image. The Dockerfile's need this to build images
62#
mmisac6780a2018-03-14 12:10:52 +000063TAGS="--tag onap/${IMAGE}:latest"
mmis824a75e2018-03-02 18:04:48 +000064#
65# This has the nexus repo prepended and only major/minor version with latest
66#
mmisac6780a2018-03-14 12:10:52 +000067TAGS="${TAGS} --tag ${DOCKER_REPOSITORY}/onap/${IMAGE}:${MVN_MAJMIN_VERSION}-latest"
mmis824a75e2018-03-02 18:04:48 +000068#
69# This has the nexus repo prepended and major/minor/patch version with timestamp
70#
mmis43380df2018-03-29 09:47:04 +010071TAGS="${TAGS} --tag ${DOCKER_REPOSITORY}/onap/${IMAGE}:${MVN_VERSION}-${TIMESTAMP}Z"
mmis824a75e2018-03-02 18:04:48 +000072
73echo $TAGS
74
Jorge Hernandez3ad27752018-04-30 17:24:44 -050075docker build --quiet ${BUILD_ARGS} $TAGS packages/docker/target/$IMAGE
mmis824a75e2018-03-02 18:04:48 +000076
77if [ $? -ne 0 ]
78then
79 echo "Docker build failed"
80 docker images
81 exit 1
82fi
83
84docker images
85
86#
87# Push image
88#
89echo "Pushing $IMAGE"
mmisac6780a2018-03-14 12:10:52 +000090docker push ${DOCKER_REPOSITORY}/onap/$IMAGE:${MVN_MAJMIN_VERSION}-latest
mmis824a75e2018-03-02 18:04:48 +000091
92if [ $? -ne 0 ]
93then
94 echo "Docker push failed"
95 exit 1
96fi
97
mmis43380df2018-03-29 09:47:04 +010098docker push ${DOCKER_REPOSITORY}/onap/$IMAGE:${MVN_VERSION}-${TIMESTAMP}Z
mmis824a75e2018-03-02 18:04:48 +000099
100if [ $? -ne 0 ]
101then
102 echo "Docker push failed"
103 exit 1
104fi
105