Michael Lando | 451a340 | 2017-02-19 10:28:42 +0200 | [diff] [blame^] | 1 | #!/bin/bash |
| 2 | |
| 3 | |
| 4 | function usage |
| 5 | { |
| 6 | echo "usage: docker_run.sh [ -r|--release <RELEASE-NAME> ] [ -e|--environment <ENV-NAME> ] [ -p|--port <Docker-hub-port>] [ -h|--help ]" |
| 7 | } |
| 8 | |
| 9 | |
| 10 | RELEASE=1.0.0-SNAPSHOT |
| 11 | [ -f /opt/config/env_name.txt ] && DEP_ENV=$(cat /opt/config/env_name.txt) || DEP_ENV=__ENV-NAME__ |
| 12 | PORT=51212 |
| 13 | |
| 14 | while [ "$1" != "" ]; do |
| 15 | case $1 in |
| 16 | -r | --release ) |
| 17 | shift |
| 18 | RELEASE=${1} |
| 19 | ;; |
| 20 | -e | --environment ) |
| 21 | shift |
| 22 | DEP_ENV=${1} |
| 23 | ;; |
| 24 | -p | --port ) |
| 25 | shift |
| 26 | PORT=${1} |
| 27 | ;; |
| 28 | -h | --help ) |
| 29 | usage |
| 30 | exit |
| 31 | ;; |
| 32 | * ) |
| 33 | usage |
| 34 | exit 1 |
| 35 | esac |
| 36 | shift |
| 37 | done |
| 38 | |
| 39 | [ -f /opt/config/nexus_username.txt ] && NEXUS_USERNAME=$(cat /opt/config/nexus_username.txt) || NEXUS_USERNAME=release |
| 40 | [ -f /opt/config/nexus_password.txt ] && NEXUS_PASSWD=$(cat /opt/config/nexus_password.txt) || NEXUS_PASSWD=sfWU3DFVdBr7GVxB85mTYgAW |
| 41 | [ -f /opt/config/nexus_docker_repo.txt ] && NEXUS_DOCKER_REPO=$(cat /opt/config/nexus_docker_repo.txt) || NEXUS_DOCKER_REPO=ecomp-nexus:${PORT} |
| 42 | |
| 43 | [ -f /opt/config/nexus_username.txt ] && docker login -u $NEXUS_USERNAME -p $NEXUS_PASSWD $NEXUS_DOCKER_REPO |
| 44 | |
| 45 | |
| 46 | # cleanup |
| 47 | echo "performing old dockers cleanup" |
| 48 | docker_ids=`docker ps -a | egrep "ecomp-nexus:${PORT}/sdc|sdc|Exit" | awk '{print $1}'` |
| 49 | for X in ${docker_ids} |
| 50 | do |
| 51 | docker rm -f ${X} |
| 52 | done |
| 53 | |
| 54 | export IP=`ifconfig eth0 | awk -F: '/inet addr/ {gsub(/ .*/,"",$2); print $2}'` |
| 55 | |
| 56 | echo "" |
| 57 | |
| 58 | # Elastic-Search |
| 59 | echo "docker run sdc-elasticsearch..." |
| 60 | docker pull ecomp-nexus:${PORT}/ecomp/sdc-elasticsearch:${RELEASE} |
| 61 | 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 ecomp-nexus:${PORT}/ecomp/sdc-elasticsearch:${RELEASE} |
| 62 | |
| 63 | |
| 64 | # cassandra |
| 65 | echo "docker run sdc-cassandra..." |
| 66 | docker pull ecomp-nexus:${PORT}/ecomp/sdc-cassandra:${RELEASE} |
| 67 | docker run --detach --name sdc-cs --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 ecomp-nexus:${PORT}/ecomp/sdc-cassandra:${RELEASE} |
| 68 | |
| 69 | |
| 70 | echo "please wait while CS is starting..." |
| 71 | echo "" |
| 72 | c=25 # seconds to wait |
| 73 | REWRITE="\e[25D\e[1A\e[K" |
| 74 | while [ $c -gt 0 ]; do |
| 75 | c=$((c-1)) |
| 76 | sleep 1 |
| 77 | echo -e "${REWRITE}$c" |
| 78 | done |
| 79 | echo -e "" |
| 80 | |
| 81 | |
| 82 | # kibana |
| 83 | echo "docker run sdc-kibana..." |
| 84 | docker pull ecomp-nexus:${PORT}/ecomp/sdc-kibana:${RELEASE} |
| 85 | 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 ecomp-nexus:${PORT}/ecomp/sdc-kibana:${RELEASE} |
| 86 | |
| 87 | |
| 88 | # Back-End |
| 89 | echo "docker run sdc-backend..." |
| 90 | docker pull ecomp-nexus:${PORT}/ecomp/sdc-backend:${RELEASE} |
| 91 | docker run --detach --name sdc-BE --env HOST_IP=${IP} --env ENVNAME="${DEP_ENV}" --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 ecomp-nexus:${PORT}/ecomp/sdc-backend:${RELEASE} |
| 92 | |
| 93 | echo "please wait while BE is starting..." |
| 94 | echo "" |
| 95 | c=45 # seconds to wait |
| 96 | REWRITE="\e[45D\e[1A\e[K" |
| 97 | while [ $c -gt 0 ]; do |
| 98 | c=$((c-1)) |
| 99 | sleep 1 |
| 100 | echo -e "${REWRITE}$c" |
| 101 | done |
| 102 | echo -e "" |
| 103 | |
| 104 | |
| 105 | # Front-End |
| 106 | echo "docker run sdc-frontend..." |
| 107 | docker pull ecomp-nexus:${PORT}/ecomp/sdc-frontend:${RELEASE} |
| 108 | docker run --detach --name sdc-FE --env HOST_IP=${IP} --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/logs/FE/:/var/lib/jetty/logs --volume /data/environments:/root/chef-solo/environments --publish 9443:9443 --publish 8181:8181 ecomp-nexus:${PORT}/ecomp/sdc-frontend:${RELEASE} |
| 109 | |
| 110 | |
| 111 | |
| 112 | # running healthCheck scripts |
| 113 | echo "Running health checks, please wait..." |
| 114 | echo "" |
| 115 | c=25 # seconds to wait |
| 116 | REWRITE="\e[45D\e[1A\e[K" |
| 117 | while [ $c -gt 0 ]; do |
| 118 | c=$((c-1)) |
| 119 | sleep 1 |
| 120 | echo -e "${REWRITE}$c" |
| 121 | done |
| 122 | echo -e "" |
| 123 | |
| 124 | /data/scripts/docker_health.sh |
| 125 | |
| 126 | if [ $? -ne 0 ]; then |
| 127 | exit 1 |
| 128 | fi |