deploy and undeploy as audits.
[policy/drools-pdp.git] / docker_build.sh
1 #!/bin/bash
2 # Copyright 2018-2019 AT&T Intellectual Property. All rights reserved
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 #         http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 #
17 echo '============== STARTING SCRIPT TO BUILD DOCKER IMAGES ================='
18 DOCKER_REPOSITORY=nexus3.onap.org:10003
19 MVN_VERSION=$(cat packages/docker/target/version)
20 MVN_MAJMIN_VERSION=$(cut -f 1,2 -d . packages/docker/target/version)
21 TIMESTAMP=$(date -u +%Y%m%dT%H%M%S)
22 BUILD_ARGS="--build-arg BUILD_VERSION=${MVN_VERSION}"
23 IMAGE=policy-drools
24
25 echo $DOCKER_REPOSITORY
26 echo $MVN_VERSION
27 echo $MVN_MAJMIN_VERSION
28 echo $TIMESTAMP
29
30 if [[ -z $MVN_VERSION ]]
31 then
32     echo "MVN_VERSION is empty"
33     exit 1
34 fi
35
36 if [[ -z $MVN_MAJMIN_VERSION ]]
37 then
38     echo "MVN_MAJMIN_VERSION is empty"
39     exit 1
40 fi
41
42 if [[ $MVN_VERSION == *"SNAPSHOT"* ]]
43 then
44     MVN_MAJMIN_VERSION="${MVN_MAJMIN_VERSION}-SNAPSHOT"
45 else
46     MVN_MAJMIN_VERSION="${MVN_MAJMIN_VERSION}-STAGING"
47 fi
48
49 echo $MVN_MAJMIN_VERSION
50
51 echo "Building $IMAGE"
52
53 #
54 # This is the local latest tagged image. The Dockerfile's need this to build images
55 #
56 TAGS="--tag onap/${IMAGE}:latest"
57 #
58 # This is the nexus repo prepended for latest tagged image.
59 #
60 TAGS="${TAGS} --tag ${DOCKER_REPOSITORY}/onap/${IMAGE}:latest"
61 #
62 # This has the nexus repo prepended and only major/minor version with latest
63 #
64 TAGS="${TAGS} --tag ${DOCKER_REPOSITORY}/onap/${IMAGE}:${MVN_MAJMIN_VERSION}-latest"
65 #
66 # This has the nexus repo prepended and major/minor/patch version with timestamp
67 #
68 TAGS="${TAGS} --tag ${DOCKER_REPOSITORY}/onap/${IMAGE}:${MVN_VERSION}-STAGING-${TIMESTAMP}Z"
69
70 echo $TAGS
71
72 docker build --quiet ${BUILD_ARGS} $TAGS packages/docker/target/$IMAGE
73
74 if [ $? -ne 0 ]
75 then
76     echo "Docker build failed"
77     docker images
78     exit 1
79 fi
80
81 docker images
82
83 echo "Pushing $IMAGE"
84
85 docker push ${DOCKER_REPOSITORY}/onap/${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/${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/${IMAGE}:${MVN_VERSION}-STAGING-${TIMESTAMP}Z
103
104 if [ $? -ne 0 ]
105 then
106     echo "Docker push failed"
107     exit 1
108
109 fi
110