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