blob: 72f153231f148baa3667c21e88c1b377e03a200e [file] [log] [blame]
Pamela Dragosh6f91e0b2017-02-23 10:37:49 -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 Shankar6e36eec2017-06-29 12:52:59 -07008PROXY_ARGS=""
mmis0d856912018-03-05 18:23:39 +00009IMAGE=policy-nexus
Shashank Kumar Shankar6e36eec2017-06-29 12:52:59 -070010
11if [ $HTTP_PROXY ]; then
12 PROXY_ARGS+="--build-arg HTTP_PROXY=${HTTP_PROXY}"
13fi
14if [ $HTTPS_PROXY ]; then
15 PROXY_ARGS+=" --build-arg HTTPS_PROXY=${HTTPS_PROXY}"
16fi
Pamela Dragosh6f91e0b2017-02-23 10:37:49 -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 Dragosh6f91e0b2017-02-23 10:37:49 -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#
mmis6dc5a242018-03-14 12:35:35 +000051TAGS="--tag onap/${IMAGE}:latest"
mmis0d856912018-03-05 18:23:39 +000052#
53# This has the nexus repo prepended and only major/minor version with latest
54#
mmis6dc5a242018-03-14 12:35:35 +000055TAGS="${TAGS} --tag ${DOCKER_REPOSITORY}/onap/${IMAGE}:${MVN_MAJMIN_VERSION}-latest"
mmis0d856912018-03-05 18:23:39 +000056#
57# This has the nexus repo prepended and major/minor/patch version with timestamp
58#
mmis6dc5a242018-03-14 12:35:35 +000059TAGS="${TAGS} --tag ${DOCKER_REPOSITORY}/onap/${IMAGE}:${MVN_VERSION}-${TIMESTAMP}"
Pamela Dragosh3fe4d9c2017-03-07 15:39:48 -050060
mmis0d856912018-03-05 18:23:39 +000061echo $TAGS
Pamela Dragosh3fe4d9c2017-03-07 15:39:48 -050062
mmis0d856912018-03-05 18:23:39 +000063docker build --quiet ${PROXY_ARGS} $TAGS target/$IMAGE
Pamela Dragosh3311eb72017-03-16 11:30:29 -040064
mmis0d856912018-03-05 18:23:39 +000065if [ $? -ne 0 ]
66then
67 echo "Docker build failed"
68 docker images
69 exit 1
70fi
Pamela Dragosh2fc22222017-03-15 16:12:02 -040071
Pamela Dragosh9bd4bf62017-03-30 12:46:08 -040072docker images
73
Pamela Dragoshceba3d82017-03-16 11:02:05 -040074#
mmis0d856912018-03-05 18:23:39 +000075# Push image
Pamela Dragoshceba3d82017-03-16 11:02:05 -040076#
mmis0d856912018-03-05 18:23:39 +000077echo "Pushing $IMAGE"
mmis6dc5a242018-03-14 12:35:35 +000078docker push ${DOCKER_REPOSITORY}/onap/$IMAGE:${MVN_MAJMIN_VERSION}-latest
Pamela Dragosh9bd4bf62017-03-30 12:46:08 -040079
mmis0d856912018-03-05 18:23:39 +000080if [ $? -ne 0 ]
81then
82 echo "Docker push failed"
83 exit 1
84fi
Pamela Dragosh9bd4bf62017-03-30 12:46:08 -040085
mmis6dc5a242018-03-14 12:35:35 +000086docker push ${DOCKER_REPOSITORY}/onap/$IMAGE:${MVN_VERSION}-${TIMESTAMP}
Pamela Dragosh9bd4bf62017-03-30 12:46:08 -040087
mmis0d856912018-03-05 18:23:39 +000088if [ $? -ne 0 ]
89then
90 echo "Docker push failed"
91 exit 1
92fi