feat: bootstrap solution, Docker image and Gitea pipelines (M0)
CI / Build and test (SQLite) (pull_request) Successful in 43s
CI / PostgreSQL 16 integration (pull_request) Skipped
CI / PostgreSQL 17 integration (pull_request) Skipped
CI / YAML check (pull_request) Successful in 15s
CI / Docker image (pull_request) Successful in 59s

Start development with the skeleton every later milestone builds on, so
that code, image and release path exist and are verified from day one.

- Khaemhat.sln with the ten projects of SPEC section 3 and six MSTest
  projects; shared build rules with warnings as errors, analyzers and
  Central Package Management restricted to the allowlist.
- Architecture tests and scripts/check-packages.sh fail on any project
  reference or package that SPEC does not allow.
- Khaemhat.Web serves an Italian "under construction" page with the
  official icons and version, plus /health/live, /health/ready and
  /health (ADR 0012); honours KHAEMHAT_URLS and KHAEMHAT_LOG_LEVEL.
- docker/Dockerfile (non-root app user aligned to PUID/PGID by the
  entrypoint, pg_dump 17, healthcheck, OCI and Unraid labels) and
  compose files for PostgreSQL and a standalone SQLite demo.
- Gitea Actions: ci.yml (build, tests, image smoke test, PostgreSQL
  16/17 on tags, YAML check), release.yml (image and release from a
  vX.Y.Z tag, skipping versions already published) and wiki.yml.
- Development scripts, VS Code launch/tasks for debugging, and ADR
  0012-0017 deciding the M0 open points of docs/STATUS.md.

Closes #1, #2, #3, #4, #5, #114

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-11 11:53:39 +01:00
1 parent 88de272b3e
commit 12277733f5
101 files changed
+3245 -67

No files matched your search

+180
View File
@@ -0,0 +1,180 @@
name: CI
# Gitea Actions (ADR 0009). The runner is act_runner in Docker mode on the server that also runs Gitea: one job at a
# time, so the triggers are frugal. The .NET jobs use the SDK image and check out with git (the image has no Node.js
# for JavaScript actions); nothing is cached or uploaded. Builds use BUILD_CPUS cores so the host keeps room for Gitea.
on:
pull_request:
branches: [main]
push:
branches: [main]
tags: ["v*"]
paths-ignore: ["docs/**", "*.md", "assets/**", "deploy/**"]
workflow_dispatch:
concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true
env:
DOTNET_NOLOGO: "1"
DOTNET_CLI_TELEMETRY_OPTOUT: "1"
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: "1"
BUILD_CPUS: "4"
KHAEMHAT_LICENSE_MODE: test
jobs:
build:
name: Build and test (SQLite)
runs-on: ubuntu-latest
container:
image: mcr.microsoft.com/dotnet/sdk:10.0
timeout-minutes: 30
defaults:
run:
shell: bash
steps:
- name: Checkout
env:
TOKEN: ${{ github.token }}
run: |
git config --global --add safe.directory "$PWD"
git init -q .
git remote add origin "${{ github.server_url }}/${{ github.repository }}.git"
git -c http.extraheader="Authorization: basic $(printf 'x-access-token:%s' "$TOKEN" | base64 -w0)" fetch -q --depth=1 origin "${{ github.sha }}"
git checkout -q FETCH_HEAD
git log -1 --format='%h %s'
- name: Package allowlist
run: bash scripts/check-packages.sh
- name: Build (warnings are errors)
run: dotnet build Khaemhat.sln -c Release -warnaserror -m:"$BUILD_CPUS"
- name: Test
run: dotnet test Khaemhat.sln -c Release --no-build
# PostgreSQL integration (SPEC §20): only on release tags and manual runs, against the two supported servers.
postgres:
name: PostgreSQL ${{ matrix.pg }} integration
needs: build
if: startsWith(github.ref, 'refs/tags/v') || github.event_name == 'workflow_dispatch'
strategy:
fail-fast: false
matrix:
pg: ["16", "17"]
runs-on: ubuntu-latest
container:
image: mcr.microsoft.com/dotnet/sdk:10.0
timeout-minutes: 30
services:
postgres:
image: postgres:${{ matrix.pg }}
env:
POSTGRES_USER: khaemhat
POSTGRES_PASSWORD: khaemhat-ci
POSTGRES_DB: khaemhat_test
defaults:
run:
shell: bash
env:
KHAEMHAT_TEST_PG: postgres://khaemhat:khaemhat-ci@postgres:5432/khaemhat_test
steps:
- name: Checkout
env:
TOKEN: ${{ github.token }}
run: |
git config --global --add safe.directory "$PWD"
git init -q .
git remote add origin "${{ github.server_url }}/${{ github.repository }}.git"
git -c http.extraheader="Authorization: basic $(printf 'x-access-token:%s' "$TOKEN" | base64 -w0)" fetch -q --depth=1 origin "${{ github.sha }}"
git checkout -q FETCH_HEAD
- name: Test · Data (PostgreSQL)
run: dotnet test tests/Khaemhat.Data.Tests -c Release -m:"$BUILD_CPUS"
# The image builds and answers /health/live (issue #2). The runner's own image has the docker CLI and talks to the
# host's daemon; the job joins a network of its own to reach the container. Everything is labelled with the job
# container's id: a cancelled job skips its clean-up, so the next one removes what a vanished job left on the host.
# Release tags skip it: release.yml builds and tests the same image.
docker:
name: Docker image
needs: build
if: "!startsWith(github.ref, 'refs/tags/')"
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Remove what cancelled jobs left
run: |
echo "NAME=khaemhat-ci-$(hostname)" >> "$GITHUB_ENV"
for c in $(docker ps -aq --filter label=khaemhat-ci.job); do
job="$(docker inspect -f '{{index .Config.Labels "khaemhat-ci.job"}}' "$c")"
docker inspect "$job" > /dev/null 2>&1 || docker rm -f -v "$c"
done
for n in $(docker network ls -q --filter label=khaemhat-ci.job); do
job="$(docker network inspect -f '{{index .Labels "khaemhat-ci.job"}}' "$n")"
docker inspect "$job" > /dev/null 2>&1 || docker network rm "$n"
done
for i in $(docker image ls -q --filter label=khaemhat-ci.job | sort -u); do
job="$(docker image inspect -f '{{index .Config.Labels "khaemhat-ci.job"}}' "$i")"
docker inspect "$job" > /dev/null 2>&1 || docker image rm -f "$i"
done
- name: Checkout
env:
TOKEN: ${{ github.token }}
run: |
git config --global --add safe.directory "$PWD"
git init -q .
git remote add origin "${{ github.server_url }}/${{ github.repository }}.git"
git -c http.extraheader="Authorization: basic $(printf 'x-access-token:%s' "$TOKEN" | base64 -w0)" fetch -q --depth=1 origin "${{ github.sha }}"
git checkout -q FETCH_HEAD
- name: Build image
run: |
docker build -f docker/Dockerfile --build-arg VERSION=0.0.0-ci --build-arg GIT_SHA="$(git rev-parse --short HEAD)" \
--label khaemhat-ci.job="$(hostname)" -t "$NAME:image" .
- name: Smoke test (/health/live, non-root user, PUID/PGID)
run: |
docker network create --label khaemhat-ci.job="$(hostname)" "$NAME"
docker network connect "$NAME" "$(hostname)"
docker run -d --name "$NAME-app" --network "$NAME" --label khaemhat-ci.job="$(hostname)" \
-e KHAEMHAT_SYSTEM_DB=sqlite:///data/system.db -e KHAEMHAT_LICENSE_MODE=test -e PUID=99 -e PGID=100 "$NAME:image"
for i in $(seq 1 30); do
if curl -fsS --max-time 5 "http://$NAME-app:8080/health/live"; then echo; break; fi
sleep 2
done
curl -fsS --max-time 5 "http://$NAME-app:8080/health"
echo
curl -fsS --max-time 5 "http://$NAME-app:8080/" | grep -q "in costruzione"
test "$(docker exec "$NAME-app" sh -c 'stat -c %u:%g /proc/1')" = "99:100"
test "$(docker exec "$NAME-app" stat -c %u:%g /data)" = "99:100"
docker exec "$NAME-app" pg_dump --version
- name: Container logs and clean-up
if: always()
run: |
docker logs "$NAME-app" || true
docker rm -f -v "$NAME-app" || true
docker network disconnect "$NAME" "$(hostname)" || true
docker network rm "$NAME" || true
docker image rm "$NAME:image" || true
# Gitea fails a workflow that does not parse. The Ruby image has no git: the sources come as an archive.
yaml:
name: YAML check
runs-on: ubuntu-latest
container:
image: ruby:3.3-alpine
timeout-minutes: 10
steps:
- name: Workflows and compose files
env:
TOKEN: ${{ github.token }}
run: |
wget -q --header "Authorization: token $TOKEN" -O /tmp/sources.tar.gz \
"${{ github.server_url }}/api/v1/repos/${{ github.repository }}/archive/${{ github.sha }}.tar.gz"
mkdir -p /tmp/sources && tar -xzf /tmp/sources.tar.gz -C /tmp/sources
cd /tmp/sources/*/
ruby .gitea/scripts/check-yaml.rb .gitea/workflows/*.yml deploy/*.yml
+184
View File
@@ -0,0 +1,184 @@
name: Release
# A tag vX.Y.Z[-pre] publishes the image gitea.encke-hake.ts.net/balbosoft/khaemhat:X.Y.Z (ADR 0009, 0010, 0015) and a
# Gitea release whose notes are the CHANGELOG.md section of that version (no binaries). When the version is already
# in the registry (published by scripts/publish-image.sh) the build is skipped and only the release is created.
# The runner's own image has the docker CLI and builds with the host's daemon.
on:
push:
tags: ["v*"]
workflow_dispatch:
inputs:
tag:
description: "Tag esistente da (ri)pubblicare, es. v0.0.1"
required: true
arm64:
description: "Anche linux/arm64 (richiede QEMU e buildx sull'host)"
type: boolean
default: false
permissions:
contents: write
packages: write
env:
TAG: ${{ github.event.inputs.tag || github.ref_name }}
# Where people and programs reach Gitea (the runner itself uses github.server_url). Variable PUBLIC_URL overrides it.
PUBLIC_URL: ${{ vars.PUBLIC_URL || 'https://gitea.encke-hake.ts.net' }}
jobs:
release:
name: Image and release
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
- name: Remove what cancelled jobs left
run: |
echo "NAME=khaemhat-rel-$(hostname)" >> "$GITHUB_ENV"
for c in $(docker ps -aq --filter label=khaemhat-ci.job); do
job="$(docker inspect -f '{{index .Config.Labels "khaemhat-ci.job"}}' "$c")"
docker inspect "$job" > /dev/null 2>&1 || docker rm -f -v "$c"
done
for n in $(docker network ls -q --filter label=khaemhat-ci.job); do
job="$(docker network inspect -f '{{index .Labels "khaemhat-ci.job"}}' "$n")"
docker inspect "$job" > /dev/null 2>&1 || docker network rm "$n"
done
- name: Version
run: |
case "$TAG" in
v[0-9]*.[0-9]*.[0-9]*) ;;
*) echo "::error title=Tag::$TAG is not vX.Y.Z[-pre]"; exit 1 ;;
esac
version="${TAG#v}"
prerelease=false
case "$version" in *-*) prerelease=true ;; esac
major_minor="${version%%-*}"
major_minor="${major_minor%.*}"
owner="$(printf '%s' "${{ github.repository_owner }}" | tr '[:upper:]' '[:lower:]')"
registry="${{ vars.REGISTRY }}"
registry="${registry:-$(printf '%s' "$PUBLIC_URL" | sed -E 's#^[a-z]+://##; s#/.*$##')}"
{
echo "VERSION=$version"
echo "PRERELEASE=$prerelease"
echo "MAJOR_MINOR=$major_minor"
echo "REGISTRY_HOST=$registry"
echo "IMAGE=$registry/$owner/khaemhat"
} >> "$GITHUB_ENV"
echo "Tag $TAG -> image $registry/$owner/khaemhat:$version (prerelease: $prerelease)"
- name: Checkout
env:
TOKEN: ${{ github.token }}
run: |
git config --global --add safe.directory "$PWD"
git init -q .
git remote add origin "${{ github.server_url }}/${{ github.repository }}.git"
git -c http.extraheader="Authorization: basic $(printf 'x-access-token:%s' "$TOKEN" | base64 -w0)" fetch -q --depth=1 origin "refs/tags/$TAG:refs/tags/$TAG"
git checkout -q "refs/tags/$TAG"
echo "GIT_SHA=$(git rev-parse --short HEAD)" >> "$GITHUB_ENV"
- name: Sign in to the registry
env:
USER: ${{ vars.REGISTRY_USER || github.actor }}
TOKEN: ${{ secrets.REGISTRY_TOKEN }}
run: |
if [ -z "$TOKEN" ] || ! printf '%s' "$TOKEN" | docker login "$REGISTRY_HOST" -u "$USER" --password-stdin; then
echo "::error title=Registry::Sign-in to $REGISTRY_HOST refused. The organisation secret REGISTRY_TOKEN must be an access token with package read and write."
exit 1
fi
status="$(curl -s -o /dev/null -w '%{http_code}' -H "Authorization: token $TOKEN" \
"${{ github.server_url }}/api/v1/packages/${{ github.repository_owner }}/container/khaemhat/$VERSION")"
if [ "$status" = "200" ]; then
echo "Version $VERSION is already in the registry: build and push skipped (ADR 0015)."
echo "PUBLISHED=true" >> "$GITHUB_ENV"
else
echo "PUBLISHED=false" >> "$GITHUB_ENV"
fi
- name: Build image
if: env.PUBLISHED != 'true'
run: |
icon="$PUBLIC_URL/${{ github.repository }}/raw/branch/main/assets/icon-256.png"
if [ -f "assets/icon-v$MAJOR_MINOR-256.png" ]; then
icon="$PUBLIC_URL/${{ github.repository }}/raw/branch/main/assets/icon-v$MAJOR_MINOR-256.png"
fi
echo "ICON_URL=$icon" >> "$GITHUB_ENV"
docker build -f docker/Dockerfile \
--build-arg VERSION="$VERSION" \
--build-arg GIT_SHA="$GIT_SHA" \
--build-arg CREATED="$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
--build-arg SOURCE_URL="$PUBLIC_URL/${{ github.repository }}" \
--build-arg ICON_URL="$icon" \
--label khaemhat-ci.job="$(hostname)" \
-t "$IMAGE:$VERSION" .
- name: Smoke test (/health/live)
if: env.PUBLISHED != 'true'
run: |
docker network create --label khaemhat-ci.job="$(hostname)" "$NAME"
docker network connect "$NAME" "$(hostname)"
docker run -d --name "$NAME-app" --network "$NAME" --label khaemhat-ci.job="$(hostname)" \
-e KHAEMHAT_SYSTEM_DB=sqlite:///data/system.db -e KHAEMHAT_LICENSE_MODE=test "$IMAGE:$VERSION"
for i in $(seq 1 30); do
if curl -fsS --max-time 5 "http://$NAME-app:8080/health/live"; then echo; break; fi
sleep 2
done
report="$(curl -fsS --max-time 5 "http://$NAME-app:8080/health")"
echo "$report"
echo "$report" | grep -q "\"version\":\"$VERSION\""
- name: Push
if: env.PUBLISHED != 'true'
run: |
docker push "$IMAGE:$VERSION"
if [ "$PRERELEASE" != "true" ]; then
docker tag "$IMAGE:$VERSION" "$IMAGE:latest"
docker push "$IMAGE:latest"
fi
echo "Image: $IMAGE:$VERSION$([ "$PRERELEASE" != "true" ] && echo " and :latest")"
- name: Multi-architecture push (arm64)
if: env.PUBLISHED != 'true' && github.event.inputs.arm64 == 'true'
run: |
docker buildx build --platform linux/amd64,linux/arm64 -f docker/Dockerfile \
--build-arg VERSION="$VERSION" --build-arg GIT_SHA="$GIT_SHA" \
--build-arg SOURCE_URL="$PUBLIC_URL/${{ github.repository }}" --build-arg ICON_URL="$ICON_URL" \
-t "$IMAGE:$VERSION" --push .
# Notes: the "## [X.Y.Z]" section of CHANGELOG.md. The release is created or, when it exists, left as it is.
- name: Gitea release
env:
TOKEN: ${{ github.token }}
run: |
api="${{ github.server_url }}/api/v1/repos/${{ github.repository }}"
if curl -fs -o /dev/null -H "Authorization: token $TOKEN" "$api/releases/tags/$TAG"; then
echo "Release $TAG already exists."
exit 0
fi
awk -v v="$VERSION" '
index($0, "## [" v "]") == 1 { on = 1; next }
on && /^## \[/ { exit }
on { print }
' CHANGELOG.md > "$RUNNER_TEMP/notes.md"
if [ ! -s "$RUNNER_TEMP/notes.md" ]; then
echo "::warning title=Changelog::No section [$VERSION] in CHANGELOG.md"
echo "Vedi CHANGELOG.md." > "$RUNNER_TEMP/notes.md"
fi
printf '\nImmagine: `%s:%s`\n' "$IMAGE" "$VERSION" >> "$RUNNER_TEMP/notes.md"
body="$(awk 'BEGIN { ORS = "\\n" } { gsub(/\r/, ""); gsub(/\\/, "\\\\"); gsub(/"/, "\\\""); gsub(/\t/, "\\t"); print }' "$RUNNER_TEMP/notes.md")"
printf '{"tag_name":"%s","name":"Khaemhat %s","body":"%s","draft":false,"prerelease":%s}' \
"$TAG" "$VERSION" "$body" "$PRERELEASE" > "$RUNNER_TEMP/release.json"
curl -fsS -X POST -H "Authorization: token $TOKEN" -H "Content-Type: application/json" \
--data-binary "@$RUNNER_TEMP/release.json" "$api/releases" > /dev/null
echo "Release $TAG created."
- name: Clean up
if: always()
run: |
docker logs "$NAME-app" 2> /dev/null || true
docker rm -f -v "$NAME-app" 2> /dev/null || true
docker network disconnect "$NAME" "$(hostname)" 2> /dev/null || true
docker network rm "$NAME" 2> /dev/null || true
docker image rm "$IMAGE:$VERSION" "$IMAGE:latest" 2> /dev/null || true
docker logout "$REGISTRY_HOST" || true
+38
View File
@@ -0,0 +1,38 @@
name: Wiki
# docs/wiki/ is the source of the Gitea wiki (ADR 0009): every push to main that touches it publishes it with
# scripts/publish-wiki.sh, which makes Khaemhat.wiki.git an exact copy. The secret WIKI_TOKEN (an access token with
# repository write) overrides the workflow's own token if that one cannot push to the wiki.
on:
push:
branches: [main]
paths: ["docs/wiki/**"]
workflow_dispatch:
concurrency:
group: wiki
cancel-in-progress: false
jobs:
publish:
name: Publish the wiki
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout
env:
TOKEN: ${{ github.token }}
run: |
git config --global --add safe.directory "$PWD"
git init -q .
git remote add origin "${{ github.server_url }}/${{ github.repository }}.git"
git -c http.extraheader="Authorization: basic $(printf 'x-access-token:%s' "$TOKEN" | base64 -w0)" fetch -q --depth=1 origin "${{ github.sha }}"
git checkout -q FETCH_HEAD
- name: Publish docs/wiki
env:
GITEA_TOKEN: ${{ secrets.WIKI_TOKEN || github.token }}
WIKI_REMOTE: ${{ github.server_url }}/${{ github.repository }}.wiki.git
GIT_AUTHOR_NAME: Khaemhat CI
GIT_AUTHOR_EMAIL: ci@khaemhat.invalid
run: bash scripts/publish-wiki.sh