diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3644c6db..95567dbf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,6 +3,9 @@ on: - push - pull_request +env: + CI: 1 + defaults: run: shell: bash @@ -21,7 +24,6 @@ jobs: image: redis ports: - 6379:6379 - options: --entrypoint redis-server steps: - name: Set up repo diff --git a/.gitignore b/.gitignore index 76e2db25..999d6145 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,5 @@ docs/source/reference/ # from prettier node_modules/ + +celerybeat-schedule diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..4f90adf1 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,16 @@ +FROM python:3.11-slim-bookworm + +# reduce the number of celery warnings +RUN useradd celery + +ENV PIPENV_VENV_IN_PROJECT=1 + +COPY Pipfile . +COPY Pipfile.lock . + +RUN pip install pipenv && \ + pipenv install + +ENV PATH="/.venv/bin:$PATH" + +WORKDIR /app diff --git a/compose.yaml b/compose.yaml new file mode 100644 index 00000000..58c63ff5 --- /dev/null +++ b/compose.yaml @@ -0,0 +1,61 @@ +services: + redis: + image: redis:latest + networks: + - tin-network + expose: + - "6379" + + celery: + image: tin-base + user: celery + entrypoint: + - celery + - -A + - tin + - worker + networks: + - tin-network + depends_on: + - django + volumes: + - .:/app + + celerybeat: + container_name: tin_celerybeat + image: tin-base + entrypoint: + - celery + - -A + - tin + - beat + networks: + - tin-network + volumes: + - .:/app + depends_on: + - django + + django: + container_name: tin_django + build: . + image: tin-base + restart: on-failure + networks: + - tin-network + ports: + - 8000:8000 + volumes: + - .:/app + entrypoint: + - ./manage.py + - runserver + depends_on: + - redis + healthcheck: + test: ["CMD", "curl", "-f", "http://0.0.0.0:8000"] + +networks: + tin-network: + driver: bridge + name: tin-dev-network diff --git a/tin/settings/__init__.py b/tin/settings/__init__.py index c213a0cf..7f42e3e4 100644 --- a/tin/settings/__init__.py +++ b/tin/settings/__init__.py @@ -28,6 +28,8 @@ # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True +CI = "CI" in os.environ + ALLOWED_HOSTS = [ "127.0.0.1", "localhost", @@ -234,7 +236,12 @@ CELERY_RESULT_BACKEND = "django-db" -CELERY_BROKER_URL = "redis://localhost:6379/1" +if not CI and DEBUG: + CELERY_BROKER_URL = "redis://redis:6379/0" +else: + CELERY_BROKER_URL = "redis://localhost:6379/1" + +CELERY_BROKER_CONNECTION_RETRY_ON_STARTUP = True # Markdown