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