Commit 776a3e13 authored by Joachim Kołodziejski's avatar Joachim Kołodziejski
Browse files

Adapt deployment to ASGI, add CSRF_TRUSTED_ORIGINS to settings, fix and bump...

Adapt deployment to ASGI, add CSRF_TRUSTED_ORIGINS to settings, fix and bump dependencies, increase the number of default workers to 4
parent 1ac36a7d
Loading
Loading
Loading
Loading
+1 −3
Changes for README.md: 1 added line, 3 removed lines.
Original line number Diff line number Diff line
@@ -47,7 +47,7 @@ Voting system, initially developed for [XIV LO in Warsaw](https://staszic.waw.pl
    WorkingDirectory=/var/www/wybory
    ExecStartPre=/var/www/wybory/.venv/bin/python manage.py migrate --no-input
    ExecStartPre=/var/www/wybory/.venv/bin/python manage.py collectstatic --no-input
    ExecStart=/var/www/wybory/.venv/bin/gunicorn -c gunicorn.conf.py wybory.wsgi
    ExecStart=/var/www/wybory/.venv/bin/gunicorn -c gunicorn.conf.py wybory.asgi
    StandardOutput=file:/var/log/wybory/stdout.log
    StandardError=file:/var/log/wybory/stderr.log
    Restart=always
@@ -86,8 +86,6 @@ Voting system, initially developed for [XIV LO in Warsaw](https://staszic.waw.pl
    You can adjust gunicorn configuration with command line arguments (see `sudo -u wybory uv run gunicorn --help`),
    or by providing a different config file than `/var/www/wybory/gunicorn.conf.py`.

    It it advised to adjust the number of workers (`--workers <number-of-workers>` or `workers` variable in the config file).

- start and enable the services (for systemd: `systemctl start wybory.service && systemctl enable wybory.service && systemctl start wybory-worker.service && systemctl enable wybory-worker.service`)
- create a superuser `sudo -u wybory uv run python manage.py createsuperuser`
- serve the traffic through a reverse proxy
+1 −1
Changes for entrypoint.sh: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -8,7 +8,7 @@ if [ "$1" = "web" ]; then
        ./manage.py createsuperuser --noinput
        set -e
    fi
    gunicorn -c gunicorn.conf.py wybory.wsgi
    gunicorn -c gunicorn.conf.py wybory.asgi
elif [ "$1" = "worker" ]; then
    ./manage.py rqworker default email email_batch --job-class django_tasks_rq.Job
else
+2 −1
Changes for gunicorn.conf.py: 2 added lines, 1 removed line.
Original line number Diff line number Diff line
bind = "0.0.0.0:8000"

workers = 2
workers = 4
worker_class = "uvicorn_worker.UvicornWorker"

loglevel = "info"
errorlog = "-"
+9 −9
Changes for pyproject.toml: 9 added lines, 9 removed lines.
Original line number Diff line number Diff line
@@ -4,25 +4,25 @@ version = "0.1.0"
readme = "README.md"
requires-python = ">=3.12"
dependencies = [
    "channels>=4.3.2",
    "channels-redis>=4.3.0",
    "channels~=4.3.2",
    "channels-redis~=4.3.0",
    "dj-database-url~=3.1.2",
    "django~=6.0.3",
    "django-admin-action-forms>=2.2.1",
    "django-admin-action-forms~=2.2.1",
    "django-environ~=0.13.0",
    "django-no-queryset-admin-actions>=1.2.1",
    "django-no-queryset-admin-actions~=1.2.1",
    "django-rq~=4.0.1",
    "django-solo>=2.5.1",
    "django-summernote>=0.8.20.0",
    "django-solo~=2.5.1",
    "django-summernote~=0.8.20.0",
    "django-tasks-rq~=0.12.0",
    "djangorestframework~=3.17.1",
    "gunicorn~=25.2.0",
    "ldap3~=2.9.1",
    "matplotlib>=3.11.0",
    "matplotlib~=3.11.0",
    "psycopg[binary]~=3.3.3",
    "qrcode>=8.2",
    "qrcode~=8.2",
    "tzdata~=2025.3",
    "uvicorn[standard]>=0.54.0",
    "uvicorn-worker~=0.4.0",
    "whitenoise~=6.12.0",
]

+4 −1
Changes for sample.env: 4 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -16,7 +16,10 @@ SECRET_KEY=
#DEBUG="false"

# Comma-separated allowed hosts list (see Django settings ALLOWED_KEYS)
ALLOWED_HOSTS="localhost,wybory.example.com"
ALLOWED_HOSTS="wybory.example.com"

# Comma-separated allowed CSRF Origins (see Django settings CSRF_TRUSTED_ORIGINS)
CSRF_TRUSTED_ORIGINS="https://wybory.example.com"

# Redis instance URL (see django-rq RQ_QUEUES)
RQ_URL="redis://localhost:6379/0"
Loading