Build app package and image only for semver release tags #67
No files matched your search
@@ -1,46 +0,0 @@
|
||||
# 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 }}
|
||||
@@ -0,0 +1,172 @@
|
||||
# Release (Gitea Actions): runs only when a semantic-version tag is pushed (or a release is created
|
||||
# from a new such tag in Gitea), e.g. v1.4.0 or v2.0.0-rc.1. Nothing is built on normal pushes.
|
||||
#
|
||||
# git tag v1.4.0 && git push origin v1.4.0
|
||||
#
|
||||
# - test: PHPUnit + phpcs on the tagged commit; package and image are only built if it is green.
|
||||
# - package: install package (plenario-<version>.tar.gz: only the app incl. production vendor/, no tests/CI/Docker files)
|
||||
# + SHA256SUMS, attached to the Gitea release for that tag (created if missing, updated if present).
|
||||
# Tags with a pre-release suffix (-rc.1, -beta.2, …) become pre-releases.
|
||||
# - image: container image with the semver tags <major>.<minor>.<patch>, <major>.<minor>, <major> and (stable
|
||||
# releases only) latest, pushed to the Gitea registry.
|
||||
#
|
||||
# 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 (registry login)
|
||||
# The release itself is created with the job token; if your Gitea denies that (HTTP 403), use a PAT with
|
||||
# repository write permission instead of `gitea.token` in the "Publish release" step.
|
||||
name: Release
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- 'v[0-9]+.[0-9]+.[0-9]+'
|
||||
- 'v[0-9]+.[0-9]+.[0-9]+-*'
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Check tag is a semantic version
|
||||
env:
|
||||
REF_NAME: ${{ gitea.ref_name }}
|
||||
run: |
|
||||
if ! printf '%s' "$REF_NAME" | grep -Eq '^v(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-[0-9A-Za-z.-]+)?$'; then
|
||||
echo "'$REF_NAME' is not a semantic version tag (expected vMAJOR.MINOR.PATCH[-prerelease])." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
- name: Setup PHP
|
||||
uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: '8.5'
|
||||
extensions: mbstring, intl, pdo_sqlite, sqlite3
|
||||
coverage: none
|
||||
|
||||
- name: Install dependencies
|
||||
run: composer install --no-interaction --prefer-dist --no-progress
|
||||
|
||||
- name: Run tests
|
||||
run: vendor/bin/phpunit
|
||||
|
||||
- name: Coding standard
|
||||
run: vendor/bin/phpcs --warning-severity=0
|
||||
|
||||
package:
|
||||
needs: test
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Setup PHP
|
||||
uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: '8.5'
|
||||
extensions: mbstring, intl
|
||||
coverage: none
|
||||
|
||||
- name: Build package
|
||||
env:
|
||||
REF_NAME: ${{ gitea.ref_name }}
|
||||
run: |
|
||||
set -eu
|
||||
VERSION="${REF_NAME#v}"
|
||||
NAME="plenario-${VERSION}"
|
||||
mkdir -p build dist
|
||||
# Whitelist: only what the running app needs (no tests, CI, Docker, editor or agent files)
|
||||
git archive --format=tar --prefix="$NAME/" "$REF_NAME" \
|
||||
bin config plugins resources src templates webroot \
|
||||
index.php .htaccess composer.json composer.lock | tar -x -C build
|
||||
cd "build/$NAME"
|
||||
rm -f bin/cake.bat bin/bash_completion.sh
|
||||
# --no-scripts: the installer must not bake a random salt into app_local.php (SECURITY_SALT comes from config/.env)
|
||||
composer install --no-dev --no-scripts --no-interaction --no-progress --prefer-dist --optimize-autoloader
|
||||
cp config/app_local.example.php config/app_local.php
|
||||
mkdir -p tmp/cache/models tmp/cache/persistent tmp/cache/views tmp/sessions logs data
|
||||
printf '%s\n' "$VERSION" > VERSION
|
||||
cd ../..
|
||||
tar -czf "dist/${NAME}.tar.gz" -C build "$NAME"
|
||||
(cd dist && sha256sum "${NAME}.tar.gz" > SHA256SUMS)
|
||||
ls -l dist
|
||||
|
||||
- name: Publish release
|
||||
env:
|
||||
REF_NAME: ${{ gitea.ref_name }}
|
||||
API: ${{ gitea.server_url }}/api/v1/repos/${{ gitea.repository }}
|
||||
TOKEN: ${{ gitea.token }}
|
||||
run: |
|
||||
set -eu
|
||||
auth="Authorization: token ${TOKEN}"
|
||||
|
||||
# Changelog: commit subjects since the previous tag (merge commits left out)
|
||||
PREV="$(git describe --tags --abbrev=0 "${REF_NAME}^" 2>/dev/null || true)"
|
||||
RANGE="${REF_NAME}"
|
||||
if [ -n "$PREV" ]; then RANGE="${PREV}..${REF_NAME}"; fi
|
||||
NOTES="$(git log --no-merges --pretty='- %s' "$RANGE")"
|
||||
|
||||
PRERELEASE=false
|
||||
case "$REF_NAME" in *-*) PRERELEASE=true ;; esac
|
||||
|
||||
# Idempotent: reuse the release if this tag already has one (re-run), otherwise create it
|
||||
status="$(curl -sS -o release.json -w '%{http_code}' -H "$auth" "$API/releases/tags/$REF_NAME")"
|
||||
if [ "$status" != "200" ]; then
|
||||
jq -n --arg tag "$REF_NAME" --arg body "$NOTES" --argjson pre "$PRERELEASE" \
|
||||
'{tag_name: $tag, name: $tag, body: $body, prerelease: $pre}' > payload.json
|
||||
curl -fsS -o release.json -X POST -H "$auth" -H 'Content-Type: application/json' \
|
||||
-d @payload.json "$API/releases"
|
||||
fi
|
||||
ID="$(jq -r .id release.json)"
|
||||
|
||||
for file in dist/*; do
|
||||
base="$(basename "$file")"
|
||||
# replace an asset of the same name left over from an earlier run
|
||||
jq -r --arg n "$base" '.assets[]? | select(.name == $n) | .id' release.json | while read -r aid; do
|
||||
curl -fsS -X DELETE -H "$auth" "$API/releases/$ID/assets/$aid"
|
||||
done
|
||||
curl -fsS -o /dev/null -X POST -H "$auth" -F "attachment=@${file}" \
|
||||
"$API/releases/$ID/assets?name=${base}"
|
||||
done
|
||||
|
||||
image:
|
||||
needs: test
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Login to registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ${{ vars.DOCKER_REPO }}
|
||||
username: ${{ gitea.actor }}
|
||||
password: ${{ secrets.PAT }}
|
||||
|
||||
- name: Image tags
|
||||
id: meta
|
||||
uses: docker/metadata-action@v5
|
||||
with:
|
||||
images: ${{ vars.DOCKER_REPO }}/${{ gitea.repository_owner }}/${{ vars.IMAGE_NAME }}
|
||||
tags: |
|
||||
type=semver,pattern={{version}}
|
||||
type=semver,pattern={{major}}.{{minor}}
|
||||
type=semver,pattern={{major}},enable=${{ !contains(gitea.ref_name, '-') && !startsWith(gitea.ref_name, 'v0.') }}
|
||||
|
||||
- name: Build and push
|
||||
uses: docker/build-push-action@v6
|
||||
with:
|
||||
file: ./Dockerfile
|
||||
platforms: linux/amd64
|
||||
pull: true
|
||||
push: true
|
||||
provenance: false
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
@@ -351,8 +351,15 @@ sonst bedient er nur einen Request gleichzeitig). Code in `/app`, SQLite in Volu
|
||||
`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`.
|
||||
Beispiel: `docker-compose.yml`. Image und App-Paket entstehen nur bei Releases (siehe nächster Absatz).
|
||||
|
||||
**Releases (SemVer):** `.gitea/workflows/release.yml` läuft nur bei Tags `vMAJOR.MINOR.PATCH[-suffix]` (kein Build bei normalen
|
||||
Pushes). Job `test` (PHPUnit + phpcs) gatet `package` und `image`. `package` baut `plenario-<version>.tar.gz` (git archive des Tags,
|
||||
`composer install --no-dev --no-scripts`, `app_local.php` aus dem Example, leere `tmp/`/`logs/`/`data/`, Datei `VERSION`; nur per Whitelist: bin, config, plugins, resources, src, templates, webroot, index.php, .htaccess, composer-Dateien;
|
||||
kein tests/CI/Docker/README) + `SHA256SUMS` und hängt sie an das Gitea-Release (wird angelegt bzw. aktualisiert, Changelog = Commit-Betreffs
|
||||
seit dem letzten Tag, Suffix = Pre-Release). `image` pusht `:<version>`, `:<major>.<minor>`, `:<major>` und `:latest` (die
|
||||
beiden letzten nicht bei Pre-Releases bzw. `v0.`) in die Gitea-Registry (Variablen `DOCKER_REPO`, `IMAGE_NAME`, Secret `PAT`).
|
||||
Wer das Paket ändert (z. B. weitere Dateien ausschließen), pflegt den Schritt „Build package“ in dieser Datei.
|
||||
|
||||
Produktiv auf dem Server in `config/.env`: `DEBUG=false`, `APP_FULL_BASE_URL`, `SECURITY_SALT`, SMTP
|
||||
(`SMTP_HOST`, `SMTP_PORT`, `SMTP_USER`, `SMTP_PASSWORD`, `SMTP_TLS` – einzelne Variablen statt URL; `EMAIL_TRANSPORT_DEFAULT_URL` geht weiter als Altlast).
|
||||
|
||||
@@ -27,6 +27,7 @@ läuft lokal mit **SQLite**, ohne Build-Schritt fürs Frontend.
|
||||
- [Konfiguration](#konfiguration)
|
||||
- [Deployment mit Docker](#deployment-mit-docker)
|
||||
- [Deployment ohne Docker](#deployment-ohne-docker)
|
||||
- [Releases und Versionierung](#releases-und-versionierung)
|
||||
- [Automatisches Deployment (Gitea Actions)](#automatisches-deployment-gitea-actions)
|
||||
- [Betrieb & Skalierung](#betrieb--skalierung)
|
||||
- [Datenschutz](#datenschutz)
|
||||
@@ -140,8 +141,9 @@ Der eingebaute PHP-Server läuft mit 8 Workern auf Port **8765**, die SQLite-Dat
|
||||
Beim Start laufen die Migrationen automatisch (idempotent, mehrfaches Starten ist unproblematisch).
|
||||
|
||||
Das fertige Image liegt in der Gitea-Registry:
|
||||
`gitea.gnilebein.de/gnilebein/plenario:latest` (außerdem `:<commit-sha>` für feste Versionen).
|
||||
Der Workflow [.gitea/workflows/docker.yml](.gitea/workflows/docker.yml) baut und pusht es bei jedem Push auf `main`.
|
||||
`gitea.gnilebein.de/gnilebein/plenario:latest` (letzter stabiler Release). Für feste Versionen gibt es die
|
||||
SemVer-Tags `:1.4.0`, `:1.4` und `:1` (Pre-Releases wie `v1.5.0-rc.1` nur als `:1.5.0-rc.1`).
|
||||
Gebaut wird das Image nur bei einem neuen Release-Tag, siehe [Releases](#releases-und-versionierung).
|
||||
|
||||
### Schnellstart mit `docker run`
|
||||
|
||||
@@ -240,6 +242,34 @@ Bei Updates: Code aktualisieren, `composer install --no-dev`, Migrationen und `c
|
||||
führt `composer install --no-dev`, die Migrationen und `cache clear_all` aus. Benötigte Variablen und Secrets
|
||||
stehen im Kopf der Workflow-Datei. Einmalig auf dem Server: `config/.env` anlegen, ohne sie bricht der Deploy ab.
|
||||
|
||||
Der Workflow bedient vor allem die Instanz unter <https://plenario.gnilebein.de/>, ist aber nicht fest darauf
|
||||
verdrahtet: Ziel und Werkzeuge kommen ausschließlich aus Repository-Variablen (`SSH_HOST`, `SSH_PORT`, `SSH_USER`,
|
||||
`DEPLOY_PATH`, optional `PHP_BIN`/`COMPOSER_BIN`) und Secrets (`SSH_KEY` oder `SSH_PASSWORD`). Wer PlenarIO auf einem
|
||||
eigenen Server betreibt, setzt dort seine Werte und `DEPLOY_ENABLED=true` – die Workflow-Datei bleibt unverändert.
|
||||
Voraussetzungen: SSH-Zugang mit Shell, `git` und PHP ≥ 8.4 auf dem Server, der Server erreicht die Gitea-Instanz per
|
||||
HTTPS. Ohne `DEPLOY_ENABLED` passiert nichts (Standard).
|
||||
|
||||
## Releases und Versionierung
|
||||
|
||||
PlenarIO nutzt [Semantic Versioning](https://semver.org/lang/de/) (`MAJOR.MINOR.PATCH`): Major bei inkompatiblen
|
||||
Änderungen (z. B. Schema-/Konfigurationsumbrüche), Minor für neue Funktionen, Patch für Fehlerbehebungen.
|
||||
Eine Version entsteht durch einen Tag auf `main`:
|
||||
|
||||
```bash
|
||||
git tag v1.4.0 && git push origin v1.4.0 # Pre-Release: v1.5.0-rc.1
|
||||
```
|
||||
|
||||
Der Workflow [.gitea/workflows/release.yml](.gitea/workflows/release.yml) läuft nur bei solchen Tags (`vX.Y.Z[-suffix]`),
|
||||
führt zuerst die Tests aus und erzeugt dann
|
||||
|
||||
- ein **App-Paket** `plenario-<version>.tar.gz` samt `SHA256SUMS` als Anhang des Gitea-Releases (fertig mit
|
||||
Produktions-`vendor/`, nur die Anwendung (Whitelist), ohne Tests, CI, Docker und Entwicklerdateien, `VERSION`-Datei enthalten; Einrichtung wie unter
|
||||
[Deployment ohne Docker](#deployment-ohne-docker), nur ohne Composer-Schritt) und
|
||||
- das **Docker-Image** mit den Tags `:<version>`, `:<major>.<minor>`, `:<major>` und `:latest`.
|
||||
|
||||
Tags mit Suffix (`-rc.1`, `-beta.2`) werden als Pre-Release markiert und bekommen weder `:latest` noch `:<major>`.
|
||||
Der Workflow ist wiederholbar: ein erneuter Lauf aktualisiert das vorhandene Release.
|
||||
|
||||
## Betrieb & Skalierung
|
||||
|
||||
Live-Updates laufen über kurzes Polling (Standard alle 2 s) – kein WebSocket-Server nötig.
|
||||
|
||||
Reference in new issue
Block a user