Pamela Dragosh | 1766552 | 2017-02-21 09:05:08 -0500 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | echo '============== STARTING SCRIPT TO BUILD DOCKER IMAGES =================' |
Pamela Dragosh | 18882a0 | 2017-03-30 10:50:45 -0400 | [diff] [blame] | 4 | DOCKER_REPOSITORY=nexus3.onap.org:10003 |
Pamela Dragosh | 3fe4d9c | 2017-03-07 15:39:48 -0500 | [diff] [blame] | 5 | MVN_VERSION=$(cat target/version) |
Pamela Dragosh | e9f737a | 2017-03-23 07:44:56 -0400 | [diff] [blame] | 6 | MVN_MAJMIN_VERSION=$(cut -f 1,2 -d . target/version) |
Pamela Dragosh | 3fe4d9c | 2017-03-07 15:39:48 -0500 | [diff] [blame] | 7 | TIMESTAMP=$(date -u +%Y%m%dT%H%M%S) |
Shashank Kumar Shankar | 3e5a0c3 | 2017-06-27 16:10:28 -0700 | [diff] [blame] | 8 | PROXY_ARGS="" |
mmis | 0d85691 | 2018-03-05 18:23:39 +0000 | [diff] [blame] | 9 | IMAGE=policy-nexus |
Shashank Kumar Shankar | 3e5a0c3 | 2017-06-27 16:10:28 -0700 | [diff] [blame] | 10 | |
| 11 | if [ $HTTP_PROXY ]; then |
| 12 | PROXY_ARGS+="--build-arg HTTP_PROXY=${HTTP_PROXY}" |
| 13 | fi |
| 14 | if [ $HTTPS_PROXY ]; then |
Shashank Kumar Shankar | 6e36eec | 2017-06-29 12:52:59 -0700 | [diff] [blame] | 15 | PROXY_ARGS+=" --build-arg HTTPS_PROXY=${HTTPS_PROXY}" |
Shashank Kumar Shankar | 3e5a0c3 | 2017-06-27 16:10:28 -0700 | [diff] [blame] | 16 | fi |
Pamela Dragosh | 1766552 | 2017-02-21 09:05:08 -0500 | [diff] [blame] | 17 | |
Pamela Dragosh | 3fe4d9c | 2017-03-07 15:39:48 -0500 | [diff] [blame] | 18 | echo $DOCKER_REPOSITORY |
| 19 | echo $MVN_VERSION |
Pamela Dragosh | e9f737a | 2017-03-23 07:44:56 -0400 | [diff] [blame] | 20 | echo $MVN_MAJMIN_VERSION |
Pamela Dragosh | 3fe4d9c | 2017-03-07 15:39:48 -0500 | [diff] [blame] | 21 | echo $TIMESTAMP |
Pamela Dragosh | 6f91e0b | 2017-02-23 10:37:49 -0500 | [diff] [blame] | 22 | |
Pamela Dragosh | e9f737a | 2017-03-23 07:44:56 -0400 | [diff] [blame] | 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 | |
mmis | 0d85691 | 2018-03-05 18:23:39 +0000 | [diff] [blame] | 44 | echo "Building $IMAGE" |
| 45 | mkdir -p target/$IMAGE |
| 46 | cp $IMAGE/* target/$IMAGE |
Pamela Dragosh | 1e54728 | 2017-02-21 09:41:58 -0500 | [diff] [blame] | 47 | |
mmis | 0d85691 | 2018-03-05 18:23:39 +0000 | [diff] [blame] | 48 | # |
| 49 | # This is the local latest tagged image. The Dockerfile's need this to build images |
| 50 | # |
| 51 | TAGS="--tag onap/policy/${IMAGE}:latest" |
| 52 | # |
| 53 | # This is the nexus repo prepended for latest tagged image. |
| 54 | # |
| 55 | TAGS="${TAGS} --tag ${DOCKER_REPOSITORY}/onap/policy/${IMAGE}:latest" |
| 56 | # |
| 57 | # This has the nexus repo prepended and only major/minor version with latest |
| 58 | # |
| 59 | TAGS="${TAGS} --tag ${DOCKER_REPOSITORY}/onap/policy/${IMAGE}:${MVN_MAJMIN_VERSION}-latest" |
| 60 | # |
| 61 | # This has the nexus repo prepended and major/minor/patch version with timestamp |
| 62 | # |
| 63 | TAGS="${TAGS} --tag ${DOCKER_REPOSITORY}/onap/policy/${IMAGE}:${MVN_VERSION}-STAGING-${TIMESTAMP}" |
Pamela Dragosh | 3fe4d9c | 2017-03-07 15:39:48 -0500 | [diff] [blame] | 64 | |
mmis | 0d85691 | 2018-03-05 18:23:39 +0000 | [diff] [blame] | 65 | echo $TAGS |
Pamela Dragosh | 3fe4d9c | 2017-03-07 15:39:48 -0500 | [diff] [blame] | 66 | |
mmis | 0d85691 | 2018-03-05 18:23:39 +0000 | [diff] [blame] | 67 | docker build --quiet ${PROXY_ARGS} $TAGS target/$IMAGE |
Pamela Dragosh | 3fe4d9c | 2017-03-07 15:39:48 -0500 | [diff] [blame] | 68 | |
mmis | 0d85691 | 2018-03-05 18:23:39 +0000 | [diff] [blame] | 69 | if [ $? -ne 0 ] |
| 70 | then |
| 71 | echo "Docker build failed" |
| 72 | docker images |
| 73 | exit 1 |
| 74 | fi |
Pamela Dragosh | 1766552 | 2017-02-21 09:05:08 -0500 | [diff] [blame] | 75 | |
Pamela Dragosh | 9bd4bf6 | 2017-03-30 12:46:08 -0400 | [diff] [blame] | 76 | docker images |
| 77 | |
mmis | 0d85691 | 2018-03-05 18:23:39 +0000 | [diff] [blame] | 78 | echo "Pushing $IMAGE" |
Pamela Dragosh | 9bd4bf6 | 2017-03-30 12:46:08 -0400 | [diff] [blame] | 79 | |
mmis | 0d85691 | 2018-03-05 18:23:39 +0000 | [diff] [blame] | 80 | docker push ${DOCKER_REPOSITORY}/onap/policy/$IMAGE:latest |
Pamela Dragosh | 9bd4bf6 | 2017-03-30 12:46:08 -0400 | [diff] [blame] | 81 | |
mmis | 0d85691 | 2018-03-05 18:23:39 +0000 | [diff] [blame] | 82 | if [ $? -ne 0 ] |
| 83 | then |
| 84 | echo "Docker push failed" |
| 85 | exit 1 |
Pamela Dragosh | 9bd4bf6 | 2017-03-30 12:46:08 -0400 | [diff] [blame] | 86 | |
mmis | 0d85691 | 2018-03-05 18:23:39 +0000 | [diff] [blame] | 87 | fi |
Pamela Dragosh | 9bd4bf6 | 2017-03-30 12:46:08 -0400 | [diff] [blame] | 88 | |
mmis | 0d85691 | 2018-03-05 18:23:39 +0000 | [diff] [blame] | 89 | docker push ${DOCKER_REPOSITORY}/onap/policy/$IMAGE:${MVN_MAJMIN_VERSION}-latest |
Pamela Dragosh | 9bd4bf6 | 2017-03-30 12:46:08 -0400 | [diff] [blame] | 90 | |
mmis | 0d85691 | 2018-03-05 18:23:39 +0000 | [diff] [blame] | 91 | if [ $? -ne 0 ] |
| 92 | then |
| 93 | echo "Docker push failed" |
| 94 | exit 1 |
Pamela Dragosh | 9bd4bf6 | 2017-03-30 12:46:08 -0400 | [diff] [blame] | 95 | |
mmis | 0d85691 | 2018-03-05 18:23:39 +0000 | [diff] [blame] | 96 | fi |
| 97 | docker push ${DOCKER_REPOSITORY}/onap/policy/$IMAGE:${MVN_VERSION}-STAGING-${TIMESTAMP} |
Pamela Dragosh | 9bd4bf6 | 2017-03-30 12:46:08 -0400 | [diff] [blame] | 98 | |
mmis | 0d85691 | 2018-03-05 18:23:39 +0000 | [diff] [blame] | 99 | if [ $? -ne 0 ] |
| 100 | then |
| 101 | echo "Docker push failed" |
| 102 | exit 1 |
Pamela Dragosh | 9bd4bf6 | 2017-03-30 12:46:08 -0400 | [diff] [blame] | 103 | |
mmis | 0d85691 | 2018-03-05 18:23:39 +0000 | [diff] [blame] | 104 | fi |