blob: 2f11b0ba41c40182bb04ba93c4d4ae2e22032673 [file] [log] [blame]
mmis13368732018-03-01 16:50:11 +00001#!/bin/bash
2#
Jim Hahndaee9222018-04-19 11:28:41 -04003#============LICENSE_START==================================================
4# ONAP Policy Engine
5#===========================================================================
6# Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
7#===========================================================================
8# Licensed under the Apache License, Version 2.0 (the "License");
9# you may not use this file except in compliance with the License.
10# You may obtain a copy of the License at
11#
12# http://www.apache.org/licenses/LICENSE-2.0
13#
14# Unless required by applicable law or agreed to in writing, software
15# distributed under the License is distributed on an "AS IS" BASIS,
16# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17# See the License for the specific language governing permissions and
18# limitations under the License.
19#============LICENSE_END==================================================
20#
21
22#
mmis13368732018-03-01 16:50:11 +000023echo '============== STARTING SCRIPT TO BUILD DOCKER IMAGES ================='
24DOCKER_REPOSITORY=nexus3.onap.org:10003
25MVN_VERSION=$(cat packages/docker/target/version)
26MVN_MAJMIN_VERSION=$(cut -f 1,2 -d . packages/docker/target/version)
27TIMESTAMP=$(date -u +%Y%m%dT%H%M%S)
jhhb5df17d2019-04-26 12:17:40 -050028BUILD_ARGS="--build-arg BUILD_VERSION_ENGINE=${MVN_VERSION}"
mmis13368732018-03-01 16:50:11 +000029IMAGE=policy-pe
30
31if [ $HTTP_PROXY ]; then
Jorge Hernandez973929c2018-05-07 18:22:12 -050032 BUILD_ARGS+=" --build-arg HTTP_PROXY=${HTTP_PROXY}"
mmis13368732018-03-01 16:50:11 +000033fi
34if [ $HTTPS_PROXY ]; then
Jorge Hernandez973929c2018-05-07 18:22:12 -050035 BUILD_ARGS+=" --build-arg HTTPS_PROXY=${HTTPS_PROXY}"
mmis13368732018-03-01 16:50:11 +000036fi
37
38echo $DOCKER_REPOSITORY
39echo $MVN_VERSION
40echo $MVN_MAJMIN_VERSION
41echo $TIMESTAMP
42
43if [[ -z $MVN_VERSION ]]
44then
45 echo "MVN_VERSION is empty"
46 exit 1
47fi
48
49if [[ -z $MVN_MAJMIN_VERSION ]]
50then
51 echo "MVN_MAJMIN_VERSION is empty"
52 exit 1
53fi
54
55if [[ $MVN_VERSION == *"SNAPSHOT"* ]]
56then
57 MVN_MAJMIN_VERSION="${MVN_MAJMIN_VERSION}-SNAPSHOT"
58else
59 MVN_MAJMIN_VERSION="${MVN_MAJMIN_VERSION}-STAGING"
60fi
61
62echo $MVN_MAJMIN_VERSION
63
jhhfa324fe2019-04-25 22:58:37 -050064docker login -u docker -p docker nexus3.onap.org:10001
65docker pull nexus3.onap.org:10001/onap/policy-common-alpine:1.4.0
66docker tag nexus3.onap.org:10001/onap/policy-common-alpine:1.4.0 onap/policy-common-alpine:1.4.0
67
mmis13368732018-03-01 16:50:11 +000068echo "Building $IMAGE"
mmis13368732018-03-01 16:50:11 +000069
70#
71# This is the local latest tagged image. The Dockerfile's need this to build images
72#
mmis4ea66782018-03-14 12:03:37 +000073TAGS="--tag onap/${IMAGE}:latest"
mmis13368732018-03-01 16:50:11 +000074#
75# This is the nexus repo prepended for latest tagged image.
76#
mmis4ea66782018-03-14 12:03:37 +000077TAGS="${TAGS} --tag ${DOCKER_REPOSITORY}/onap/${IMAGE}:latest"
mmis13368732018-03-01 16:50:11 +000078#
79# This has the nexus repo prepended and only major/minor version with latest
80#
mmis4ea66782018-03-14 12:03:37 +000081TAGS="${TAGS} --tag ${DOCKER_REPOSITORY}/onap/${IMAGE}:${MVN_MAJMIN_VERSION}-latest"
mmis13368732018-03-01 16:50:11 +000082#
83# This has the nexus repo prepended and major/minor/patch version with timestamp
84#
mmisd7eac782018-03-29 09:37:45 +010085TAGS="${TAGS} --tag ${DOCKER_REPOSITORY}/onap/${IMAGE}:${MVN_VERSION}-STAGING-${TIMESTAMP}Z"
mmis13368732018-03-01 16:50:11 +000086
87echo $TAGS
88
Jorge Hernandez973929c2018-05-07 18:22:12 -050089docker build --quiet ${BUILD_ARGS} $TAGS packages/docker/target/$IMAGE
mmis13368732018-03-01 16:50:11 +000090
91if [ $? -ne 0 ]
92then
93 echo "Docker build failed"
94 docker images
95 exit 1
96fi
97
98docker images
99
100echo "Pushing $IMAGE"
101
mmis4ea66782018-03-14 12:03:37 +0000102docker push ${DOCKER_REPOSITORY}/onap/${IMAGE}:latest
mmis13368732018-03-01 16:50:11 +0000103
104if [ $? -ne 0 ]
105then
106 echo "Docker push failed"
107 exit 1
108
109fi
110
mmis4ea66782018-03-14 12:03:37 +0000111docker push ${DOCKER_REPOSITORY}/onap/${IMAGE}:${MVN_MAJMIN_VERSION}-latest
mmis13368732018-03-01 16:50:11 +0000112
113if [ $? -ne 0 ]
114then
115 echo "Docker push failed"
116 exit 1
117
118fi
mmisd7eac782018-03-29 09:37:45 +0100119docker push ${DOCKER_REPOSITORY}/onap/${IMAGE}:${MVN_VERSION}-STAGING-${TIMESTAMP}Z
mmis13368732018-03-01 16:50:11 +0000120
121if [ $? -ne 0 ]
122then
123 echo "Docker push failed"
124 exit 1
125
126fi