Update dockerfile of vfc-nfvo-lcm 69/9869/1
authorfujinhua <fu.jinhua@zte.com.cn>
Fri, 1 Sep 2017 06:00:05 +0000 (14:00 +0800)
committerfujinhua <fu.jinhua@zte.com.cn>
Fri, 1 Sep 2017 06:00:05 +0000 (14:00 +0800)
Add entrypoint to dockerfile

Change-Id: Iaf5f42ccc056062f2031e88437253ee8927eb697
Issue-Id: VFC-225
Signed-off-by: fujinhua <fu.jinhua@zte.com.cn>
docker/Dockerfile
docker/build_image.sh
docker/docker-entrypoint.sh [new file with mode: 0755]
docker/instance_init.sh

index 0b6c42f..e474e04 100755 (executable)
@@ -2,11 +2,9 @@ FROM ubuntu:14.04
 
 ARG HTTP_PROXY=${HTTP_PROXY}
 ARG HTTPS_PROXY=${HTTPS_PROXY}
-ARG MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
 
 ENV http_proxy $HTTP_PROXY
 ENV https_proxy $HTTPS_PROXY
-ENV MYSQL_ROOT_PASSWORD $MYSQL_ROOT_PASSWORD
 
 RUN apt-get update && \
     apt-get install -y python-devel && \
@@ -37,6 +35,5 @@ RUN wget -q -O vfc-nfvo-lcm.zip 'https://nexus.onap.org/service/local/artifact/m
 EXPOSE 8403
 EXPOSE 3306
 
-WORKDIR /
-
-CMD service/vfc/nfvo/lcm/docker/instance_init.sh
+WORKDIR /service
+ENTRYPOINT vfc/nfvo/lcm/docker/docker-entrypoint.sh
index 508f0b4..9fc4879 100755 (executable)
@@ -16,7 +16,7 @@ if [ $HTTPS_PROXY ]; then
 fi
 
 function build_lcm {
-    docker build ${PROXY_ARGS} --build-arg MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD} -t ${ORG}/${PROJECT}/${IMAGE}:${VERSION} -t ${ORG}/${PROJECT}/${IMAGE}:latest .
+    docker build ${PROXY_ARGS} -t ${ORG}/${PROJECT}/${IMAGE}:${VERSION} -t ${ORG}/${PROJECT}/${IMAGE}:latest .
 }
 
 function push_lcm {
diff --git a/docker/docker-entrypoint.sh b/docker/docker-entrypoint.sh
new file mode 100755 (executable)
index 0000000..90341e8
--- /dev/null
@@ -0,0 +1,35 @@
+#!/bin/bash
+
+if [ -z "$SERVICE_IP" ]; then
+    export SERVICE_IP=`hostname -i`
+fi
+echo "SERVICE_IP=$SERVICE_IP"
+
+if [ -z "$MYSQL_ROOT_PASSWORD" ]; then
+    export MYSQL_ROOT_PASSWORD="root"
+fi
+echo "MYSQL_ROOT_PASSWORD=$MYSQL_ROOT_PASSWORD"
+
+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"
+
+# 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
+
+# Configure service based on docker environment variables
+./instance-config.sh
+
+# microservice-specific one-time initialization
+./instance-init.sh
+
+date > init.log
+
+# Start the microservice
+./instance-run.sh
index f880c6b..c3a3b54 100755 (executable)
@@ -10,6 +10,7 @@ function start_redis_server {
 }
 
 function start_mysql {
+    su mysql -c /usr/bin/mysqld_safe &
     service mysql start
     # Wait for mysql to initialize; Set mysql root password
     for i in {1..10}; do
@@ -23,23 +24,7 @@ function create_database {
     bash initDB.sh root $MYSQL_ROOT_PASSWORD 3306 127.0.0.1
 }
 
-function edit_configs {
-    cd /service/vfc/nfvo/lcm/
-    bash docker/instance_config.sh
-}
-
-function start_server {
-    cd /service/vfc/nfvo/lcm/
-    bash run.sh
-}
-
-if [ $MYSQL_ROOT_PASSWORD ]; then
-    install_python_libs
-    start_redis_server
-    start_mysql
-    create_database
-    edit_configs
-    start_server
-else
-    echo "MYSQL_ROOT_PASSWORD environment variable not set."
-fi
+install_python_libs
+start_redis_server
+start_mysql
+create_database