Scaffold the app, chart, CI and release (26.11.1)
ci / olares chart · sanity (pull_request) Successful in 5s
ci / app · types + tests + build (pull_request) Successful in 3m54s
release / which version (pull_request) Successful in 1s
release / olares chart · sanity (pull_request) Successful in 3s
release / app (pull_request) Successful in 1m25s
release / tag and release (pull_request) Skipped
ci / olares chart · sanity (pull_request) Successful in 5s
ci / app · types + tests + build (pull_request) Successful in 3m54s
release / which version (pull_request) Successful in 1s
release / olares chart · sanity (pull_request) Successful in 3s
release / app (pull_request) Successful in 1m25s
release / tag and release (pull_request) Skipped
Next.js 15 with next-intl (de, en, fr, es; locale per person, no URL prefix), Tailwind v4 tokens for the warm palette with dark mode, a shadcn/ui button, Serwist service worker and PWA manifest with icons. One Postgres pool with withHousehold() setting app.household_id per transaction; the first migration creates households with FORCE ROW LEVEL SECURITY, and a two-household test checks the isolation as the table owner. scripts/migrate.mjs applies db/migrations once each with a checksum and retries until the database is reachable. Olares chart with one deployment (init: chown, migrate from the same image), ClusterIP service, entrance internal until the own sign-in exists, image path fixed in the template and tag from appVersion. scripts/check-chart.sh carries the rules from Rocket; CI runs it, type check, tests against Postgres and the build; release builds lunch-app, tags and attaches the chart. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HUc2nv7rJVU2gp3Bgtha3q
This commit is contained in:
1 parent
14c0973ac6
commit
fa83e560b2
52 files changed
+6474
-3
No files matched your search
@@ -0,0 +1,107 @@
|
||||
name: ci
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches: [main]
|
||||
# Nachts alles auf main. Gestaffelt mit den anderen Apps auf dem einen
|
||||
# Runner (Relay 05:30, Rocket 06:00, Insilo 06:30 MESZ): Lunch 07:00 MESZ.
|
||||
# Der Cron ist UTC.
|
||||
schedule:
|
||||
- cron: "0 5 * * *"
|
||||
workflow_dispatch:
|
||||
|
||||
# Ein neuer Push in einen PR ersetzt seinen älteren Lauf.
|
||||
concurrency:
|
||||
group: ci-${{ github.head_ref || github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
chart:
|
||||
name: olares chart · sanity
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
# get.helm.sh ist vom Gitea-Runner nicht erreichbar: Helm liegt als
|
||||
# Release-Anhang in aimighty/ci-tools, get.helm.sh bleibt Rückfall.
|
||||
- name: install helm 3.16.2
|
||||
run: |
|
||||
for url in \
|
||||
"https://git.aimighty.olares.de/aimighty/ci-tools/releases/download/helm-3.16.2/helm-v3.16.2-linux-amd64.tar.gz" \
|
||||
"https://get.helm.sh/helm-v3.16.2-linux-amd64.tar.gz"; do
|
||||
echo "hole $url"
|
||||
if curl -fsSL --retry 3 --retry-all-errors --max-time 180 -o /tmp/helm.tgz "$url" \
|
||||
&& tar -tzf /tmp/helm.tgz >/dev/null 2>&1; then
|
||||
break
|
||||
fi
|
||||
done
|
||||
tar -C /tmp -xzf /tmp/helm.tgz
|
||||
install -m 0755 /tmp/linux-amd64/helm /usr/local/bin/helm
|
||||
helm version --short
|
||||
|
||||
- name: codified Olares lessons (scripts/check-chart.sh)
|
||||
run: bash scripts/check-chart.sh
|
||||
|
||||
app:
|
||||
name: app · types + tests + build
|
||||
runs-on: ubuntu-latest
|
||||
services:
|
||||
postgres:
|
||||
image: postgres:16
|
||||
env:
|
||||
POSTGRES_PASSWORD: postgres
|
||||
# Kein ports: — auf Gitea läuft der Job in einem Container neben dem
|
||||
# Dienst und erreicht ihn über dessen Namen (Muster aimighty/rocket).
|
||||
options: >-
|
||||
--health-cmd "pg_isready -U postgres"
|
||||
--health-interval 5s
|
||||
--health-timeout 5s
|
||||
--health-retries 10
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: database host
|
||||
run: |
|
||||
if getent hosts postgres >/dev/null 2>&1; then H=postgres; else H=localhost; fi
|
||||
echo "PGHOST=$H" >> "$GITHUB_ENV"
|
||||
echo "DB_HOST=$H" >> "$GITHUB_ENV"
|
||||
echo "TEST_DATABASE_URL=postgres://lunch:lunch_dev_only@$H/lunch" >> "$GITHUB_ENV"
|
||||
echo "Datenbank unter $H"
|
||||
|
||||
- name: psql
|
||||
run: |
|
||||
command -v psql >/dev/null && { psql --version; exit 0; }
|
||||
SUDO=""; [ "$(id -u)" != "0" ] && command -v sudo >/dev/null && SUDO="sudo"
|
||||
$SUDO apt-get update -qq
|
||||
$SUDO env DEBIAN_FRONTEND=noninteractive apt-get install -y -qq postgresql-client
|
||||
psql --version
|
||||
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: "22"
|
||||
cache: "npm"
|
||||
|
||||
- name: install
|
||||
run: npm ci
|
||||
|
||||
- name: type-check
|
||||
run: npm run type-check
|
||||
|
||||
# Wie auf der Box: Die Migrationen laufen mit der Rolle der App, die
|
||||
# dadurch Eigentümerin der Tabellen wird — kein Superuser. Nur so prüft
|
||||
# der Test mit zwei Haushalten, dass FORCE ROW LEVEL SECURITY greift.
|
||||
- name: database and migrations
|
||||
run: |
|
||||
PGPASSWORD=postgres psql -U postgres -c "create role lunch login password 'lunch_dev_only';"
|
||||
PGPASSWORD=postgres psql -U postgres -c "create database lunch owner lunch;"
|
||||
DATABASE_URL="$TEST_DATABASE_URL" MIGRATE_ATTEMPTS=3 npm run migrate
|
||||
# Ein zweiter Lauf darf nichts tun.
|
||||
DATABASE_URL="$TEST_DATABASE_URL" MIGRATE_ATTEMPTS=3 npm run migrate
|
||||
|
||||
- name: unit and database tests
|
||||
run: npm test
|
||||
|
||||
- name: build
|
||||
run: npm run build
|
||||
env:
|
||||
NEXT_TELEMETRY_DISABLED: "1"
|
||||
@@ -0,0 +1,276 @@
|
||||
name: release
|
||||
|
||||
# Baut das Abbild und legt es unter
|
||||
# git.aimighty.olares.de/aimighty/lunch-app:<version> ab (Gitea-Registry,
|
||||
# Organisation aimighty, öffentlich: Die Box zieht ohne Anmeldung). Dazu das
|
||||
# gepackte Chart als Anhang am Release — die Datei, die in den Markt geht.
|
||||
# Vorbild: aimighty/rocket .github/workflows/release.yml.
|
||||
#
|
||||
# Auslöser:
|
||||
# - **Merge nach main mit neuer Version** in olares/Chart.yaml: bauen, danach
|
||||
# Tag `v<version>` samt Release über die Gitea-API — erst nach
|
||||
# erfolgreichem Bau. Gibt es den Tag schon, passiert nichts.
|
||||
# - **PR**, der Dockerfile, Abhängigkeiten oder diesen Workflow ändert: Chart
|
||||
# prüfen und packen, Abbild bauen, nichts hochladen.
|
||||
# - **Run workflow** mit Version: bauen und hochladen, ohne Tag.
|
||||
#
|
||||
# Kein Auslöser auf Tags: Tags setzt nur dieser Workflow selbst.
|
||||
# Gitea-Besonderheiten: ein Runner; Helm aus aimighty/ci-tools; der
|
||||
# Docker-Daemon sitzt hinter dem Bridge-Gateway; gebaut wird nur amd64.
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
paths:
|
||||
- Dockerfile
|
||||
- package-lock.json
|
||||
- .github/workflows/release.yml
|
||||
push:
|
||||
branches: [main]
|
||||
# Auch der Workflow selbst: Wer ihn ändert, soll sehen, dass er läuft
|
||||
# — und eine noch nicht getaggte Version wird dabei veröffentlicht.
|
||||
paths: [olares/Chart.yaml, .github/workflows/release.yml]
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
version:
|
||||
description: "Image tag without leading v (e.g. 26.10.26); empty = olares/Chart.yaml"
|
||||
required: false
|
||||
|
||||
# Die Probe eines PR: nur sein neuester Push zählt. Ein Release auf main
|
||||
# bekommt eine eigene Gruppe (run_id) und wird nie abgebrochen (Kai,
|
||||
# 14.10.2026).
|
||||
concurrency:
|
||||
group: release-${{ github.head_ref || github.run_id }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
version:
|
||||
name: which version
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
version: ${{ steps.v.outputs.version }}
|
||||
proceed: ${{ steps.v.outputs.proceed }}
|
||||
push: ${{ steps.v.outputs.push }}
|
||||
create_tag: ${{ steps.v.outputs.create_tag }}
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0 # die Tags gehören zur Entscheidung
|
||||
|
||||
- id: v
|
||||
run: |
|
||||
CHART_VERSION="$(grep -E '^version:' olares/Chart.yaml | head -1 | awk '{print $2}' | tr -d '"')"
|
||||
PROCEED=true; PUSH=true; CREATE=false
|
||||
if [ "${{ github.event_name }}" = "pull_request" ]; then
|
||||
V="$CHART_VERSION"; PUSH=false
|
||||
echo "### PR: Chart $V prüfen und packen, Abbilder bauen ohne Hochladen" >> "$GITHUB_STEP_SUMMARY"
|
||||
elif [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
|
||||
V="${{ inputs.version }}"; [ -n "$V" ] || V="$CHART_VERSION"
|
||||
else
|
||||
V="$CHART_VERSION"
|
||||
if git rev-parse -q --verify "refs/tags/v$V" >/dev/null; then
|
||||
PROCEED=false
|
||||
echo "### v$V ist schon getaggt — kein Release" >> "$GITHUB_STEP_SUMMARY"
|
||||
else
|
||||
CREATE=true
|
||||
echo "### Neue Version $V — bauen, dann v$V taggen" >> "$GITHUB_STEP_SUMMARY"
|
||||
fi
|
||||
fi
|
||||
echo "version=$V" >> "$GITHUB_OUTPUT"
|
||||
echo "proceed=$PROCEED" >> "$GITHUB_OUTPUT"
|
||||
echo "push=$PUSH" >> "$GITHUB_OUTPUT"
|
||||
echo "create_tag=$CREATE" >> "$GITHUB_OUTPUT"
|
||||
echo "version=$V proceed=$PROCEED push=$PUSH create_tag=$CREATE"
|
||||
|
||||
preflight:
|
||||
name: olares chart · sanity
|
||||
needs: version
|
||||
if: needs.version.outputs.proceed == 'true'
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
build_images: ${{ steps.decide.outputs.build_images }}
|
||||
env:
|
||||
VERSION: ${{ needs.version.outputs.version }}
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
# get.helm.sh ist vom Gitea-Runner nicht erreichbar: Helm liegt als
|
||||
# Release-Anhang in aimighty/ci-tools, get.helm.sh bleibt Rückfall.
|
||||
- name: install helm 3.16.2
|
||||
run: |
|
||||
for url in \
|
||||
"https://git.aimighty.olares.de/aimighty/ci-tools/releases/download/helm-3.16.2/helm-v3.16.2-linux-amd64.tar.gz" \
|
||||
"https://get.helm.sh/helm-v3.16.2-linux-amd64.tar.gz"; do
|
||||
echo "hole $url"
|
||||
if curl -fsSL --retry 3 --retry-all-errors --max-time 180 -o /tmp/helm.tgz "$url" \
|
||||
&& tar -tzf /tmp/helm.tgz >/dev/null 2>&1; then
|
||||
break
|
||||
fi
|
||||
done
|
||||
tar -C /tmp -xzf /tmp/helm.tgz
|
||||
install -m 0755 /tmp/linux-amd64/helm /usr/local/bin/helm
|
||||
helm version --short
|
||||
|
||||
- name: codified Olares lessons (scripts/check-chart.sh)
|
||||
run: bash scripts/check-chart.sh
|
||||
|
||||
- name: chart version must match the version to release
|
||||
if: github.event_name == 'push'
|
||||
run: |
|
||||
CHART_VERSION="$(grep -E '^version:' olares/Chart.yaml | head -1 | awk '{print $2}' | tr -d '"')"
|
||||
if [ "$VERSION" != "$CHART_VERSION" ]; then
|
||||
echo "::error::version $VERSION does not match olares/Chart.yaml version $CHART_VERSION"
|
||||
exit 1
|
||||
fi
|
||||
echo "version $VERSION matches the chart"
|
||||
|
||||
# Ein leerer Tag in values.yaml heißt „folgt Chart.AppVersion" — der
|
||||
# Normalfall, das Chart referenziert dann genau diesen Tag. Ein
|
||||
# gesetzter Tag ist ein Pin auf eine Vorversion: Die Abbilder gibt es
|
||||
# schon, nichts bauen.
|
||||
- name: are images needed for this version?
|
||||
id: decide
|
||||
run: |
|
||||
BUILD=true
|
||||
PINS="$(grep -E "^[[:space:]]+tag:" olares/values.yaml | grep -vE 'tag:[[:space:]]*(""|'"''"')[[:space:]]*$' || true)"
|
||||
if [ -n "$PINS" ] \
|
||||
&& ! grep -qE "^[[:space:]]+tag:[[:space:]]*[\"']?${VERSION}[\"']?[[:space:]]*$" olares/values.yaml; then
|
||||
BUILD=false
|
||||
fi
|
||||
echo "build_images=$BUILD" >> "$GITHUB_OUTPUT"
|
||||
if [ "$BUILD" = "true" ]; then
|
||||
echo "### Abbilder werden gebaut ($VERSION)" >> "$GITHUB_STEP_SUMMARY"
|
||||
else
|
||||
echo "### Abbild-Bau übersprungen — values.yaml pinnt eine Vorversion" >> "$GITHUB_STEP_SUMMARY"
|
||||
fi
|
||||
|
||||
- name: package chart
|
||||
run: |
|
||||
mkdir -p dist
|
||||
helm package olares -d dist
|
||||
ls -la dist
|
||||
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: chart
|
||||
path: dist/*.tgz
|
||||
if-no-files-found: error
|
||||
|
||||
build:
|
||||
name: ${{ matrix.service }}
|
||||
needs: [version, preflight]
|
||||
if: needs.preflight.outputs.build_images == 'true' || github.event_name == 'workflow_dispatch'
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
strategy:
|
||||
fail-fast: false
|
||||
# Ein Runner, ein Daemon: nacheinander.
|
||||
max-parallel: 1
|
||||
matrix:
|
||||
include:
|
||||
- service: app
|
||||
context: .
|
||||
dockerfile: ./Dockerfile
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
# Der Docker-Daemon des Runners ist ein dind-InitContainer im
|
||||
# Runner-Pod (privileged, :2375). Aus dem Job-Container erreicht man
|
||||
# weder den Socket noch 127.0.0.1, nur das Bridge-Gateway des
|
||||
# Job-Netzes (aimighty/insilo UEBERGABE.md). `ip` fehlt im
|
||||
# act-Container: das Gateway steht in /proc/net/route.
|
||||
- name: find the runner's Docker daemon (dind at the bridge gateway)
|
||||
run: |
|
||||
read -r _ dest gw _ < <(awk '$2=="00000000" {print; exit}' /proc/net/route)
|
||||
GW="$(printf "%d.%d.%d.%d" 0x${gw:6:2} 0x${gw:4:2} 0x${gw:2:2} 0x${gw:0:2})"
|
||||
ok=0
|
||||
for KANDIDAT in "$GW" "172.17.0.1"; do
|
||||
[ -n "$KANDIDAT" ] || continue
|
||||
if DOCKER_HOST="tcp://$KANDIDAT:2375" docker version >/dev/null 2>&1; then
|
||||
echo "DOCKER_HOST=tcp://$KANDIDAT:2375" >> "$GITHUB_ENV"
|
||||
echo "Daemon erreichbar unter tcp://$KANDIDAT:2375"
|
||||
ok=1
|
||||
break
|
||||
fi
|
||||
done
|
||||
[ "$ok" = "1" ] || { echo "::error::kein Docker-Daemon am Bridge-Gateway gefunden"; exit 1; }
|
||||
|
||||
- uses: docker/setup-buildx-action@v3
|
||||
|
||||
# REGISTRY_TOKEN (Organisations-Geheimnis in aimighty): ein Gitea-Token
|
||||
# mit package Lesen und Schreiben eines Kontos, das in der Organisation
|
||||
# Pakete anlegen darf.
|
||||
- name: Log in to the Gitea registry
|
||||
if: needs.version.outputs.push == 'true'
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: git.aimighty.olares.de
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.REGISTRY_TOKEN }}
|
||||
|
||||
# Nur amd64 — das Manifest verspricht auch nur das. Ein Next.js-Bau
|
||||
# unter QEMU für arm64 dauert eine halbe Stunde, und keine Box, die
|
||||
# diese App bekommt, ist eine ARM-Maschine.
|
||||
- name: Build (and push)
|
||||
uses: docker/build-push-action@v6
|
||||
with:
|
||||
context: ${{ matrix.context }}
|
||||
file: ${{ matrix.dockerfile }}
|
||||
platforms: linux/amd64
|
||||
push: ${{ needs.version.outputs.push == 'true' }}
|
||||
tags: |
|
||||
git.aimighty.olares.de/aimighty/lunch-${{ matrix.service }}:${{ needs.version.outputs.version }}
|
||||
git.aimighty.olares.de/aimighty/lunch-${{ matrix.service }}:latest
|
||||
|
||||
# Erst wenn das Abbild draußen ist: Tag und Release, mit dem Chart
|
||||
# als Anhang — dieselbe Datei, die in den Markt geht.
|
||||
release:
|
||||
name: tag and release
|
||||
needs: [version, preflight, build]
|
||||
# Gitea meldet einen übersprungenen Job nicht verlässlich als „skipped":
|
||||
# laufen, sobald ein Tag fällig ist, und das Ergebnis selbst prüfen.
|
||||
if: always() && needs.version.outputs.create_tag == 'true'
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
VERSION: ${{ needs.version.outputs.version }}
|
||||
GITEA_API: https://git.aimighty.olares.de/api/v1
|
||||
steps:
|
||||
- name: chart and images ready?
|
||||
env:
|
||||
PREFLIGHT: ${{ needs.preflight.result }}
|
||||
BUILD: ${{ needs.build.result }}
|
||||
BUILD_IMAGES: ${{ needs.preflight.outputs.build_images }}
|
||||
run: |
|
||||
echo "preflight '$PREFLIGHT', build '$BUILD', build_images '$BUILD_IMAGES'"
|
||||
[ "$PREFLIGHT" = "success" ] || { echo "::error::Chart nicht geprüft ($PREFLIGHT) — kein Tag, kein Release"; exit 1; }
|
||||
if [ "$BUILD_IMAGES" = "true" ]; then
|
||||
[ "$BUILD" = "success" ] || { echo "::error::Abbilder nicht gebaut ($BUILD) — kein Tag, kein Release"; exit 1; }
|
||||
else
|
||||
# Release nur mit Chart: ein absichtlich übersprungener Bau ist in
|
||||
# Ordnung, ein gescheiterter oder abgebrochener nicht.
|
||||
case "$BUILD" in failure|cancelled) echo "::error::Bau $BUILD"; exit 1 ;; esac
|
||||
fi
|
||||
|
||||
- uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: chart
|
||||
path: dist
|
||||
|
||||
- name: create tag and release (Gitea API)
|
||||
env:
|
||||
GITEA_TOKEN: ${{ secrets.MARKT_TOKEN }}
|
||||
run: |
|
||||
[ -n "$GITEA_TOKEN" ] || { echo "::error::Geheimnis MARKT_TOKEN fehlt"; exit 1; }
|
||||
NOTES="Lunch $VERSION — Abbild git.aimighty.olares.de/aimighty/lunch-app:$VERSION, Chart im Anhang. Automatisch nach dem Merge angelegt."
|
||||
BODY=$(python3 -c 'import json,sys; print(json.dumps({"tag_name":"v"+sys.argv[1],"target_commitish":sys.argv[2],"name":"v"+sys.argv[1],"body":sys.argv[3]}))' "$VERSION" "${{ github.sha }}" "$NOTES")
|
||||
RESP=$(curl -sS -X POST -H "Authorization: token $GITEA_TOKEN" -H "Content-Type: application/json" \
|
||||
"$GITEA_API/repos/$GITHUB_REPOSITORY/releases" -d "$BODY")
|
||||
RID=$(printf '%s' "$RESP" | python3 -c "import sys,json; print(json.load(sys.stdin).get('id') or '')")
|
||||
[ -n "$RID" ] || { echo "::error::Release-Anlage fehlgeschlagen"; printf '%s\n' "$RESP" | head -c 300; exit 1; }
|
||||
curl -fsS -X POST -H "Authorization: token $GITEA_TOKEN" -F "attachment=@dist/lunch-$VERSION.tgz" \
|
||||
"$GITEA_API/repos/$GITHUB_REPOSITORY/releases/$RID/assets?name=lunch-$VERSION.tgz" > /dev/null
|
||||
echo "Tag und Release v$VERSION angelegt"
|
||||
echo "### Tag und Release v$VERSION angelegt" >> "${GITHUB_STEP_SUMMARY:-/dev/null}"
|
||||
|
||||
# Der Markt-Eintrag (markt.yml) kommt mit der eigenen Anmeldung; erst
|
||||
# dann geht Lunch in den Markt (docs/PROJEKTSTART.md).
|
||||
Reference in new issue
Block a user