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