diff options
author | liangke <lokyse@163.com> | 2017-09-01 11:44:09 +0800 |
---|---|---|
committer | liangke <lokyse@163.com> | 2017-09-12 00:17:04 +0800 |
commit | 8c606e39936fc8676920c04bd08042b3ed7e82aa (patch) | |
tree | 5b58a613d3e4ac9239729a0c5cccbe59f52bdc5f /vio | |
parent | 4b94970eeb32c688d63542d0468130fb8d3953e9 (diff) |
Multicloud VIO docker build files
Change-Id: I9e6188de471cd3ced174f65a31413bc1f7ee06d3
Issue-Id: MULTICLOUD-74
Signed-off-by: liangke <lokyse@163.com>
Diffstat (limited to 'vio')
-rw-r--r-- | vio/assembly.xml | 8 | ||||
-rw-r--r-- | vio/docker/Dockerfile | 27 | ||||
-rwxr-xr-x | vio/docker/build_image.sh | 34 | ||||
-rwxr-xr-x | vio/docker/docker-entrypoint.sh | 41 | ||||
-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 | 11 | ||||
-rw-r--r-- | vio/pom.xml | 8 | ||||
-rwxr-xr-x | vio/run.sh | 29 | ||||
-rw-r--r-- | vio/version.properties | 13 |
10 files changed, 193 insertions, 16 deletions
diff --git a/vio/assembly.xml b/vio/assembly.xml index c59ad59..5df8abe 100644 --- a/vio/assembly.xml +++ b/vio/assembly.xml @@ -38,6 +38,14 @@ <include>*.txt</include> </includes> </fileSet> + <fileSet> + <directory>docker</directory> + <outputDirectory>/docker</outputDirectory> + <includes> + <include>*.sh</include> + <include>Dockerfile</include> + </includes> + </fileSet> <fileSet> <directory>.</directory> <outputDirectory>/</outputDirectory> 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 diff --git a/vio/pom.xml b/vio/pom.xml index c58aeb9..dd05ffe 100644 --- a/vio/pom.xml +++ b/vio/pom.xml @@ -12,7 +12,9 @@ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. --> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> +<project + xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <parent> <groupId>org.onap.oparent</groupId> <artifactId>oparent</artifactId> @@ -24,8 +26,8 @@ <artifactId>multicloud-vio</artifactId> <version>1.0.0-SNAPSHOT</version> <packaging>pom</packaging> - <name>multicloud/openstack/vmware</name> - <description>multiclouddriver for vio</description> + <name>multicloud/opentack/vmware</name> + <description>multicloud vio</description> <build> <plugins> <plugin> @@ -1,14 +1,17 @@ #!/bin/bash -# Copyright (c) 2017 VMware, Inc. -# -# 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. - -nohup python manage.py runserver 127.0.0.1:9004 > /dev/null & + +sed -i "s/MSB_SERVICE_IP =.*/MSB_SERVICE_IP = \"${MSB_ADDR}\"/g" vio/pub/config/config.py +sed -i "s/MSB_SERVICE_PORT =.*/MSB_SERVICE_PORT = \"${MSB_PORT}\"/g" vio/pub/config/config.py +sed -i "s/AAI_ADDR =.*/AAI_ADDR = \"${AAI_ADDR}\"/g" vio/pub/config/config.py +sed -i "s/AAI_PORT =.*/AAI_PORT = \"${AAI_PORT}\"/g" vio/pub/config/config.py +sed -i "s/AAI_SCHEMA_VERSION =.*/AAI_SCHEMA_VERSION = \"${AAI_SCHEMA_VERSION}\"/g" vio/pub/config/config.py +sed -i "s/AAI_USERNAME =.*/AAI_USERNAME = \"${AAI_USERNAME}\"/g" vio/pub/config/config.py +sed -i "s/AAI_PASSWORD =.*/AAI_PASSWORD = \"${AAI_PASSWORD}\"/g" vio/pub/config/config.py + +nohup python manage.py runserver 0.0.0.0:9004 2>&1 & + +while [ ! -f logs/runtime_vio.log ]; do + sleep 1 +done + +tail -F logs/runtime_vio.log diff --git a/vio/version.properties b/vio/version.properties new file mode 100644 index 0000000..5128787 --- /dev/null +++ b/vio/version.properties @@ -0,0 +1,13 @@ +# Versioning variables +# Note that these variables cannot be structured (e.g. : version.release or version.snapshot etc... ) +# because they are used in Jenkins, whose plug-in doesn't support + +major=1 +minor=0 +patch=0 + +base_version=${major}.${minor}.${patch} + +# Release must be completed with git revision # in Jenkins +release_version=${base_version} +snapshot_version=${base_version}-SNAPSHOT |