diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml new file mode 100644 index 0000000..37c4f31 --- /dev/null +++ b/docker/docker-compose.yml @@ -0,0 +1,32 @@ +version: "3.7" +services: + db: + container_name: db + image: postgres + volumes: + - ./pg-init-scripts/initdb.sh:/docker-entrypoint-initdb.d/initdb.sh + ports: + - "5432:5432" + environment: + - POSTGRES_USER=crc_user + - POSTGRES_PASSWORD=crc_pass + - POSTGRES_MULTIPLE_DATABASES=crc_test,crc_dev + healthcheck: + test: ["CMD", "ping", "-h", "localhost"] + timeout: 20s + retries: 10 + start_period: 20s + + backend: + container_name: backend + depends_on: + - db + image: sartography/cr-connect-workflow + volumes: + - ./flask-config/config.py:/crc-workflow/instance/config.py + environment: + - FLASK_APP=./crc/__init__.py + - RESET_DB=true + ports: + - "5000:5000" + command: ./wait-for-it.sh db:5432 -t 0 -- ./docker_run.sh diff --git a/docker/flask-config/config.py b/docker/flask-config/config.py new file mode 100644 index 0000000..5dce543 --- /dev/null +++ b/docker/flask-config/config.py @@ -0,0 +1,9 @@ +import os +basedir = os.path.abspath(os.path.dirname(__file__)) + +NAME = "CR Connect Workflow" +CORS_ENABLED = False +DEVELOPMENT = True +SQLALCHEMY_DATABASE_URI = "postgresql://crc_user:crc_pass@db:5432/crc_dev" + +print('\n\n*** USING INSTANCE CONFIG ***\n\n') diff --git a/docker/pg-init-scripts/initdb.sh b/docker/pg-init-scripts/initdb.sh new file mode 100644 index 0000000..aa665fa --- /dev/null +++ b/docker/pg-init-scripts/initdb.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +set -e +set -u + +function create_user_and_database() { + local database=$1 + echo " Creating user and database '$database'" + psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" <<-EOSQL + CREATE USER $database; + CREATE DATABASE $database; + GRANT ALL PRIVILEGES ON DATABASE $database TO $database; +EOSQL +} + +if [ -n "$POSTGRES_MULTIPLE_DATABASES" ]; then + echo "Multiple database creation requested: $POSTGRES_MULTIPLE_DATABASES" + for db in $(echo $POSTGRES_MULTIPLE_DATABASES | tr ',' ' '); do + create_user_and_database $db + done + echo "Multiple databases created" +fi diff --git a/package.json b/package.json index 623f984..dd5d937 100644 --- a/package.json +++ b/package.json @@ -12,13 +12,12 @@ "test:once": "ng test --code-coverage --watch=false", "lint": "ng lint", "e2e": "./node_modules/protractor/bin/webdriver-manager update && ng e2e", - "e2e:with-wf": "npm run wf && ng e2e", - "wf:stop": "docker stop wf || true && docker rm wf || true && docker system prune -f", - "wf:build": "docker build -t wf github.com/sartography/cr-connect-workflow#master", - "wf:start": "docker run -d --name wf -p 5000:5000 wf", - "wf:db": "docker exec -it wf sh -c 'pipenv run flask db upgrade'", - "wf:data": "docker exec -it wf sh -c 'pipenv run flask load-example-data'", - "wf": "npm run wf:stop && npm run wf:build && npm run wf:start && npm run wf:db && npm run wf:data", + "e2e:with-wf": "npm run e2e-wf && ng e2e", + "e2e-wf:stop": "docker stop db && docker stop backend", + "e2e-wf:clean": "docker system prune -f && cd docker && docker-compose rm -f -v -s && cd ..", + "e2e-wf:build": "cd docker && docker-compose pull && docker-compose build --no-cache && cd ..", + "e2e-wf:start": "cd docker && docker-compose up -d && cd ..", + "e2e-wf": "npm run e2e-wf:stop && npm run e2e-wf:clean && npm run e2e-wf:build && npm run e2e-wf:start", "ci": "npm run lint && npm run test:once && npm run e2e:with-wf && sonar-scanner" }, "private": true,