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