2 # Deployment script for MSO lab
3 # ===================================================
4 # Available parameters :
6 # env DOCKER_HOST (optional)
7 # | sets the docker host to be used if not local unix socket
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
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
18 ################################### Functions definition ################################
21 if [ "$#" -ne 6 ]; then
22 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>
23 - env DOCKER_HOST (optional)
24 sets the docker host to be used if not local unix socket
26 - env MSO_DOCKER_IMAGE_VERSION (required)
27 sets the mso docker image version
29 - env MSO_CONFIG_UPDATES (optional)
30 json structure that matches volumes/mso/chef-config/mso-docker.json
31 elements whose value needs to be updated before the deployment
36 if [ -z "$MSO_DOCKER_IMAGE_VERSION" ]; then
37 echo "Env variable MSO_DOCKER_IMAGE_VERSION must be SET to a version before running this script"
41 NEXUS_DOCKER_REPO_MSO=$1
44 NEXUS_DOCKER_REPO_MARIADB=$4
45 NEXUS_USERNAME_MARIADB=$5
46 NEXUS_PASSWD_MARIADB=$6
50 function init_docker_command() {
51 if [ -z ${DOCKER_HOST+x} ];
54 LBL_DOCKER_HOST="local docker using unix socket"
56 DOCKER_CMD="docker -H ${DOCKER_HOST}"
57 LBL_DOCKER_HOST="(remote) docker using ${DOCKER_HOST}"
60 if [ -f "/opt/docker/docker-compose" ];
62 DOCKER_COMPOSE_CMD="/opt/docker/docker-compose"
64 DOCKER_COMPOSE_CMD="docker-compose"
67 echo "docker command: ${LBL_DOCKER_HOST}"
70 function container_name() {
72 BASE=$(echo $(basename `pwd`) | sed "s/[^a-z0-9]//i" | tr [:upper:] [:lower:])
73 echo ${BASE}_${SERVICE}_1
76 function update_json_config() {
77 if [ -n "$MSO_CONFIG_UPDATES" ];
79 chmod u+x $SCRIPT_DIR/json_updater.py
80 echo $MSO_CONFIG_UPDATES | $SCRIPT_DIR/json_updater.py $SCRIPT_DIR/volumes/mso/chef-config/mso-docker.json
81 echo "MSO docker JSON updated"
86 function pull_docker_images() {
87 echo "Using Nexus for MSO: $NEXUS_DOCKER_REPO_MSO (user "$NEXUS_USERNAME_MSO")"
89 $DOCKER_CMD login -u $NEXUS_USERNAME_MSO -p $NEXUS_PASSWD_MSO $NEXUS_DOCKER_REPO_MSO
90 $DOCKER_CMD login -u $NEXUS_USERNAME_MARIADB -p $NEXUS_PASSWD_MARIADB $NEXUS_DOCKER_REPO_MARIADB
93 $DOCKER_CMD pull $NEXUS_DOCKER_REPO_MSO/openecomp/mso:$MSO_DOCKER_IMAGE_VERSION
94 $DOCKER_CMD tag $NEXUS_DOCKER_REPO_MSO/openecomp/mso:$MSO_DOCKER_IMAGE_VERSION openecomp/mso:latest
95 $DOCKER_CMD rmi $NEXUS_DOCKER_REPO_MSO/openecomp/mso:$MSO_DOCKER_IMAGE_VERSION
97 echo "Using Nexus for MARIADB: $NEXUS_DOCKER_REPO_MARIADB (user "$NEXUS_USERNAME_MARIADB")"
98 $DOCKER_CMD pull $NEXUS_DOCKER_REPO_MARIADB/mariadb:10.1.11
99 $DOCKER_CMD tag $NEXUS_DOCKER_REPO_MARIADB/mariadb:10.1.11 mariadb:10.1.11
100 $DOCKER_CMD rmi $NEXUS_DOCKER_REPO_MARIADB/mariadb:10.1.11
104 function wait_for_mariadb() {
109 # wait for the real startup
110 AMOUNT_STARTUP=$($DOCKER_CMD logs ${CONTAINER_NAME} 2>&1 | grep 'mysqld: ready for connections.' | wc -l)
111 while [[ ${AMOUNT_STARTUP} -lt 2 ]];
113 echo "Waiting for '$CONTAINER_NAME' deployment to finish ..."
114 AMOUNT_STARTUP=$($DOCKER_CMD logs ${CONTAINER_NAME} 2>&1 | grep 'mysqld: ready for connections.' | wc -l)
115 if [ "$TIMEOUT" = "0" ];
117 echo "ERROR: Mariadb deployment failed."
125 ################################### Script entry - Starting CODE ################################
126 SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
132 # don't remove the containers,no cleanup
133 #$DOCKER_COMPOSE_CMD stop
134 #$DOCKER_COMPOSE_CMD rm -f -v
137 #Running docker-compose up -d starts the containers in the background and leaves them running.
138 #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.
139 #If you want to force Compose to stop and recreate all containers, use the --force-recreate flag.
140 $DOCKER_COMPOSE_CMD up -d --no-recreate mariadb
141 CONTAINER_NAME=$(container_name mariadb)
142 wait_for_mariadb $CONTAINER_NAME
143 $DOCKER_COMPOSE_CMD up -d mso