878e367259cf9ea22345671255c03213895fdb35
[vfc/nfvo/driver/vnfm/svnfm.git] / nokiav2 / deployment / src / main / resources / build_image.sh
1 #!/bin/bash
2 #
3 # Copyright 2017, Nokia Corporation
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 #     http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 #
17
18 if [ "a$1" != "abuildDocker" ] ; then
19   echo "Skipping building Docker image"
20   echo "If you would like to build the docker image by maven execute mvn package -Dexec.args=\"buildDocker\"" 
21   exit
22 fi 
23
24 DIRNAME=`dirname $0`
25 DOCKER_BUILD_DIR=`cd $DIRNAME/; pwd`
26 echo "DOCKER_BUILD_DIR=${DOCKER_BUILD_DIR}"
27 cd ${DOCKER_BUILD_DIR}
28
29 BUILD_ARGS="--no-cache --squash"
30 ORG="onap"
31 VERSION="1.1.0"
32 PROJECT="vfc"
33 IMAGE="nfvo/svnfm/nokiav2"
34 DOCKER_REPOSITORY="nexus3.onap.org:10003"
35 IMAGE_NAME="${DOCKER_REPOSITORY}/${ORG}/${PROJECT}/${IMAGE}"
36 TIMESTAMP=$(date +"%Y%m%dT%H%M%S")
37
38 if [ $HTTP_PROXY ]; then
39     BUILD_ARGS+=" --build-arg HTTP_PROXY=${HTTP_PROXY}"
40 fi
41 if [ $HTTPS_PROXY ]; then
42     BUILD_ARGS+=" --build-arg HTTPS_PROXY=${HTTPS_PROXY}"
43 fi
44
45 function build_image {
46     echo "Start build docker image: ${IMAGE_NAME}"
47     docker build ${BUILD_ARGS} -t ${IMAGE_NAME}:latest .
48 }
49
50 function push_image_tag {
51     TAG_NAME=$1
52     echo "Start push ${TAG_NAME}"
53     docker tag ${IMAGE_NAME}:latest ${TAG_NAME}
54     docker push ${TAG_NAME}
55 }
56
57 function push_image {
58     echo "Start push ${IMAGE_NAME}:latest"
59     docker push ${IMAGE_NAME}:latest
60     
61     push_image_tag ${IMAGE_NAME}:${VERSION}-SNAPSHOT-latest
62     push_image_tag ${IMAGE_NAME}:${VERSION}-STAGING-latest
63     push_image_tag ${IMAGE_NAME}:${VERSION}-STAGING-${TIMESTAMP}
64 }
65
66 build_image
67
68 if [ "a$2" != "apushImage" ]; then
69    echo "Skipping image pushing"
70    echo "If you would like to push the docker image by maven execute mvn package -Dexec.args=\"buildDocker pushImage\""
71    push_image
72 fi