summaryrefslogtreecommitdiffstats
path: root/VNFs/DPPD-PROX/helper-scripts/rapid/dockerimage.sh
diff options
context:
space:
mode:
Diffstat (limited to 'VNFs/DPPD-PROX/helper-scripts/rapid/dockerimage.sh')
-rwxr-xr-xVNFs/DPPD-PROX/helper-scripts/rapid/dockerimage.sh95
1 files changed, 95 insertions, 0 deletions
diff --git a/VNFs/DPPD-PROX/helper-scripts/rapid/dockerimage.sh b/VNFs/DPPD-PROX/helper-scripts/rapid/dockerimage.sh
new file mode 100755
index 00000000..3d77aaed
--- /dev/null
+++ b/VNFs/DPPD-PROX/helper-scripts/rapid/dockerimage.sh
@@ -0,0 +1,95 @@
+#!/usr/bin/env bash
+##
+## Copyright (c) 2010-2019 Intel Corporation
+##
+## Licensed under the Apache License, Version 2.0 (the "License");
+## you may not use this file except in compliance with the License.
+## You may obtain a copy of the License at
+##
+## http://www.apache.org/licenses/LICENSE-2.0
+##
+## Unless required by applicable law or agreed to in writing, software
+## distributed under the License is distributed on an "AS IS" BASIS,
+## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+## See the License for the specific language governing permissions and
+## limitations under the License.
+##
+
+PROX_DEPLOY_DIR="."
+PROX_IMAGE_NAME="prox_slim"
+RSA_KEY_FILE_NAME="rapid_rsa_key"
+
+DOCKERFILE="Dockerfile"
+DOCKER_REGISTRY="localhost:5000"
+
+USE_DOCKER_CACHE="n"
+
+function create_ssh_key()
+{
+ if [ -f ./${RSA_KEY_FILE_NAME} ]; then
+ read -p "RSA key already exist! Do you want to remove it (yYnN)?" -n 1 -r
+
+ if [ "$REPLY" == "y" ] || [ "$REPLY" == "Y" ]; then
+ echo "Removing existing key..."
+ sleep 3
+
+ [ -f "./${RSA_KEY_FILE_NAME}" ] && rm -rf ./${RSA_KEY_FILE_NAME}
+ [ -f "./${RSA_KEY_FILE_NAME}.pub" ] && rm -rf ./${RSA_KEY_FILE_NAME}.pub
+ else
+ echo "Using existing key..."
+ return
+ fi
+ fi
+
+ echo "Generating new RSA key..."
+ ssh-keygen -t rsa -b 4096 -N "" -f ./${RSA_KEY_FILE_NAME}
+}
+
+function build_prox_image()
+{
+ if [ "${USE_DOCKER_CACHE}" == "y" ]; then
+ echo "Building image using cache..."
+ docker build --rm -t ${PROX_IMAGE_NAME}:latest -f ${DOCKERFILE} ${PROX_DEPLOY_DIR}
+ else
+ echo "Building image without cache..."
+ docker build --no-cache --rm -t ${PROX_IMAGE_NAME}:latest -f ${DOCKERFILE} ${PROX_DEPLOY_DIR}
+ fi
+}
+
+function save_prox_image()
+{
+ echo "Saving image ${PROX_IMAGE_NAME}:latest to ./${PROX_IMAGE_NAME}.tar"
+ docker save -o ./${PROX_IMAGE_NAME}.tar ${PROX_IMAGE_NAME}:latest
+}
+
+function load_prox_image()
+{
+ echo "Loading image ./${PROX_IMAGE_NAME}.tar"
+ docker load -i ./${PROX_IMAGE_NAME}.tar
+}
+
+function push_prox_image()
+{
+ docker tag ${PROX_IMAGE_NAME}:latest ${DOCKER_REGISTRY}/${PROX_IMAGE_NAME}
+ docker push ${DOCKER_REGISTRY}/${PROX_IMAGE_NAME}
+}
+
+function print_help()
+{
+ echo "${0}: [build|load|push]"
+ echo " build: build and save image ${PROX_IMAGE_NAME}:latest using ${DOCKERFILE}"
+ echo " load: load saved image from ${PROX_IMAGE_NAME}.tar file in the local registry"
+ echo " push: tag and push local ${PROX_IMAGE_NAME}:latest image in the ${DOCKER_REGISTRY}/${PROX_IMAGE_NAME} registry"
+}
+
+if [ "$1" == "build" ]; then
+ create_ssh_key
+ build_prox_image
+ save_prox_image
+elif [ "$1" == "load" ]; then
+ load_prox_image
+elif [ "$1" == "push" ]; then
+ push_prox_image
+else
+ print_help
+fi