blob: cf0ea8c2f62eb70356e7ec32c35cb9308df76b3e [file] [log] [blame]
mmis824a75e2018-03-02 18:04:48 +00001#!/bin/bash
Jorge Hernandezb001c1a2019-02-28 10:10:49 -06002# Copyright 2018-2019 AT&T Intellectual Property. All rights reserved
Pamela Dragosh7bfe2222018-04-16 09:40:04 -04003#
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)
jhh7df0f4e2019-04-26 12:01:14 -050022BUILD_ARGS="--build-arg BUILD_VERSION_DROOLS=${MVN_VERSION}"
mmis824a75e2018-03-02 18:04:48 +000023IMAGE=policy-drools
24
mmis824a75e2018-03-02 18:04:48 +000025echo $DOCKER_REPOSITORY
26echo $MVN_VERSION
27echo $MVN_MAJMIN_VERSION
28echo $TIMESTAMP
29
30if [[ -z $MVN_VERSION ]]
31then
32 echo "MVN_VERSION is empty"
33 exit 1
34fi
35
36if [[ -z $MVN_MAJMIN_VERSION ]]
37then
38 echo "MVN_MAJMIN_VERSION is empty"
39 exit 1
40fi
41
42if [[ $MVN_VERSION == *"SNAPSHOT"* ]]
43then
44 MVN_MAJMIN_VERSION="${MVN_MAJMIN_VERSION}-SNAPSHOT"
45else
46 MVN_MAJMIN_VERSION="${MVN_MAJMIN_VERSION}-STAGING"
47fi
48
49echo $MVN_MAJMIN_VERSION
50
jhhf8b78e92019-04-25 15:32:13 -050051docker login -u docker -p docker nexus3.onap.org:10001
52docker pull nexus3.onap.org:10001/onap/policy-common-alpine:1.4.0
53docker tag nexus3.onap.org:10001/onap/policy-common-alpine:1.4.0 onap/policy-common-alpine:1.4.0
54
mmis824a75e2018-03-02 18:04:48 +000055echo "Building $IMAGE"
mmis824a75e2018-03-02 18:04:48 +000056
57#
58# This is the local latest tagged image. The Dockerfile's need this to build images
59#
mmisac6780a2018-03-14 12:10:52 +000060TAGS="--tag onap/${IMAGE}:latest"
mmis824a75e2018-03-02 18:04:48 +000061#
62# This is the nexus repo prepended for latest tagged image.
63#
mmisac6780a2018-03-14 12:10:52 +000064TAGS="${TAGS} --tag ${DOCKER_REPOSITORY}/onap/${IMAGE}:latest"
mmis824a75e2018-03-02 18:04:48 +000065#
66# This has the nexus repo prepended and only major/minor version with latest
67#
mmisac6780a2018-03-14 12:10:52 +000068TAGS="${TAGS} --tag ${DOCKER_REPOSITORY}/onap/${IMAGE}:${MVN_MAJMIN_VERSION}-latest"
mmis824a75e2018-03-02 18:04:48 +000069#
70# This has the nexus repo prepended and major/minor/patch version with timestamp
71#
mmis43380df2018-03-29 09:47:04 +010072TAGS="${TAGS} --tag ${DOCKER_REPOSITORY}/onap/${IMAGE}:${MVN_VERSION}-STAGING-${TIMESTAMP}Z"
mmis824a75e2018-03-02 18:04:48 +000073
74echo $TAGS
75
Jorge Hernandez3ad27752018-04-30 17:24:44 -050076docker build --quiet ${BUILD_ARGS} $TAGS packages/docker/target/$IMAGE
mmis824a75e2018-03-02 18:04:48 +000077
78if [ $? -ne 0 ]
79then
80 echo "Docker build failed"
81 docker images
82 exit 1
83fi
84
85docker images
86
87echo "Pushing $IMAGE"
88
mmisac6780a2018-03-14 12:10:52 +000089docker push ${DOCKER_REPOSITORY}/onap/${IMAGE}:latest
mmis824a75e2018-03-02 18:04:48 +000090
91if [ $? -ne 0 ]
92then
93 echo "Docker push failed"
94 exit 1
95
96fi
97
mmisac6780a2018-03-14 12:10:52 +000098docker push ${DOCKER_REPOSITORY}/onap/${IMAGE}:${MVN_MAJMIN_VERSION}-latest
mmis824a75e2018-03-02 18:04:48 +000099
100if [ $? -ne 0 ]
101then
102 echo "Docker push failed"
103 exit 1
104
105fi
mmis43380df2018-03-29 09:47:04 +0100106docker push ${DOCKER_REPOSITORY}/onap/${IMAGE}:${MVN_VERSION}-STAGING-${TIMESTAMP}Z
mmis824a75e2018-03-02 18:04:48 +0000107
108if [ $? -ne 0 ]
109then
110 echo "Docker push failed"
111 exit 1
112
113fi
114