Michael Lando | 451a340 | 2017-02-19 10:28:42 +0200 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | |
Grinberg Moti | c3bda48 | 2017-02-23 11:24:34 +0200 | [diff] [blame] | 4 | function usage { |
Idan Amit | c7f57ec | 2017-08-31 14:26:21 +0300 | [diff] [blame] | 5 | 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 ]" |
Michael Lando | 451a340 | 2017-02-19 10:28:42 +0200 | [diff] [blame] | 6 | } |
| 7 | |
| 8 | |
Grinberg Moti | c3bda48 | 2017-02-23 11:24:34 +0200 | [diff] [blame] | 9 | function cleanup { |
| 10 | echo "performing old dockers cleanup" |
Idan Amit | c7f57ec | 2017-08-31 14:26:21 +0300 | [diff] [blame] | 11 | docker_ids=`docker ps -a | egrep -v "openecomp/sdc-simulator" | egrep "ecomp-nexus:${PORT}/sdc|sdc|Exit" | awk '{print $1}'` |
Grinberg Moti | c3bda48 | 2017-02-23 11:24:34 +0200 | [diff] [blame] | 12 | for X in ${docker_ids} |
| 13 | do |
| 14 | docker rm -f ${X} |
| 15 | done |
| 16 | } |
| 17 | |
| 18 | |
| 19 | function dir_perms { |
| 20 | mkdir -p /data/logs/BE/ASDC/ASDC-BE |
| 21 | mkdir -p /data/logs/FE/ASDC/ASDC-FE |
Michael Lando | 33d78d8 | 2017-02-27 19:48:33 +0200 | [diff] [blame] | 22 | chmod -R 777 /data/logs |
Grinberg Moti | c3bda48 | 2017-02-23 11:24:34 +0200 | [diff] [blame] | 23 | } |
| 24 | |
| 25 | |
Grinberg Moti | 9724621 | 2017-02-21 19:30:31 +0200 | [diff] [blame] | 26 | RELEASE=latest |
Idan Amit | c7f57ec | 2017-08-31 14:26:21 +0300 | [diff] [blame] | 27 | LOCAL=false |
Michael Lando | 451a340 | 2017-02-19 10:28:42 +0200 | [diff] [blame] | 28 | [ -f /opt/config/env_name.txt ] && DEP_ENV=$(cat /opt/config/env_name.txt) || DEP_ENV=__ENV-NAME__ |
Grinberg Moti | 53fbfb5 | 2017-02-21 14:22:40 +0200 | [diff] [blame] | 29 | [ -f /opt/config/nexus_username.txt ] && NEXUS_USERNAME=$(cat /opt/config/nexus_username.txt) || NEXUS_USERNAME=release |
| 30 | [ -f /opt/config/nexus_password.txt ] && NEXUS_PASSWD=$(cat /opt/config/nexus_password.txt) || NEXUS_PASSWD=sfWU3DFVdBr7GVxB85mTYgAW |
| 31 | [ -f /opt/config/nexus_docker_repo.txt ] && NEXUS_DOCKER_REPO=$(cat /opt/config/nexus_docker_repo.txt) || NEXUS_DOCKER_REPO=ecomp-nexus:${PORT} |
Michael Lando | 451a340 | 2017-02-19 10:28:42 +0200 | [diff] [blame] | 32 | |
| 33 | while [ "$1" != "" ]; do |
| 34 | case $1 in |
| 35 | -r | --release ) |
| 36 | shift |
| 37 | RELEASE=${1} |
| 38 | ;; |
| 39 | -e | --environment ) |
| 40 | shift |
| 41 | DEP_ENV=${1} |
| 42 | ;; |
| 43 | -p | --port ) |
| 44 | shift |
| 45 | PORT=${1} |
| 46 | ;; |
Idan Amit | c7f57ec | 2017-08-31 14:26:21 +0300 | [diff] [blame] | 47 | -l | --local ) |
| 48 | shift |
| 49 | LOCAL=true |
| 50 | ;; |
Michael Lando | 451a340 | 2017-02-19 10:28:42 +0200 | [diff] [blame] | 51 | -h | --help ) |
| 52 | usage |
| 53 | exit |
| 54 | ;; |
| 55 | * ) |
| 56 | usage |
| 57 | exit 1 |
| 58 | esac |
| 59 | shift |
| 60 | done |
| 61 | |
Michael Lando | 451a340 | 2017-02-19 10:28:42 +0200 | [diff] [blame] | 62 | [ -f /opt/config/nexus_username.txt ] && docker login -u $NEXUS_USERNAME -p $NEXUS_PASSWD $NEXUS_DOCKER_REPO |
| 63 | |
| 64 | |
Grinberg Moti | c3bda48 | 2017-02-23 11:24:34 +0200 | [diff] [blame] | 65 | cleanup |
| 66 | |
Michael Lando | 451a340 | 2017-02-19 10:28:42 +0200 | [diff] [blame] | 67 | |
| 68 | export IP=`ifconfig eth0 | awk -F: '/inet addr/ {gsub(/ .*/,"",$2); print $2}'` |
Idan Amit | c7f57ec | 2017-08-31 14:26:21 +0300 | [diff] [blame] | 69 | export PREFIX=${NEXUS_DOCKER_REPO}'/openecomp' |
| 70 | |
| 71 | if [ ${LOCAL} = true ]; then |
| 72 | PREFIX='openecomp' |
| 73 | fi |
Michael Lando | 451a340 | 2017-02-19 10:28:42 +0200 | [diff] [blame] | 74 | |
| 75 | echo "" |
| 76 | |
| 77 | # Elastic-Search |
| 78 | echo "docker run sdc-elasticsearch..." |
Idan Amit | c7f57ec | 2017-08-31 14:26:21 +0300 | [diff] [blame] | 79 | if [ ${LOCAL} = false ]; then |
| 80 | echo "pulling code" |
| 81 | docker pull ${PREFIX}/sdc-elasticsearch:${RELEASE} |
| 82 | fi |
| 83 | docker run --detach --name sdc-es --env ENVNAME="${DEP_ENV}" --log-driver=json-file --log-opt max-size=100m --log-opt max-file=10 --memory 1g --memory-swap=1g --ulimit memlock=-1:-1 --ulimit nofile=4096:100000 --volume /etc/localtime:/etc/localtime:ro -e ES_HEAP_SIZE=1024M --volume /data/ES:/usr/share/elasticsearch/data --volume /data/environments:/root/chef-solo/environments --publish 9200:9200 --publish 9300:9300 ${PREFIX}/sdc-elasticsearch:${RELEASE} |
| 84 | |
| 85 | |
| 86 | # cassandra |
| 87 | echo "docker run sdc-cassandra..." |
| 88 | if [ ${LOCAL} = false ]; then |
| 89 | docker pull ${PREFIX}/sdc-cassandra:${RELEASE} |
| 90 | fi |
Idan Amit | 9409da0 | 2017-09-03 14:46:10 +0300 | [diff] [blame^] | 91 | docker run --detach --name sdc-cs --env RELEASE="${RELEASE}" --env ENVNAME="${DEP_ENV}" --env HOST_IP=${IP} --log-driver=json-file --log-opt max-size=100m --log-opt max-file=10 --ulimit memlock=-1:-1 --ulimit nofile=4096:100000 --volume /etc/localtime:/etc/localtime:ro --volume /data/CS:/var/lib/cassandra --volume /data/environments:/root/chef-solo/environments --publish 9042:9042 --publish 9160:9160 ${PREFIX}/sdc-cassandra:${RELEASE} |
Michael Lando | 451a340 | 2017-02-19 10:28:42 +0200 | [diff] [blame] | 92 | |
| 93 | |
| 94 | echo "please wait while CS is starting..." |
| 95 | echo "" |
Michael Lando | ed64b5e | 2017-06-09 03:19:04 +0300 | [diff] [blame] | 96 | c=120 # seconds to wait |
Michael Lando | 451a340 | 2017-02-19 10:28:42 +0200 | [diff] [blame] | 97 | REWRITE="\e[25D\e[1A\e[K" |
| 98 | while [ $c -gt 0 ]; do |
| 99 | c=$((c-1)) |
| 100 | sleep 1 |
| 101 | echo -e "${REWRITE}$c" |
| 102 | done |
| 103 | echo -e "" |
| 104 | |
Michael Lando | 451a340 | 2017-02-19 10:28:42 +0200 | [diff] [blame] | 105 | # kibana |
| 106 | echo "docker run sdc-kibana..." |
Idan Amit | c7f57ec | 2017-08-31 14:26:21 +0300 | [diff] [blame] | 107 | if [ ${LOCAL} = false ]; then |
| 108 | docker pull ${PREFIX}/sdc-kibana:${RELEASE} |
| 109 | fi |
| 110 | docker run --detach --name sdc-kbn --env ENVNAME="${DEP_ENV}" --log-driver=json-file --log-opt max-size=100m --log-opt max-file=10 --ulimit memlock=-1:-1 --memory 2g --memory-swap=2g --ulimit nofile=4096:100000 --volume /etc/localtime:/etc/localtime:ro --volume /data/environments:/root/chef-solo/environments --publish 5601:5601 ${PREFIX}/sdc-kibana:${RELEASE} |
Michael Lando | 451a340 | 2017-02-19 10:28:42 +0200 | [diff] [blame] | 111 | |
Grinberg Moti | c3bda48 | 2017-02-23 11:24:34 +0200 | [diff] [blame] | 112 | dir_perms |
Michael Lando | 451a340 | 2017-02-19 10:28:42 +0200 | [diff] [blame] | 113 | |
| 114 | # Back-End |
| 115 | echo "docker run sdc-backend..." |
Idan Amit | c7f57ec | 2017-08-31 14:26:21 +0300 | [diff] [blame] | 116 | if [ ${LOCAL} = false ]; then |
| 117 | docker pull ${PREFIX}/sdc-backend:${RELEASE} |
| 118 | fi |
| 119 | docker run --detach --name sdc-BE --env HOST_IP=${IP} --env ENVNAME="${DEP_ENV}" --env http_proxy=${http_proxy} --env https_proxy=${https_proxy} --env no_proxy=${no_proxy} --log-driver=json-file --log-opt max-size=100m --log-opt max-file=10 --ulimit memlock=-1:-1 --memory 4g --memory-swap=4g --ulimit nofile=4096:100000 --volume /etc/localtime:/etc/localtime:ro --volume /data/logs/BE/:/var/lib/jetty/logs --volume /data/environments:/root/chef-solo/environments --publish 8443:8443 --publish 8080:8080 ${PREFIX}/sdc-backend:${RELEASE} |
Michael Lando | 451a340 | 2017-02-19 10:28:42 +0200 | [diff] [blame] | 120 | |
| 121 | echo "please wait while BE is starting..." |
| 122 | echo "" |
| 123 | c=45 # seconds to wait |
| 124 | REWRITE="\e[45D\e[1A\e[K" |
| 125 | while [ $c -gt 0 ]; do |
| 126 | c=$((c-1)) |
| 127 | sleep 1 |
| 128 | echo -e "${REWRITE}$c" |
| 129 | done |
| 130 | echo -e "" |
| 131 | |
| 132 | |
| 133 | # Front-End |
| 134 | echo "docker run sdc-frontend..." |
Idan Amit | c7f57ec | 2017-08-31 14:26:21 +0300 | [diff] [blame] | 135 | if [ ${LOCAL} = false ]; then |
| 136 | docker pull ${PREFIX}/sdc-frontend:${RELEASE} |
| 137 | fi |
| 138 | docker run --detach --name sdc-FE --env HOST_IP=${IP} --env ENVNAME="${DEP_ENV}" --env http_proxy=${http_proxy} --env https_proxy=${https_proxy} --env no_proxy=${no_proxy} --log-driver=json-file --log-opt max-size=100m --log-opt max-file=10 --ulimit memlock=-1:-1 --memory 2g --memory-swap=2g --ulimit nofile=4096:100000 --volume /etc/localtime:/etc/localtime:ro --volume /data/logs/FE/:/var/lib/jetty/logs --volume /data/environments:/root/chef-solo/environments --publish 9443:9443 --publish 8181:8181 ${PREFIX}/sdc-frontend:${RELEASE} |
Michael Lando | 451a340 | 2017-02-19 10:28:42 +0200 | [diff] [blame] | 139 | |
| 140 | |
| 141 | |
| 142 | # running healthCheck scripts |
| 143 | echo "Running health checks, please wait..." |
| 144 | echo "" |
| 145 | c=25 # seconds to wait |
| 146 | REWRITE="\e[45D\e[1A\e[K" |
| 147 | while [ $c -gt 0 ]; do |
| 148 | c=$((c-1)) |
| 149 | sleep 1 |
| 150 | echo -e "${REWRITE}$c" |
| 151 | done |
| 152 | echo -e "" |
| 153 | |
| 154 | /data/scripts/docker_health.sh |
| 155 | |
| 156 | if [ $? -ne 0 ]; then |
| 157 | exit 1 |
| 158 | fi |
ml636r | 0649e65 | 2017-02-20 21:10:54 +0200 | [diff] [blame] | 159 | |