blob: 5fe01bed84ce08c4046a8e4c9281530fbc52a101 [file] [log] [blame]
Pamela Dragosh17665522017-02-21 09:05:08 -05001#!/bin/bash
2#
3echo '============== STARTING SCRIPT TO BUILD DOCKER IMAGES ================='
Pamela Dragosh18882a02017-03-30 10:50:45 -04004DOCKER_REPOSITORY=nexus3.onap.org:10003
Pamela Dragosh3fe4d9c2017-03-07 15:39:48 -05005MVN_VERSION=$(cat target/version)
Pamela Dragoshe9f737a2017-03-23 07:44:56 -04006MVN_MAJMIN_VERSION=$(cut -f 1,2 -d . target/version)
Pamela Dragosh3fe4d9c2017-03-07 15:39:48 -05007TIMESTAMP=$(date -u +%Y%m%dT%H%M%S)
Shashank Kumar Shankar3e5a0c32017-06-27 16:10:28 -07008PROXY_ARGS=""
mmis0d856912018-03-05 18:23:39 +00009IMAGE=policy-nexus
Shashank Kumar Shankar3e5a0c32017-06-27 16:10:28 -070010
11if [ $HTTP_PROXY ]; then
12 PROXY_ARGS+="--build-arg HTTP_PROXY=${HTTP_PROXY}"
13fi
14if [ $HTTPS_PROXY ]; then
Shashank Kumar Shankar6e36eec2017-06-29 12:52:59 -070015 PROXY_ARGS+=" --build-arg HTTPS_PROXY=${HTTPS_PROXY}"
Shashank Kumar Shankar3e5a0c32017-06-27 16:10:28 -070016fi
Pamela Dragosh17665522017-02-21 09:05:08 -050017
Pamela Dragosh3fe4d9c2017-03-07 15:39:48 -050018echo $DOCKER_REPOSITORY
19echo $MVN_VERSION
Pamela Dragoshe9f737a2017-03-23 07:44:56 -040020echo $MVN_MAJMIN_VERSION
Pamela Dragosh3fe4d9c2017-03-07 15:39:48 -050021echo $TIMESTAMP
Pamela Dragosh6f91e0b2017-02-23 10:37:49 -050022
Pamela Dragoshe9f737a2017-03-23 07:44:56 -040023if [[ -z $MVN_VERSION ]]
24then
25 echo "MVN_VERSION is empty"
26 exit 1
27fi
28
29if [[ -z $MVN_MAJMIN_VERSION ]]
30then
31 echo "MVN_MAJMIN_VERSION is empty"
32 exit 1
33fi
34
35if [[ $MVN_VERSION == *"SNAPSHOT"* ]]
36then
37 MVN_MAJMIN_VERSION="${MVN_MAJMIN_VERSION}-SNAPSHOT"
38else
39 MVN_MAJMIN_VERSION="${MVN_MAJMIN_VERSION}-STAGING"
40fi
41
42echo $MVN_MAJMIN_VERSION
43
mmis0d856912018-03-05 18:23:39 +000044echo "Building $IMAGE"
45mkdir -p target/$IMAGE
46cp $IMAGE/* target/$IMAGE
Pamela Dragosh1e547282017-02-21 09:41:58 -050047
mmis0d856912018-03-05 18:23:39 +000048#
49# This is the local latest tagged image. The Dockerfile's need this to build images
50#
51TAGS="--tag onap/policy/${IMAGE}:latest"
52#
53# This is the nexus repo prepended for latest tagged image.
54#
55TAGS="${TAGS} --tag ${DOCKER_REPOSITORY}/onap/policy/${IMAGE}:latest"
56#
57# This has the nexus repo prepended and only major/minor version with latest
58#
59TAGS="${TAGS} --tag ${DOCKER_REPOSITORY}/onap/policy/${IMAGE}:${MVN_MAJMIN_VERSION}-latest"
60#
61# This has the nexus repo prepended and major/minor/patch version with timestamp
62#
63TAGS="${TAGS} --tag ${DOCKER_REPOSITORY}/onap/policy/${IMAGE}:${MVN_VERSION}-STAGING-${TIMESTAMP}"
Pamela Dragosh3fe4d9c2017-03-07 15:39:48 -050064
mmis0d856912018-03-05 18:23:39 +000065echo $TAGS
Pamela Dragosh3fe4d9c2017-03-07 15:39:48 -050066
mmis0d856912018-03-05 18:23:39 +000067docker build --quiet ${PROXY_ARGS} $TAGS target/$IMAGE
Pamela Dragosh3fe4d9c2017-03-07 15:39:48 -050068
mmis0d856912018-03-05 18:23:39 +000069if [ $? -ne 0 ]
70then
71 echo "Docker build failed"
72 docker images
73 exit 1
74fi
Pamela Dragosh17665522017-02-21 09:05:08 -050075
Pamela Dragosh9bd4bf62017-03-30 12:46:08 -040076docker images
77
mmis0d856912018-03-05 18:23:39 +000078echo "Pushing $IMAGE"
Pamela Dragosh9bd4bf62017-03-30 12:46:08 -040079
mmis0d856912018-03-05 18:23:39 +000080docker push ${DOCKER_REPOSITORY}/onap/policy/$IMAGE:latest
Pamela Dragosh9bd4bf62017-03-30 12:46:08 -040081
mmis0d856912018-03-05 18:23:39 +000082if [ $? -ne 0 ]
83then
84 echo "Docker push failed"
85 exit 1
Pamela Dragosh9bd4bf62017-03-30 12:46:08 -040086
mmis0d856912018-03-05 18:23:39 +000087fi
Pamela Dragosh9bd4bf62017-03-30 12:46:08 -040088
mmis0d856912018-03-05 18:23:39 +000089docker push ${DOCKER_REPOSITORY}/onap/policy/$IMAGE:${MVN_MAJMIN_VERSION}-latest
Pamela Dragosh9bd4bf62017-03-30 12:46:08 -040090
mmis0d856912018-03-05 18:23:39 +000091if [ $? -ne 0 ]
92then
93 echo "Docker push failed"
94 exit 1
Pamela Dragosh9bd4bf62017-03-30 12:46:08 -040095
mmis0d856912018-03-05 18:23:39 +000096fi
97docker push ${DOCKER_REPOSITORY}/onap/policy/$IMAGE:${MVN_VERSION}-STAGING-${TIMESTAMP}
Pamela Dragosh9bd4bf62017-03-30 12:46:08 -040098
mmis0d856912018-03-05 18:23:39 +000099if [ $? -ne 0 ]
100then
101 echo "Docker push failed"
102 exit 1
Pamela Dragosh9bd4bf62017-03-30 12:46:08 -0400103
mmis0d856912018-03-05 18:23:39 +0000104fi