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

+64
View File
@@ -0,0 +1,64 @@
#!/usr/bin/env bash
# Builds the solution with warnings as errors (SPEC §19).
# scripts/build.sh [-c Debug|Release] build
# scripts/build.sh --icon [X.Y] also generate the versioned icon (ADR 0016); X.Y from the last tag
set -euo pipefail
root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$root"
configuration=Release
icon=""
while (( $# > 0 )); do
case "$1" in
-c | --configuration) configuration="${2:?manca la configurazione}"; shift 2 ;;
--icon)
if [[ "${2:-}" =~ ^[0-9]+\.[0-9]+$ ]]; then icon="$2"; shift 2; else icon="auto"; shift; fi ;;
-h | --help) sed -n '2,5p' "$0"; exit 0 ;;
*) echo "argomento sconosciuto: $1" >&2; exit 2 ;;
esac
done
# Generates assets/icon-v<X.Y>.svg from the template by string replacement, then the PNGs if a rasterizer exists.
generate_icon() {
local version="$1" svg png size tool=""
if [[ "$version" == "auto" ]]; then
version="$(git describe --tags --match 'v[0-9]*' --abbrev=0 2>/dev/null || true)"
[[ -n "$version" ]] || { echo "nessun tag vX.Y.Z: indica la versione, es. --icon 1.0" >&2; exit 2; }
version="${version#v}"
version="${version%.*}"
fi
svg="assets/icon-v${version}.svg"
if [[ "$version" != "1.0" ]]; then
sed "s/v 1\.0/v ${version}/" assets/icon-v1.0.svg > "$svg"
grep -q "v ${version}" "$svg" || { echo "il modello assets/icon-v1.0.svg non contiene il testo 'v 1.0'" >&2; exit 1; }
fi
echo "icona: $svg"
for candidate in rsvg-convert inkscape magick; do
if command -v "$candidate" > /dev/null 2>&1; then tool="$candidate"; break; fi
done
if [[ -z "$tool" ]]; then
echo "nessun rasterizzatore (rsvg-convert, inkscape, magick): genera i PNG su una macchina che ne ha uno (ADR 0016)." >&2
return 0
fi
for size in 128 256 512; do
png="assets/icon-v${version}-${size}.png"
case "$tool" in
rsvg-convert) rsvg-convert -w "$size" -h "$size" -o "$png" "$svg" ;;
inkscape) inkscape "$svg" --export-type=png --export-filename="$png" -w "$size" -h "$size" > /dev/null ;;
magick) magick -background none -density 384 "$svg" -resize "${size}x${size}" "$png" ;;
esac
echo "icona: $png ($tool)"
done
echo "Committa i file generati su main prima del tag che li usa (ADR 0016)."
}
bash scripts/check-packages.sh
dotnet build Khaemhat.sln -c "$configuration" -warnaserror
if [[ -n "$icon" ]]; then
generate_icon "$icon"
fi
+60
View File
@@ -0,0 +1,60 @@
#!/usr/bin/env bash
# Package allowlist (SPEC §1.2, ADR 0002). Fails when an MSBuild file references a package that is not allowed, or an
# allowed package outside its project. The architecture tests check the same rules; this script runs before any build
# (Dockerfile, CI) so a forbidden package never gets restored.
set -euo pipefail
root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$root"
# package -> where it may be referenced (a project file name, or "tests/" for any test project)
allowed_in() {
case "$1" in
Npgsql) echo "src/Khaemhat.Data.PostgreSql/Khaemhat.Data.PostgreSql.csproj" ;;
Microsoft.Data.Sqlite) echo "src/Khaemhat.Data.Sqlite/Khaemhat.Data.Sqlite.csproj" ;;
Microsoft.NET.Test.Sdk | MSTest) echo "tests/" ;;
*) echo "" ;;
esac
}
# Prints "<file> <package>" for each element of the given kind (PackageReference, PackageVersion).
references() {
local element="$1" file
while IFS= read -r file; do
file="${file#./}"
grep -oE "<${element}[[:space:]]+(Include|Update)=\"[^\"]+\"" "$file" \
| sed -E 's/.*="([^"]+)"/\1/' \
| while IFS= read -r package; do printf '%s %s\n' "$file" "$package"; done || true
done < <(find . \( -name bin -o -name obj -o -name .git -o -name .claude -o -name out \) -prune -o \
-type f \( -name '*.csproj' -o -name '*.props' -o -name '*.targets' \) -print | sort)
}
errors=0
checked=0
while read -r file package; do
checked=$((checked + 1))
where="$(allowed_in "$package")"
if [[ -z "$where" ]]; then
echo "ERRORE: $file: il pacchetto $package non è nell'allowlist (SPEC §1.2)." >&2
errors=$((errors + 1))
elif [[ "$where" == "tests/" && "$file" != tests/* ]]; then
echo "ERRORE: $file: $package è ammesso solo nei progetti di test." >&2
errors=$((errors + 1))
elif [[ "$where" != "tests/" && "$file" != "$where" ]]; then
echo "ERRORE: $file: $package è ammesso solo in $where." >&2
errors=$((errors + 1))
fi
done < <(references PackageReference)
while read -r file package; do
if [[ -z "$(allowed_in "$package")" ]]; then
echo "ERRORE: $file: versione centrale per $package, che non è nell'allowlist." >&2
errors=$((errors + 1))
fi
done < <(references PackageVersion)
if (( errors > 0 )); then
echo "check-packages: $errors violazioni." >&2
exit 1
fi
echo "check-packages: OK ($checked riferimenti a pacchetti, tutti ammessi)."
+9
View File
@@ -0,0 +1,9 @@
#!/usr/bin/env bash
# Regenerates docs/DATA-MODEL.md from the entity maps (SPEC §18).
# scripts/gen-datamodel.sh
# Stub: completed in milestone M1 (SPEC §20). Until then it explains what it will do and exits with an error.
set -euo pipefail
echo "gen-datamodel.sh: non ancora disponibile, arriva con la milestone M1." >&2
echo "Uso previsto: scripts/gen-datamodel.sh" >&2
exit 1
+9
View File
@@ -0,0 +1,9 @@
#!/usr/bin/env bash
# Creates a new numbered migration for the system or company schema (SPEC §5.3).
# scripts/new-migration.sh <system|company> <descrizione-breve>
# Stub: completed in milestone M1 (SPEC §20). Until then it explains what it will do and exits with an error.
set -euo pipefail
echo "new-migration.sh: non ancora disponibile, arriva con la milestone M1." >&2
echo "Uso previsto: scripts/new-migration.sh <system|company> <descrizione-breve>" >&2
exit 1
+70
View File
@@ -0,0 +1,70 @@
#!/usr/bin/env bash
# Builds the image on this machine and pushes it to the Gitea package registry (ADR 0009, ADR 0015). The normal path
# is release.yml on a vX.Y.Z tag; use this when the runner is not available. It does NOT create git tags: pushing the
# tag later makes release.yml find the version in the registry and only create the release.
#
# scripts/publish-image.sh vX.Y.Z [--arm64] [--force]
#
# Environment: GITEA_TOKEN (required, scope write:package), GITEA_URL (https://gitea.encke-hake.ts.net),
# GITEA_OWNER (BalboSoft), GITEA_USER (login of the token owner; defaults to GITEA_OWNER).
set -euo pipefail
root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$root"
tag="${1:-}"
[[ "$tag" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.]+)?$ ]] || { echo "uso: publish-image.sh vX.Y.Z [--arm64] [--force]" >&2; exit 2; }
shift
platforms="linux/amd64"
force=false
for arg in "$@"; do
case "$arg" in
--arm64) platforms="linux/amd64,linux/arm64" ;;
--force) force=true ;;
*) echo "argomento sconosciuto: $arg" >&2; exit 2 ;;
esac
done
gitea_url="${GITEA_URL:-https://gitea.encke-hake.ts.net}"
gitea_url="${gitea_url%/}"
registry="${gitea_url#https://}"
registry="${registry#http://}"
owner="${GITEA_OWNER:-BalboSoft}"
owner_lc="$(printf '%s' "$owner" | tr '[:upper:]' '[:lower:]')"
image="$registry/$owner_lc/khaemhat"
version="${tag#v}"
sha="$(git rev-parse --short HEAD)"
token="${GITEA_TOKEN:?imposta GITEA_TOKEN (permesso write:package)}"
if [[ -n "$(git status --porcelain)" ]]; then
echo "ATTENZIONE: ci sono modifiche non committate; l'immagine riporterà lo SHA $sha." >&2
fi
status="$(curl -s -o /dev/null -w '%{http_code}' -H "Authorization: token $token" \
"$gitea_url/api/v1/packages/$owner/container/khaemhat/$version")"
if [[ "$status" == "200" && "$force" != true ]]; then
echo "La versione $version è già nel registro: niente da fare (usa --force per sovrascriverla)." >&2
exit 1
fi
# Versioned icon for Unraid if committed, otherwise the plain one (ADR 0016).
major_minor="${version%%-*}"
major_minor="${major_minor%.*}"
icon_url="$gitea_url/$owner/Khaemhat/raw/branch/main/assets/icon-256.png"
if git cat-file -e "origin/main:assets/icon-v${major_minor}-256.png" 2>/dev/null; then
icon_url="$gitea_url/$owner/Khaemhat/raw/branch/main/assets/icon-v${major_minor}-256.png"
fi
tags=(-t "$image:$version")
[[ "$version" == *-* ]] || tags+=(-t "$image:latest")
printf '%s' "$token" | docker login "$registry" -u "${GITEA_USER:-$owner}" --password-stdin
docker buildx build --platform "$platforms" -f docker/Dockerfile \
--build-arg VERSION="$version" \
--build-arg GIT_SHA="$sha" \
--build-arg CREATED="$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
--build-arg SOURCE_URL="$gitea_url/$owner/Khaemhat" \
--build-arg ICON_URL="$icon_url" \
"${tags[@]}" --push .
echo "Pubblicata $image:$version ($platforms)."
+37
View File
@@ -0,0 +1,37 @@
#!/usr/bin/env bash
# Publishes docs/wiki/ to the Gitea wiki (Khaemhat.wiki.git), the same job as .gitea/workflows/wiki.yml.
# The wiki becomes an exact copy of docs/wiki/: pages removed here are removed there.
#
# Environment: GITEA_URL (https://gitea.encke-hake.ts.net), GITEA_OWNER (BalboSoft); GITEA_TOKEN is optional (without
# it git uses the credentials already configured on this machine). WIKI_REMOTE overrides the whole URL.
set -euo pipefail
root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$root"
gitea_url="${GITEA_URL:-https://gitea.encke-hake.ts.net}"
remote="${WIKI_REMOTE:-${gitea_url%/}/${GITEA_OWNER:-BalboSoft}/Khaemhat.wiki.git}"
sha="$(git rev-parse --short HEAD)"
auth=()
if [[ -n "${GITEA_TOKEN:-}" ]]; then
auth=(-c "http.extraheader=Authorization: basic $(printf 'x-access-token:%s' "$GITEA_TOKEN" | base64 -w0)")
fi
work="$(mktemp -d)"
trap 'rm -rf "$work"' EXIT
git "${auth[@]}" clone -q --depth 1 "$remote" "$work/wiki"
find "$work/wiki" -mindepth 1 -maxdepth 1 ! -name .git -exec rm -rf {} +
cp -R docs/wiki/. "$work/wiki/"
cd "$work/wiki"
git add -A
if git diff --cached --quiet; then
echo "Wiki già allineata a docs/wiki ($sha)."
exit 0
fi
git -c user.name="${GIT_AUTHOR_NAME:-Khaemhat wiki}" -c user.email="${GIT_AUTHOR_EMAIL:-wiki@khaemhat.invalid}" \
commit -q -m "docs(wiki): sync from $sha"
git "${auth[@]}" push -q origin HEAD
echo "Wiki pubblicata da docs/wiki ($sha): $(git diff --stat HEAD~1 | tail -n 1)"
+9
View File
@@ -0,0 +1,9 @@
#!/usr/bin/env bash
# Restores the system database from a backup with the instance stopped (SPEC §13, ADR 0017). Shipped in the image as /app/scripts/restore-system.sh.
# docker compose run --rm --entrypoint /app/scripts/restore-system.sh khaemhat <file-di-backup>
# Stub: completed in milestone M12 (SPEC §20). Until then it explains what it will do and exits with an error.
set -euo pipefail
echo "restore-system.sh: non ancora disponibile, arriva con la milestone M12." >&2
echo "Uso previsto: docker compose run --rm --entrypoint /app/scripts/restore-system.sh khaemhat <file-di-backup>" >&2
exit 1
+25
View File
@@ -0,0 +1,25 @@
#!/usr/bin/env bash
# Starts Khaemhat locally on http://localhost:5080 with SQLite in .data/dev (ignored by git).
# Any KHAEMHAT_* variable already set in the shell wins over the defaults below.
set -euo pipefail
root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$root"
data_dir="$root/.data/dev"
mkdir -p "$data_dir"
export ASPNETCORE_ENVIRONMENT="${ASPNETCORE_ENVIRONMENT:-Development}"
export KHAEMHAT_DATA_DIR="${KHAEMHAT_DATA_DIR:-$data_dir}"
export KHAEMHAT_SYSTEM_DB="${KHAEMHAT_SYSTEM_DB:-sqlite://$data_dir/system.db}"
# Development-only key: never use it outside this script.
export KHAEMHAT_SECRET_KEY="${KHAEMHAT_SECRET_KEY:-a2hhZW1oYXQtZGV2ZWxvcG1lbnQtb25seS1ub3QtYS1zZWNyZXQ=}"
export KHAEMHAT_SUPERUSER="${KHAEMHAT_SUPERUSER:-root}"
export KHAEMHAT_SUPERUSER_PASSWORD="${KHAEMHAT_SUPERUSER_PASSWORD:-Khaemhat-dev-1}"
export KHAEMHAT_COMPANY_CODE="${KHAEMHAT_COMPANY_CODE:-DEMO}"
export KHAEMHAT_COMPANY_NAME="${KHAEMHAT_COMPANY_NAME:-Khaemhat Demo S.r.l.}"
export KHAEMHAT_LICENSE_MODE="${KHAEMHAT_LICENSE_MODE:-test}"
export KHAEMHAT_SEED_DEMO="${KHAEMHAT_SEED_DEMO:-true}"
echo "Khaemhat in sviluppo: http://localhost:5080 (dati in $KHAEMHAT_DATA_DIR)"
exec dotnet run --project src/Khaemhat.Web -- --urls http://localhost:5080 "$@"
+9
View File
@@ -0,0 +1,9 @@
#!/usr/bin/env bash
# Loads base tables and demo data into a company database (SPEC §15).
# scripts/seed.sh --base | --demo [--scale N] [--company CODE]
# Stub: completed in milestone M4 (SPEC §20). Until then it explains what it will do and exits with an error.
set -euo pipefail
echo "seed.sh: non ancora disponibile, arriva con la milestone M4." >&2
echo "Uso previsto: scripts/seed.sh --base | --demo [--scale N] [--company CODE]" >&2
exit 1
+15
View File
@@ -0,0 +1,15 @@
#!/usr/bin/env bash
# Runs every test (SPEC §20). SQLite always; PostgreSQL when KHAEMHAT_TEST_PG is set
# (e.g. postgres://khaemhat:secret@localhost:5432/postgres); Redis when KHAEMHAT_TEST_REDIS is set.
# Extra arguments go to "dotnet test", e.g. scripts/test.sh --filter FullyQualifiedName~Health
set -euo pipefail
root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$root"
export KHAEMHAT_LICENSE_MODE=test
echo "PostgreSQL: ${KHAEMHAT_TEST_PG:+attivo}${KHAEMHAT_TEST_PG:-non configurato (KHAEMHAT_TEST_PG), test saltati}"
echo "Redis: ${KHAEMHAT_TEST_REDIS:+attivo}${KHAEMHAT_TEST_REDIS:-non configurato (KHAEMHAT_TEST_REDIS), test saltati}"
bash scripts/check-packages.sh
dotnet test Khaemhat.sln -c Release "$@"