Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add docker setup for Tin #98

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ jobs:
image: redis
ports:
- 6379:6379
options: --entrypoint redis-server

steps:
- name: Set up repo
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ docs/source/reference/

# from prettier
node_modules/

celerybeat-schedule
16 changes: 16 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
51 changes: 51 additions & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
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
environment:
IN_DOCKER: true

django:
container_name: tin_django
build: .
image: tin-base
restart: on-failure
networks:
- tin-network
ports:
- 8000:8080
volumes:
- .:/app
entrypoint:
- ./manage.py
- runserver
- 0.0.0.0:8080
depends_on:
- redis
JasonGrace2282 marked this conversation as resolved.
Show resolved Hide resolved
healthcheck:
test: ["CMD", "curl", "-f", "http://0.0.0.0:8000"]
environment:
IN_DOCKER: true

networks:
tin-network:
driver: bridge
name: tin-dev-network
23 changes: 7 additions & 16 deletions docs/source/contributing/setup.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,12 @@ Now you're all set! Try running the development server
Head on over to `http://127.0.0.1:8000 <http://127.0.0.1:8000>`_, and login
as ``admin`` and the password you just entered.

Docker
------
If you prefer, you can also run the development setup with `Docker <https://www.docker.com/>`_. To do so,
``cd`` into the project directory and run::

docker compose build
docker compose up

NixOS Setup
-----------
A ``flake.nix`` file is provided for NixOS users. To use it, first enable the redis service globally.
Place the following in your ``/etc/nixos/configuration.nix``::

services.redis.server."".enable = true

This will start a systemd service called ``redis``. After that, you can start the flake with::

nix develop

You can then install dependencies, setup the database, and run the development server as described above.

.. tip::

You may also need to set ``nix.settings.experimental-features = ["nix-command" "flakes"];`` in your ``configuration.nix``.
The latter command will start up the django development server, as well as celery tasks for submissions.
62 changes: 0 additions & 62 deletions flake.lock

This file was deleted.

23 changes: 0 additions & 23 deletions flake.nix

This file was deleted.

16 changes: 14 additions & 2 deletions tin/settings/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

IN_DOCKER = os.environ.get("IN_DOCKER", False)

ALLOWED_HOSTS = [
"127.0.0.1",
"localhost",
Expand Down Expand Up @@ -106,7 +108,11 @@
CHANNEL_LAYERS = {
"default": {
"BACKEND": "channels_redis.core.RedisChannelLayer",
"CONFIG": {"hosts": [("localhost", 6379)]},
"CONFIG": {
"hosts": [
("redis" if IN_DOCKER else "localhost", 6379),
]
},
},
}

Expand Down Expand Up @@ -234,7 +240,13 @@
CELERY_RESULT_BACKEND = "django-db"


CELERY_BROKER_URL = "redis://localhost:6379/1"
if IN_DOCKER:
CELERY_BROKER_URL = "redis://redis:6379/0"
else:
CELERY_BROKER_URL = "redis://localhost:6379/1"


CELERY_BROKER_CONNECTION_RETRY_ON_STARTUP = True


# Markdown
Expand Down
Loading