Reinstate installation of igb_uio
[samplevnf.git] / VNFs / DPPD-PROX / helper-scripts / rapid / dockerimage.sh
1 #!/usr/bin/env bash
2 ##
3 ## Copyright (c) 2010-2019 Intel 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 PROX_DEPLOY_DIR="."
19 PROX_IMAGE_NAME="prox_slim"
20 RSA_KEY_FILE_NAME="rapid_rsa_key"
21
22 DOCKERFILE="Dockerfile"
23 DOCKER_REGISTRY="localhost:5000"
24
25 USE_DOCKER_CACHE="n"
26
27 IMAGE_BUILD_LOG="dockerimage-build.log"
28
29 function create_ssh_key()
30 {
31         if [ -f ./${RSA_KEY_FILE_NAME} ]; then
32                 read -p "RSA key already exist! Do you want to remove it (yYnN)?" -n 1 -r
33
34                 if [ "${REPLY}" == "y" ] || [ "${REPLY}" == "Y" ]; then
35                         echo "Removing existing key..."
36                         sleep 3
37
38                         [ -f "./${RSA_KEY_FILE_NAME}" ] && rm -rf ./${RSA_KEY_FILE_NAME}
39                         [ -f "./${RSA_KEY_FILE_NAME}.pub" ] && rm -rf ./${RSA_KEY_FILE_NAME}.pub
40                 else
41                         echo "Using existing key..."
42                         return
43                 fi
44         fi
45
46         echo "Generating new RSA key..."
47         ssh-keygen -t rsa -b 4096 -N "" -f ./${RSA_KEY_FILE_NAME}
48 }
49
50 function build_prox_image()
51 {
52         if [ "${USE_DOCKER_CACHE}" == "y" ]; then
53                 echo "Building image using cache..."
54                 docker build --rm -t ${PROX_IMAGE_NAME}:latest -f ${DOCKERFILE} ${PROX_DEPLOY_DIR} 2>&1 | tee ./${IMAGE_BUILD_LOG}
55         else
56                 echo "Building image without cache..."
57                 docker build --no-cache --rm -t ${PROX_IMAGE_NAME}:latest -f ${DOCKERFILE} ${PROX_DEPLOY_DIR} 2>&1 | tee ./${IMAGE_BUILD_LOG}
58         fi
59 }
60
61 function save_prox_image()
62 {
63         echo "Saving image ${PROX_IMAGE_NAME}:latest to ./${PROX_IMAGE_NAME}.tar"
64         docker save -o ./${PROX_IMAGE_NAME}.tar ${PROX_IMAGE_NAME}:latest
65 }
66
67 function load_prox_image()
68 {
69         echo "Loading image ./${PROX_IMAGE_NAME}.tar"
70         docker load -i ./${PROX_IMAGE_NAME}.tar
71 }
72
73 function push_prox_image()
74 {
75         docker tag ${PROX_IMAGE_NAME}:latest ${DOCKER_REGISTRY}/${PROX_IMAGE_NAME}
76         docker push ${DOCKER_REGISTRY}/${PROX_IMAGE_NAME}
77 }
78
79 function print_help()
80 {
81         echo "${0}: [build|load|push]"
82         echo "    build: build and save image ${PROX_IMAGE_NAME}:latest using ${DOCKERFILE}"
83         echo "    load:  load saved image from ${PROX_IMAGE_NAME}.tar file in the local registry"
84         echo "    push:  tag and push local ${PROX_IMAGE_NAME}:latest image in the ${DOCKER_REGISTRY}/${PROX_IMAGE_NAME} registry"
85 }
86
87 if [ "$1" == "build" ]; then
88         create_ssh_key
89         build_prox_image
90         save_prox_image
91 elif [ "$1" == "load" ]; then
92         load_prox_image
93 elif [ "$1" == "push" ]; then
94         push_prox_image
95 else
96         print_help
97 fi