forgot DOCKER_REPOSITORY latest tag
[policy/docker.git] / docker_build.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 is the nexus repo prepended for latest tagged image.
49     #
50     TAGS="${TAGS} --tag ${DOCKER_REPOSITORY}/onap/policy/${image}:latest"
51     #
52     # This has the nexus repo prepended and only major/minor version with latest
53     #
54     TAGS="${TAGS} --tag ${DOCKER_REPOSITORY}/onap/policy/${image}:${MVN_MAJMIN_VERSION}-latest"
55     #
56     # This has the nexus repo prepended and major/minor/patch version with timestamp
57     #
58     TAGS="${TAGS} --tag ${DOCKER_REPOSITORY}/onap/policy/${image}:${MVN_VERSION}-STAGING-${TIMESTAMP}"
59
60     echo $TAGS
61
62     docker build --quiet $TAGS target/$image
63
64     if [ $? -ne 0 ]
65     then
66         echo "Docker build failed"
67         docker images
68         exit 1
69     fi
70 done
71
72 docker images
73
74 for image in policy-nexus policy-db policy-drools policy-pe; do
75     echo "Pushing $image"
76
77     docker push ${DOCKER_REPOSITORY}/onap/policy/$image:latest
78
79     if [ $? -ne 0 ]
80     then
81         echo "Docker push failed"
82         exit 1
83
84     fi
85
86     docker push ${DOCKER_REPOSITORY}/onap/policy/$image:${MVN_MAJMIN_VERSION}-latest
87
88     if [ $? -ne 0 ]
89     then
90         echo "Docker push failed"
91         exit 1
92
93     fi
94     docker push ${DOCKER_REPOSITORY}/onap/policy/$image:${MVN_VERSION}-STAGING-${TIMESTAMP}
95
96     if [ $? -ne 0 ]
97     then
98         echo "Docker push failed"
99         exit 1
100
101     fi
102 done