aboutsummaryrefslogtreecommitdiffstats
path: root/deploy.sh
diff options
context:
space:
mode:
authorpiclose <pc457b@intl.att.com>2017-02-21 14:52:45 +0100
committerpiclose <pc457b@intl.att.com>2017-02-21 14:53:09 +0100
commitc4e65037584636b7a3b3c9920fd501126fb68fcc (patch)
treef914324c859ff53b1da12b84180d9baec1dc4461 /deploy.sh
parentfad0de5e6dd7aa1cb079e4a2d7b3baa03efc23aa (diff)
Initial OpenECOMP MSO Docker Configuration commit
Change-Id: Iaabe6803a6087f59726e290cb75aef2f755097d9 Signed-off-by: piclose <pc457b@intl.att.com>
Diffstat (limited to 'deploy.sh')
-rw-r--r--deploy.sh143
1 files changed, 143 insertions, 0 deletions
diff --git a/deploy.sh b/deploy.sh
new file mode 100644
index 0000000..4e61a3f
--- /dev/null
+++ b/deploy.sh
@@ -0,0 +1,143 @@
+#!/bin/bash
+# Deployment script for MSO lab
+# ===================================================
+# Available parameters :
+#
+# env DOCKER_HOST (optional)
+# | sets the docker host to be used if not local unix socket
+#
+# env MSO_CONFIG_UPDATES (optional)
+# | json structure that matches volumes/mso/chef-config/mso-docker.json
+# | elements whose value needs to be updated before the deployment
+# | phase.
+#
+# env MSO_DOCKER_IMAGE_VERSION
+# | json structure that matches volumes/mso/chef-config/mso-docker.json
+# | elements whose value needs to be updated before the deployment
+# | phase.
+################################### Functions definition ################################
+
+
+if [ "$#" -ne 6 ]; then
+ 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>
+ - env DOCKER_HOST (optional)
+ sets the docker host to be used if not local unix socket
+
+ - env MSO_DOCKER_IMAGE_VERSION (required)
+ sets the mso docker image version
+
+ - env MSO_CONFIG_UPDATES (optional)
+ json structure that matches volumes/mso/chef-config/mso-docker.json
+ elements whose value needs to be updated before the deployment
+ phase."
+
+ exit 1
+fi
+if [ -z "$MSO_DOCKER_IMAGE_VERSION" ]; then
+ echo "Env variable MSO_DOCKER_IMAGE_VERSION must be SET to a version before running this script"
+ exit 1
+fi
+
+NEXUS_DOCKER_REPO_MSO=$1
+NEXUS_USERNAME_MSO=$2
+NEXUS_PASSWD_MSO=$3
+NEXUS_DOCKER_REPO_MARIADB=$4
+NEXUS_USERNAME_MARIADB=$5
+NEXUS_PASSWD_MARIADB=$6
+
+
+
+function init_docker_command() {
+ if [ -z ${DOCKER_HOST+x} ];
+ then
+ DOCKER_CMD="docker"
+ LBL_DOCKER_HOST="local docker using unix socket"
+ else
+ DOCKER_CMD="docker -H ${DOCKER_HOST}"
+ LBL_DOCKER_HOST="(remote) docker using ${DOCKER_HOST}"
+ fi
+
+ if [ -f "/opt/docker/docker-compose" ];
+ then
+ DOCKER_COMPOSE_CMD="/opt/docker/docker-compose"
+ else
+ DOCKER_COMPOSE_CMD="docker-compose"
+ fi
+
+ echo "docker command: ${LBL_DOCKER_HOST}"
+}
+
+function container_name() {
+ SERVICE=$1
+ BASE=$(echo $(basename `pwd`) | sed "s/[^a-z0-9]//i" | tr [:upper:] [:lower:])
+ echo ${BASE}_${SERVICE}_1
+}
+
+function update_json_config() {
+ if [ -n "$MSO_CONFIG_UPDATES" ];
+ then
+ chmod u+x $SCRIPT_DIR/json_updater.py
+ echo $MSO_CONFIG_UPDATES | $SCRIPT_DIR/json_updater.py $SCRIPT_DIR/volumes/mso/chef-config/mso-docker.json
+ echo "MSO docker JSON updated"
+ fi
+
+}
+
+function pull_docker_images() {
+ echo "Using Nexus for MSO: $NEXUS_DOCKER_REPO_MSO (user "$NEXUS_USERNAME_MSO")"
+ # login to nexus
+ $DOCKER_CMD login -u $NEXUS_USERNAME_MSO -p $NEXUS_PASSWD_MSO $NEXUS_DOCKER_REPO_MSO
+ $DOCKER_CMD login -u $NEXUS_USERNAME_MARIADB -p $NEXUS_PASSWD_MARIADB $NEXUS_DOCKER_REPO_MARIADB
+
+ # get images
+ $DOCKER_CMD pull $NEXUS_DOCKER_REPO_MSO/ecomp/mso:$MSO_DOCKER_IMAGE_VERSION
+ $DOCKER_CMD tag $NEXUS_DOCKER_REPO_MSO/ecomp/mso:$MSO_DOCKER_IMAGE_VERSION ecomp/mso:latest
+ $DOCKER_CMD rmi $NEXUS_DOCKER_REPO_MSO/ecomp/mso:$MSO_DOCKER_IMAGE_VERSION
+
+ echo "Using Nexus for MARIADB: $NEXUS_DOCKER_REPO_MARIADB (user "$NEXUS_USERNAME_MARIADB")"
+ $DOCKER_CMD pull $NEXUS_DOCKER_REPO_MARIADB/mariadb:10.1.11
+ $DOCKER_CMD tag $NEXUS_DOCKER_REPO_MARIADB/mariadb:10.1.11 mariadb:10.1.11
+ $DOCKER_CMD rmi $NEXUS_DOCKER_REPO_MARIADB/mariadb:10.1.11
+
+}
+
+function wait_for_mariadb() {
+ CONTAINER_NAME=$1
+
+ TIMEOUT=120
+
+ # wait for the real startup
+ AMOUNT_STARTUP=$($DOCKER_CMD logs ${CONTAINER_NAME} 2>&1 | grep 'mysqld: ready for connections.' | wc -l)
+ while [[ ${AMOUNT_STARTUP} -lt 2 ]];
+ do
+ echo "Waiting for '$CONTAINER_NAME' deployment to finish ..."
+ AMOUNT_STARTUP=$($DOCKER_CMD logs ${CONTAINER_NAME} 2>&1 | grep 'mysqld: ready for connections.' | wc -l)
+ if [ "$TIMEOUT" = "0" ];
+ then
+ echo "ERROR: Mariadb deployment failed."
+ exit 1
+ fi
+ let TIMEOUT-=1
+ sleep 1
+ done
+}
+
+################################### Script entry - Starting CODE ################################
+SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+
+init_docker_command
+update_json_config
+pull_docker_images
+
+# don't remove the containers,no cleanup
+#$DOCKER_COMPOSE_CMD stop
+#$DOCKER_COMPOSE_CMD rm -f -v
+
+# deploy
+#Running docker-compose up -d starts the containers in the background and leaves them running.
+#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.
+#If you want to force Compose to stop and recreate all containers, use the --force-recreate flag.
+$DOCKER_COMPOSE_CMD up -d --no-recreate mariadb
+CONTAINER_NAME=$(container_name mariadb)
+wait_for_mariadb $CONTAINER_NAME
+$DOCKER_COMPOSE_CMD up -d mso \ No newline at end of file