blob: 4a8c416ffc7b78ca2c5e5f1e1715f8bbe1e4a0af [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=""
9
10if [ $HTTP_PROXY ]; then
11 PROXY_ARGS+="--build-arg HTTP_PROXY=${HTTP_PROXY}"
12fi
13if [ $HTTPS_PROXY ]; then
Shashank Kumar Shankar6e36eec2017-06-29 12:52:59 -070014 PROXY_ARGS+=" --build-arg HTTPS_PROXY=${HTTPS_PROXY}"
Shashank Kumar Shankar3e5a0c32017-06-27 16:10:28 -070015fi
Pamela Dragosh17665522017-02-21 09:05:08 -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 Dragosh1e547282017-02-21 09:41:58 -050043cp policy-pe/* target/policy-pe/
44cp policy-drools/* target/policy-drools/
45
Pamela Dragosh17665522017-02-21 09:05:08 -050046for 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 #
Pamela Dragosh64e7ad32017-03-30 15:28:50 -040056 # This is the nexus repo prepended for latest tagged image.
57 #
58 TAGS="${TAGS} --tag ${DOCKER_REPOSITORY}/onap/policy/${image}:latest"
59 #
Pamela Dragoshe9f737a2017-03-23 07:44:56 -040060 # This has the nexus repo prepended and only major/minor version with latest
61 #
Pamela Dragosh18882a02017-03-30 10:50:45 -040062 TAGS="${TAGS} --tag ${DOCKER_REPOSITORY}/onap/policy/${image}:${MVN_MAJMIN_VERSION}-latest"
Pamela Dragoshe9f737a2017-03-23 07:44:56 -040063 #
64 # This has the nexus repo prepended and major/minor/patch version with timestamp
65 #
Pamela Dragosh18882a02017-03-30 10:50:45 -040066 TAGS="${TAGS} --tag ${DOCKER_REPOSITORY}/onap/policy/${image}:${MVN_VERSION}-STAGING-${TIMESTAMP}"
Pamela Dragosh3fe4d9c2017-03-07 15:39:48 -050067
68 echo $TAGS
69
Shashank Kumar Shankar3e5a0c32017-06-27 16:10:28 -070070 docker build --quiet ${PROXY_ARGS} $TAGS target/$image
Pamela Dragosh9bd4bf62017-03-30 12:46:08 -040071
72 if [ $? -ne 0 ]
73 then
74 echo "Docker build failed"
75 docker images
76 exit 1
77 fi
Pamela Dragosh17665522017-02-21 09:05:08 -050078done
79
Pamela Dragosh9bd4bf62017-03-30 12:46:08 -040080docker images
81
Pamela Dragosh17665522017-02-21 09:05:08 -050082for image in policy-nexus policy-db policy-drools policy-pe; do
83 echo "Pushing $image"
Pamela Dragosh9bd4bf62017-03-30 12:46:08 -040084
Pamela Dragosh18882a02017-03-30 10:50:45 -040085 docker push ${DOCKER_REPOSITORY}/onap/policy/$image:latest
Pamela Dragosh9bd4bf62017-03-30 12:46:08 -040086
87 if [ $? -ne 0 ]
88 then
89 echo "Docker push failed"
90 exit 1
91
92 fi
93
Pamela Dragosh18882a02017-03-30 10:50:45 -040094 docker push ${DOCKER_REPOSITORY}/onap/policy/$image:${MVN_MAJMIN_VERSION}-latest
Pamela Dragosh9bd4bf62017-03-30 12:46:08 -040095
96 if [ $? -ne 0 ]
97 then
98 echo "Docker push failed"
99 exit 1
100
101 fi
Pamela Dragosh18882a02017-03-30 10:50:45 -0400102 docker push ${DOCKER_REPOSITORY}/onap/policy/$image:${MVN_VERSION}-STAGING-${TIMESTAMP}
Pamela Dragosh9bd4bf62017-03-30 12:46:08 -0400103
104 if [ $? -ne 0 ]
105 then
106 echo "Docker push failed"
107 exit 1
108
109 fi
Pamela Dragosh17665522017-02-21 09:05:08 -0500110done