blob: 6f00f7e8b8aa27368ea1f6f52e72620e8dccf5ca [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)
22PROXY_ARGS=""
23IMAGE=policy-drools
24
25if [ $HTTP_PROXY ]; then
26 PROXY_ARGS+="--build-arg HTTP_PROXY=${HTTP_PROXY}"
27fi
28if [ $HTTPS_PROXY ]; then
29 PROXY_ARGS+=" --build-arg HTTPS_PROXY=${HTTPS_PROXY}"
30fi
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 is the nexus repo prepended for latest tagged image.
66#
mmisac6780a2018-03-14 12:10:52 +000067TAGS="${TAGS} --tag ${DOCKER_REPOSITORY}/onap/${IMAGE}:latest"
mmis824a75e2018-03-02 18:04:48 +000068#
69# This has the nexus repo prepended and only major/minor version with latest
70#
mmisac6780a2018-03-14 12:10:52 +000071TAGS="${TAGS} --tag ${DOCKER_REPOSITORY}/onap/${IMAGE}:${MVN_MAJMIN_VERSION}-latest"
mmis824a75e2018-03-02 18:04:48 +000072#
73# This has the nexus repo prepended and major/minor/patch version with timestamp
74#
mmis43380df2018-03-29 09:47:04 +010075TAGS="${TAGS} --tag ${DOCKER_REPOSITORY}/onap/${IMAGE}:${MVN_VERSION}-STAGING-${TIMESTAMP}Z"
mmis824a75e2018-03-02 18:04:48 +000076
77echo $TAGS
78
79docker build --quiet ${PROXY_ARGS} $TAGS packages/docker/target/$IMAGE
80
81if [ $? -ne 0 ]
82then
83 echo "Docker build failed"
84 docker images
85 exit 1
86fi
87
88docker images
89
90echo "Pushing $IMAGE"
91
mmisac6780a2018-03-14 12:10:52 +000092docker push ${DOCKER_REPOSITORY}/onap/${IMAGE}:latest
mmis824a75e2018-03-02 18:04:48 +000093
94if [ $? -ne 0 ]
95then
96 echo "Docker push failed"
97 exit 1
98
99fi
100
mmisac6780a2018-03-14 12:10:52 +0000101docker push ${DOCKER_REPOSITORY}/onap/${IMAGE}:${MVN_MAJMIN_VERSION}-latest
mmis824a75e2018-03-02 18:04:48 +0000102
103if [ $? -ne 0 ]
104then
105 echo "Docker push failed"
106 exit 1
107
108fi
mmis43380df2018-03-29 09:47:04 +0100109docker push ${DOCKER_REPOSITORY}/onap/${IMAGE}:${MVN_VERSION}-STAGING-${TIMESTAMP}Z
mmis824a75e2018-03-02 18:04:48 +0000110
111if [ $? -ne 0 ]
112then
113 echo "Docker push failed"
114 exit 1
115
116fi
117