mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-09-26 13:30:13 +00:00
CI: run pytest in Docker container
Use `.env.example` and `.env.ci` as the environment, instead of `.env`.
This commit is contained in:
parent
072bd3ffe5
commit
1d8873d960
7 changed files with 92 additions and 91 deletions
5
.env.ci
Normal file
5
.env.ci
Normal file
|
@ -0,0 +1,5 @@
|
|||
# overrides for .env.example for CI
|
||||
SECRET_KEY=beepbeep
|
||||
USE_DUMMY_CACHE=true
|
||||
EMAIL_HOST_USER=
|
||||
EMAIL_HOST_PASSWORD=
|
71
.github/workflows/django-tests.yml
vendored
71
.github/workflows/django-tests.yml
vendored
|
@ -7,64 +7,17 @@ on:
|
|||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
COMPOSE_FILE: "docker-compose.yml:docker-compose.ci.yml"
|
||||
COMPOSE_ENV_FILES: ".env.example:.env.ci"
|
||||
|
||||
runs-on: ubuntu-20.04
|
||||
services:
|
||||
postgres:
|
||||
image: postgres:13
|
||||
env:
|
||||
POSTGRES_USER: postgres
|
||||
POSTGRES_PASSWORD: hunter2
|
||||
options: >-
|
||||
--health-cmd pg_isready
|
||||
--health-interval 10s
|
||||
--health-timeout 5s
|
||||
--health-retries 5
|
||||
ports:
|
||||
- 5432:5432
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v4
|
||||
with:
|
||||
python-version: 3.9
|
||||
- name: Install Dependencies
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
pip install -r requirements.txt
|
||||
- name: Check migrations up-to-date
|
||||
run: |
|
||||
python ./manage.py makemigrations --check
|
||||
env:
|
||||
SECRET_KEY: beepbeep
|
||||
DOMAIN: your.domain.here
|
||||
EMAIL_HOST: ""
|
||||
EMAIL_HOST_USER: ""
|
||||
EMAIL_HOST_PASSWORD: ""
|
||||
- name: Run Tests
|
||||
env:
|
||||
SECRET_KEY: beepbeep
|
||||
DEBUG: false
|
||||
USE_HTTPS: true
|
||||
DOMAIN: your.domain.here
|
||||
BOOKWYRM_DATABASE_BACKEND: postgres
|
||||
MEDIA_ROOT: images/
|
||||
POSTGRES_PASSWORD: hunter2
|
||||
POSTGRES_USER: postgres
|
||||
POSTGRES_DB: github_actions
|
||||
POSTGRES_HOST: 127.0.0.1
|
||||
CELERY_BROKER: ""
|
||||
REDIS_BROKER_PORT: 6379
|
||||
REDIS_BROKER_PASSWORD: beep
|
||||
USE_DUMMY_CACHE: true
|
||||
FLOWER_PORT: 8888
|
||||
EMAIL_HOST: "smtp.mailgun.org"
|
||||
EMAIL_PORT: 587
|
||||
EMAIL_HOST_USER: ""
|
||||
EMAIL_HOST_PASSWORD: ""
|
||||
EMAIL_USE_TLS: true
|
||||
ENABLE_PREVIEW_IMAGES: false
|
||||
ENABLE_THUMBNAIL_GENERATION: true
|
||||
HTTP_X_FORWARDED_PROTO: false
|
||||
run: |
|
||||
pytest -n 3
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v3
|
||||
- name: Build Docker images
|
||||
run: docker-compose build
|
||||
- name: Check if migrations are up-to-date
|
||||
run: docker-compose run web python manage.py makemigrations --check
|
||||
- name: Run pytest
|
||||
run: docker-compose run web pytest -n 3
|
||||
|
|
9
bw-dev
9
bw-dev
|
@ -28,6 +28,7 @@ if docker compose &> /dev/null ; then
|
|||
else
|
||||
DOCKER_COMPOSE="docker-compose"
|
||||
fi
|
||||
DOCKER_COMPOSE_CI="$DOCKER_COMPOSE --env-file .env.example --env-file .env.ci -f docker-compose.yml -f docker-compose.ci.yml"
|
||||
|
||||
function clean {
|
||||
$DOCKER_COMPOSE stop
|
||||
|
@ -38,6 +39,10 @@ function runweb {
|
|||
$DOCKER_COMPOSE run --rm web "$@"
|
||||
}
|
||||
|
||||
function runwebci {
|
||||
$DOCKER_COMPOSE_CI run --rm web "$@"
|
||||
}
|
||||
|
||||
function execdb {
|
||||
$DOCKER_COMPOSE exec db $@
|
||||
}
|
||||
|
@ -126,11 +131,11 @@ case "$CMD" in
|
|||
;;
|
||||
pytest)
|
||||
prod_error
|
||||
runweb pytest --no-cov-on-fail "$@"
|
||||
runwebci pytest --no-cov-on-fail "$@"
|
||||
;;
|
||||
pytest_coverage_report)
|
||||
prod_error
|
||||
runweb pytest -n 3 --cov-report term-missing "$@"
|
||||
runwebci pytest -n 3 --cov-report term-missing "$@"
|
||||
;;
|
||||
compile_themes)
|
||||
runweb python manage.py compile_themes
|
||||
|
|
38
docker-compose.ci.yml
Normal file
38
docker-compose.ci.yml
Normal file
|
@ -0,0 +1,38 @@
|
|||
version: '3'
|
||||
|
||||
# Pass the variables defined in .env.example and .env.ci to the containers
|
||||
# instead of .env (which is ignored).
|
||||
|
||||
services:
|
||||
db:
|
||||
env_file:
|
||||
- .env.example
|
||||
- .env.ci
|
||||
web:
|
||||
env_file:
|
||||
- .env.example
|
||||
- .env.ci
|
||||
redis_activity:
|
||||
env_file:
|
||||
- .env.example
|
||||
- .env.ci
|
||||
redis_broker:
|
||||
env_file:
|
||||
- .env.example
|
||||
- .env.ci
|
||||
celery_worker:
|
||||
env_file:
|
||||
- .env.example
|
||||
- .env.ci
|
||||
celery_beat:
|
||||
env_file:
|
||||
- .env.example
|
||||
- .env.ci
|
||||
flower:
|
||||
env_file:
|
||||
- .env.example
|
||||
- .env.ci
|
||||
dev-tools:
|
||||
env_file:
|
||||
- .env.example
|
||||
- .env.ci
|
27
docker-compose.override.yml
Normal file
27
docker-compose.override.yml
Normal file
|
@ -0,0 +1,27 @@
|
|||
version: '3'
|
||||
|
||||
services:
|
||||
db:
|
||||
env_file:
|
||||
- .env
|
||||
web:
|
||||
env_file:
|
||||
- .env
|
||||
redis_activity:
|
||||
env_file:
|
||||
- .env
|
||||
redis_broker:
|
||||
env_file:
|
||||
- .env
|
||||
celery_worker:
|
||||
env_file:
|
||||
- .env
|
||||
celery_beat:
|
||||
env_file:
|
||||
- .env
|
||||
flower:
|
||||
env_file:
|
||||
- .env
|
||||
dev-tools:
|
||||
env_file:
|
||||
- .env
|
|
@ -1,5 +1,8 @@
|
|||
version: '3'
|
||||
|
||||
# This file is merged with docker-compose.ci.yml for CI, and with
|
||||
# docker-compose.override.yml for all other purposes.
|
||||
|
||||
services:
|
||||
nginx:
|
||||
image: nginx:1.25.2
|
||||
|
@ -16,14 +19,12 @@ services:
|
|||
- media_volume:/app/images
|
||||
db:
|
||||
image: postgres:13
|
||||
env_file: .env
|
||||
volumes:
|
||||
- pgdata:/var/lib/postgresql/data
|
||||
networks:
|
||||
- main
|
||||
web:
|
||||
build: .
|
||||
env_file: .env
|
||||
command: python manage.py runserver 0.0.0.0:8000
|
||||
volumes:
|
||||
- .:/app
|
||||
|
@ -43,7 +44,6 @@ services:
|
|||
volumes:
|
||||
- ./redis.conf:/etc/redis/redis.conf
|
||||
- redis_activity_data:/data
|
||||
env_file: .env
|
||||
networks:
|
||||
- main
|
||||
restart: on-failure
|
||||
|
@ -53,12 +53,10 @@ services:
|
|||
volumes:
|
||||
- ./redis.conf:/etc/redis/redis.conf
|
||||
- redis_broker_data:/data
|
||||
env_file: .env
|
||||
networks:
|
||||
- main
|
||||
restart: on-failure
|
||||
celery_worker:
|
||||
env_file: .env
|
||||
build: .
|
||||
networks:
|
||||
- main
|
||||
|
@ -73,7 +71,6 @@ services:
|
|||
- redis_broker
|
||||
restart: on-failure
|
||||
celery_beat:
|
||||
env_file: .env
|
||||
build: .
|
||||
networks:
|
||||
- main
|
||||
|
@ -88,7 +85,6 @@ services:
|
|||
flower:
|
||||
build: .
|
||||
command: celery -A celerywyrm flower --basic_auth=${FLOWER_USER}:${FLOWER_PASSWORD} --url_prefix=flower
|
||||
env_file: .env
|
||||
volumes:
|
||||
- .:/app
|
||||
networks:
|
||||
|
@ -99,7 +95,6 @@ services:
|
|||
restart: on-failure
|
||||
dev-tools:
|
||||
build: dev-tools
|
||||
env_file: .env
|
||||
volumes:
|
||||
- /app/dev-tools/
|
||||
- .:/app
|
||||
|
|
22
pytest.ini
22
pytest.ini
|
@ -4,25 +4,3 @@ python_files = tests.py test_*.py *_tests.py
|
|||
addopts = --cov=bookwyrm --cov-config=.coveragerc
|
||||
markers =
|
||||
integration: marks tests as requiring external resources (deselect with '-m "not integration"')
|
||||
|
||||
env =
|
||||
LANGUAGE_CODE = en-US
|
||||
SECRET_KEY = beepbeep
|
||||
DEBUG = false
|
||||
USE_HTTPS = true
|
||||
DOMAIN = your.domain.here
|
||||
BOOKWYRM_DATABASE_BACKEND = postgres
|
||||
MEDIA_ROOT = images/
|
||||
CELERY_BROKER = ""
|
||||
REDIS_BROKER_PORT = 6379
|
||||
REDIS_BROKER_PASSWORD = beep
|
||||
REDIS_ACTIVITY_PORT = 6379
|
||||
REDIS_ACTIVITY_PASSWORD = beep
|
||||
USE_DUMMY_CACHE = true
|
||||
FLOWER_PORT = 8888
|
||||
EMAIL_HOST = "smtp.mailgun.org"
|
||||
EMAIL_PORT = 587
|
||||
EMAIL_HOST_USER = ""
|
||||
EMAIL_HOST_PASSWORD = ""
|
||||
EMAIL_USE_TLS = true
|
||||
ENABLE_PREVIEW_IMAGES = false
|
||||
|
|
Loading…
Reference in a new issue