blob: 83fd239d35f3704f5368f50ac9bc225f0c13c766 [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=""
9
10if [ $HTTP_PROXY ]; then
11 PROXY_ARGS+="--build-arg HTTP_PROXY=${HTTP_PROXY}"
12fi
13if [ $HTTPS_PROXY ]; then
14 PROXY_ARGS+=" --build-arg HTTPS_PROXY=${HTTPS_PROXY}"
15fi
Pamela Dragosh6f91e0b2017-02-23 10:37:49 -050016
Pamela Dragosh3fe4d9c2017-03-07 15:39:48 -050017echo $DOCKER_REPOSITORY
18echo $MVN_VERSION
Pamela Dragoshe9f737a2017-03-23 07:44:56 -040019echo $MVN_MAJMIN_VERSION
Pamela Dragosh3fe4d9c2017-03-07 15:39:48 -050020echo $TIMESTAMP
Pamela Dragosh6f91e0b2017-02-23 10:37:49 -050021
Pamela Dragoshe9f737a2017-03-23 07:44:56 -040022if [[ -z $MVN_VERSION ]]
23then
24 echo "MVN_VERSION is empty"
25 exit 1
26fi
27
28if [[ -z $MVN_MAJMIN_VERSION ]]
29then
30 echo "MVN_MAJMIN_VERSION is empty"
31 exit 1
32fi
33
34if [[ $MVN_VERSION == *"SNAPSHOT"* ]]
35then
36 MVN_MAJMIN_VERSION="${MVN_MAJMIN_VERSION}-SNAPSHOT"
37else
38 MVN_MAJMIN_VERSION="${MVN_MAJMIN_VERSION}-STAGING"
39fi
40
41echo $MVN_MAJMIN_VERSION
42
Pamela Dragosh6f91e0b2017-02-23 10:37:49 -050043cp policy-pe/* target/policy-pe/
44cp policy-drools/* target/policy-drools/
45
46for image in policy-os policy-nexus policy-db policy-base policy-drools policy-pe ; do
47 echo "Building $image"
48 mkdir -p target/$image
49 cp $image/* target/$image
Pamela Dragosh3fe4d9c2017-03-07 15:39:48 -050050
Pamela Dragoshe9f737a2017-03-23 07:44:56 -040051 #
52 # This is the local latest tagged image. The Dockerfile's need this to build images
53 #
Pamela Dragosh18882a02017-03-30 10:50:45 -040054 TAGS="--tag onap/policy/${image}:latest"
Pamela Dragoshe9f737a2017-03-23 07:44:56 -040055 #
56 # This has the nexus repo prepended and only major/minor version with latest
57 #
Pamela Dragosh18882a02017-03-30 10:50:45 -040058 TAGS="${TAGS} --tag ${DOCKER_REPOSITORY}/onap/policy/${image}:${MVN_MAJMIN_VERSION}-latest"
Pamela Dragoshe9f737a2017-03-23 07:44:56 -040059 #
60 # This has the nexus repo prepended and major/minor/patch version with timestamp
61 #
Pamela Dragosh18882a02017-03-30 10:50:45 -040062 TAGS="${TAGS} --tag ${DOCKER_REPOSITORY}/onap/policy/${image}:${MVN_VERSION}-${TIMESTAMP}"
Pamela Dragosh3fe4d9c2017-03-07 15:39:48 -050063
64 echo $TAGS
Pamela Dragosh3311eb72017-03-16 11:30:29 -040065
Shashank Kumar Shankar6e36eec2017-06-29 12:52:59 -070066 docker build --quiet ${PROXY_ARGS} $TAGS target/$image
Pamela Dragosh9bd4bf62017-03-30 12:46:08 -040067
68 if [ $? -ne 0 ]
69 then
70 echo "Docker build failed"
71 docker images
72 exit 1
73 fi
Pamela Dragosh6f91e0b2017-02-23 10:37:49 -050074done
Pamela Dragosh2fc22222017-03-15 16:12:02 -040075
Pamela Dragosh9bd4bf62017-03-30 12:46:08 -040076docker images
77
Pamela Dragoshceba3d82017-03-16 11:02:05 -040078#
Pamela Dragoshe9f737a2017-03-23 07:44:56 -040079# Push images
Pamela Dragoshceba3d82017-03-16 11:02:05 -040080#
81for image in policy-nexus policy-db policy-drools policy-pe; do
82 echo "Pushing $image"
Pamela Dragosh18882a02017-03-30 10:50:45 -040083 docker push ${DOCKER_REPOSITORY}/onap/policy/$image:${MVN_MAJMIN_VERSION}-latest
Pamela Dragosh9bd4bf62017-03-30 12:46:08 -040084
85 if [ $? -ne 0 ]
86 then
87 echo "Docker push failed"
88 exit 1
89 fi
90
Pamela Dragosh18882a02017-03-30 10:50:45 -040091 docker push ${DOCKER_REPOSITORY}/onap/policy/$image:${MVN_VERSION}-${TIMESTAMP}
Pamela Dragosh9bd4bf62017-03-30 12:46:08 -040092
93 if [ $? -ne 0 ]
94 then
95 echo "Docker push failed"
96 exit 1
97 fi
Pamela Dragoshceba3d82017-03-16 11:02:05 -040098done