Update k8splugin for G release
[multicloud/k8s.git] / deployments / build.sh
1 #!/bin/bash
2 # SPDX-license-identifier: Apache-2.0
3 ##############################################################################
4 # Copyright (c) 2018 Intel Corporation
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
10
11 set -o nounset
12 set -o pipefail
13
14 k8s_path="$(git rev-parse --show-toplevel)"
15
16 VERSION="0.7.0-SNAPSHOT"
17 export IMAGE_NAME="nexus3.onap.org:10003/onap/multicloud/k8s"
18
19 function _compile_src {
20     echo "Compiling source code"
21     pushd $k8s_path/src/k8splugin/
22     make
23     popd
24 }
25
26 function _move_bin {
27     echo "Moving binaries"
28     rm -f k8plugin *so
29     mv $k8s_path/src/k8splugin/k8plugin .
30     mv $k8s_path/src/k8splugin/plugins/*.so .
31 }
32
33 function _cleanup {
34     echo "Cleaning previous execution"
35     docker-compose kill
36     image=$(grep "image.*k8plugin" docker-compose.yml)
37     if [[ -n ${image} ]]; then
38         docker images ${image#*:} -q | xargs docker rmi -f
39     fi
40     docker ps -a --filter "status=exited" -q | xargs docker rm
41 }
42
43 function _build_docker {
44     echo "Building docker image"
45     docker-compose build --no-cache
46 }
47
48 function _push_image {
49     local tag_name=${IMAGE_NAME}:${1:-latest}
50
51     echo "Start push {$tag_name}"
52     docker push ${IMAGE_NAME}:latest
53     docker tag ${IMAGE_NAME}:latest ${tag_name}
54     docker push ${tag_name}
55 }
56
57 if [[ -n "${JENKINS_HOME+x}" ]]; then
58     set -o xtrace
59     _compile_src
60     _move_bin
61     _build_docker
62     _push_image $VERSION
63 else
64     source /etc/environment
65
66     _compile_src
67     _move_bin
68     _cleanup
69     _build_docker
70 fi