blob: bbc0ca9297f64526241780c44f0f1af022f89276 [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)
Pamela Dragosh6f91e0b2017-02-23 10:37:49 -05008
Pamela Dragosh3fe4d9c2017-03-07 15:39:48 -05009echo $DOCKER_REPOSITORY
10echo $MVN_VERSION
Pamela Dragoshe9f737a2017-03-23 07:44:56 -040011echo $MVN_MAJMIN_VERSION
Pamela Dragosh3fe4d9c2017-03-07 15:39:48 -050012echo $TIMESTAMP
Pamela Dragosh6f91e0b2017-02-23 10:37:49 -050013
Pamela Dragoshe9f737a2017-03-23 07:44:56 -040014if [[ -z $MVN_VERSION ]]
15then
16 echo "MVN_VERSION is empty"
17 exit 1
18fi
19
20if [[ -z $MVN_MAJMIN_VERSION ]]
21then
22 echo "MVN_MAJMIN_VERSION is empty"
23 exit 1
24fi
25
26if [[ $MVN_VERSION == *"SNAPSHOT"* ]]
27then
28 MVN_MAJMIN_VERSION="${MVN_MAJMIN_VERSION}-SNAPSHOT"
29else
30 MVN_MAJMIN_VERSION="${MVN_MAJMIN_VERSION}-STAGING"
31fi
32
33echo $MVN_MAJMIN_VERSION
34
Pamela Dragosh6f91e0b2017-02-23 10:37:49 -050035cp policy-pe/* target/policy-pe/
36cp policy-drools/* target/policy-drools/
37
38for image in policy-os policy-nexus policy-db policy-base policy-drools policy-pe ; do
39 echo "Building $image"
40 mkdir -p target/$image
41 cp $image/* target/$image
Pamela Dragosh3fe4d9c2017-03-07 15:39:48 -050042
Pamela Dragoshe9f737a2017-03-23 07:44:56 -040043 #
44 # This is the local latest tagged image. The Dockerfile's need this to build images
45 #
Pamela Dragosh18882a02017-03-30 10:50:45 -040046 TAGS="--tag onap/policy/${image}:latest"
Pamela Dragoshe9f737a2017-03-23 07:44:56 -040047 #
48 # This has the nexus repo prepended and only major/minor version with latest
49 #
Pamela Dragosh18882a02017-03-30 10:50:45 -040050 TAGS="${TAGS} --tag ${DOCKER_REPOSITORY}/onap/policy/${image}:${MVN_MAJMIN_VERSION}-latest"
Pamela Dragoshe9f737a2017-03-23 07:44:56 -040051 #
52 # This has the nexus repo prepended and major/minor/patch version with timestamp
53 #
Pamela Dragosh18882a02017-03-30 10:50:45 -040054 TAGS="${TAGS} --tag ${DOCKER_REPOSITORY}/onap/policy/${image}:${MVN_VERSION}-${TIMESTAMP}"
Pamela Dragosh3fe4d9c2017-03-07 15:39:48 -050055
56 echo $TAGS
Pamela Dragosh3311eb72017-03-16 11:30:29 -040057
58 docker build --quiet $TAGS target/$image
Pamela Dragosh9bd4bf62017-03-30 12:46:08 -040059
60 if [ $? -ne 0 ]
61 then
62 echo "Docker build failed"
63 docker images
64 exit 1
65 fi
Pamela Dragosh6f91e0b2017-02-23 10:37:49 -050066done
Pamela Dragosh2fc22222017-03-15 16:12:02 -040067
Pamela Dragosh9bd4bf62017-03-30 12:46:08 -040068docker images
69
Pamela Dragoshceba3d82017-03-16 11:02:05 -040070#
Pamela Dragoshe9f737a2017-03-23 07:44:56 -040071# Push images
Pamela Dragoshceba3d82017-03-16 11:02:05 -040072#
73for image in policy-nexus policy-db policy-drools policy-pe; do
74 echo "Pushing $image"
Pamela Dragosh18882a02017-03-30 10:50:45 -040075 docker push ${DOCKER_REPOSITORY}/onap/policy/$image:${MVN_MAJMIN_VERSION}-latest
Pamela Dragosh9bd4bf62017-03-30 12:46:08 -040076
77 if [ $? -ne 0 ]
78 then
79 echo "Docker push failed"
80 exit 1
81 fi
82
Pamela Dragosh18882a02017-03-30 10:50:45 -040083 docker push ${DOCKER_REPOSITORY}/onap/policy/$image:${MVN_VERSION}-${TIMESTAMP}
Pamela Dragosh9bd4bf62017-03-30 12:46:08 -040084
85 if [ $? -ne 0 ]
86 then
87 echo "Docker push failed"
88 exit 1
89 fi
Pamela Dragoshceba3d82017-03-16 11:02:05 -040090done