Adds docker-compose to start backend and database for e2e testing

This commit is contained in:
Aaron Louie 2020-02-06 22:04:01 -05:00
parent 324f20681d
commit 26eda7cc8a
4 changed files with 69 additions and 7 deletions

32
docker/docker-compose.yml Normal file
View File

@ -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

View File

@ -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')

View File

@ -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

View File

@ -12,13 +12,12 @@
"test:once": "ng test --code-coverage --watch=false", "test:once": "ng test --code-coverage --watch=false",
"lint": "ng lint", "lint": "ng lint",
"e2e": "./node_modules/protractor/bin/webdriver-manager update && ng e2e", "e2e": "./node_modules/protractor/bin/webdriver-manager update && ng e2e",
"e2e:with-wf": "npm run wf && ng e2e", "e2e:with-wf": "npm run e2e-wf && ng e2e",
"wf:stop": "docker stop wf || true && docker rm wf || true && docker system prune -f", "e2e-wf:stop": "docker stop db && docker stop backend",
"wf:build": "docker build -t wf github.com/sartography/cr-connect-workflow#master", "e2e-wf:clean": "docker system prune -f && cd docker && docker-compose rm -f -v -s && cd ..",
"wf:start": "docker run -d --name wf -p 5000:5000 wf", "e2e-wf:build": "cd docker && docker-compose pull && docker-compose build --no-cache && cd ..",
"wf:db": "docker exec -it wf sh -c 'pipenv run flask db upgrade'", "e2e-wf:start": "cd docker && docker-compose up -d && cd ..",
"wf:data": "docker exec -it wf sh -c 'pipenv run flask load-example-data'", "e2e-wf": "npm run e2e-wf:stop && npm run e2e-wf:clean && npm run e2e-wf:build && npm run e2e-wf:start",
"wf": "npm run wf:stop && npm run wf:build && npm run wf:start && npm run wf:db && npm run wf:data",
"ci": "npm run lint && npm run test:once && npm run e2e:with-wf && sonar-scanner" "ci": "npm run lint && npm run test:once && npm run e2e:with-wf && sonar-scanner"
}, },
"private": true, "private": true,