[Policy-24] Updated the Database Properties
[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
9 echo $DOCKER_REPOSITORY
10 echo $MVN_VERSION
11 echo $MVN_MAJMIN_VERSION
12 echo $TIMESTAMP
13
14 if [[ -z $MVN_VERSION ]]
15 then
16     echo "MVN_VERSION is empty"
17     exit 1
18 fi
19
20 if [[ -z $MVN_MAJMIN_VERSION ]]
21 then
22     echo "MVN_MAJMIN_VERSION is empty"
23     exit 1
24 fi
25
26 if [[ $MVN_VERSION == *"SNAPSHOT"* ]]
27 then
28     MVN_MAJMIN_VERSION="${MVN_MAJMIN_VERSION}-SNAPSHOT"
29 else
30     MVN_MAJMIN_VERSION="${MVN_MAJMIN_VERSION}-STAGING"
31 fi
32
33 echo $MVN_MAJMIN_VERSION
34
35 cp policy-pe/* target/policy-pe/
36 cp policy-drools/* target/policy-drools/
37
38 for 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
42
43     #
44     # This is the local latest tagged image. The Dockerfile's need this to build images
45     #
46     TAGS="--tag onap/policy/${image}:latest"
47     #
48     # This has the nexus repo prepended and only major/minor version with latest
49     #
50     TAGS="${TAGS} --tag ${DOCKER_REPOSITORY}/onap/policy/${image}:${MVN_MAJMIN_VERSION}-latest"
51     #
52     # This has the nexus repo prepended and major/minor/patch version with timestamp
53     #
54     TAGS="${TAGS} --tag ${DOCKER_REPOSITORY}/onap/policy/${image}:${MVN_VERSION}-${TIMESTAMP}"
55
56     echo $TAGS
57
58     docker build --quiet $TAGS target/$image
59
60     if [ $? -ne 0 ]
61     then
62         echo "Docker build failed"
63         docker images
64         exit 1
65     fi
66 done
67
68 docker images
69
70 #
71 # Push images
72 #
73 for image in policy-nexus policy-db policy-drools policy-pe; do
74     echo "Pushing $image"
75     docker push ${DOCKER_REPOSITORY}/onap/policy/$image:${MVN_MAJMIN_VERSION}-latest
76
77     if [ $? -ne 0 ]
78     then
79         echo "Docker push failed"
80         exit 1
81     fi
82
83     docker push ${DOCKER_REPOSITORY}/onap/policy/$image:${MVN_VERSION}-${TIMESTAMP}
84
85     if [ $? -ne 0 ]
86     then
87         echo "Docker push failed"
88         exit 1
89     fi
90 done