blob: 4e85ca6a0a0d975c7965bdd7b184fef61bd899ab [file] [log] [blame]
piclosec4e65032017-02-21 14:52:45 +01001#!/bin/bash
seshukm318c9f72018-08-21 07:50:12 +08002# Deployment script for SO lab
piclosec4e65032017-02-21 14:52:45 +01003# ===================================================
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)7f036c82017-03-09 09:42:46 -080020NEXUS=1
Alexis de Talhouëtc1570952017-03-08 11:40:51 -050021if [ "$#" = 0 ]; then
Determe, Sebastien (sd378r)7f036c82017-03-09 09:42:46 -080022 echo "Deploying with local images, not pulling them from Nexus."
23 NEXUS=0
Alexis de Talhouëtc1570952017-03-08 11:40:51 -050024fi
Determe, Sebastien (sd378r)7f036c82017-03-09 09:42:46 -080025
26if [ "$#" -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
piclosec4e65032017-02-21 14:52:45 +010040fi
Determe, Sebastien (sd378r)7f036c82017-03-09 09:42:46 -080041
42if [ -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
piclosec4e65032017-02-21 14:52:45 +010045fi
46
47NEXUS_DOCKER_REPO_MSO=$1
48NEXUS_USERNAME_MSO=$2
49NEXUS_PASSWD_MSO=$3
50NEXUS_DOCKER_REPO_MARIADB=$4
51NEXUS_USERNAME_MARIADB=$5
52NEXUS_PASSWD_MARIADB=$6
53
54
55
56function init_docker_command() {
Determe, Sebastien (sd378r)7f036c82017-03-09 09:42:46 -080057 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
piclosec4e65032017-02-21 14:52:45 +010065
Determe, Sebastien (sd378r)7f036c82017-03-09 09:42:46 -080066 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
piclosec4e65032017-02-21 14:52:45 +010072
Determe, Sebastien (sd378r)7f036c82017-03-09 09:42:46 -080073 echo "docker command: ${LBL_DOCKER_HOST}"
piclosec4e65032017-02-21 14:52:45 +010074}
75
76function 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
piclosec4e65032017-02-21 14:52:45 +010082function pull_docker_images() {
Determe, Sebastien (sd378r)7f036c82017-03-09 09:42:46 -080083 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 Daugherty14149bb2018-08-20 13:06:32 -040089 $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)eb49c0f2018-08-06 13:15:04 -040091
Rob Daugherty14149bb2018-08-20 13:06:32 -040092 $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)eb49c0f2018-08-06 13:15:04 -040094
Rob Daughertyf9cc60c2018-08-23 15:40:52 -040095 $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)eb49c0f2018-08-06 13:15:04 -040097
Rob Daugherty14149bb2018-08-20 13:06:32 -040098 $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)eb49c0f2018-08-06 13:15:04 -0400100
Rob Daugherty14149bb2018-08-20 13:06:32 -0400101 $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)eb49c0f2018-08-06 13:15:04 -0400103
Rob Daugherty14149bb2018-08-20 13:06:32 -0400104 $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)eb49c0f2018-08-06 13:15:04 -0400106
Rob Daugherty14149bb2018-08-20 13:06:32 -0400107 $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)eb49c0f2018-08-06 13:15:04 -0400109
Rob Daugherty14149bb2018-08-20 13:06:32 -0400110 $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)7f036c82017-03-09 09:42:46 -0800112
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
piclosec4e65032017-02-21 14:52:45 +0100116
117}
118
119function wait_for_mariadb() {
120 CONTAINER_NAME=$1
121
Kanagaraj Manickam k00365106801e3762017-06-13 19:47:56 +0530122 TIMEOUT=600
piclosec4e65032017-02-21 14:52:45 +0100123
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-M8d73a692017-10-17 18:06:26 +0530126 while [[ ${AMOUNT_STARTUP} -lt 1 ]];
piclosec4e65032017-02-21 14:52:45 +0100127 do
Determe, Sebastien (sd378r)7f036c82017-03-09 09:42:46 -0800128 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 k00365106801e3762017-06-13 19:47:56 +0530135 let TIMEOUT-=5
136 sleep 5
piclosec4e65032017-02-21 14:52:45 +0100137 done
138}
139
140################################### Script entry - Starting CODE ################################
141SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
142
143init_docker_command
Determe, Sebastien (sd378r)7f036c82017-03-09 09:42:46 -0800144if [ $NEXUS -eq 1 ]; then
145 pull_docker_images
Alexis de Talhouëtc1570952017-03-08 11:40:51 -0500146fi
piclosec4e65032017-02-21 14:52:45 +0100147
148# don't remove the containers,no cleanup
149#$DOCKER_COMPOSE_CMD stop
150#$DOCKER_COMPOSE_CMD rm -f -v
151
seshukm318c9f72018-08-21 07:50:12 +0800152#brought in the down to stop and remove the images created by up
153$DOCKER_COMPOSE_CMD down
154
piclosec4e65032017-02-21 14:52:45 +0100155# 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
160CONTAINER_NAME=$(container_name mariadb)
161wait_for_mariadb $CONTAINER_NAME
seshukm318c9f72018-08-21 07:50:12 +0800162#adding the detach mode (run in background)
163$DOCKER_COMPOSE_CMD up -d