diff --git a/README.md b/README.md index 9b9c33a..d53a638 100755 --- a/README.md +++ b/README.md @@ -3,22 +3,9 @@ ![License][license-badge] ![Last Commit][last-commit-badge] -Back end for ChRIS Store. This is a Django-MySQL project that houses descriptions of ChRIS plugin-apps and workflows for registering to a ChRIS CUBE instance. +Back end for the ChRIS store. This is a Django-MySQL project that houses descriptions of ChRIS plugin-apps and workflows for registering to a ChRIS CUBE instance. -## ChRIS Store development and testing - -### TL;DR - -If you read nothing else on this page, and just want to get an instance of the ChRIS store backend services up and -running with no mess, no fuss: - -```bash -git clone https://github.com/FNNDSC/ChRIS_store -cd ChRIS_store -./make.sh down ; ./make.sh up -``` - -The resulting instance uses the default Django development server and therefore is not suitable for production. +## ChRIS store development, testing and deployment ### Abstract @@ -35,31 +22,62 @@ This page describes how to quickly get the set of services comprising the backen Consult this page https://docs.docker.com/engine/install/linux-postinstall/ +### TL;DR + +If you read nothing else on this page, and just want to get an instance of the ChRIS store backend services up and +running with no mess, no fuss: + +```bash +git clone https://github.com/FNNDSC/ChRIS_store +cd ChRIS_store +./make.sh down ; ./make.sh up +``` + +The resulting instance uses the default Django development server and therefore is not suitable for production. ### Production deployment #### To get the production system up: +Start a local Docker Swarm cluster if not already started: + +```bash +docker swarm init --advertise-addr 127.0.0.1 +``` + +Fetch source code: + ```bash git clone https://github.com/FNNDSC/ChRIS_store cd ChRIS_store mkdir secrets ``` + Now copy all the required secret configuration files into the secrets directory, please take a look at [this](https://github.com/FNNDSC/ChRIS_store/wiki/ChRIS-store-backend-production-services-secret-configuration-files) wiki page to learn more about these files +Deploy ChRIS store backend containers: + ```bash ./docker-deploy.sh up ``` #### To tear down: +Remove ChRIS store backend containers: + ```bash cd ChRIS_store ./docker-deploy.sh down ``` +Remove the local Docker Swarm cluster if desired: + +```bash +docker swarm leave --force +``` + ### Development diff --git a/docker-compose_dev.yml b/docker-compose_dev.yml index 4d37679..d1a53ce 100755 --- a/docker-compose_dev.yml +++ b/docker-compose_dev.yml @@ -17,6 +17,8 @@ services: context: . args: ENVIRONMENT: local + stdin_open: true # docker run -i + tty: true # docker run -t command: python manage.py runserver 0.0.0.0:8010 volumes: - ./store_backend:/home/localuser/store_backend:z diff --git a/docker-deploy.sh b/docker-deploy.sh index 5a141d2..7c07059 100755 --- a/docker-deploy.sh +++ b/docker-deploy.sh @@ -34,22 +34,28 @@ declare -i STEP=0 if [[ "$1" == 'up' ]]; then - title -d 1 "Stopping and restarting docker swarm cluster... " - docker swarm leave --force - docker swarm init --advertise-addr 127.0.0.1 - windowBottom - - title -d 1 "Starting containerized production environment using " " ./docker-compose.yml" - docker pull mysql:5 - docker pull fnndsc/docker-swift-onlyone - docker pull fnndsc/chris_store + title -d 1 "Starting containerized production environment on using " " ./docker-compose.yml" echo "" echo "docker stack deploy -c docker-compose.yml chris_store_stack" docker stack deploy -c docker-compose.yml chris_store_stack windowBottom + title -d 1 "Waiting until chris store stack containers are running on swarm" + for i in {1..30}; do + sleep 5 + chris_store=$(docker ps -f name=chris_store.1. -q) + if [ -n "$chris_store" ]; then + echo "Success: chris store container is up" + break + fi + done + if [ -z "$chris_store" ]; then + echo "Error: couldn't start chris store container" + exit 1 + fi + windowBottom + title -d 1 "Waiting until ChRIS store is ready to accept connections..." - chris_store=$(docker ps -f ancestor=fnndsc/chris_store -f name=chris_store.1. -q) docker exec $chris_store sh -c 'while ! curl -sSf http://localhost:8010/api/v1/users/ 2> /dev/null; do sleep 5; done;' windowBottom @@ -70,13 +76,14 @@ if [[ "$1" == 'down' ]]; then title -d 1 "Destroying containerized production environment" "from ./docker-compose.yml" echo docker stack rm chris_store_stack - docker swarm leave --force + sleep 10 echo printf "Do you want to also remove persistent volumes?" read -p " [y/n] " -n 1 -r echo echo if [[ $REPLY =~ ^[Yy]$ ]] ; then + sleep 10 docker volume rm chris_store_stack_chris_store_db_data docker volume rm chris_store_stack_swift_storage fi diff --git a/make.sh b/make.sh index bb57bf0..d5c6cbb 100755 --- a/make.sh +++ b/make.sh @@ -4,11 +4,11 @@ G_SYNOPSIS=" NAME - docker-make.sh + make.sh SYNOPSIS - docker-make.sh [up|down] + make.sh [up|down] ARGS @@ -17,7 +17,7 @@ G_SYNOPSIS=" DESCRIPTION - docker-make.sh script will depending on the argument fire up or tear down the + make.sh script will depending on the argument fire up or tear down the Chris store development environment. " @@ -125,10 +125,10 @@ if [[ "$1" == 'up' ]]; then docker-compose -f docker-compose_dev.yml exec chris_store_dev python pipelines/services/manager.py add "${PIPELINE_NAME}" cubeadmin "${PLUGIN_TREE}" --unlock windowBottom - title -d 1 "Restarting ChRIS store's Django development server" "in interactive mode..." - docker-compose -f docker-compose_dev.yml stop chris_store_dev - docker-compose -f docker-compose_dev.yml rm -f chris_store_dev - docker-compose -f docker-compose_dev.yml run --service-ports chris_store_dev + title -d 1 "Restarting ChRIS store's Django development server..." + docker-compose -f docker-compose_dev.yml restart chris_store_dev + chris_store_dev=$(docker ps -f name=chris_store_dev_1 -q) + docker attach --detach-keys ctrl-c $chris_store_dev echo "" windowBottom fi