Rename actor from MSO 2 SO in vDNS policy creation
[policy/docker.git] / docker_merge.sh
1 #!/bin/bash
2 #
3 echo '============== STARTING SCRIPT TO BUILD DOCKER IMAGES ================='
4 DOCKER_REPOSITORY=nexus3.onap.org:10003
5 MVN_VERSION=$(cat target/version)
6 MVN_MAJMIN_VERSION=$(cut -f 1,2 -d . target/version)
7 TIMESTAMP=$(date -u +%Y%m%dT%H%M%S)
8 PROXY_ARGS=""
9
10 if [ $HTTP_PROXY ]; then
11     PROXY_ARGS+="--build-arg HTTP_PROXY=${HTTP_PROXY}"
12 fi
13 if [ $HTTPS_PROXY ]; then
14     PROXY_ARGS+=" --build-arg HTTPS_PROXY=${HTTPS_PROXY}"
15 fi
16
17 echo $DOCKER_REPOSITORY
18 echo $MVN_VERSION
19 echo $MVN_MAJMIN_VERSION
20 echo $TIMESTAMP
21
22 if [[ -z $MVN_VERSION ]]
23 then
24     echo "MVN_VERSION is empty"
25     exit 1
26 fi
27
28 if [[ -z $MVN_MAJMIN_VERSION ]]
29 then
30     echo "MVN_MAJMIN_VERSION is empty"
31     exit 1
32 fi
33
34 if [[ $MVN_VERSION == *"SNAPSHOT"* ]]
35 then
36     MVN_MAJMIN_VERSION="${MVN_MAJMIN_VERSION}-SNAPSHOT"
37 else
38     MVN_MAJMIN_VERSION="${MVN_MAJMIN_VERSION}-STAGING"
39 fi
40
41 echo $MVN_MAJMIN_VERSION
42
43 cp policy-pe/* target/policy-pe/
44 cp policy-drools/* target/policy-drools/
45
46 for 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
50
51     #
52     # This is the local latest tagged image. The Dockerfile's need this to build images
53     #
54     TAGS="--tag onap/policy/${image}:latest"
55     #
56     # This has the nexus repo prepended and only major/minor version with latest
57     #
58     TAGS="${TAGS} --tag ${DOCKER_REPOSITORY}/onap/policy/${image}:${MVN_MAJMIN_VERSION}-latest"
59     #
60     # This has the nexus repo prepended and major/minor/patch version with timestamp
61     #
62     TAGS="${TAGS} --tag ${DOCKER_REPOSITORY}/onap/policy/${image}:${MVN_VERSION}-${TIMESTAMP}"
63
64     echo $TAGS
65
66     docker build --quiet ${PROXY_ARGS} $TAGS target/$image
67
68     if [ $? -ne 0 ]
69     then
70         echo "Docker build failed"
71         docker images
72         exit 1
73     fi
74 done
75
76 docker images
77
78 #
79 # Push images
80 #
81 for image in policy-nexus policy-db policy-drools policy-pe; do
82     echo "Pushing $image"
83     docker push ${DOCKER_REPOSITORY}/onap/policy/$image:${MVN_MAJMIN_VERSION}-latest
84
85     if [ $? -ne 0 ]
86     then
87         echo "Docker push failed"
88         exit 1
89     fi
90
91     docker push ${DOCKER_REPOSITORY}/onap/policy/$image:${MVN_VERSION}-${TIMESTAMP}
92
93     if [ $? -ne 0 ]
94     then
95         echo "Docker push failed"
96         exit 1
97     fi
98 done