Handle service health checks with Django #236
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Things to check before start: | |
# * https://github.com/marketplace/actions/python-poetry-action | |
# * https://github.com/packetcoders/action-setup-cache-python-poetry/blob/main/action.yml | |
# * https://gist.github.com/soof-golan/6ebb97a792ccd87816c0bda1e6e8b8c2 | |
# * https://github.com/nicoloboschi/poetry-dockerize-plugin | |
# * https://github.com/wemake-services/wemake-django-template/blob/master/%7B%7Bcookiecutter.project_name%7D%7D/docker/django/Dockerfile | |
# * https://github.com/orgs/python-poetry/discussions/1879 | |
name: "tests" | |
on: | |
workflow_dispatch: | |
push: | |
branches: | |
- main | |
pull_request: ~ | |
env: | |
PYTHON_VERSION: 3.12.6 | |
POETRY_VERSION: 1.8.3 | |
jobs: | |
test: | |
runs-on: ubuntu-24.04 | |
services: | |
postgres: | |
image: postgres:16.4-alpine3.20 | |
env: | |
POSTGRES_USER: postgres | |
POSTGRES_PASSWORD: postgres | |
POSTGRES_DB: postgres | |
ports: | |
- 5432:5432 | |
redis: | |
image: redis:7.4.0-alpine3.20 | |
ports: | |
- 6379:6379 | |
options: >- | |
--health-cmd "redis-cli ping" | |
--health-interval 10s | |
--health-timeout 5s | |
--health-retries 5 | |
steps: | |
- uses: actions/checkout@v4.1.7 | |
name: Checkout | |
- uses: actions/setup-python@v5.2.0 | |
id: setup_python | |
name: Set up Python ${{ env.PYTHON_VERSION }} | |
with: | |
python-version: ${{ env.PYTHON_VERSION }} | |
- uses: actions/cache@v4.0.2 | |
name: Cache for Poetry setup | |
id: poetry_install_cache | |
with: | |
key: poetry_install-${{ runner.os }}-${{ env.PYTHON_VERSION }}-pre-commit-${{ env.PRE_COMMIT_VERSION }} | |
path: ${{ env.pythonLocation }} | |
restore-keys: | | |
poetry_install-${{ runner.os }}-${{ env.PYTHON_VERSION }}-pre-commit- | |
- name: Setup Poetry | |
if: steps.poetry_install_cache.outputs.cache-hit != 'true' | |
run: pip install poetry==${{ env.POETRY_VERSION }} | |
# TODO: | |
# This step must be cached too; but with current small list of packages, | |
# installing them is faster than cache retrieval and update. | |
- name: Install packages | |
run: poetry install | |
- name: Run tests | |
working-directory: ./src | |
env: | |
APP_REDIS_URL: "redis://localhost:${{ job.services.redis.ports[6379] }}/1" | |
CELERY_BROKER_URL: "" | |
CELERY_RESULT_BACKEND: "" | |
DATABASE_URL: postgres://postgres:postgres@localhost:${{ job.services.postgres.ports[5432] }}/postgres | |
SECRET_KEY: "" | |
run: | | |
poetry run python manage.py wait_for_db | |
poetry run python manage.py test --parallel --shuffle |