mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-06-20 14:10:38 +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
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:
|
jobs:
|
||||||
build:
|
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:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- name: Checkout code
|
||||||
- name: Set up Python
|
uses: actions/checkout@v3
|
||||||
uses: actions/setup-python@v4
|
- name: Build Docker images
|
||||||
with:
|
run: docker-compose build
|
||||||
python-version: 3.9
|
- name: Check if migrations are up-to-date
|
||||||
- name: Install Dependencies
|
run: docker-compose run web python manage.py makemigrations --check
|
||||||
run: |
|
- name: Run pytest
|
||||||
python -m pip install --upgrade pip
|
run: docker-compose run web pytest -n 3
|
||||||
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
|
|
||||||
|
|
9
bw-dev
9
bw-dev
|
@ -28,6 +28,7 @@ if docker compose &> /dev/null ; then
|
||||||
else
|
else
|
||||||
DOCKER_COMPOSE="docker-compose"
|
DOCKER_COMPOSE="docker-compose"
|
||||||
fi
|
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 {
|
function clean {
|
||||||
$DOCKER_COMPOSE stop
|
$DOCKER_COMPOSE stop
|
||||||
|
@ -38,6 +39,10 @@ function runweb {
|
||||||
$DOCKER_COMPOSE run --rm web "$@"
|
$DOCKER_COMPOSE run --rm web "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function runwebci {
|
||||||
|
$DOCKER_COMPOSE_CI run --rm web "$@"
|
||||||
|
}
|
||||||
|
|
||||||
function execdb {
|
function execdb {
|
||||||
$DOCKER_COMPOSE exec db $@
|
$DOCKER_COMPOSE exec db $@
|
||||||
}
|
}
|
||||||
|
@ -126,11 +131,11 @@ case "$CMD" in
|
||||||
;;
|
;;
|
||||||
pytest)
|
pytest)
|
||||||
prod_error
|
prod_error
|
||||||
runweb pytest --no-cov-on-fail "$@"
|
runwebci pytest --no-cov-on-fail "$@"
|
||||||
;;
|
;;
|
||||||
pytest_coverage_report)
|
pytest_coverage_report)
|
||||||
prod_error
|
prod_error
|
||||||
runweb pytest -n 3 --cov-report term-missing "$@"
|
runwebci pytest -n 3 --cov-report term-missing "$@"
|
||||||
;;
|
;;
|
||||||
compile_themes)
|
compile_themes)
|
||||||
runweb python manage.py 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'
|
version: '3'
|
||||||
|
|
||||||
|
# This file is merged with docker-compose.ci.yml for CI, and with
|
||||||
|
# docker-compose.override.yml for all other purposes.
|
||||||
|
|
||||||
services:
|
services:
|
||||||
nginx:
|
nginx:
|
||||||
image: nginx:1.25.2
|
image: nginx:1.25.2
|
||||||
|
@ -16,14 +19,12 @@ services:
|
||||||
- media_volume:/app/images
|
- media_volume:/app/images
|
||||||
db:
|
db:
|
||||||
image: postgres:13
|
image: postgres:13
|
||||||
env_file: .env
|
|
||||||
volumes:
|
volumes:
|
||||||
- pgdata:/var/lib/postgresql/data
|
- pgdata:/var/lib/postgresql/data
|
||||||
networks:
|
networks:
|
||||||
- main
|
- main
|
||||||
web:
|
web:
|
||||||
build: .
|
build: .
|
||||||
env_file: .env
|
|
||||||
command: python manage.py runserver 0.0.0.0:8000
|
command: python manage.py runserver 0.0.0.0:8000
|
||||||
volumes:
|
volumes:
|
||||||
- .:/app
|
- .:/app
|
||||||
|
@ -43,7 +44,6 @@ services:
|
||||||
volumes:
|
volumes:
|
||||||
- ./redis.conf:/etc/redis/redis.conf
|
- ./redis.conf:/etc/redis/redis.conf
|
||||||
- redis_activity_data:/data
|
- redis_activity_data:/data
|
||||||
env_file: .env
|
|
||||||
networks:
|
networks:
|
||||||
- main
|
- main
|
||||||
restart: on-failure
|
restart: on-failure
|
||||||
|
@ -53,12 +53,10 @@ services:
|
||||||
volumes:
|
volumes:
|
||||||
- ./redis.conf:/etc/redis/redis.conf
|
- ./redis.conf:/etc/redis/redis.conf
|
||||||
- redis_broker_data:/data
|
- redis_broker_data:/data
|
||||||
env_file: .env
|
|
||||||
networks:
|
networks:
|
||||||
- main
|
- main
|
||||||
restart: on-failure
|
restart: on-failure
|
||||||
celery_worker:
|
celery_worker:
|
||||||
env_file: .env
|
|
||||||
build: .
|
build: .
|
||||||
networks:
|
networks:
|
||||||
- main
|
- main
|
||||||
|
@ -73,7 +71,6 @@ services:
|
||||||
- redis_broker
|
- redis_broker
|
||||||
restart: on-failure
|
restart: on-failure
|
||||||
celery_beat:
|
celery_beat:
|
||||||
env_file: .env
|
|
||||||
build: .
|
build: .
|
||||||
networks:
|
networks:
|
||||||
- main
|
- main
|
||||||
|
@ -88,7 +85,6 @@ services:
|
||||||
flower:
|
flower:
|
||||||
build: .
|
build: .
|
||||||
command: celery -A celerywyrm flower --basic_auth=${FLOWER_USER}:${FLOWER_PASSWORD} --url_prefix=flower
|
command: celery -A celerywyrm flower --basic_auth=${FLOWER_USER}:${FLOWER_PASSWORD} --url_prefix=flower
|
||||||
env_file: .env
|
|
||||||
volumes:
|
volumes:
|
||||||
- .:/app
|
- .:/app
|
||||||
networks:
|
networks:
|
||||||
|
@ -99,7 +95,6 @@ services:
|
||||||
restart: on-failure
|
restart: on-failure
|
||||||
dev-tools:
|
dev-tools:
|
||||||
build: dev-tools
|
build: dev-tools
|
||||||
env_file: .env
|
|
||||||
volumes:
|
volumes:
|
||||||
- /app/dev-tools/
|
- /app/dev-tools/
|
||||||
- .:/app
|
- .:/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
|
addopts = --cov=bookwyrm --cov-config=.coveragerc
|
||||||
markers =
|
markers =
|
||||||
integration: marks tests as requiring external resources (deselect with '-m "not integration"')
|
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