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