piclose | c4e6503 | 2017-02-21 14:52:45 +0100 | [diff] [blame] | 1 | #!/bin/bash |
seshukm | 318c9f7 | 2018-08-21 07:50:12 +0800 | [diff] [blame] | 2 | # Deployment script for SO lab |
piclose | c4e6503 | 2017-02-21 14:52:45 +0100 | [diff] [blame] | 3 | # =================================================== |
| 4 | # Available parameters : |
| 5 | # |
| 6 | # env DOCKER_HOST (optional) |
| 7 | # | sets the docker host to be used if not local unix socket |
| 8 | # |
| 9 | # env MSO_CONFIG_UPDATES (optional) |
| 10 | # | json structure that matches volumes/mso/chef-config/mso-docker.json |
| 11 | # | elements whose value needs to be updated before the deployment |
| 12 | # | phase. |
| 13 | # |
| 14 | # env MSO_DOCKER_IMAGE_VERSION |
| 15 | # | json structure that matches volumes/mso/chef-config/mso-docker.json |
| 16 | # | elements whose value needs to be updated before the deployment |
| 17 | # | phase. |
| 18 | ################################### Functions definition ################################ |
| 19 | |
Determe, Sebastien (sd378r) | 7f036c8 | 2017-03-09 09:42:46 -0800 | [diff] [blame] | 20 | NEXUS=1 |
Alexis de Talhouët | c157095 | 2017-03-08 11:40:51 -0500 | [diff] [blame] | 21 | if [ "$#" = 0 ]; then |
Determe, Sebastien (sd378r) | 7f036c8 | 2017-03-09 09:42:46 -0800 | [diff] [blame] | 22 | echo "Deploying with local images, not pulling them from Nexus." |
| 23 | NEXUS=0 |
Alexis de Talhouët | c157095 | 2017-03-08 11:40:51 -0500 | [diff] [blame] | 24 | fi |
Determe, Sebastien (sd378r) | 7f036c8 | 2017-03-09 09:42:46 -0800 | [diff] [blame] | 25 | |
| 26 | if [ "$#" -ne 6 ] && [ $NEXUS -eq 1 ]; then |
| 27 | echo "Usage: deploy.sh <NEXUS_HOST_MSO:NEXUS_PORT_MSO> <NEXUS_LOGIN_MSO> <NEXUS_PASSWORD_MSO> <NEXUS_HOST_MARIADB:NEXUS_PORT_MARIADB> <NEXUS_LOGIN_MARIADB> <NEXUS_PASSWORD_MARIADB> |
| 28 | - env DOCKER_HOST (optional) |
| 29 | sets the docker host to be used if not local unix socket |
| 30 | |
| 31 | - env MSO_DOCKER_IMAGE_VERSION (required) |
| 32 | sets the mso docker image version |
| 33 | |
| 34 | - env MSO_CONFIG_UPDATES (optional) |
| 35 | json structure that matches volumes/mso/chef-config/mso-docker.json |
| 36 | elements whose value needs to be updated before the deployment |
| 37 | phase." |
| 38 | |
| 39 | exit 1 |
piclose | c4e6503 | 2017-02-21 14:52:45 +0100 | [diff] [blame] | 40 | fi |
Determe, Sebastien (sd378r) | 7f036c8 | 2017-03-09 09:42:46 -0800 | [diff] [blame] | 41 | |
| 42 | if [ -z "$MSO_DOCKER_IMAGE_VERSION" ] && [ $NEXUS -eq 1 ]; then |
| 43 | echo "Env variable MSO_DOCKER_IMAGE_VERSION must be SET to a version before running this script" |
| 44 | exit 1 |
piclose | c4e6503 | 2017-02-21 14:52:45 +0100 | [diff] [blame] | 45 | fi |
| 46 | |
| 47 | NEXUS_DOCKER_REPO_MSO=$1 |
| 48 | NEXUS_USERNAME_MSO=$2 |
| 49 | NEXUS_PASSWD_MSO=$3 |
| 50 | NEXUS_DOCKER_REPO_MARIADB=$4 |
| 51 | NEXUS_USERNAME_MARIADB=$5 |
| 52 | NEXUS_PASSWD_MARIADB=$6 |
| 53 | |
| 54 | |
| 55 | |
| 56 | function init_docker_command() { |
Determe, Sebastien (sd378r) | 7f036c8 | 2017-03-09 09:42:46 -0800 | [diff] [blame] | 57 | if [ -z ${DOCKER_HOST+x} ]; |
| 58 | then |
| 59 | DOCKER_CMD="docker" |
| 60 | LBL_DOCKER_HOST="local docker using unix socket" |
| 61 | else |
| 62 | DOCKER_CMD="docker -H ${DOCKER_HOST}" |
| 63 | LBL_DOCKER_HOST="(remote) docker using ${DOCKER_HOST}" |
| 64 | fi |
piclose | c4e6503 | 2017-02-21 14:52:45 +0100 | [diff] [blame] | 65 | |
Determe, Sebastien (sd378r) | 7f036c8 | 2017-03-09 09:42:46 -0800 | [diff] [blame] | 66 | if [ -f "/opt/docker/docker-compose" ]; |
| 67 | then |
| 68 | DOCKER_COMPOSE_CMD="/opt/docker/docker-compose" |
| 69 | else |
| 70 | DOCKER_COMPOSE_CMD="docker-compose" |
| 71 | fi |
piclose | c4e6503 | 2017-02-21 14:52:45 +0100 | [diff] [blame] | 72 | |
Determe, Sebastien (sd378r) | 7f036c8 | 2017-03-09 09:42:46 -0800 | [diff] [blame] | 73 | echo "docker command: ${LBL_DOCKER_HOST}" |
piclose | c4e6503 | 2017-02-21 14:52:45 +0100 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | function container_name() { |
| 77 | SERVICE=$1 |
| 78 | BASE=$(echo $(basename `pwd`) | sed "s/[^a-z0-9]//i" | tr [:upper:] [:lower:]) |
| 79 | echo ${BASE}_${SERVICE}_1 |
| 80 | } |
| 81 | |
piclose | c4e6503 | 2017-02-21 14:52:45 +0100 | [diff] [blame] | 82 | function pull_docker_images() { |
Determe, Sebastien (sd378r) | 7f036c8 | 2017-03-09 09:42:46 -0800 | [diff] [blame] | 83 | echo "Using Nexus for MSO: $NEXUS_DOCKER_REPO_MSO (user "$NEXUS_USERNAME_MSO")" |
| 84 | # login to nexus |
| 85 | $DOCKER_CMD login -u $NEXUS_USERNAME_MSO -p $NEXUS_PASSWD_MSO $NEXUS_DOCKER_REPO_MSO |
| 86 | $DOCKER_CMD login -u $NEXUS_USERNAME_MARIADB -p $NEXUS_PASSWD_MARIADB $NEXUS_DOCKER_REPO_MARIADB |
| 87 | |
| 88 | # get images |
Rob Daugherty | 14149bb | 2018-08-20 13:06:32 -0400 | [diff] [blame] | 89 | $DOCKER_CMD pull $NEXUS_DOCKER_REPO_MSO/onap/so/api-handler-infra:$MSO_DOCKER_IMAGE_VERSION |
| 90 | $DOCKER_CMD tag $NEXUS_DOCKER_REPO_MSO/onap/so/api-handler-infra:$MSO_DOCKER_IMAGE_VERSION onap/so/api-handler-infra:latest |
Smokowski, Steve (ss835w) | eb49c0f | 2018-08-06 13:15:04 -0400 | [diff] [blame] | 91 | |
Rob Daugherty | 14149bb | 2018-08-20 13:06:32 -0400 | [diff] [blame] | 92 | $DOCKER_CMD pull $NEXUS_DOCKER_REPO_MSO/onap/so/bpmn-infra:$MSO_DOCKER_IMAGE_VERSION |
| 93 | $DOCKER_CMD tag $NEXUS_DOCKER_REPO_MSO/onap/so/bpmn-infra:$MSO_DOCKER_IMAGE_VERSION onap/so/bpmn-infra:latest |
Smokowski, Steve (ss835w) | eb49c0f | 2018-08-06 13:15:04 -0400 | [diff] [blame] | 94 | |
Rob Daugherty | f9cc60c | 2018-08-23 15:40:52 -0400 | [diff] [blame^] | 95 | $DOCKER_CMD pull $NEXUS_DOCKER_REPO_MSO/onap/so/sdc-controller:$MSO_DOCKER_IMAGE_VERSION |
| 96 | $DOCKER_CMD tag $NEXUS_DOCKER_REPO_MSO/onap/so/sdc-controller:$MSO_DOCKER_IMAGE_VERSION onap/so/sdc-controller:latest |
Smokowski, Steve (ss835w) | eb49c0f | 2018-08-06 13:15:04 -0400 | [diff] [blame] | 97 | |
Rob Daugherty | 14149bb | 2018-08-20 13:06:32 -0400 | [diff] [blame] | 98 | $DOCKER_CMD pull $NEXUS_DOCKER_REPO_MSO/onap/so/vfc-adapter:$MSO_DOCKER_IMAGE_VERSION |
| 99 | $DOCKER_CMD tag $NEXUS_DOCKER_REPO_MSO/onap/so/vfc-adapter:$MSO_DOCKER_IMAGE_VERSION onap/so/vfc-adapter:latest |
Smokowski, Steve (ss835w) | eb49c0f | 2018-08-06 13:15:04 -0400 | [diff] [blame] | 100 | |
Rob Daugherty | 14149bb | 2018-08-20 13:06:32 -0400 | [diff] [blame] | 101 | $DOCKER_CMD pull $NEXUS_DOCKER_REPO_MSO/onap/so/openstack-adapter:$MSO_DOCKER_IMAGE_VERSION |
| 102 | $DOCKER_CMD tag $NEXUS_DOCKER_REPO_MSO/onap/so/openstack-adapter:$MSO_DOCKER_IMAGE_VERSION onap/so/openstack-adapter:latest |
Smokowski, Steve (ss835w) | eb49c0f | 2018-08-06 13:15:04 -0400 | [diff] [blame] | 103 | |
Rob Daugherty | 14149bb | 2018-08-20 13:06:32 -0400 | [diff] [blame] | 104 | $DOCKER_CMD pull $NEXUS_DOCKER_REPO_MSO/onap/so/catalog-db-adapter:$MSO_DOCKER_IMAGE_VERSION |
| 105 | $DOCKER_CMD tag $NEXUS_DOCKER_REPO_MSO/onap/so/catalog-db-adapter:$MSO_DOCKER_IMAGE_VERSION onap/so/catalog-db-adapter:latest |
Smokowski, Steve (ss835w) | eb49c0f | 2018-08-06 13:15:04 -0400 | [diff] [blame] | 106 | |
Rob Daugherty | 14149bb | 2018-08-20 13:06:32 -0400 | [diff] [blame] | 107 | $DOCKER_CMD pull $NEXUS_DOCKER_REPO_MSO/onap/so/request-db-adapter:$MSO_DOCKER_IMAGE_VERSION |
| 108 | $DOCKER_CMD tag $NEXUS_DOCKER_REPO_MSO/onap/so/request-db-adapter:$MSO_DOCKER_IMAGE_VERSION onap/so/request-db-adapter:latest |
Smokowski, Steve (ss835w) | eb49c0f | 2018-08-06 13:15:04 -0400 | [diff] [blame] | 109 | |
Rob Daugherty | 14149bb | 2018-08-20 13:06:32 -0400 | [diff] [blame] | 110 | $DOCKER_CMD pull $NEXUS_DOCKER_REPO_MSO/onap/so/sdnc-adapter:$MSO_DOCKER_IMAGE_VERSION |
| 111 | $DOCKER_CMD tag $NEXUS_DOCKER_REPO_MSO/onap/so/sdnc-adapter:$MSO_DOCKER_IMAGE_VERSION onap/so/sdnc-adapter:latest |
Determe, Sebastien (sd378r) | 7f036c8 | 2017-03-09 09:42:46 -0800 | [diff] [blame] | 112 | |
| 113 | echo "Using Nexus for MARIADB: $NEXUS_DOCKER_REPO_MARIADB (user "$NEXUS_USERNAME_MARIADB")" |
| 114 | $DOCKER_CMD pull $NEXUS_DOCKER_REPO_MARIADB/mariadb:10.1.11 |
| 115 | $DOCKER_CMD tag $NEXUS_DOCKER_REPO_MARIADB/mariadb:10.1.11 mariadb:10.1.11 |
piclose | c4e6503 | 2017-02-21 14:52:45 +0100 | [diff] [blame] | 116 | |
| 117 | } |
| 118 | |
| 119 | function wait_for_mariadb() { |
| 120 | CONTAINER_NAME=$1 |
| 121 | |
Kanagaraj Manickam k00365106 | 801e376 | 2017-06-13 19:47:56 +0530 | [diff] [blame] | 122 | TIMEOUT=600 |
piclose | c4e6503 | 2017-02-21 14:52:45 +0100 | [diff] [blame] | 123 | |
| 124 | # wait for the real startup |
| 125 | AMOUNT_STARTUP=$($DOCKER_CMD logs ${CONTAINER_NAME} 2>&1 | grep 'mysqld: ready for connections.' | wc -l) |
Seshu-Kumar-M | 8d73a69 | 2017-10-17 18:06:26 +0530 | [diff] [blame] | 126 | while [[ ${AMOUNT_STARTUP} -lt 1 ]]; |
piclose | c4e6503 | 2017-02-21 14:52:45 +0100 | [diff] [blame] | 127 | do |
Determe, Sebastien (sd378r) | 7f036c8 | 2017-03-09 09:42:46 -0800 | [diff] [blame] | 128 | echo "Waiting for '$CONTAINER_NAME' deployment to finish ..." |
| 129 | AMOUNT_STARTUP=$($DOCKER_CMD logs ${CONTAINER_NAME} 2>&1 | grep 'mysqld: ready for connections.' | wc -l) |
| 130 | if [ "$TIMEOUT" = "0" ]; |
| 131 | then |
| 132 | echo "ERROR: Mariadb deployment failed." |
| 133 | exit 1 |
| 134 | fi |
Kanagaraj Manickam k00365106 | 801e376 | 2017-06-13 19:47:56 +0530 | [diff] [blame] | 135 | let TIMEOUT-=5 |
| 136 | sleep 5 |
piclose | c4e6503 | 2017-02-21 14:52:45 +0100 | [diff] [blame] | 137 | done |
| 138 | } |
| 139 | |
| 140 | ################################### Script entry - Starting CODE ################################ |
| 141 | SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" |
| 142 | |
| 143 | init_docker_command |
Determe, Sebastien (sd378r) | 7f036c8 | 2017-03-09 09:42:46 -0800 | [diff] [blame] | 144 | if [ $NEXUS -eq 1 ]; then |
| 145 | pull_docker_images |
Alexis de Talhouët | c157095 | 2017-03-08 11:40:51 -0500 | [diff] [blame] | 146 | fi |
piclose | c4e6503 | 2017-02-21 14:52:45 +0100 | [diff] [blame] | 147 | |
| 148 | # don't remove the containers,no cleanup |
| 149 | #$DOCKER_COMPOSE_CMD stop |
| 150 | #$DOCKER_COMPOSE_CMD rm -f -v |
| 151 | |
seshukm | 318c9f7 | 2018-08-21 07:50:12 +0800 | [diff] [blame] | 152 | #brought in the down to stop and remove the images created by up |
| 153 | $DOCKER_COMPOSE_CMD down |
| 154 | |
piclose | c4e6503 | 2017-02-21 14:52:45 +0100 | [diff] [blame] | 155 | # deploy |
| 156 | #Running docker-compose up -d starts the containers in the background and leaves them running. |
| 157 | #If there are existing containers for a service, and the service’s configuration or image was changed after the container’s creation, docker-compose up picks up the changes by stopping and recreating the containers (preserving mounted volumes). To prevent Compose from picking up changes, use the --no-recreate flag. |
| 158 | #If you want to force Compose to stop and recreate all containers, use the --force-recreate flag. |
| 159 | $DOCKER_COMPOSE_CMD up -d --no-recreate mariadb |
| 160 | CONTAINER_NAME=$(container_name mariadb) |
| 161 | wait_for_mariadb $CONTAINER_NAME |
seshukm | 318c9f7 | 2018-08-21 07:50:12 +0800 | [diff] [blame] | 162 | #adding the detach mode (run in background) |
| 163 | $DOCKER_COMPOSE_CMD up -d |