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
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:
1 parent
88de272b3e
commit
12277733f5
101 files changed
+3245
-67
No files matched your search
@@ -0,0 +1,90 @@
|
||||
# syntax=docker/dockerfile:1
|
||||
# Khaemhat image (SPEC §16.1, ADR 0009, 0010, 0013, 0015, 0016, 0017). Build from the repository root:
|
||||
# docker build -f docker/Dockerfile --build-arg VERSION=0.0.1 --build-arg GIT_SHA=$(git rev-parse --short HEAD) .
|
||||
|
||||
ARG DOTNET_VERSION=10.0
|
||||
|
||||
# ---------------------------------------------------------------------------------------------------------------------
|
||||
FROM mcr.microsoft.com/dotnet/sdk:${DOTNET_VERSION} AS build
|
||||
ARG VERSION=0.0.0-dev
|
||||
ARG GIT_SHA=unknown
|
||||
ARG RUN_TESTS=false
|
||||
ENV DOTNET_NOLOGO=1 DOTNET_CLI_TELEMETRY_OPTOUT=1 DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
|
||||
WORKDIR /src
|
||||
|
||||
# Restore first, from the build files only, so the layer is reused while no project or package changes.
|
||||
COPY global.json Directory.Build.props Directory.Build.targets Directory.Packages.props .editorconfig ./
|
||||
COPY src/Khaemhat.Core/Khaemhat.Core.csproj src/Khaemhat.Core/
|
||||
COPY src/Khaemhat.Fiscal.Abstractions/Khaemhat.Fiscal.Abstractions.csproj src/Khaemhat.Fiscal.Abstractions/
|
||||
COPY src/Khaemhat.Fiscal.Italy/Khaemhat.Fiscal.Italy.csproj src/Khaemhat.Fiscal.Italy/
|
||||
COPY src/Khaemhat.Data/Khaemhat.Data.csproj src/Khaemhat.Data/
|
||||
COPY src/Khaemhat.Data.Sqlite/Khaemhat.Data.Sqlite.csproj src/Khaemhat.Data.Sqlite/
|
||||
COPY src/Khaemhat.Data.PostgreSql/Khaemhat.Data.PostgreSql.csproj src/Khaemhat.Data.PostgreSql/
|
||||
COPY src/Khaemhat.Infrastructure/Khaemhat.Infrastructure.csproj src/Khaemhat.Infrastructure/
|
||||
COPY src/Khaemhat.Application/Khaemhat.Application.csproj src/Khaemhat.Application/
|
||||
COPY src/Khaemhat.Web/Khaemhat.Web.csproj src/Khaemhat.Web/
|
||||
RUN dotnet restore src/Khaemhat.Web/Khaemhat.Web.csproj
|
||||
|
||||
COPY . .
|
||||
RUN bash scripts/check-packages.sh
|
||||
RUN if [ "$RUN_TESTS" = "true" ]; then \
|
||||
dotnet test Khaemhat.sln -c Release /p:Version="$VERSION" /p:SourceRevisionId="$GIT_SHA"; \
|
||||
fi
|
||||
RUN dotnet publish src/Khaemhat.Web/Khaemhat.Web.csproj -c Release -o /app --no-restore \
|
||||
/p:Version="$VERSION" /p:SourceRevisionId="$GIT_SHA" /p:UseAppHost=false
|
||||
|
||||
# ---------------------------------------------------------------------------------------------------------------------
|
||||
FROM mcr.microsoft.com/dotnet/aspnet:${DOTNET_VERSION} AS runtime
|
||||
ARG VERSION=0.0.0-dev
|
||||
ARG GIT_SHA=unknown
|
||||
ARG CREATED=unknown
|
||||
ARG SOURCE_URL=https://gitea.encke-hake.ts.net/BalboSoft/Khaemhat
|
||||
ARG ICON_URL=https://gitea.encke-hake.ts.net/BalboSoft/Khaemhat/raw/branch/main/assets/icon-256.png
|
||||
|
||||
# OS tools allowed by SPEC §1.2 (not application components): pg_dump/pg_restore 17 from the PGDG repository (a
|
||||
# client >= the server: works with PostgreSQL 16 and 17), curl for the health check, tzdata for TZ.
|
||||
RUN set -eux; \
|
||||
apt-get update; \
|
||||
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends ca-certificates curl tzdata; \
|
||||
. /etc/os-release; \
|
||||
install -d /usr/share/postgresql-common/pgdg; \
|
||||
curl -fsSL -o /usr/share/postgresql-common/pgdg/apt.postgresql.org.asc https://www.postgresql.org/media/keys/ACCC4CF8.asc; \
|
||||
echo "deb [signed-by=/usr/share/postgresql-common/pgdg/apt.postgresql.org.asc] https://apt.postgresql.org/pub/repos/apt ${VERSION_CODENAME}-pgdg main" \
|
||||
> /etc/apt/sources.list.d/pgdg.list; \
|
||||
apt-get update; \
|
||||
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends postgresql-client-17; \
|
||||
rm -rf /var/lib/apt/lists/*; \
|
||||
pg_dump --version
|
||||
|
||||
ENV ASPNETCORE_ENVIRONMENT=Production \
|
||||
ASPNETCORE_HTTP_PORTS=8080 \
|
||||
KHAEMHAT_DATA_DIR=/data \
|
||||
DOTNET_NOLOGO=1 \
|
||||
TZ=Europe/Rome
|
||||
|
||||
WORKDIR /app
|
||||
COPY --from=build /app ./
|
||||
COPY docker/entrypoint.sh /app/entrypoint.sh
|
||||
COPY scripts/restore-system.sh /app/scripts/restore-system.sh
|
||||
RUN chmod 0755 /app/entrypoint.sh /app/scripts/restore-system.sh \
|
||||
&& install -d -o app -g app -m 0750 /data
|
||||
|
||||
LABEL org.opencontainers.image.title="Khaemhat" \
|
||||
org.opencontainers.image.description="Gestionale ERP e CRM per PMI italiane" \
|
||||
org.opencontainers.image.vendor="BalboSoft" \
|
||||
org.opencontainers.image.version="${VERSION}" \
|
||||
org.opencontainers.image.revision="${GIT_SHA}" \
|
||||
org.opencontainers.image.created="${CREATED}" \
|
||||
org.opencontainers.image.source="${SOURCE_URL}" \
|
||||
org.opencontainers.image.url="${SOURCE_URL}" \
|
||||
org.opencontainers.image.documentation="${SOURCE_URL}/wiki" \
|
||||
net.unraid.docker.icon="${ICON_URL}" \
|
||||
net.unraid.docker.webui="http://[IP]:[PORT:8080]/"
|
||||
|
||||
VOLUME /data
|
||||
EXPOSE 8080
|
||||
HEALTHCHECK --interval=30s --timeout=5s --start-period=20s --retries=3 \
|
||||
CMD curl -fs http://localhost:8080/health/live || exit 1
|
||||
|
||||
# Starts as root only to align the app user with PUID/PGID; the .NET process runs as "app" (ADR 0013).
|
||||
ENTRYPOINT ["/app/entrypoint.sh"]
|
||||
Executable
+84
@@ -0,0 +1,84 @@
|
||||
#!/usr/bin/env bash
|
||||
# Container entrypoint (docs/DEPLOY.md §2.4, ADR 0013, ADR 0014). It only prepares the user, waits for the system
|
||||
# database and starts the app: migrations and bootstrap live in the .NET code.
|
||||
set -euo pipefail
|
||||
|
||||
APP_DLL=/app/Khaemhat.Web.dll
|
||||
DATA_DIR="${KHAEMHAT_DATA_DIR:-/data}"
|
||||
DB_WAIT_SECONDS=120
|
||||
|
||||
log() { printf '%s khaemhat-entrypoint: %s\n' "$(date -u +%Y-%m-%dT%H:%M:%SZ)" "$*" >&2; }
|
||||
fail() { log "ERRORE: $*"; exit 1; }
|
||||
|
||||
# The system database URL, from KHAEMHAT_SYSTEM_DB or KHAEMHAT_SYSTEM_DB_FILE (ADR 0014). Only host and port are used.
|
||||
system_db() {
|
||||
if [[ -n "${KHAEMHAT_SYSTEM_DB:-}" && -n "${KHAEMHAT_SYSTEM_DB_FILE:-}" ]]; then
|
||||
fail "KHAEMHAT_SYSTEM_DB e KHAEMHAT_SYSTEM_DB_FILE sono entrambe impostate: usane una sola."
|
||||
fi
|
||||
if [[ -n "${KHAEMHAT_SYSTEM_DB_FILE:-}" ]]; then
|
||||
[[ -r "$KHAEMHAT_SYSTEM_DB_FILE" ]] || fail "KHAEMHAT_SYSTEM_DB_FILE: file non leggibile ($KHAEMHAT_SYSTEM_DB_FILE)."
|
||||
head -n 1 "$KHAEMHAT_SYSTEM_DB_FILE" | tr -d '\r\n'
|
||||
else
|
||||
printf '%s' "${KHAEMHAT_SYSTEM_DB:-}"
|
||||
fi
|
||||
}
|
||||
|
||||
# Waits until the PostgreSQL server of the system database accepts connections. SQLite needs no wait.
|
||||
wait_for_database() {
|
||||
local url host port rest deadline
|
||||
url="$(system_db)"
|
||||
case "$url" in
|
||||
postgres://* | postgresql://*) ;;
|
||||
*) return 0 ;;
|
||||
esac
|
||||
|
||||
rest="${url#*://}" # user:pwd@host:port/db?x
|
||||
rest="${rest##*@}" # host:port/db?x
|
||||
rest="${rest%%/*}" # host:port
|
||||
rest="${rest%%\?*}"
|
||||
host="${rest%%:*}"
|
||||
port=5432
|
||||
[[ "$rest" == *:* ]] && port="${rest##*:}"
|
||||
[[ -n "$host" ]] || fail "KHAEMHAT_SYSTEM_DB: host mancante."
|
||||
|
||||
deadline=$((SECONDS + DB_WAIT_SECONDS))
|
||||
until pg_isready -q -h "$host" -p "$port" -t 3; do
|
||||
if (( SECONDS >= deadline )); then
|
||||
fail "il database di sistema su $host:$port non risponde dopo ${DB_WAIT_SECONDS}s."
|
||||
fi
|
||||
log "attendo il database di sistema su $host:$port..."
|
||||
sleep 2
|
||||
done
|
||||
log "database di sistema raggiungibile su $host:$port."
|
||||
}
|
||||
|
||||
# Aligns the "app" user with PUID/PGID and gives it /data (ADR 0013). Only when started as root.
|
||||
prepare_user() {
|
||||
local puid="${PUID:-$(id -u app)}" pgid="${PGID:-$(id -g app)}"
|
||||
[[ "$puid" =~ ^[0-9]+$ && "$pgid" =~ ^[0-9]+$ ]] || fail "PUID e PGID devono essere numeri (PUID=$puid, PGID=$pgid)."
|
||||
(( puid != 0 && pgid != 0 )) || fail "PUID e PGID non possono essere 0: l'applicazione non gira come root."
|
||||
|
||||
if [[ "$(id -g app)" != "$pgid" ]]; then
|
||||
groupmod -o -g "$pgid" app
|
||||
fi
|
||||
if [[ "$(id -u app)" != "$puid" ]]; then
|
||||
usermod -o -u "$puid" app
|
||||
fi
|
||||
|
||||
mkdir -p "$DATA_DIR"
|
||||
if [[ "$(stat -c '%u:%g' "$DATA_DIR")" != "$puid:$pgid" ]]; then
|
||||
log "assegno $DATA_DIR a $puid:$pgid..."
|
||||
chown -R "$puid:$pgid" "$DATA_DIR"
|
||||
fi
|
||||
}
|
||||
|
||||
wait_for_database
|
||||
|
||||
if [[ "$(id -u)" == "0" ]]; then
|
||||
prepare_user
|
||||
log "avvio Khaemhat come utente app ($(id -u app):$(id -g app))."
|
||||
exec setpriv --reuid=app --regid=app --init-groups -- dotnet "$APP_DLL" "$@"
|
||||
fi
|
||||
|
||||
log "avvio Khaemhat come utente $(id -u):$(id -g)."
|
||||
exec dotnet "$APP_DLL" "$@"
|
||||
@@ -0,0 +1,14 @@
|
||||
-- Optional init script for the official postgres image (mount it in /docker-entrypoint-initdb.d/): it runs once,
|
||||
-- when the data directory is empty. Khaemhat creates every table itself (migrations in .NET, one database per
|
||||
-- company), so this only sets defaults for the application role.
|
||||
--
|
||||
-- The role must be able to create databases (CREATEDB): the POSTGRES_USER of the official image is a superuser and
|
||||
-- already can; for an existing server see docs/DEPLOY.md.
|
||||
|
||||
DO $$
|
||||
BEGIN
|
||||
-- Timestamps are stored as timestamptz and handled in UTC by the application.
|
||||
EXECUTE format('ALTER ROLE %I SET timezone TO %L', current_user, 'UTC');
|
||||
EXECUTE format('ALTER ROLE %I SET client_encoding TO %L', current_user, 'UTF8');
|
||||
END
|
||||
$$;
|
||||
Reference in new issue
Block a user