Add Docker image, entrypoint, compose example and registry build workflow
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
5b3fccde67
commit
c75f311324
7 files changed
+157
No files matched your search
@@ -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
|
||||||
@@ -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 :<commit sha>
|
||||||
|
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 }}
|
||||||
@@ -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
|
- Benötigte Variablen/Secrets sind im Kopf der Workflow-Datei dokumentiert. Zugangsdaten nur als
|
||||||
Gitea-Secret, nie ins Repo.
|
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` + `:<sha>` 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.
|
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.
|
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`),
|
Document-Root zeigt idealerweise auf `webroot/`; liegt die App direkt im Document-Root (z. B. `public_html`),
|
||||||
|
|||||||
+40
@@ -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"]
|
||||||
@@ -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`
|
Liegt die App direkt im Document-Root (z. B. `public_html`), leiten `.htaccess` und `index.php`
|
||||||
im Projektroot alles nach `webroot/` weiter.
|
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.
|
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.
|
Für sehr große Runden (mehrere hundert Teilnehmende) `POLL_INTERVAL_MS` erhöhen und MySQL/PostgreSQL statt SQLite verwenden.
|
||||||
|
|
||||||
|
|||||||
@@ -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:
|
||||||
@@ -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}"
|
||||||
Reference in new issue
Block a user