Extend deployment for CSIT env quirks 35/18035/1
authorChristopher Lott (cl778h) <clott@research.att.com>
Tue, 10 Oct 2017 19:54:38 +0000 (15:54 -0400)
committerChristopher Lott (cl778h) <clott@research.att.com>
Tue, 10 Oct 2017 19:55:51 +0000 (15:55 -0400)
Define new environment variables so a host IP and name can be
added to a docker container /etc/hosts file for inter-app comms
using the semi-well-known name portal.api.simpledemo.openecomp.org

Issue: PORTAL-59
Change-Id: If1c23a77a4b227aac314d966f41e5d5aaad846f8
Signed-off-by: Christopher Lott (cl778h) <clott@research.att.com>
deliveries/.env
deliveries/Dockerfile.portalapps
deliveries/Dockerfile.widgetms
deliveries/docker-compose.yml
deliveries/start-apps-cmd.sh
deliveries/wait-for.sh

index f5d1090..0a3230d 100644 (file)
@@ -14,6 +14,16 @@ PORTAL_TAG=1.3.0
 # Name of directory in apps container (NOT host)
 WEBAPPS_DIR=/opt/apache-tomcat-8.0.37/webapps
 
-# Expected environment variables (NOT defined here):
-# LOGS_DIR
-# PROPS_DIR
+# Required settings with default values.
+# Export shell environment variables on ALL hosts.
+LOGS_DIR=./logs
+PROPS_DIR=./properties_rackspace
+
+# Optional settings with no defaults.
+EXTRA_HOST_IP=""
+EXTRA_HOST_NAME=""
+# Export shell environment variables on hosts with no DNS;
+# a line is added to docker container's /etc/hosts.
+# For example:
+#EXTRA_HOST_IP="-i 135.207.161.163"
+#EXTRA_HOST_NAME="-n portal.api.simpledemo.openecomp.org"
index c9fab4d..b1bf88c 100644 (file)
@@ -25,9 +25,6 @@ ENV https_proxy $HTTPS_PROXY
 RUN if [ ! -z ${HTTP_PROXY} ]; then echo "Acquire::http::proxy  \"${HTTP_PROXY}\";" >> /etc/apt/apt.conf; fi && \
     if [ ! -z ${HTTPS_PROXY} ]; then echo "Acquire::https::proxy \"${HTTPS_PROXY}\";" >> /etc/apt/apt.conf; fi
 
-# Install the wait script
-COPY wait-for.sh /
-
 # Install Tomcat.  This image already has curl.
 WORKDIR /tmp
 RUN wget -q http://archive.apache.org/dist/tomcat/tomcat-8/v8.0.37/bin/apache-tomcat-8.0.37.tar.gz
@@ -61,7 +58,10 @@ WORKDIR /
 
 # Define commonly used ENV variables
 ENV PATH $PATH:$JAVA_HOME/bin:${TOMCATHOME}/bin
+# Install the wait script
+COPY wait-for.sh /
+# Install the launch script
 COPY start-apps-cmd.sh /
 
-# Define default command.
+# Define default command
 CMD /start-apps-cmd.sh
index 16bf60b..72a11bb 100644 (file)
@@ -1,18 +1,19 @@
 # Large image
 # FROM openjdk:8-jdk
-# Very small image
+# Tiny image; it includes java and nc
 FROM frolvlad/alpine-oraclejdk8:slim
 
 # Arguments are supplied by build script;
 # the defaults below only support testing
 ARG WMS_JAR=build/widget-ms.jar
-# Launch script
-COPY start-wms-cmd.sh /
-# Wait script, which depends on nc
-COPY wait-for.sh /
 # Onejar
 COPY ${WMS_JAR} /app.jar
 RUN sh -c 'touch /app.jar'
-VOLUME /tmp
-ENV JAVA_OPTS=""
+
+# Wait script, which depends on nc
+COPY wait-for.sh /
+# Launch script
+COPY start-wms-cmd.sh /
+
+# Define default command
 CMD /start-wms-cmd.sh
index 73a19da..d80b6a0 100644 (file)
@@ -91,5 +91,8 @@ services:
       - portal-db:3306
       - --
       - /start-apps-cmd.sh
+      # see comments in .env file
+      - $EXTRA_HOST_IP
+      - $EXTRA_HOST_NAME
     logging:
       driver: json-file
index bbe2a7c..7d3a8ad 100755 (executable)
@@ -1,5 +1,48 @@
 #!/bin/sh
+# Starts the Apache-Tomcat web container with the Portal, EPSDK and DMaaP BC web apps.
+# If arguments "-i ip.2.3.4" AND "-n name" are present, adds an entry to /etc/hosts;
+# this was added as a workaround for missing DNS in the CSIT environment.
 
-LOGFILE=/opt/apache-tomcat-8.0.37/logs/catalina.out
+hostip=""
+hostname=""
+while [ $# -gt 0 ]; do
+    key="$1"
+    case $key in
+        -i|--ip)
+        hostip="$2"
+        shift # past argument
+        shift # past value
+        ;;
+        -n|--name)
+        hostname="$2"
+        shift # past argument
+        shift # past value
+        ;;
+        *)
+        echo "$0: ignoring argument $key"
+       shift
+        ;;
+    esac
+done
+
+# Optionally add to /etc/hosts
+if [ -z "${hostip}" -o -z "${hostname}" ]; then
+    echo "$0: Arguments for IP and name not found, continuing."
+else
+    echo "$0: Using IP-name arguments $hostip $hostname"
+    grep $hostname /etc/hosts
+    ret_code=$?
+    if [ $ret_code != 0 ]; then
+        echo "$hostip $hostname" >> /etc/hosts
+    fi
+fi
+
+BASE=/opt/apache-tomcat-8.0.37
+if [ ! -d $BASE ] ; then
+    echo "$0: $BASE not found or not a directory"
+    exit 1
+fi
+echo "$0: Starting server from $BASE"
+LOGFILE=${BASE}/logs/catalina.out
 echo "`date`:<--------------------    Starting     -------------------->" >> $LOGFILE
-exec /opt/apache-tomcat-8.0.37/bin/catalina.sh run  2>&1 | tee -a $LOGFILE
+exec ${BASE}/bin/catalina.sh run  2>&1 | tee -a $LOGFILE
index be9a443..2525821 100755 (executable)
@@ -23,19 +23,22 @@ USAGE
 
 wait_for() {
   command="$*"
+  if [ "$QUIET" -ne 1 ]; then echo "$0: probing host $HOST port $PORT"; fi
   for i in `seq $TIMEOUT` ; do
     nc -z "$HOST" "$PORT" > /dev/null 2>&1
     result=$?
     if [ $result -eq 0 ] ; then
-      if [ "$QUIET" -ne 1 ]; then echo "Operation succeeded on try $i"; fi
+      if [ "$QUIET" -ne 1 ]; then echo "$0: operation succeeded on try $i"; fi
       if [ -n "$command" ] ; then
+        if [ "$QUIET" -ne 1 ]; then echo "$0: exec-ing command $command"; fi
         exec $command
       fi
       exit 0
     fi
+    if [ "$QUIET" -ne 1 ]; then echo "$0: sleeping after try $i"; fi
     sleep 1
   done
-  echo "Operation timed out" >&2
+  echo "$0: Operation timed out" >&2
   exit 1
 }