Commit 9947d76b authored by Joachim Kołodziejski's avatar Joachim Kołodziejski
Browse files

Add traditional production deployment instructions to readme

parent c6f797c2
Loading
Loading
Loading
Loading
+67 −0
Changes for README.md: 67 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -24,3 +24,70 @@ Voting system, initially developed for [XIV LO in Warsaw](https://staszic.waw.pl
    - review and adjust `compose.yaml`
    - run the stack (e.g. `podman compose up -d` or `docker compose up -d`)
- if not, look at `compose.yaml` and `sample.env`

## Production (traditional)
- install [uv](https://docs.astral.sh/uv/) (Debian does not have it in the official repositories, so you can download a tarball from [github](https://github.com/astral-sh/uv/releases) and extract `uv` binary to `/usr/local/bin`)
- install and start redis/valkey (Debian: `apt install valkey-server` and `systemctl start valkey-server && systemctl enable valkey-server`)
- create user, group and homedir: `useradd --system --home-dir /var/www/wybory --shell /sbin/nologin --user-group wybory && mkdir -p /var/www/wybory && chown wybory:wybory /var/www/wybory`
- clone the repo: `git clone <...> /var/www/wybory && cd /var/www/wybory`
- write the config file: `cp sample.env .env` and adjust .env to your needs
- prepare venv: `sudo -u wybory uv sync --locked`
- write service config, e.g. for systemd:

    write `/etc/systemd/system/wybory.service`:
    ```
    [Unit]
    After=valkey-server.service network.target
    Requires=valkey-server.service

    [Service]
    Type=exec
    User=wybory
    Group=wybory
    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
    StandardOutput=file:/var/log/wybory/stdout.log
    StandardError=file:/var/log/wybory/stderr.log
    Restart=always
    RestartSec=5s
    KillMode=mixed
    TimeoutStopSec=20s

    [Install]
    WantedBy=multi-user.target
    ```

    write `/etc/systemd/system/wybory-worker.service`:
    ```
    [Unit]
    After=valkey-server.service network.target
    Requires=valkey-server.service

    [Service]
    Type=exec
    User=wybory
    Group=wybory
    WorkingDirectory=/var/www/wybory
    ExecStart=/var/www/wybory/.venv/bin/python manage.py rqworker default email email_batch --job-class django_tasks_rq.Job
    StandardOutput=file:/var/log/wybory/worker_stdout.log
    StandardError=file:/var/log/wybory/worker_stderr.log
    Restart=always
    RestartSec=5s
    KillMode=mixed
    TimeoutStopSec=20s

    [Install]
    WantedBy=multi-user.target
    ```
    `mkdir -p /var/log/wybory` and and do `systemctl daemon-reload` to read the new service file.

    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