blob: bc7aac1dee6d58edf85599ca2fc20be102073b8e [file] [log] [blame]
mmisef24b052018-07-10 10:50:05 +01001#!/bin/bash
2#
3echo '============== STARTING SCRIPT TO BUILD DOCKER IMAGES ================='
4DOCKER_REPOSITORY=nexus3.onap.org:10003
5MVN_VERSION=$(cat packages/apex-pdp-docker/target/version)
6MVN_MAJMIN_VERSION=$(cut -f 1,2 -d . packages/apex-pdp-docker/target/version)
7TIMESTAMP=$(date -u +%Y%m%dT%H%M%S)
8PROXY_ARGS=""
9IMAGE=policy-apex-pdp
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"
45
46#
47# This is the local latest tagged image. The Dockerfile's need this to build images
48#
49TAGS="--tag onap/${IMAGE}:latest"
50#
51# This has the nexus repo prepended and only major/minor version with latest
52#
53TAGS="${TAGS} --tag ${DOCKER_REPOSITORY}/onap/${IMAGE}:${MVN_MAJMIN_VERSION}-latest"
54#
55# This has the nexus repo prepended and major/minor/patch version with timestamp
56#
57TAGS="${TAGS} --tag ${DOCKER_REPOSITORY}/onap/${IMAGE}:${MVN_VERSION}-${TIMESTAMP}Z"
58
59echo $TAGS
60
61docker build --quiet ${PROXY_ARGS} $TAGS packages/apex-pdp-docker/target/$IMAGE
62
63if [ $? -ne 0 ]
64then
65 echo "Docker build failed"
66 docker images
67 exit 1
68fi
69
70docker images
71
72#
73# Push image
74#
75echo "Pushing $IMAGE"
76docker push ${DOCKER_REPOSITORY}/onap/$IMAGE:${MVN_MAJMIN_VERSION}-latest
77
78if [ $? -ne 0 ]
79then
80 echo "Docker push failed"
81 exit 1
82fi
83
84docker push ${DOCKER_REPOSITORY}/onap/$IMAGE:${MVN_VERSION}-${TIMESTAMP}Z
85
86if [ $? -ne 0 ]
87then
88 echo "Docker push failed"
89 exit 1
90fi
91