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="" |
| 9 | |
| 10 | if [ $HTTP_PROXY ]; then |
| 11 | PROXY_ARGS+="--build-arg HTTP_PROXY=${HTTP_PROXY}" |
| 12 | fi |
| 13 | if [ $HTTPS_PROXY ]; then |
Shashank Kumar Shankar | 6e36eec | 2017-06-29 12:52:59 -0700 | [diff] [blame] | 14 | PROXY_ARGS+=" --build-arg HTTPS_PROXY=${HTTPS_PROXY}" |
Shashank Kumar Shankar | 3e5a0c3 | 2017-06-27 16:10:28 -0700 | [diff] [blame] | 15 | fi |
Pamela Dragosh | 1766552 | 2017-02-21 09:05:08 -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 | 1e54728 | 2017-02-21 09:41:58 -0500 | [diff] [blame] | 43 | cp policy-pe/* target/policy-pe/ |
| 44 | cp policy-drools/* target/policy-drools/ |
| 45 | |
Pamela Dragosh | 1766552 | 2017-02-21 09:05:08 -0500 | [diff] [blame] | 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 | # |
Pamela Dragosh | 64e7ad3 | 2017-03-30 15:28:50 -0400 | [diff] [blame] | 56 | # This is the nexus repo prepended for latest tagged image. |
| 57 | # |
| 58 | TAGS="${TAGS} --tag ${DOCKER_REPOSITORY}/onap/policy/${image}:latest" |
| 59 | # |
Pamela Dragosh | e9f737a | 2017-03-23 07:44:56 -0400 | [diff] [blame] | 60 | # This has the nexus repo prepended and only major/minor version with latest |
| 61 | # |
Pamela Dragosh | 18882a0 | 2017-03-30 10:50:45 -0400 | [diff] [blame] | 62 | TAGS="${TAGS} --tag ${DOCKER_REPOSITORY}/onap/policy/${image}:${MVN_MAJMIN_VERSION}-latest" |
Pamela Dragosh | e9f737a | 2017-03-23 07:44:56 -0400 | [diff] [blame] | 63 | # |
| 64 | # This has the nexus repo prepended and major/minor/patch version with timestamp |
| 65 | # |
Pamela Dragosh | 18882a0 | 2017-03-30 10:50:45 -0400 | [diff] [blame] | 66 | TAGS="${TAGS} --tag ${DOCKER_REPOSITORY}/onap/policy/${image}:${MVN_VERSION}-STAGING-${TIMESTAMP}" |
Pamela Dragosh | 3fe4d9c | 2017-03-07 15:39:48 -0500 | [diff] [blame] | 67 | |
| 68 | echo $TAGS |
| 69 | |
Shashank Kumar Shankar | 3e5a0c3 | 2017-06-27 16:10:28 -0700 | [diff] [blame] | 70 | docker build --quiet ${PROXY_ARGS} $TAGS target/$image |
Pamela Dragosh | 9bd4bf6 | 2017-03-30 12:46:08 -0400 | [diff] [blame] | 71 | |
| 72 | if [ $? -ne 0 ] |
| 73 | then |
| 74 | echo "Docker build failed" |
| 75 | docker images |
| 76 | exit 1 |
| 77 | fi |
Pamela Dragosh | 1766552 | 2017-02-21 09:05:08 -0500 | [diff] [blame] | 78 | done |
| 79 | |
Pamela Dragosh | 9bd4bf6 | 2017-03-30 12:46:08 -0400 | [diff] [blame] | 80 | docker images |
| 81 | |
Pamela Dragosh | 1766552 | 2017-02-21 09:05:08 -0500 | [diff] [blame] | 82 | for image in policy-nexus policy-db policy-drools policy-pe; do |
| 83 | echo "Pushing $image" |
Pamela Dragosh | 9bd4bf6 | 2017-03-30 12:46:08 -0400 | [diff] [blame] | 84 | |
Pamela Dragosh | 18882a0 | 2017-03-30 10:50:45 -0400 | [diff] [blame] | 85 | docker push ${DOCKER_REPOSITORY}/onap/policy/$image:latest |
Pamela Dragosh | 9bd4bf6 | 2017-03-30 12:46:08 -0400 | [diff] [blame] | 86 | |
| 87 | if [ $? -ne 0 ] |
| 88 | then |
| 89 | echo "Docker push failed" |
| 90 | exit 1 |
| 91 | |
| 92 | fi |
| 93 | |
Pamela Dragosh | 18882a0 | 2017-03-30 10:50:45 -0400 | [diff] [blame] | 94 | docker push ${DOCKER_REPOSITORY}/onap/policy/$image:${MVN_MAJMIN_VERSION}-latest |
Pamela Dragosh | 9bd4bf6 | 2017-03-30 12:46:08 -0400 | [diff] [blame] | 95 | |
| 96 | if [ $? -ne 0 ] |
| 97 | then |
| 98 | echo "Docker push failed" |
| 99 | exit 1 |
| 100 | |
| 101 | fi |
Pamela Dragosh | 18882a0 | 2017-03-30 10:50:45 -0400 | [diff] [blame] | 102 | docker push ${DOCKER_REPOSITORY}/onap/policy/$image:${MVN_VERSION}-STAGING-${TIMESTAMP} |
Pamela Dragosh | 9bd4bf6 | 2017-03-30 12:46:08 -0400 | [diff] [blame] | 103 | |
| 104 | if [ $? -ne 0 ] |
| 105 | then |
| 106 | echo "Docker push failed" |
| 107 | exit 1 |
| 108 | |
| 109 | fi |
Pamela Dragosh | 1766552 | 2017-02-21 09:05:08 -0500 | [diff] [blame] | 110 | done |