From c75f3113246ef951a61024e053adec35d55d6f5b Mon Sep 17 00:00:00 2001 From: Patrick Niebeling Date: Wed, 11 Nov 2026 20:49:25 +0100 Subject: [PATCH 1/2] Add Docker image, entrypoint, compose example and registry build workflow Co-Authored-By: Claude Sonnet 5.5 --- .dockerignore | 16 +++++++++++++ .gitea/workflows/docker.yml | 46 +++++++++++++++++++++++++++++++++++++ AGENTS.md | 10 ++++++++ Dockerfile | 40 ++++++++++++++++++++++++++++++++ README.md | 14 +++++++++++ docker-compose.yml | 15 ++++++++++++ docker/entrypoint.sh | 16 +++++++++++++ 7 files changed, 157 insertions(+) create mode 100644 .dockerignore create mode 100644 .gitea/workflows/docker.yml create mode 100644 Dockerfile create mode 100644 docker-compose.yml create mode 100644 docker/entrypoint.sh diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..c912c95 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,16 @@ +.git +.gitea +.gitattributes +.phpunit.cache +.claude +vendor +tmp +logs +data +tests +config/app_local.php +config/.env +.env +CLAUDE.local.md +Dockerfile +docker-compose.yml diff --git a/.gitea/workflows/docker.yml b/.gitea/workflows/docker.yml new file mode 100644 index 0000000..bb33172 --- /dev/null +++ b/.gitea/workflows/docker.yml @@ -0,0 +1,46 @@ +# Container image build (Gitea Actions): builds the Dockerfile and pushes it to the Gitea registry +# on every push to main (main is protected: only merged PRs with green tests land there). +# +# Repository variables (Settings → Actions → Variables): +# DOCKER_REPO registry host, e.g. gitea.gnilebein.de +# IMAGE_NAME image name, e.g. plenario +# Repository secrets: +# PAT personal access token with package write permission +# +# Image: ${DOCKER_REPO}/${owner}/${IMAGE_NAME}:latest and : +name: Container Image + +on: + push: + branches: + - main + workflow_dispatch: + +jobs: + docker-build-image: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v6 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to registry + uses: docker/login-action@v4 + with: + registry: ${{ vars.DOCKER_REPO }} + username: ${{ gitea.actor }} + password: ${{ secrets.PAT }} + + - name: Build and push + uses: docker/build-push-action@v6 + with: + file: ./Dockerfile + platforms: linux/amd64 + pull: true + push: true + provenance: false + tags: | + ${{ vars.DOCKER_REPO }}/${{ gitea.repository_owner }}/${{ vars.IMAGE_NAME }}:latest + ${{ vars.DOCKER_REPO }}/${{ gitea.repository_owner }}/${{ vars.IMAGE_NAME }}:${{ gitea.sha }} diff --git a/AGENTS.md b/AGENTS.md index 88cd67d..f6b2d0f 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -314,6 +314,16 @@ Deploy erfolgt über Git (Remote: Gitea) mit `.gitea/workflows/ci.yml`: - Benötigte Variablen/Secrets sind im Kopf der Workflow-Datei dokumentiert. Zugangsdaten nur als Gitea-Secret, nie ins Repo. +**Container (Docker):** `Dockerfile` (`php:8.5-cli-alpine`, Multi-Stage mit Composer) startet über +`docker/entrypoint.sh` den eingebauten Server (`bin/cake server -H 0.0.0.0 -p 8765`, `PHP_CLI_SERVER_WORKERS=8`, +sonst bedient er nur einen Request gleichzeitig). Code in `/app`, SQLite in Volume `/data` +(`DATABASE_URL=sqlite:////data/plenario.sqlite`), Konfiguration nur per Umgebungsvariablen (`config/.env.example`). +`SECURITY_SALT` ist Pflicht (Entrypoint bricht sonst ab; `composer install --no-scripts`, damit kein Salt eingebrannt wird). +Der Start ist idempotent (Migrationen + `cache clear_all`). Der Healthcheck prüft eine statische Datei, weil die Host-Prüfung +(`APP_FULL_BASE_URL`) `127.0.0.1` auf echten Seiten mit 400 ablehnt. Betrieb hinter einem TLS-Proxy mit `X-Forwarded-Proto`. +`.gitea/workflows/docker.yml` baut bei Push auf `main` und pusht `:latest` + `:` in die Gitea-Registry +(Variablen `DOCKER_REPO`, `IMAGE_NAME`, Secret `PAT`). Beispiel: `docker-compose.yml`. + Produktiv auf dem Server in `config/.env`: `DEBUG=false`, `APP_FULL_BASE_URL`, `SECURITY_SALT`, SMTP. Ohne `DEBUG=false` steht die per Composer erzeugte `app_local.php` auf debug=true und zeigt Admin-Links direkt an. Document-Root zeigt idealerweise auf `webroot/`; liegt die App direkt im Document-Root (z. B. `public_html`), diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..5f7b8fa --- /dev/null +++ b/Dockerfile @@ -0,0 +1,40 @@ +# PlenarIO container: PHP's built-in server via `bin/cake server`, app in /app, SQLite in /data. +# Configuration only through environment variables (see config/.env.example). + +FROM php:8.5-cli-alpine AS base +RUN apk add --no-cache icu-libs \ + && apk add --no-cache --virtual .build-deps $PHPIZE_DEPS icu-dev \ + && docker-php-ext-install -j"$(nproc)" intl \ + && apk del .build-deps + +FROM base AS build +COPY --from=composer:2 /usr/bin/composer /usr/bin/composer +WORKDIR /app +COPY composer.json composer.lock ./ +# --no-scripts: the installer must not bake a random salt into app_local.php (SECURITY_SALT comes at runtime) +RUN composer install --no-dev --no-scripts --no-progress --prefer-dist --optimize-autoloader +COPY . . +RUN composer dump-autoload --no-dev --optimize \ + && cp config/app_local.example.php config/app_local.php + +FROM base +WORKDIR /app +COPY --from=build /app /app +COPY docker/entrypoint.sh /usr/local/bin/plenario-entrypoint + +ENV DEBUG=false \ + SHOW_ADMIN_LINK_AFTER_CREATE=false \ + DATABASE_URL=sqlite:////data/plenario.sqlite \ + PHP_CLI_SERVER_WORKERS=8 + +RUN chmod +x /usr/local/bin/plenario-entrypoint \ + && mkdir -p /data /app/tmp /app/logs \ + && chown -R www-data:www-data /data /app/tmp /app/logs + +USER www-data +VOLUME /data +EXPOSE 8765 +# static file: the Host-header check (APP_FULL_BASE_URL) would reject 127.0.0.1 on real pages +HEALTHCHECK --interval=30s --timeout=5s --start-period=20s \ + CMD wget -q -O /dev/null http://127.0.0.1:8765/css/plenario.css || exit 1 +ENTRYPOINT ["plenario-entrypoint"] diff --git a/README.md b/README.md index d65aab3..8aa6755 100644 --- a/README.md +++ b/README.md @@ -94,6 +94,20 @@ stehen im Kopf der Workflow-Datei. Einmalig auf dem Server: `config/.env` anlege Liegt die App direkt im Document-Root (z. B. `public_html`), leiten `.htaccess` und `index.php` im Projektroot alles nach `webroot/` weiter. +**Container:** Das [Dockerfile](Dockerfile) baut ein schlankes Image (`php:8.5-cli-alpine`, eingebauter Server auf Port 8765). +Der Workflow [.gitea/workflows/docker.yml](.gitea/workflows/docker.yml) pusht es bei jedem Push auf `main` in die Gitea-Registry. + +```bash +docker run -d -p 8765:8765 -v plenario-data:/data \ + -e SECURITY_SALT="$(php -r 'echo bin2hex(random_bytes(32));')" \ + -e APP_FULL_BASE_URL=https://plenario.example.org \ + gitea.gnilebein.de/gnilebein/plenario:latest +``` + +Die Datenbank liegt im Volume `/data`; weitere Einstellungen (SMTP, Captcha, …) als Umgebungsvariablen +(siehe `config/.env.example`, Beispiel in `docker-compose.yml`). Beim Start laufen die Migrationen automatisch. +Vor einen TLS-Proxy schalten, der `X-Forwarded-Proto` setzt. + Live-Updates laufen über kurzes Polling (Standard alle 2 s) – kein WebSocket-Server nötig. Für sehr große Runden (mehrere hundert Teilnehmende) `POLL_INTERVAL_MS` erhöhen und MySQL/PostgreSQL statt SQLite verwenden. diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..df0ffc2 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,15 @@ +# Example: docker compose up -d +# Put it behind a TLS reverse proxy that sets X-Forwarded-Proto; APP_FULL_BASE_URL = public URL. +services: + plenario: + image: gitea.gnilebein.de/gnilebein/plenario:latest + # build: . + restart: unless-stopped + ports: + - "8765:8765" + env_file: .env # SECURITY_SALT, APP_FULL_BASE_URL, MAIL_FROM, EMAIL_TRANSPORT_DEFAULT_URL, ... + volumes: + - plenario-data:/data + +volumes: + plenario-data: diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh new file mode 100644 index 0000000..473c2d0 --- /dev/null +++ b/docker/entrypoint.sh @@ -0,0 +1,16 @@ +#!/bin/sh +# Idempotent start: prepare writable dirs, migrate the database, then run the built-in server. +set -eu + +cd /app +mkdir -p tmp/cache tmp/sessions tmp/mails tmp/dompdf logs + +if [ -z "${SECURITY_SALT:-}" ] || [ "${SECURITY_SALT}" = "__SALT__" ]; then + echo "SECURITY_SALT is not set. Generate one with: php -r \"echo bin2hex(random_bytes(32));\"" >&2 + exit 1 +fi + +php bin/cake.php migrations migrate +php bin/cake.php cache clear_all + +exec php bin/cake.php server -H 0.0.0.0 -p "${PORT:-8765}" -- 2.54.1 From 95bcd6b14dbda6ce2c271c8bd1a54f25e669cf17 Mon Sep 17 00:00:00 2001 From: Patrick Niebeling Date: Wed, 11 Nov 2026 22:07:31 +0100 Subject: [PATCH 2/2] chore: test signed commit -- 2.54.1