Cancel modifying the config file in the docker entrypoint 36/110536/6
authordengyh <dengyuanhong @chinamobile.com>
Fri, 24 Jul 2020 02:28:00 +0000 (10:28 +0800)
committerYuanhong Deng <dengyuanhong@chinamobile.com>
Tue, 28 Jul 2020 02:26:03 +0000 (02:26 +0000)
script with sed

Issue-ID: MODELING-391
Change-Id: Ia40e85d03cdb29660536576576453cbfc135eaf2
Signed-off-by: dengyh <dengyuanhong @chinamobile.com>
catalog/pub/config/config.py
docker/docker-entrypoint.sh
docker/instance_config.sh [deleted file]
docker/instance_init.sh [deleted file]

index c1d4695..2c42c7a 100644 (file)
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import os
+env_dict = os.environ
+
 # [MSB]
-MSB_SERVICE_PROTOCOL = 'http'
-MSB_SERVICE_IP = '127.0.0.1'
-MSB_SERVICE_PORT = '80'
+MSB_SERVICE_PROTOCOL = env_dict.get("MSB_PROTO", "http")
+MSB_SERVICE_IP = env_dict.get("MSB_ADDR", "127.0.0.1:80").split(':')[0]
+MSB_SERVICE_PORT = env_dict.get("MSB_ADDR", "127.0.0.1:80").split(':')[1]
 MSB_BASE_URL = "%s://%s:%s" % (MSB_SERVICE_PROTOCOL, MSB_SERVICE_IP, MSB_SERVICE_PORT)
 
 # [mysql]
-DB_IP = "127.0.0.1"
-DB_PORT = 3306
+DB_IP = env_dict.get("MYSQL_ADDR", "127.0.0.1:3306").split(':')[0]
+DB_PORT = env_dict.get("MYSQL_ADDR", "127.0.0.1:3306").split(':')[1]
 DB_NAME = "etsicatalog"
 DB_USER = "etsicatalog"
 DB_PASSWD = "etsicatalog"
@@ -32,12 +35,13 @@ FORWARDED_FOR_FIELDS = ["HTTP_X_FORWARDED_FOR", "HTTP_X_FORWARDED_HOST",
 
 # [register]
 REG_TO_MSB_WHEN_START = True
-SSL_ENABLED = "true"
 REG_TO_MSB_REG_URL = "/api/microservices/v1/services"
+SSL_ENABLED = env_dict.get("SSL_ENABLED", "true")
 if SSL_ENABLED == "true":
     enable_ssl = "true"
 else:
     enable_ssl = "false"
+svc_ip = env_dict.get("SERVICE_IP", "127.0.0.1")
 REG_TO_MSB_REG_PARAM = [{
     "serviceName": "catalog",
     "version": "v1",
@@ -46,7 +50,7 @@ REG_TO_MSB_REG_PARAM = [{
     "protocol": "REST",
     "visualRange": "1",
     "nodes": [{
-        "ip": "127.0.0.1",
+        "ip": svc_ip,
         "port": "8806",
         "ttl": 0
     }]
@@ -58,7 +62,7 @@ REG_TO_MSB_REG_PARAM = [{
     "protocol": "REST",
     "visualRange": "1",
     "nodes": [{
-        "ip": "127.0.0.1",
+        "ip": svc_ip,
         "port": "8806",
         "ttl": 0
     }]
@@ -70,7 +74,7 @@ REG_TO_MSB_REG_PARAM = [{
     "protocol": "REST",
     "visualRange": "1",
     "nodes": [{
-        "ip": "127.0.0.1",
+        "ip": svc_ip,
         "port": "8806",
         "ttl": 0
     }]
@@ -82,7 +86,7 @@ REG_TO_MSB_REG_PARAM = [{
     "protocol": "REST",
     "visualRange": "1",
     "nodes": [{
-        "ip": "127.0.0.1",
+        "ip": svc_ip,
         "port": "8806",
         "ttl": 0
     }]
index b6b09a5..05b094a 100755 (executable)
@@ -11,33 +11,40 @@ if [ -z "$MSB_ADDR" ]; then
 fi
 echo "MSB_ADDR=$MSB_ADDR"
 
-if [ -z "$MYSQL_ADDR" ]; then
-    echo "Missing required variable MYSQL_ADDR: <ip>:<port>"
-    exit 1
+# Configure config file based on  environment variables
+
+python modeling/etsicatalog/catalog/pub/config/config.py
+cat modeling/etsicatalog/catalog/pub/config/config.py
+
+# microservice-specific one-time initialization
+
+MYSQL_IP=`echo $MYSQL_ADDR | cut -d: -f 1`
+MYSQL_PORT=`echo $MYSQL_ADDR | cut -d: -f 2`
+
+if [ $MYSQL_ROOT_USER ] && [ $MYSQL_ROOT_PASSWORD ]; then
+    MYSQL_ROOT_USER=$MYSQL_ROOT_USER
+    MYSQL_ROOT_PASSWORD=$MYSQL_ROOT_PASSWORD
+else
+    MYSQL_ROOT_USER="root"
+    MYSQL_ROOT_PASSWORD="root"
 fi
-echo "MYSQL_ADDR=$MYSQL_ADDR"
 
-# Wait for MSB initialization
-echo "Wait for MSB initialization"
-for i in {1..5}; do
-    curl -sS -m 1 $MSB_ADDR > /dev/null && break
-    sleep $i
-done
+function create_database {
 
-# Wait for DB initialization
-echo "Wait for DB initialization"
-for i in {1..5}; do
-    curl -sS -m 1 $MYSQL_ADDR > /dev/null && break
-    sleep $i
-done
+    cd /service/modeling/etsicatalog/resources/bin
+    bash initDB.sh $MYSQL_ROOT_USER $MYSQL_ROOT_PASSWORD $MYSQL_PORT $MYSQL_IP
 
-# Configure service based on docker environment variables
-modeling/etsicatalog/docker/instance_config.sh
+ }
 
-# microservice-specific one-time initialization
-modeling/etsicatalog/docker/instance_init.sh
+function migrate_database {
+    cd /service/modeling/etsicatalog
+    python manage.py migrate
+}
+
+create_database
+migrate_database
 
-date > init.log
+date > /service/init.log
 
 # Start the microservice
-modeling/etsicatalog/docker/instance_run.sh
+/service/modeling/etsicatalog/docker/instance_run.sh
diff --git a/docker/instance_config.sh b/docker/instance_config.sh
deleted file mode 100755 (executable)
index f4abef0..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-#!/bin/bash
-
-MSB_PROTO=`echo $MSB_PROTO`
-MSB_IP=`echo $MSB_ADDR | cut -d: -f 1`
-MSB_PORT=`echo $MSB_ADDR | cut -d: -f 2`
-# modeling/etsicatalog
-
-if [ $MSB_PROTO ]; then
-    sed -i "s|MSB_SERVICE_PROTOCOL = .*|MSB_SERVICE_PROTOCOL = '$MSB_PROTO'|" modeling/etsicatalog/catalog/pub/config/config.py
-fi
-
-if [ $MSB_IP ]; then
-    sed -i "s|MSB_SERVICE_IP = .*|MSB_SERVICE_IP = '$MSB_IP'|"  modeling/etsicatalog/catalog/pub/config/config.py
-fi
-
-if [ $MSB_PORT ]; then
-    sed -i "s|MSB_SERVICE_PORT = .*|MSB_SERVICE_PORT = '$MSB_PORT'|" modeling/etsicatalog/catalog/pub/config/config.py
-fi
-
-if [ $SERVICE_IP ]; then
-    sed -i "s|\"ip\": \".*\"|\"ip\": \"$SERVICE_IP\"|" modeling/etsicatalog/catalog/pub/config/config.py
-fi
-
-
-if [ $SSL_ENABLED ]; then
-    sed -i "s|SSL_ENABLED = .*|SSL_ENABLED = '$SSL_ENABLED'|"  modeling/etsicatalog/catalog/pub/config/config.py
-fi
-
-MYSQL_IP=`echo $MYSQL_ADDR | cut -d: -f 1`
-MYSQL_PORT=`echo $MYSQL_ADDR | cut -d: -f 2`
-echo "MYSQL_ADDR=$MYSQL_ADDR"
-
-# if [ $REDIS_ADDR ]; then
-#     REDIS_IP=`echo $REDIS_ADDR | cut -d: -f 1`
-# else
-#     REDIS_IP="$MYSQL_ADDR"
-# fi
-
-
-sed -i "s|DB_IP.*|DB_IP = '$MYSQL_IP'|" modeling/etsicatalog/catalog/pub/config/config.py
-sed -i "s|DB_PORT.*|DB_PORT = $MYSQL_PORT|" modeling/etsicatalog/catalog/pub/config/config.py
-# sed -i "s|REDIS_HOST.*|REDIS_HOST = '$REDIS_IP'|"modeling/etsicatalog/catalog/pub/config/config.py
-
-cat modeling/etsicatalog/catalog/pub/config/config.py
diff --git a/docker/instance_init.sh b/docker/instance_init.sh
deleted file mode 100755 (executable)
index d545d67..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-#!/bin/bash
-
-MYSQL_IP=`echo $MYSQL_ADDR | cut -d: -f 1`
-MYSQL_PORT=`echo $MYSQL_ADDR | cut -d: -f 2`
-
-if [ $MYSQL_AUTH ]; then
-    MYSQL_ROOT_USER=`echo $MYSQL_AUTH | cut -d: -f 1`
-    MYSQL_ROOT_PASSWORD=`echo $MYSQL_AUTH | cut -d: -f 2`
-else
-    MYSQL_ROOT_USER="root"
-    MYSQL_ROOT_PASSWORD="root"
-fi
-
-function create_database {
-
-    cd /service/modeling/etsicatalog/resources/bin
-    bash initDB.sh $MYSQL_ROOT_USER $MYSQL_ROOT_PASSWORD $MYSQL_PORT $MYSQL_IP
-
- }
-
-function migrate_database {
-    cd /service/modeling/etsicatalog
-    python manage.py migrate
-}
-
-create_database
-migrate_database