persit controller configuration upon restarts 85/39885/1
authorJorge Hernandez <jh1730@att.com>
Wed, 28 Mar 2018 23:38:53 +0000 (18:38 -0500)
committerJorge Hernandez <jh1730@att.com>
Wed, 28 Mar 2018 23:38:53 +0000 (18:38 -0500)
case of drools containers restarts or pulling new images.

Change-Id: I30747a605bf1cb5ae351cd1359263728d82afcca
Issue-ID: POLICY-575
Signed-off-by: Jorge Hernandez <jh1730@att.com>
packages/docker/src/main/docker/Dockerfile
packages/docker/src/main/docker/do-start.sh
packages/docker/src/main/docker/docker-install.sh

index d7af6be..d4d427b 100644 (file)
@@ -2,11 +2,16 @@ FROM ubuntu:14.04
 
 ARG HTTP_PROXY=${HTTP_PROXY}
 ARG HTTPS_PROXY=${HTTPS_PROXY}
-ARG POLICY_LOGS=/var/log/ONAP/policy
+ARG POLICY_HOME=/opt/app/policy
+ARG POLICY_LOGS=/var/log/onap/policy/pdpd
+ARG POLICY_INSTALL=/tmp/policy-install
 
 ENV http_proxy $HTTP_PROXY
 ENV https_proxy $HTTPS_PROXY
+ENV POLICY_INSTALL ${POLICY_INSTALL}
+ENV POLICY_HOME ${POLICY_HOME}
 ENV POLICY_LOGS ${POLICY_LOGS}
+ENV POLICY_DOCKER true
 
 RUN \
         apt-get clean && \
@@ -32,18 +37,23 @@ RUN \
         apt-get install -y mariadb-client
 
 RUN pip install http-prompt
-RUN mkdir -p /opt/app/policy/ /tmp/policy-install/ ${POLICY_LOGS} && \
-    chown -R policy /opt/app/policy/ /tmp/policy-install/ ${POLICY_LOGS}
+RUN mkdir -p ${POLICY_HOME}/config ${POLICY_LOGS} ${POLICY_INSTALL}/config && \
+    chown -R policy:policy ${POLICY_HOME} ${POLICY_LOGS} ${POLICY_INSTALL}
 
-WORKDIR /tmp/policy-install
+WORKDIR ${POLICY_INSTALL}
 
 COPY install-drools.zip apps.zip docker-install.sh do-start.sh wait-for-port.sh ./
 
+VOLUME [ "${POLICY_INSTALL}/config", "${POLICY_HOME}/config" ]
+
 RUN unzip -o install-drools.zip && \
     unzip -o apps.zip && \
     rm install-drools.zip apps.zip && \
-    chown -R policy * && \
+    chown -R policy:policy * && \
     chmod +x *.sh
 
+EXPOSE 9696 6969
+
 USER policy
+
 CMD ./do-start.sh
index e185744..5f15697 100644 (file)
@@ -1,10 +1,12 @@
 #!/bin/bash
 
 # skip installation if build.info file is present (restarting an existing container)
-if [[ -f /opt/app/policy/etc/build.info ]]; then
+if [[ -f ${POLICY_HOME}/etc/build.info ]]; then
        echo "Found existing installation, will not reinstall"
-       . /opt/app/policy/etc/profile.d/env.sh
+       . ${POLICY_HOME}/etc/profile.d/env.sh
 else 
+       echo "installing .."
+
        # replace conf files from installer with environment-specific files
        # mounted from the hosting VM
        if [[ -d config ]]; then
@@ -15,13 +17,22 @@ else
        # needs to deploy some artifacts to the repo
        ./wait-for-port.sh nexus 8081
 
+       # remove broken symbolic links if any in data directory
+       if [[ -d ${POLICY_HOME}/config ]]; then
+               echo "removing dangling symbolic links"
+               find -L ${POLICY_HOME}/config -type l -exec rm -- {} +
+       fi
+
+       echo "docker install at ${PWD}"
+
        ./docker-install.sh
 
        . /opt/app/policy/etc/profile.d/env.sh
 
        # install policy keystore
-       mkdir -p $POLICY_HOME/etc/ssl
-       cp config/policy-keystore $POLICY_HOME/etc/ssl
+
+       mkdir -p ${POLICY_HOME}/etc/ssl
+       cp config/policy-keystore ${POLICY_HOME}/etc/ssl
 
        if [[ -x config/drools-tweaks.sh ]] ; then
                echo "Executing tweaks"
@@ -29,16 +40,10 @@ else
                # argument to bash avoids needing execute perms.
                bash config/drools-tweaks.sh
        fi
-
-       # wait for DB up
-       ./wait-for-port.sh mariadb 3306
-
-       # now that DB is up, invoke database upgrade:
-       # sql provisioning scripts should be invoked here.
 fi
 
 echo "Starting processes"
 
 policy start
 
-sleep 1000d
+tail -f /dev/null
index 2ff6a0b..5fb59c2 100644 (file)
@@ -374,27 +374,29 @@ function install_base() {
                exit 1
        fi
 
-       if ! /bin/rm -fr "${POLICY_HOME}"/* > /dev/null 2>&1; then
-               echo "error: aborting base installation: cannot delete the underlying ${POLICY_HOME} files"
-               exit 1
-       fi
-       
-       POLICY_HOME_CONTENTS=$(ls -A "${POLICY_HOME}" 2> /dev/null)
-       if [[ -n ${POLICY_HOME_CONTENTS} ]]; then
-               echo "error: aborting base installation: ${POLICY_HOME} directory is not empty"
-               exit 1
-       fi
+       if [[ -z ${POLICY_DOCKER} ]]; then
+               if ! /bin/rm -fr "${POLICY_HOME}"/* > /dev/null 2>&1; then
+                       echo "error: aborting base installation: cannot delete the underlying ${POLICY_HOME} files"
+                       exit 1
+               fi
        
-       if ! /bin/mkdir -p "${POLICY_HOME}/logs/" > /dev/null 2>&1; then        
-               echo "error: aborting base installation: cannot create ${POLICY_HOME}/logs/"
-               exit 1
-       fi      
+               POLICY_HOME_CONTENTS=$(ls -A "${POLICY_HOME}" 2> /dev/null)
+               if [[ -n ${POLICY_HOME_CONTENTS} ]]; then
+                       echo "error: aborting base installation: ${POLICY_HOME} directory is not empty"
+                       exit 1
+               fi
        
-       if [[ -n ${POLICY_LOGS} ]]; then
-               if ! /bin/mkdir -p "${POLICY_LOGS}" > /dev/null 2>&1; then      
-                       echo "error: aborting base installation: cannot create ${POLICY_LOGS}"
+               if ! /bin/mkdir -p "${POLICY_HOME}/logs/" > /dev/null 2>&1; then
+                       echo "error: aborting base installation: cannot create ${POLICY_HOME}/logs/"
                        exit 1
                fi      
+       
+               if [[ -n ${POLICY_LOGS} ]]; then
+                       if ! /bin/mkdir -p "${POLICY_LOGS}" > /dev/null 2>&1; then      
+                               echo "error: aborting base installation: cannot create ${POLICY_LOGS}"
+                               exit 1
+                       fi      
+               fi
        fi
        
        BASE_TGZ=$(ls base-*.tar.gz)
@@ -868,7 +870,7 @@ function do_install()
                set -x
        fi
 
-       echo "Starting installation at $(date)"
+       echo "Starting installation at $(date) at ${PWD}"
        echo
        
        COMPONENT_TYPE=base