Pamela Dragosh | b174339 | 2017-02-21 12:04:28 -0500 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | echo '============== STARTING SCRIPT TO BUILD DOCKER IMAGES =================' |
Pamela Dragosh | ceba3d8 | 2017-03-16 11:02:05 -0400 | [diff] [blame] | 4 | # |
| 5 | # JUST VERIFY ONLY - NO PUSHING |
| 6 | # |
Pamela Dragosh | 18882a0 | 2017-03-30 10:50:45 -0400 | [diff] [blame] | 7 | DOCKER_REPOSITORY=nexus3.onap.org:10003 |
Pamela Dragosh | 3fe4d9c | 2017-03-07 15:39:48 -0500 | [diff] [blame] | 8 | MVN_VERSION=$(cat target/version) |
Pamela Dragosh | e9f737a | 2017-03-23 07:44:56 -0400 | [diff] [blame] | 9 | MVN_MAJMIN_VERSION=$(cut -f 1,2 -d . target/version) |
Pamela Dragosh | 3fe4d9c | 2017-03-07 15:39:48 -0500 | [diff] [blame] | 10 | TIMESTAMP=$(date -u +%Y%m%dT%H%M%S) |
Shashank Kumar Shankar | 6e36eec | 2017-06-29 12:52:59 -0700 | [diff] [blame] | 11 | PROXY_ARGS="" |
mmis | 0d85691 | 2018-03-05 18:23:39 +0000 | [diff] [blame] | 12 | IMAGE=policy-nexus |
Shashank Kumar Shankar | 6e36eec | 2017-06-29 12:52:59 -0700 | [diff] [blame] | 13 | |
| 14 | if [ $HTTP_PROXY ]; then |
| 15 | PROXY_ARGS+="--build-arg HTTP_PROXY=${HTTP_PROXY}" |
| 16 | fi |
| 17 | if [ $HTTPS_PROXY ]; then |
| 18 | PROXY_ARGS+=" --build-arg HTTPS_PROXY=${HTTPS_PROXY}" |
| 19 | fi |
Pamela Dragosh | b174339 | 2017-02-21 12:04:28 -0500 | [diff] [blame] | 20 | |
Pamela Dragosh | 3fe4d9c | 2017-03-07 15:39:48 -0500 | [diff] [blame] | 21 | echo $DOCKER_REPOSITORY |
| 22 | echo $MVN_VERSION |
Pamela Dragosh | e9f737a | 2017-03-23 07:44:56 -0400 | [diff] [blame] | 23 | echo $MVN_MAJMIN_VERSION |
Pamela Dragosh | 3fe4d9c | 2017-03-07 15:39:48 -0500 | [diff] [blame] | 24 | echo $TIMESTAMP |
Pamela Dragosh | 6f91e0b | 2017-02-23 10:37:49 -0500 | [diff] [blame] | 25 | |
Pamela Dragosh | e9f737a | 2017-03-23 07:44:56 -0400 | [diff] [blame] | 26 | if [[ -z $MVN_VERSION ]] |
| 27 | then |
| 28 | echo "MVN_VERSION is empty" |
| 29 | exit 1 |
| 30 | fi |
| 31 | |
| 32 | if [[ -z $MVN_MAJMIN_VERSION ]] |
| 33 | then |
| 34 | echo "MVN_MAJMIN_VERSION is empty" |
| 35 | exit 1 |
| 36 | fi |
| 37 | |
| 38 | if [[ $MVN_VERSION == *"SNAPSHOT"* ]] |
| 39 | then |
| 40 | MVN_MAJMIN_VERSION="${MVN_MAJMIN_VERSION}-SNAPSHOT" |
| 41 | else |
| 42 | MVN_MAJMIN_VERSION="${MVN_MAJMIN_VERSION}-STAGING" |
| 43 | fi |
| 44 | |
| 45 | echo $MVN_MAJMIN_VERSION |
| 46 | |
mmis | 0d85691 | 2018-03-05 18:23:39 +0000 | [diff] [blame] | 47 | echo "Building $IMAGE" |
| 48 | mkdir -p target/$IMAGE |
| 49 | cp $IMAGE/* target/$IMAGE |
Pamela Dragosh | 6f91e0b | 2017-02-23 10:37:49 -0500 | [diff] [blame] | 50 | |
mmis | 0d85691 | 2018-03-05 18:23:39 +0000 | [diff] [blame] | 51 | # |
| 52 | # This is the local latest tagged image. The Dockerfile's need this to build images |
| 53 | # |
mmis | 6dc5a24 | 2018-03-14 12:35:35 +0000 | [diff] [blame] | 54 | TAGS="--tag onap/${IMAGE}:latest" |
mmis | 0d85691 | 2018-03-05 18:23:39 +0000 | [diff] [blame] | 55 | # |
| 56 | # This has the nexus repo prepended and only major/minor version with latest |
| 57 | # |
mmis | 6dc5a24 | 2018-03-14 12:35:35 +0000 | [diff] [blame] | 58 | TAGS="${TAGS} --tag ${DOCKER_REPOSITORY}/onap/${IMAGE}:${MVN_MAJMIN_VERSION}-latest" |
mmis | 0d85691 | 2018-03-05 18:23:39 +0000 | [diff] [blame] | 59 | # |
| 60 | # This has the nexus repo prepended and major/minor/patch version with timestamp |
| 61 | # |
mmis | 6dc5a24 | 2018-03-14 12:35:35 +0000 | [diff] [blame] | 62 | TAGS="${TAGS} --tag ${DOCKER_REPOSITORY}/onap/${IMAGE}:${MVN_VERSION}-${TIMESTAMP}" |
Pamela Dragosh | 3fe4d9c | 2017-03-07 15:39:48 -0500 | [diff] [blame] | 63 | |
mmis | 0d85691 | 2018-03-05 18:23:39 +0000 | [diff] [blame] | 64 | echo $TAGS |
Pamela Dragosh | 3fe4d9c | 2017-03-07 15:39:48 -0500 | [diff] [blame] | 65 | |
mmis | 0d85691 | 2018-03-05 18:23:39 +0000 | [diff] [blame] | 66 | docker build --quiet ${PROXY_ARGS} $TAGS target/$IMAGE |
Pamela Dragosh | 3311eb7 | 2017-03-16 11:30:29 -0400 | [diff] [blame] | 67 | |
mmis | 0d85691 | 2018-03-05 18:23:39 +0000 | [diff] [blame] | 68 | if [ $? -ne 0 ] |
| 69 | then |
| 70 | echo "Docker build failed" |
| 71 | docker images |
| 72 | exit 1 |
| 73 | fi |
Pamela Dragosh | 3311eb7 | 2017-03-16 11:30:29 -0400 | [diff] [blame] | 74 | |
| 75 | docker images |
| 76 | |