Propagate error upward
[aaf/sms.git] / sms-service / bin / build_sms_image.sh
1 #!/bin/bash
2 set -e
3 DIRNAME=`dirname $0`
4 DOCKER_BUILD_DIR=`cd $DIRNAME/; pwd`
5 echo "DOCKER_BUILD_DIR=${DOCKER_BUILD_DIR}"
6 cd ${DOCKER_BUILD_DIR}
7
8 BUILD_ARGS="--no-cache"
9 ORG="onap"
10 VERSION="2.0.0"
11 PROJECT="aaf"
12 IMAGE="sms"
13 DOCKER_REPOSITORY="nexus3.onap.org:10003"
14 IMAGE_NAME="${DOCKER_REPOSITORY}/${ORG}/${PROJECT}/${IMAGE}"
15 TIMESTAMP=$(date +"%Y%m%dT%H%M%S")
16
17 if [ $HTTP_PROXY ]; then
18     BUILD_ARGS+=" --build-arg HTTP_PROXY=${HTTP_PROXY}"
19 fi
20 if [ $HTTPS_PROXY ]; then
21     BUILD_ARGS+=" --build-arg HTTPS_PROXY=${HTTPS_PROXY}"
22 fi
23
24 function generate_binary {
25     pushd ../src/sms
26     make build
27     popd
28     cp ../target/sms .
29 }
30
31 function copy_certificates {
32     cp ../src/sms/certs/aaf_root_ca.cer .
33     cp ../src/sms/certs/aaf-sms.pub .
34     cp ../src/sms/certs/aaf-sms.pr .
35 }
36
37 function cleanup {
38     rm sms
39     rm aaf-sms.pub
40     rm aaf-sms.pr
41     rm aaf_root_ca.cer
42 }
43
44 function build_image {
45     echo "Start build docker image: ${IMAGE_NAME}"
46     docker build ${BUILD_ARGS} -t ${IMAGE_NAME}:latest -f smsdockerfile .
47 }
48
49 function push_image_tag {
50     TAG_NAME=$1
51     echo "Start push ${TAG_NAME}"
52     docker tag ${IMAGE_NAME}:latest ${TAG_NAME}
53     docker push ${TAG_NAME}
54 }
55
56 function push_image {
57     echo "Start push ${IMAGE_NAME}:latest"
58     docker push ${IMAGE_NAME}:latest
59
60     push_image_tag ${IMAGE_NAME}:${VERSION}-SNAPSHOT-latest
61 }
62
63 generate_binary
64 copy_certificates
65 build_image
66 push_image
67 cleanup