Skip to content

Commit

Permalink
Created docker compose scripts to easily run py.test
Browse files Browse the repository at this point in the history
  • Loading branch information
marblestation committed Nov 19, 2020
1 parent 6e76521 commit a9c8d35
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM python:2.7

WORKDIR /app

COPY requirements.txt /app
COPY dev-requirements.txt /app

RUN pip install --upgrade setuptools && \
pip install --upgrade pip && \
pip install -r requirements.txt && \
pip install -r dev-requirements.txt
40 changes: 40 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
version: '3.1'
services:
pytest_citation_capture_pipeline:
build: .
image: pytest_citation_capture_pipeline:latest
container_name: pytest_citation_capture_pipeline
volumes:
- ./:/app
networks:
- pytest_citation_capture_pipeline
stdin_open: true
tty: true
entrypoint: scripts/support/pytest.sh
#entrypoint: bash
depends_on:
- pytest_citation_capture_db
environment:
- SQLALCHEMY_URL='postgres://citation_capture_pipeline:citation_capture_pipeline@pytest_citation_capture_db:5432/citation_capture_pipeline'
# When 'True', no events are emitted to the broker via the webhook
- TESTING_MODE=True
# When 'True', it converts all the asynchronous calls into synchronous,
# thus no need for rabbitmq, it does not forward to master
# and it allows debuggers to run if needed:
- CELERY_ALWAYS_EAGER=True
- CELERY_EAGER_PROPAGATES_EXCEPTIONS=True
pytest_citation_capture_db:
container_name: pytest_citation_capture_db
image: postgres:9.6
restart: always
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
- POSTGRES_DB=postgres
volumes:
- ./scripts/support/init-db.sh:/docker-entrypoint-initdb.d/initdb.sh
networks:
- pytest_citation_capture_pipeline
networks:
pytest_citation_capture_pipeline:
driver: bridge
4 changes: 4 additions & 0 deletions scripts/clean-pytest.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
set -x
docker-compose rm -fsv
docker rmi pytest_citation_capture_pipeline:latest
3 changes: 3 additions & 0 deletions scripts/run-pytest.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash
set -x
docker-compose up --force-recreate --abort-on-container-exit
9 changes: 9 additions & 0 deletions scripts/support/init-db.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash
set -e
psql "postgres://$POSTGRES_USER:$POSTGRES_PASSWORD@$POSTGRES_HOST/$POSTGRES_DB?sslmode=disable" <<-EOSQL
CREATE USER citation_capture_pipeline WITH ENCRYPTED PASSWORD 'citation_capture_pipeline';
CREATE DATABASE citation_capture_pipeline;
CREATE DATABASE citation_capture_pipeline_test;
GRANT ALL PRIVILEGES ON DATABASE citation_capture_pipeline TO citation_capture_pipeline;
GRANT ALL PRIVILEGES ON DATABASE citation_capture_pipeline_test TO citation_capture_pipeline;
EOSQL
19 changes: 19 additions & 0 deletions scripts/support/pytest.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

USER=root
GROUP=root

cd /app
if [ -e alembic.ini ]; then
if [ "${DISABLE_ALEMBIC_UPGRADE}" != True ] && [ "${DISABLE_ALEMBIC_UPGRADE}" != true ]; then
su -s /bin/bash -c "mkdir -p alembic/versions/" -g ${GROUP} ${USER}
su -s /bin/bash -c "alembic -c ./alembic.ini upgrade head" -g ${GROUP} ${USER}
fi
fi

py.test

echo "For interactive access, run in a diferent terminal:"
echo " docker exec -it pytest_citation_capture_pipeline bash"
echo "Press CTRL+c to stop"
tail -f /dev/null

0 comments on commit a9c8d35

Please sign in to comment.