Pamela Dragosh | 6f91e0b | 2017-02-23 10:37:49 -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 | 6e36eec | 2017-06-29 12:52:59 -0700 | [diff] [blame] | 8 | PROXY_ARGS="" |
mmis | 0d85691 | 2018-03-05 18:23:39 +0000 | [diff] [blame] | 9 | IMAGE=policy-nexus |
Shashank Kumar Shankar | 6e36eec | 2017-06-29 12:52:59 -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 |
| 15 | PROXY_ARGS+=" --build-arg HTTPS_PROXY=${HTTPS_PROXY}" |
| 16 | fi |
Pamela Dragosh | 6f91e0b | 2017-02-23 10:37:49 -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 | 6f91e0b | 2017-02-23 10:37:49 -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 | # |
mmis | 6dc5a24 | 2018-03-14 12:35:35 +0000 | [diff] [blame] | 51 | TAGS="--tag onap/${IMAGE}:latest" |
mmis | 0d85691 | 2018-03-05 18:23:39 +0000 | [diff] [blame] | 52 | # |
| 53 | # This has the nexus repo prepended and only major/minor version with latest |
| 54 | # |
mmis | 6dc5a24 | 2018-03-14 12:35:35 +0000 | [diff] [blame] | 55 | TAGS="${TAGS} --tag ${DOCKER_REPOSITORY}/onap/${IMAGE}:${MVN_MAJMIN_VERSION}-latest" |
mmis | 0d85691 | 2018-03-05 18:23:39 +0000 | [diff] [blame] | 56 | # |
| 57 | # This has the nexus repo prepended and major/minor/patch version with timestamp |
| 58 | # |
mmis | 6dc5a24 | 2018-03-14 12:35:35 +0000 | [diff] [blame] | 59 | TAGS="${TAGS} --tag ${DOCKER_REPOSITORY}/onap/${IMAGE}:${MVN_VERSION}-${TIMESTAMP}" |
Pamela Dragosh | 3fe4d9c | 2017-03-07 15:39:48 -0500 | [diff] [blame] | 60 | |
mmis | 0d85691 | 2018-03-05 18:23:39 +0000 | [diff] [blame] | 61 | echo $TAGS |
Pamela Dragosh | 3fe4d9c | 2017-03-07 15:39:48 -0500 | [diff] [blame] | 62 | |
mmis | 0d85691 | 2018-03-05 18:23:39 +0000 | [diff] [blame] | 63 | docker build --quiet ${PROXY_ARGS} $TAGS target/$IMAGE |
Pamela Dragosh | 3311eb7 | 2017-03-16 11:30:29 -0400 | [diff] [blame] | 64 | |
mmis | 0d85691 | 2018-03-05 18:23:39 +0000 | [diff] [blame] | 65 | if [ $? -ne 0 ] |
| 66 | then |
| 67 | echo "Docker build failed" |
| 68 | docker images |
| 69 | exit 1 |
| 70 | fi |
Pamela Dragosh | 2fc2222 | 2017-03-15 16:12:02 -0400 | [diff] [blame] | 71 | |
Pamela Dragosh | 9bd4bf6 | 2017-03-30 12:46:08 -0400 | [diff] [blame] | 72 | docker images |
| 73 | |
Pamela Dragosh | ceba3d8 | 2017-03-16 11:02:05 -0400 | [diff] [blame] | 74 | # |
mmis | 0d85691 | 2018-03-05 18:23:39 +0000 | [diff] [blame] | 75 | # Push image |
Pamela Dragosh | ceba3d8 | 2017-03-16 11:02:05 -0400 | [diff] [blame] | 76 | # |
mmis | 0d85691 | 2018-03-05 18:23:39 +0000 | [diff] [blame] | 77 | echo "Pushing $IMAGE" |
mmis | 6dc5a24 | 2018-03-14 12:35:35 +0000 | [diff] [blame] | 78 | docker push ${DOCKER_REPOSITORY}/onap/$IMAGE:${MVN_MAJMIN_VERSION}-latest |
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 | if [ $? -ne 0 ] |
| 81 | then |
| 82 | echo "Docker push failed" |
| 83 | exit 1 |
| 84 | fi |
Pamela Dragosh | 9bd4bf6 | 2017-03-30 12:46:08 -0400 | [diff] [blame] | 85 | |
mmis | 6dc5a24 | 2018-03-14 12:35:35 +0000 | [diff] [blame] | 86 | docker push ${DOCKER_REPOSITORY}/onap/$IMAGE:${MVN_VERSION}-${TIMESTAMP} |
Pamela Dragosh | 9bd4bf6 | 2017-03-30 12:46:08 -0400 | [diff] [blame] | 87 | |
mmis | 0d85691 | 2018-03-05 18:23:39 +0000 | [diff] [blame] | 88 | if [ $? -ne 0 ] |
| 89 | then |
| 90 | echo "Docker push failed" |
| 91 | exit 1 |
| 92 | fi |