7 WORKSPACE="${WORKSPACE:-}"
18 DCAE_BE_JAVA_OPTIONS="-XX:MaxPermSize=256m -Xmx1024m -Dconfig.home=config -Dlog.home=/var/lib/jetty/logs/ -Dlogging.config=config/dcae-be/logback-spring.xml"
19 DCAE_FE_JAVA_OPTIONS="-XX:MaxPermSize=256m -Xmx1024m -Dconfig.home=config -Dlog.home=/var/lib/jetty/logs/ -Dlogging.config=config/dcae-fe/logback-spring.xml"
20 DCAE_DT_JAVA_OPTIONS="-XX:MaxPermSize=256m -Xmx1024m -Dconfig.home=config -Dlog.home=/var/lib/jetty/logs/ -Dlogging.config=config/dcae-dt/logback-spring.xml"
23 #Define this as variable, so it can be excluded in run commands on Docker for OSX, as /etc/localtime cant be mounted there.
24 LOCAL_TIME_MOUNT_CMD="--volume /etc/localtime:/etc/localtime:ro"
26 # If os is OSX, unset this, so /etc/localtime is not mounted, otherwise leave it be
27 if [[ "$OSTYPE" == "darwin"* ]]; then
28 LOCAL_TIME_MOUNT_CMD=""
32 DOCKER_RUN_MODE_BG="--detach"
33 DOCKER_RUN_MODE_FG="-dti"
41 echo "usage: docker_run.sh [ -r|--release <RELEASE-NAME> ] [ -e|--environment <ENV-NAME> ] [ -p|--port <Docker-hub-port>] [ -l|--local <Run-without-pull>] [ -h|--help ]"
42 echo "example: sudo bash docker_run.sh -e AUTO -r 1.2-STAGING-latest"
48 echo "Performing old dockers cleanup"
50 if [ "$1" == "all" ] ; then
51 docker_ids=$(docker ps -a | egrep "dcae" | awk '{print $1}')
52 for X in ${docker_ids}
57 echo "performing $1 docker cleanup"
58 tmp=$(docker ps -a -q --filter="name=$1")
59 if [[ -n "$tmp" ]]; then
68 mkdir -p "${WORKSPACE}/data/logs/DCAE-BE/DCAE"
69 mkdir -p "${WORKSPACE}/data/logs/DCAE-FE/DCAE"
70 mkdir -p "${WORKSPACE}/data/logs/DCAE-DT/DCAE"
75 function docker_logs {
76 docker logs "$1" > "${WORKSPACE}/data/logs/docker_logs/$1_docker.log"
85 function ready_probe {
86 docker exec "$1" /var/lib/ready-probe.sh > /dev/null 2>&1
88 if [[ ${rc} == 0 ]]; then
89 echo "DOCKER $1 start finished in $2 seconds"
97 function probe_docker {
98 MATCH=$(docker logs --tail 30 "$1" | grep "DOCKER STARTED")
99 echo MATCH is -- "${MATCH}"
101 if [ -n "$MATCH" ] ; then
102 echo "DOCKER start finished in $2 seconds"
110 function probe_dcae_be {
111 health_check_http_code=$(curl -i -o /dev/null -w '%{http_code}' "http://${IP}:8082/dcae/conf/composition")
112 if [[ "${health_check_http_code}" -eq 200 ]] ; then
113 echo "DOCKER start finished in $1 seconds"
120 function probe_dcae_fe {
121 health_check_http_code=$(curl -i -o /dev/null -w '%{http_code}' "http://${IP}:8183/dcaed/healthCheck")
122 if [[ "${health_check_http_code}" -eq 200 ]] ; then
123 echo "DOCKER start finished in $1 seconds"
130 function probe_dcae_dt {
131 health_check_http_code=$(curl -i -o /dev/null -w '%{http_code}' "http://${IP}:8186/dcae/healthCheckOld")
132 if [[ "${health_check_http_code}" -eq 200 ]] ; then
133 echo "DOCKER start finished in $1 seconds"
140 # Not applicable for current release. Return Success in any case
141 function probe_dcae_tools {
142 health_check_http_code=$(curl -i -o /dev/null -w '%{http_code}' "http://${IP}:8082/dcae/getResourcesByMonitoringTemplateCategory")
143 if [[ "${health_check_http_code}" -eq 200 ]] ; then
144 echo "DOCKER start finished in $1 seconds"
152 function monitor_docker {
154 echo "Monitor ${DOCKER_NAME} Docker"
160 while [ "$TIME" -lt "$TIME_OUT" ]; do
162 case ${DOCKER_NAME} in
165 probe_dcae_be ${TIME} ;
169 probe_dcae_fe ${TIME} ;
173 probe_dcae_dt ${TIME} ;
181 probe_docker "${DOCKER_NAME}" ${TIME};
187 if [ ${status} == ${SUCCESS} ] ; then
191 echo "Sleep: ${INTERVAL} seconds before testing if ${DOCKER_NAME} DOCKER is up. Total wait time up now is: ${TIME} seconds. Timeout is: ${TIME_OUT} seconds"
193 TIME=$(($TIME+$INTERVAL))
196 docker_logs "${DOCKER_NAME}"
198 if [ "$TIME" -ge "$TIME_OUT" ]; then
199 echo -e "\e[1;31mTIME OUT: DOCKER was NOT fully started in $TIME_OUT seconds... Could cause problems ...\e[0m"
205 function healthCheck {
207 echo "BE health-Check:"
208 curl --noproxy "*" "http://${IP}:8080/sdc2/rest/healthCheck"
212 echo "FE health-Check:"
213 curl --noproxy "*" "http://${IP}:8181/sdc1/rest/healthCheck"
218 function command_exit_status {
221 if [ "${status}" != "0" ] ; then
222 echo "[ ERROR ] Docker ${docker} run command exit with status [${status}]"
236 DOCKER_NAME="dcae-be"
237 echo "docker run ${DOCKER_NAME}..."
238 if [ ${LOCAL} == false ]; then
239 docker pull "${PREFIX}/${DOCKER_NAME}:${RELEASE}"
241 docker run ${DOCKER_RUN_MODE_FG} --name ${DOCKER_NAME} --env HOST_IP="${IP}" --env ENVNAME="${DEP_ENV}" --env JAVA_OPTIONS="${DCAE_BE_JAVA_OPTIONS}" --log-driver=json-file --log-opt max-size=100m --log-opt max-file=10 --ulimit memlock=-1:-1 --ulimit nofile=4096:100000 ${LOCAL_TIME_MOUNT_CMD} --volume "${WORKSPACE}/data/logs/DCAE-BE/:/var/lib/jetty/logs" --volume "${WORKSPACE}/data/environments:/var/opt/dcae-be/chef-solo/environments" --publish 8444:8444 --publish 8082:8082 "${PREFIX}/${DOCKER_NAME}:${RELEASE}" /bin/sh
242 command_exit_status $? ${DOCKER_NAME}
243 echo "please wait while ${DOCKER_NAME^^} is starting....."
244 monitor_docker ${DOCKER_NAME}
250 function dcae-tools {
251 DOCKER_NAME="dcae-tools"
252 echo "docker run ${DOCKER_NAME}..."
253 if [ ${LOCAL} == false ]; then
254 docker pull "${PREFIX}/${DOCKER_NAME}:${RELEASE}"
256 docker run ${DOCKER_RUN_MODE_BG} --name ${DOCKER_NAME} --env HOST_IP="${IP}" --env ENVNAME="${DEP_ENV}" ${LOCAL_TIME_MOUNT_CMD} --volume "${WORKSPACE}/data/logs/BE/:/var/lib/jetty/logs" --volume "${WORKSPACE}/data/environments:/var/opt/dcae-tools/chef-solo/environments" "${PREFIX}/${DOCKER_NAME}:${RELEASE}"
257 command_exit_status $? ${DOCKER_NAME}
258 echo "please wait while ${DOCKER_NAME^^} is starting....."
259 monitor_docker ${DOCKER_NAME}
266 DOCKER_NAME="dcae-fe"
267 echo "docker run ${DOCKER_NAME}..."
268 if [ ${LOCAL} == false ]; then
269 docker pull "${PREFIX}/${DOCKER_NAME}:${RELEASE}"
271 docker run ${DOCKER_RUN_MODE_FG} --name ${DOCKER_NAME} --env HOST_IP="${IP}" --env ENVNAME="${DEP_ENV}" --env JAVA_OPTIONS="${DCAE_FE_JAVA_OPTIONS}" --log-driver=json-file --log-opt max-size=100m --log-opt max-file=10 --ulimit memlock=-1:-1 --ulimit nofile=4096:100000 ${LOCAL_TIME_MOUNT_CMD} --volume "${WORKSPACE}/data/logs/DCAE-FE/:/var/lib/jetty/logs" --volume "${WORKSPACE}/data/environments:/var/opt/dcae-fe/chef-solo/environments/" --publish 9444:9444 --publish 8183:8183 "${PREFIX}/${DOCKER_NAME}:${RELEASE}" /bin/sh
272 command_exit_status $? ${DOCKER_NAME}
273 echo "please wait while ${DOCKER_NAME^^} is starting....."
274 monitor_docker ${DOCKER_NAME}
280 DOCKER_NAME="dcae-dt"
281 echo "docker run ${DOCKER_NAME}..."
282 if [ ${LOCAL} == false ]; then
283 docker pull "${PREFIX}/${DOCKER_NAME}:${RELEASE}"
285 docker run ${DOCKER_RUN_MODE_FG} --name ${DOCKER_NAME} --env HOST_IP="${IP}" --env ENVNAME="${DEP_ENV}" --env JAVA_OPTIONS="${DCAE_DT_JAVA_OPTIONS}" --log-driver=json-file --log-opt max-size=100m --log-opt max-file=10 --ulimit memlock=-1:-1 --ulimit nofile=4096:100000 ${LOCAL_TIME_MOUNT_CMD} --volume "${WORKSPACE}/data/logs/DCAE-DT/:/var/lib/jetty/logs" --volume "${WORKSPACE}/data/environments:/var/opt/dcae-dt/chef-solo/environments/" --publish 9446:9446 --publish 8186:8186 "${PREFIX}/${DOCKER_NAME}:${RELEASE}" /bin/sh
286 command_exit_status $? ${DOCKER_NAME}
287 echo "please wait while ${DOCKER_NAME^^} is starting....."
288 monitor_docker ${DOCKER_NAME}
298 # Handle command line arguments
300 if [ $# -eq 0 ]; then
305 while [ $# -gt 0 ]; do
308 # -r | --release - The specific docker version to pull and deploy
314 # -e | --environment - The environment name you want to deploy
320 # -p | --port - The port from which to connect to the docker nexus
326 # -l | --local - Use this for deploying your local dockers without pulling them first
331 # -d | --docker - The init specified docker
337 # -h | --help - Display the help message with all the available run options
349 #Prefix those with WORKSPACE so it can be set to something other then /opt
350 [ -f "${WORKSPACE}/opt/config/env_name.txt" ] && DEP_ENV=$(cat "${WORKSPACE}/opt/config/env_name.txt") || echo "${DEP_ENV}"
351 [ -f "${WORKSPACE}/opt/config/nexus_username.txt" ] && NEXUS_USERNAME=$(cat "${WORKSPACE}/opt/config/nexus_username.txt") || NEXUS_USERNAME="release"
352 [ -f "${WORKSPACE}/opt/config/nexus_password.txt" ] && NEXUS_PASSWD=$(cat "${WORKSPACE}/opt/config/nexus_password.txt") || NEXUS_PASSWD="sfWU3DFVdBr7GVxB85mTYgAW"
353 [ -f "${WORKSPACE}/opt/config/nexus_docker_repo.txt" ] && NEXUS_DOCKER_REPO=$(cat "${WORKSPACE}/opt/config/nexus_docker_repo.txt") || NEXUS_DOCKER_REPO="nexus3.onap.org:${PORT}"
354 [ -f "${WORKSPACE}/opt/config/nexus_username.txt" ] && docker login -u ${NEXUS_USERNAME} -p ${NEXUS_PASSWD} ${NEXUS_DOCKER_REPO}
358 export IP=`ip route get 8.8.8.8 | awk '/src/{ print $7 }'`
359 #If OSX, then use this to get IP
360 if [[ "$OSTYPE" == "darwin"* ]]; then
361 export IP=$(ipconfig getifaddr en0)
363 export PREFIX=${NEXUS_DOCKER_REPO}'/onap'
365 if [ ${LOCAL} == true ]; then
371 if [ -z "${DOCKER}" ]; then