ee9d89da12177e255194015a7f44454af95fd65e
[ta/remote-installer.git] / scripts / build.sh
1 #!/bin/bash
2 # Copyright 2019 Nokia
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 #     http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 cd "$(dirname "$0")"/..
17
18 TAR_IMAGE="remote-installer.tar"
19 DOCKERFILE='docker-build/remote-installer/Dockerfile'
20
21 help()
22 {
23     echo -e "$(basename "$0") [-hs] -t <tag>"
24     echo -e "   -h        display this help"
25     echo -e "   -s        save image as tar to $TAR_IMAGE"
26     echo -e "   -t <tag>  specify docker base image tag"
27     echo
28     echo -e "Proxy configuration is taken from environment variables"
29     echo -e "http_proxy, https_proxy and no_proxy"
30 }
31
32 while getopts "hst:" arg; do
33     case $arg in
34         h)
35             help
36             exit 0
37             ;;
38         s)
39             SAVE_IMAGE="yes"
40             ;;
41         t)
42             BASEIMAGE_TAG="$OPTARG"
43             ;;
44   esac
45 done
46
47 docker build \
48   --network=host \
49   --no-cache \
50   --force-rm \
51   --build-arg BASEIMAGE_TAG="${BASEIMAGE_TAG}" \
52   --build-arg HTTP_PROXY="${http_proxy}" \
53   --build-arg HTTPS_PROXY="${https_proxy}" \
54   --build-arg NO_PROXY="${no_proxy}" \
55   --build-arg http_proxy="${http_proxy}" \
56   --build-arg https_proxy="${https_proxy}" \
57   --build-arg no_proxy="${no_proxy}" \
58   --tag remote-installer \
59   --file "${DOCKERFILE}" .
60
61
62 # could be compressed but it's only used until there is an registry
63 if [ -n "$SAVE_IMAGE" ]
64 then
65     echo -e "Creating image tar ball at : $(dirname "$0")/$TAR_IMAGE"
66     docker image save remote-installer >"$(dirname "$0")"/"$TAR_IMAGE"
67 fi