summaryrefslogtreecommitdiffstats
path: root/vio/docker
diff options
context:
space:
mode:
authorliangke <lokyse@163.com>2017-09-01 11:44:09 +0800
committerliangke <lokyse@163.com>2017-09-12 00:17:04 +0800
commit8c606e39936fc8676920c04bd08042b3ed7e82aa (patch)
tree5b58a613d3e4ac9239729a0c5cccbe59f52bdc5f /vio/docker
parent4b94970eeb32c688d63542d0468130fb8d3953e9 (diff)
Multicloud VIO docker build files
Change-Id: I9e6188de471cd3ced174f65a31413bc1f7ee06d3 Issue-Id: MULTICLOUD-74 Signed-off-by: liangke <lokyse@163.com>
Diffstat (limited to 'vio/docker')
-rw-r--r--vio/docker/Dockerfile27
-rwxr-xr-xvio/docker/build_image.sh34
-rwxr-xr-xvio/docker/docker-entrypoint.sh41
-rwxr-xr-xvio/docker/instance-config.sh29
-rwxr-xr-xvio/docker/instance-init.sh9
-rwxr-xr-xvio/docker/instance-run.sh11
6 files changed, 151 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..6c9d3e3
--- /dev/null
+++ b/vio/docker/docker-entrypoint.sh
@@ -0,0 +1,41 @@
+#!/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
+
+# Wait for MSB initialization
+echo Wait for MSB initialization
+for i in {1..20}; do
+ curl -sS -m 1 $MSB_ADDR > /dev/null && break
+ sleep $i
+done
+
+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..2393c5d
--- /dev/null
+++ b/vio/docker/instance-run.sh
@@ -0,0 +1,11 @@
+#!/bin/bash -v
+
+redis-server &
+
+cd ./vio
+./run.sh
+
+while [ ! -f logs/runtime_vio.log ]; do
+ sleep 1
+done
+tail -F logs/runtime_vio.log