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="" |
| 9 | |
| 10 | if [ $HTTP_PROXY ]; then |
| 11 | PROXY_ARGS+="--build-arg HTTP_PROXY=${HTTP_PROXY}" |
| 12 | fi |
| 13 | if [ $HTTPS_PROXY ]; then |
| 14 | PROXY_ARGS+=" --build-arg HTTPS_PROXY=${HTTPS_PROXY}" |
| 15 | fi |
Pamela Dragosh | 6f91e0b | 2017-02-23 10:37:49 -0500 | [diff] [blame] | 16 | |
Pamela Dragosh | 3fe4d9c | 2017-03-07 15:39:48 -0500 | [diff] [blame] | 17 | echo $DOCKER_REPOSITORY |
| 18 | echo $MVN_VERSION |
Pamela Dragosh | e9f737a | 2017-03-23 07:44:56 -0400 | [diff] [blame] | 19 | echo $MVN_MAJMIN_VERSION |
Pamela Dragosh | 3fe4d9c | 2017-03-07 15:39:48 -0500 | [diff] [blame] | 20 | echo $TIMESTAMP |
Pamela Dragosh | 6f91e0b | 2017-02-23 10:37:49 -0500 | [diff] [blame] | 21 | |
Pamela Dragosh | e9f737a | 2017-03-23 07:44:56 -0400 | [diff] [blame] | 22 | if [[ -z $MVN_VERSION ]] |
| 23 | then |
| 24 | echo "MVN_VERSION is empty" |
| 25 | exit 1 |
| 26 | fi |
| 27 | |
| 28 | if [[ -z $MVN_MAJMIN_VERSION ]] |
| 29 | then |
| 30 | echo "MVN_MAJMIN_VERSION is empty" |
| 31 | exit 1 |
| 32 | fi |
| 33 | |
| 34 | if [[ $MVN_VERSION == *"SNAPSHOT"* ]] |
| 35 | then |
| 36 | MVN_MAJMIN_VERSION="${MVN_MAJMIN_VERSION}-SNAPSHOT" |
| 37 | else |
| 38 | MVN_MAJMIN_VERSION="${MVN_MAJMIN_VERSION}-STAGING" |
| 39 | fi |
| 40 | |
| 41 | echo $MVN_MAJMIN_VERSION |
| 42 | |
Pamela Dragosh | 6f91e0b | 2017-02-23 10:37:49 -0500 | [diff] [blame] | 43 | cp policy-pe/* target/policy-pe/ |
| 44 | cp policy-drools/* target/policy-drools/ |
| 45 | |
| 46 | for image in policy-os policy-nexus policy-db policy-base policy-drools policy-pe ; do |
| 47 | echo "Building $image" |
| 48 | mkdir -p target/$image |
| 49 | cp $image/* target/$image |
Pamela Dragosh | 3fe4d9c | 2017-03-07 15:39:48 -0500 | [diff] [blame] | 50 | |
Pamela Dragosh | e9f737a | 2017-03-23 07:44:56 -0400 | [diff] [blame] | 51 | # |
| 52 | # This is the local latest tagged image. The Dockerfile's need this to build images |
| 53 | # |
Pamela Dragosh | 18882a0 | 2017-03-30 10:50:45 -0400 | [diff] [blame] | 54 | TAGS="--tag onap/policy/${image}:latest" |
Pamela Dragosh | e9f737a | 2017-03-23 07:44:56 -0400 | [diff] [blame] | 55 | # |
| 56 | # This has the nexus repo prepended and only major/minor version with latest |
| 57 | # |
Pamela Dragosh | 18882a0 | 2017-03-30 10:50:45 -0400 | [diff] [blame] | 58 | TAGS="${TAGS} --tag ${DOCKER_REPOSITORY}/onap/policy/${image}:${MVN_MAJMIN_VERSION}-latest" |
Pamela Dragosh | e9f737a | 2017-03-23 07:44:56 -0400 | [diff] [blame] | 59 | # |
| 60 | # This has the nexus repo prepended and major/minor/patch version with timestamp |
| 61 | # |
Pamela Dragosh | 18882a0 | 2017-03-30 10:50:45 -0400 | [diff] [blame] | 62 | TAGS="${TAGS} --tag ${DOCKER_REPOSITORY}/onap/policy/${image}:${MVN_VERSION}-${TIMESTAMP}" |
Pamela Dragosh | 3fe4d9c | 2017-03-07 15:39:48 -0500 | [diff] [blame] | 63 | |
| 64 | echo $TAGS |
Pamela Dragosh | 3311eb7 | 2017-03-16 11:30:29 -0400 | [diff] [blame] | 65 | |
Shashank Kumar Shankar | 6e36eec | 2017-06-29 12:52:59 -0700 | [diff] [blame] | 66 | docker build --quiet ${PROXY_ARGS} $TAGS target/$image |
Pamela Dragosh | 9bd4bf6 | 2017-03-30 12:46:08 -0400 | [diff] [blame] | 67 | |
| 68 | if [ $? -ne 0 ] |
| 69 | then |
| 70 | echo "Docker build failed" |
| 71 | docker images |
| 72 | exit 1 |
| 73 | fi |
Pamela Dragosh | 6f91e0b | 2017-02-23 10:37:49 -0500 | [diff] [blame] | 74 | done |
Pamela Dragosh | 2fc2222 | 2017-03-15 16:12:02 -0400 | [diff] [blame] | 75 | |
Pamela Dragosh | 9bd4bf6 | 2017-03-30 12:46:08 -0400 | [diff] [blame] | 76 | docker images |
| 77 | |
Pamela Dragosh | ceba3d8 | 2017-03-16 11:02:05 -0400 | [diff] [blame] | 78 | # |
Pamela Dragosh | e9f737a | 2017-03-23 07:44:56 -0400 | [diff] [blame] | 79 | # Push images |
Pamela Dragosh | ceba3d8 | 2017-03-16 11:02:05 -0400 | [diff] [blame] | 80 | # |
| 81 | for image in policy-nexus policy-db policy-drools policy-pe; do |
| 82 | echo "Pushing $image" |
Pamela Dragosh | 18882a0 | 2017-03-30 10:50:45 -0400 | [diff] [blame] | 83 | docker push ${DOCKER_REPOSITORY}/onap/policy/$image:${MVN_MAJMIN_VERSION}-latest |
Pamela Dragosh | 9bd4bf6 | 2017-03-30 12:46:08 -0400 | [diff] [blame] | 84 | |
| 85 | if [ $? -ne 0 ] |
| 86 | then |
| 87 | echo "Docker push failed" |
| 88 | exit 1 |
| 89 | fi |
| 90 | |
Pamela Dragosh | 18882a0 | 2017-03-30 10:50:45 -0400 | [diff] [blame] | 91 | docker push ${DOCKER_REPOSITORY}/onap/policy/$image:${MVN_VERSION}-${TIMESTAMP} |
Pamela Dragosh | 9bd4bf6 | 2017-03-30 12:46:08 -0400 | [diff] [blame] | 92 | |
| 93 | if [ $? -ne 0 ] |
| 94 | then |
| 95 | echo "Docker push failed" |
| 96 | exit 1 |
| 97 | fi |
Pamela Dragosh | ceba3d8 | 2017-03-16 11:02:05 -0400 | [diff] [blame] | 98 | done |