Commit 7f8e876e authored by Joachim Kołodziejski's avatar Joachim Kołodziejski
Browse files

Serve static files with whitenoise, add tini pid 1 to Containerfile, use .env...

Serve static files with whitenoise, add tini pid 1 to Containerfile, use .env in compose.yaml, improve README.md, improve .*ignore
parent 9b520673
Loading
Loading
Loading
Loading
+7 −2
Changes for .containerignore: 7 added lines, 2 removed lines.
Original line number Diff line number Diff line
.git

.venv
**/__pycache__
db.sqlite3
.DS_Store
.vscode
.ruff_cache

.env
deployment/
db.sqlite3
deployment
+4 −2
Changes for .gitignore: 4 added lines, 2 removed lines.
Original line number Diff line number Diff line
.venv
**/__pycache__
db.sqlite3
.DS_Store
.vscode
.ruff_cache

.env
db.sqlite3
deployment
.DS_Store
+2 −2
Changes for Containerfile: 2 added lines, 2 removed lines.
Original line number Diff line number Diff line
FROM docker.io/library/alpine:3.23

RUN apk add --no-cache uv
RUN apk add --no-cache uv tini

COPY . /app
WORKDIR /app
@@ -8,4 +8,4 @@ WORKDIR /app
RUN uv --no-cache venv --python 3.12
RUN uv --no-cache sync --no-dev --frozen

ENTRYPOINT ["uv", "--no-cache", "run", "./entrypoint.sh"]
ENTRYPOINT ["tini", "--", "uv", "--no-cache", "run", "./entrypoint.sh"]
+15 −11
Changes for README.md: 15 added lines, 11 removed lines.
Original line number Diff line number Diff line
# wybory

Voting system, initially developed for [XIV LO in Warsaw](https://staszic.waw.pl/).

## Prerequisites
- [Redis](https://redis.io/docs/latest/operate/oss_and_stack/install/install-stack/) instance running
- for production, a PostgreSQL server is strongly advised (any relatively recent version should work, we tested v17)
- Python (any relatively recent version, see `pyproject.toml`)
- Redis or Valkey (any redis-compatible version) server for queues
- a database server: for production, a PostgreSQL server is strongly advised (any relatively recent version should work)

## Run for development
## Development
- clone the repo
- make sure you have [uv](https://docs.astral.sh/uv/) installed
- run `uv run pre-commit install` to install the pre-commit git hook
- if you want to commit something later, run `uv run pre-commit install` to install the pre-commit git hook
- create venv and install dependencies: `uv sync --frozen`
- setup environmental variables: `cp sample.env .env` and adjust values as needed
- configure environment variables: `cp sample.env .env` and adjust `.env` as needed
- run migrations: `uv run manage.py migrate`
- create superuser: `uv run manage.py createsuperuser`
- run development server and worker `uv run honcho start`

## Deploy for production

### OCI + Compose (Podman/Docker)
- build the image (e.g. `buildah build -t wybory:latest .`)
- review and edit `compose.yaml` to your needs, you can mount a custom gunicorn config
- run the stack (e.g. `podman compose up -d`)
## Production (OCI)
- build the image (e.g. `buildah build -t wybory .` or `docker build -t wybory .`)
- if you want to use compose:
    - `cp sample.env .env` and adjust `.env` as needed
    - 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`
+17 −16
Changes for compose.yaml: 17 added lines, 16 removed lines.
Original line number Diff line number Diff line
@@ -4,45 +4,46 @@ services:
    image: wybory
    command: web
    ports:
    - "8000:8000"
    - "8000:8000/tcp"
    env_file: .env
    environment: &env
      EMAIL_URL: "smtp+tls://wybory:changeme@smtp.example.com:587"
      DEFAULT_FROM_EMAIL: "Wybory <wybory@example.com>"
      SITE_URL: "http://localhost:8000"
      RQ_URL: "redis://valkey:6379/0"
      TIME_ZONE: "Europe/Warsaw"
      DATABASE_URL: "postgres://wybory:wybory@db:5432/wybory"
      DJANGO_SUPERUSER_USERNAME: "admin"
      DJANGO_SUPERUSER_EMAIL: "admin@localhost"
      DJANGO_SUPERUSER_PASSWORD: "admin"
      RQ_URL: "redis://valkey:6379/0"
      # Create a superuser automatically (on each startup)
      #DJANGO_SUPERUSER_USERNAME: "admin"
      #DJANGO_SUPERUSER_EMAIL: "admin@localhost"
      #DJANGO_SUPERUSER_PASSWORD: "admin"
    #volumes:
    #- ./deployment/gunicorn.conf.py:/app/gunicorn.conf.py:ro
    depends_on: &dep
      db:
        condition: service_started
      queue:
      valkey:
        condition: service_started

  worker:
    image: wybory
    command: worker
    environment: *env
    env_file: .env
    environment:
      DATABASE_URL: "postgres://wybory:wybory@db:5432/wybory"
      RQ_URL: "redis://valkey:6379/0"
    depends_on: *dep

  db:
    image: docker.io/library/postgres:17-alpine
    image: docker.io/library/postgres:18-alpine
    # ports:
    # - "5432:5432"
    # - "5432:5432/tcp"
    environment:
      POSTGRES_USER: wybory
      POSTGRES_PASSWORD: wybory
      POSTGRES_DATABASE: wybory
    volumes:
    - "./deployment/db:/var/lib/postgresql/data"
    - "./deployment/db:/var/lib/postgresql/18/docker"

  valkey:
    image: docker.io/valkey/valkey:8.1-alpine
    image: docker.io/valkey/valkey:9-alpine
    # ports:
    # - "6379:6379"
    # - "6379:6379/tcp"
    volumes:
    - "./deployment/valkey:/data"
Loading