blob: 1168a2a8b8c116b6f0dc32b9323ef79749edd720 [file] [log] [blame]
mmis824a75e2018-03-02 18:04:48 +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-drools
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"
mmis824a75e2018-03-02 18:04:48 +000045
46#
47# This is the local latest tagged image. The Dockerfile's need this to build images
48#
mmisac6780a2018-03-14 12:10:52 +000049TAGS="--tag onap/${IMAGE}:latest"
mmis824a75e2018-03-02 18:04:48 +000050#
51# This is the nexus repo prepended for latest tagged image.
52#
mmisac6780a2018-03-14 12:10:52 +000053TAGS="${TAGS} --tag ${DOCKER_REPOSITORY}/onap/${IMAGE}:latest"
mmis824a75e2018-03-02 18:04:48 +000054#
55# This has the nexus repo prepended and only major/minor version with latest
56#
mmisac6780a2018-03-14 12:10:52 +000057TAGS="${TAGS} --tag ${DOCKER_REPOSITORY}/onap/${IMAGE}:${MVN_MAJMIN_VERSION}-latest"
mmis824a75e2018-03-02 18:04:48 +000058#
59# This has the nexus repo prepended and major/minor/patch version with timestamp
60#
mmisac6780a2018-03-14 12:10:52 +000061TAGS="${TAGS} --tag ${DOCKER_REPOSITORY}/onap/${IMAGE}:${MVN_VERSION}-STAGING-${TIMESTAMP}"
mmis824a75e2018-03-02 18:04:48 +000062
63echo $TAGS
64
65docker build --quiet ${PROXY_ARGS} $TAGS packages/docker/target/$IMAGE
66
67if [ $? -ne 0 ]
68then
69 echo "Docker build failed"
70 docker images
71 exit 1
72fi
73
74docker images
75
76echo "Pushing $IMAGE"
77
mmisac6780a2018-03-14 12:10:52 +000078docker push ${DOCKER_REPOSITORY}/onap/${IMAGE}:latest
mmis824a75e2018-03-02 18:04:48 +000079
80if [ $? -ne 0 ]
81then
82 echo "Docker push failed"
83 exit 1
84
85fi
86
mmisac6780a2018-03-14 12:10:52 +000087docker push ${DOCKER_REPOSITORY}/onap/${IMAGE}:${MVN_MAJMIN_VERSION}-latest
mmis824a75e2018-03-02 18:04:48 +000088
89if [ $? -ne 0 ]
90then
91 echo "Docker push failed"
92 exit 1
93
94fi
mmisac6780a2018-03-14 12:10:52 +000095docker push ${DOCKER_REPOSITORY}/onap/${IMAGE}:${MVN_VERSION}-STAGING-${TIMESTAMP}
mmis824a75e2018-03-02 18:04:48 +000096
97if [ $? -ne 0 ]
98then
99 echo "Docker push failed"
100 exit 1
101
102fi
103