diff options
Diffstat (limited to 'vio/docker')
-rw-r--r-- | vio/docker/Dockerfile | 27 | ||||
-rwxr-xr-x | vio/docker/build_image.sh | 34 | ||||
-rwxr-xr-x | vio/docker/docker-entrypoint.sh | 35 | ||||
-rwxr-xr-x | vio/docker/instance-config.sh | 29 | ||||
-rwxr-xr-x | vio/docker/instance-init.sh | 9 | ||||
-rwxr-xr-x | vio/docker/instance-run.sh | 9 |
6 files changed, 143 insertions, 0 deletions
diff --git a/vio/docker/Dockerfile b/vio/docker/Dockerfile new file mode 100644 index 0000000..7d2e84f --- /dev/null +++ b/vio/docker/Dockerfile @@ -0,0 +1,27 @@ +FROM python:2 + +ENV MSB_ADDR "127.0.0.1" +ENV MSB_PORT "80" +ENV AAI_ADDR "aai.api.simpledemo.openecomp.org" +ENV AAI_PORT "8443" +ENV AAI_SCHEMA_VERSION "v11" +ENV AAI_USERNAME "AAI" +ENV AAI_PASSWORD "AAI" + +EXPOSE 9004 + +RUN apt-get update && \ + apt-get install -y unzip && \ + apt-get install -y curl && \ + apt-get install -y wget + + +RUN cd /opt/ && \ + wget -q -O multicloud-vio.zip 'https://nexus.onap.org/service/local/artifact/maven/redirect?r=snapshots&g=org.onap.multicloud.openstack.vmware&a=multicloud-vio&v=LATEST&e=zip' && \ + unzip multicloud-vio.zip && \ + rm -rf multicloud-vio.zip && \ + pip install -r vio/requirements.txt + + +WORKDIR /opt +ENTRYPOINT vio/docker/docker-entrypoint.sh diff --git a/vio/docker/build_image.sh b/vio/docker/build_image.sh new file mode 100755 index 0000000..b1e691b --- /dev/null +++ b/vio/docker/build_image.sh @@ -0,0 +1,34 @@ +#!/bin/bash +DIRNAME=`dirname $0` +DOCKER_BUILD_DIR=`cd $DIRNAME/; pwd` +echo "DOCKER_BUILD_DIR=${DOCKER_BUILD_DIR}" +cd ${DOCKER_BUILD_DIR} + +BUILD_ARGS="--no-cache" +ORG="onap" +VERSION="1.0.0-SNAPSHOT" +PROJECT="multicloud" +IMAGE="vio" +DOCKER_REPOSITORY="nexus3.onap.org:10003" +IMAGE_NAME="${DOCKER_REPOSITORY}/${ORG}/${PROJECT}/${IMAGE}" + +if [ $HTTP_PROXY ]; then + BUILD_ARGS+=" --build-arg HTTP_PROXY=${HTTP_PROXY}" +fi +if [ $HTTPS_PROXY ]; then + BUILD_ARGS+=" --build-arg HTTPS_PROXY=${HTTPS_PROXY}" +fi + +function build_image { + echo "Start build docker image: ${IMAGE_NAME}" + docker build ${BUILD_ARGS} -t ${IMAGE_NAME}:${VERSION} -t ${IMAGE_NAME}:latest . +} + +function push_image { + echo "Start push docker image: ${IMAGE_NAME}" + docker push ${IMAGE_NAME}:${VERSION} + docker push ${IMAGE_NAME}:latest +} + +build_image +push_image diff --git a/vio/docker/docker-entrypoint.sh b/vio/docker/docker-entrypoint.sh new file mode 100755 index 0000000..632c558 --- /dev/null +++ b/vio/docker/docker-entrypoint.sh @@ -0,0 +1,35 @@ +#!/bin/bash + + +if [ -z "$SERVICE_IP" ]; then + export SERVICE_IP=`hostname -i` +fi +echo +echo Environment Variables: +echo "SERVICE_IP=$SERVICE_IP" + +if [ -z "$MSB_ADDR" ]; then + echo "Missing required variable MSB_ADDR: Microservices Service Bus address <ip>:<port>" + exit 1 +fi +echo "MSB_ADDR=$MSB_ADDR" +echo + + +echo + +# Configure service based on docker environment variables +vio/docker/instance-config.sh + + +# Perform one-time config +if [ ! -e init.log ]; then + + # microservice-specific one-time initialization + vio/docker/instance-init.sh + + date > init.log +fi + +# Start the microservice +vio/docker/instance-run.sh diff --git a/vio/docker/instance-config.sh b/vio/docker/instance-config.sh new file mode 100755 index 0000000..221cac9 --- /dev/null +++ b/vio/docker/instance-config.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash + +# Configure MSB IP address +MSB_IP=`echo $MSB_ADDR | cut -d: -f 1` +MSB_PORT=`echo $MSB_ADDR | cut -d: -f 2` +sed -i "s|MSB_SERVICE_IP.*|MSB_SERVICE_IP = '$MSB_IP'|" vio/vio/pub/config/config.py +sed -i "s|MSB_SERVICE_PORT.*|MSB_SERVICE_PORT = '$MSB_PORT'|" vio/vio/pub/config/config.py +sed -i "s|DB_NAME.*|DB_NAME = 'inventory'|" vio/vio/pub/config/config.py +sed -i "s|DB_USER.*|DB_USER = 'inventory'|" vio/vio/pub/config/config.py +sed -i "s|DB_PASSWD.*|DB_PASSWD = 'inventory'|" vio/vio/pub/config/config.py +sed -i "s|\"ip\": \".*\"|\"ip\": \"$SERVICE_IP\"|" vio/vio/pub/config/config.py + +# Configure MYSQL +if [ -z "$MYSQL_ADDR" ]; then + export MYSQL_IP=`hostname -i` + export MYSQL_PORT=3306 + export MYSQL_ADDR=$MYSQL_IP:$MYSQL_PORT +else + MYSQL_IP=`echo $MYSQL_ADDR | cut -d: -f 1` + MYSQL_PORT=`echo $MYSQL_ADDR | cut -d: -f 2` +fi +echo "MYSQL_ADDR=$MYSQL_ADDR" +sed -i "s|DB_IP.*|DB_IP = '$MYSQL_IP'|" vio/vio/pub/config/config.py +sed -i "s|DB_PORT.*|DB_PORT = $MYSQL_PORT|" vio/vio/pub/config/config.py + +cat vio/vio/pub/config/config.py + +sed -i "s/sip=.*/sip=$SERVICE_IP/g" vio/run.sh +sed -i "s/sip=.*/sip=$SERVICE_IP/g" vio/stop.sh
\ No newline at end of file diff --git a/vio/docker/instance-init.sh b/vio/docker/instance-init.sh new file mode 100755 index 0000000..f7e0e0e --- /dev/null +++ b/vio/docker/instance-init.sh @@ -0,0 +1,9 @@ +#!/bin/bash -v + +# Initialize DB schema +#./bin/initDB.sh root rootpass 3306 127.0.0.1 + +# Install python requirements +cd /opt/vio +./initialize.sh +cd /opt diff --git a/vio/docker/instance-run.sh b/vio/docker/instance-run.sh new file mode 100755 index 0000000..d01cebb --- /dev/null +++ b/vio/docker/instance-run.sh @@ -0,0 +1,9 @@ +#!/bin/bash -v + +cd ./vio +./run.sh + +while [ ! -f logs/runtime_vio.log ]; do + sleep 1 +done +tail -F logs/runtime_vio.log |