From 30b01d7bca9e3bb95e9e239c690ac6bcd663998f Mon Sep 17 00:00:00 2001 From: Pascal Linxweiler Date: Mon, 5 Oct 2026 17:12:32 +0200 Subject: [PATCH] Add Gitea release pipeline and server compose - .gitea/workflows/release.yaml: on vX.Y.Z tags run checks, build and push the image to the Gitea registry (X.Y.Z, X.Y, latest), create a release from the CHANGELOG section - scripts/release-notes.mjs: extract changelog section, create the release - deploy/compose.yaml: server setup using the released image - APP_VERSION build arg, shown in the header Co-Authored-By: Claude Opus 5.5 --- .gitea/workflows/release.yaml | 63 +++++++++++++++++++++++++++++++++++ CHANGELOG.md | 7 ++++ Dockerfile | 2 ++ README.md | 22 ++++++++++++ deploy/compose.yaml | 49 +++++++++++++++++++++++++++ scripts/release-notes.mjs | 58 ++++++++++++++++++++++++++++++++ src/app/(app)/layout.tsx | 3 +- 7 files changed, 203 insertions(+), 1 deletion(-) create mode 100644 .gitea/workflows/release.yaml create mode 100644 deploy/compose.yaml create mode 100644 scripts/release-notes.mjs diff --git a/.gitea/workflows/release.yaml b/.gitea/workflows/release.yaml new file mode 100644 index 0000000..7b308af --- /dev/null +++ b/.gitea/workflows/release.yaml @@ -0,0 +1,63 @@ +# Push a tag vX.Y.Z (matching package.json) → checks, Docker image to the Gitea registry, release. +# +# Needs: an act_runner with access to a Docker daemon (default config mounts the socket), +# and a repo secret REGISTRY_TOKEN (personal access token with package read+write). +name: Release + +on: + push: + tags: ["v*.*.*"] + +jobs: + release: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-node@v4 + with: + node-version: 24 + cache: npm + + - name: Resolve version and image name + run: | + VERSION="${GITHUB_REF_NAME#v}" + PKG_VERSION="$(node -p "require('./package.json').version")" + if [ "$VERSION" != "$PKG_VERSION" ]; then + echo "::error::Tag $GITHUB_REF_NAME does not match package.json version $PKG_VERSION" + exit 1 + fi + node scripts/release-notes.mjs notes "$VERSION" > /dev/null + REGISTRY="${GITHUB_SERVER_URL#https://}" + IMAGE="$(echo "$REGISTRY/$GITHUB_REPOSITORY" | tr '[:upper:]' '[:lower:]')" + echo "VERSION=$VERSION" >> "$GITHUB_ENV" + echo "REGISTRY=$REGISTRY" >> "$GITHUB_ENV" + echo "IMAGE=$IMAGE" >> "$GITHUB_ENV" + echo "Building $IMAGE:$VERSION" + + - name: Checks + run: | + npm ci + npm run lint + npm run typecheck + npm test + + - name: Build image + run: | + docker build \ + --build-arg APP_VERSION="$VERSION" \ + --label org.opencontainers.image.version="$VERSION" \ + --label org.opencontainers.image.revision="$GITHUB_SHA" \ + --label org.opencontainers.image.source="$GITHUB_SERVER_URL/$GITHUB_REPOSITORY" \ + -t "$IMAGE:$VERSION" -t "$IMAGE:${VERSION%.*}" -t "$IMAGE:latest" . + + - name: Push image + run: | + echo "${{ secrets.REGISTRY_TOKEN }}" | docker login "$REGISTRY" -u "${{ github.repository_owner }}" --password-stdin + for tag in "$VERSION" "${VERSION%.*}" latest; do docker push "$IMAGE:$tag"; done + docker logout "$REGISTRY" + + - name: Create release + env: + TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: node scripts/release-notes.mjs publish diff --git a/CHANGELOG.md b/CHANGELOG.md index a86368c..075e2d5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,13 @@ step 1 (Hugging Face downloader) is released as a minor version. ## [Unreleased] +### Added + +- Release pipeline (`.gitea/workflows/release.yaml`): a `vX.Y.Z` tag runs checks, pushes the Docker + image to the Gitea registry (`X.Y.Z`, `X.Y`, `latest`) and creates a release from this changelog. +- `deploy/compose.yaml` for the server, using the released image (`KANAME_VERSION` to pin). +- The app version is shown next to the app name (`APP_VERSION`, set at image build time). + ### Changed - The library is the only main page: "Add model" opens the lookup/selection form inline (open by diff --git a/Dockerfile b/Dockerfile index 6a810fd..238da3d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -29,7 +29,9 @@ RUN python -m venv /opt/hf \ && mkdir -p /data /models \ && chown app:app /data /models +ARG APP_VERSION=dev ENV PATH=/opt/hf/bin:$PATH \ + APP_VERSION=$APP_VERSION \ NODE_ENV=production \ NEXT_TELEMETRY_DISABLED=1 \ PORT=3000 \ diff --git a/README.md b/README.md index c12d246..f3b46f1 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,28 @@ Volumes: `data` (SQLite + hf home, keep on local disk) and `models` (downloaded OIDC redirect URI for the client in Pocket ID: `/api/auth/callback/pocket-id`. +## Releases and deployment + +Pushing a tag `vX.Y.Z` (must equal `version` in `package.json` and have a `## [X.Y.Z]` section in +`CHANGELOG.md`) runs `.gitea/workflows/release.yaml` on Gitea Actions: + +1. lint, typecheck, unit tests +2. builds the image and pushes `git.linxweiler.xyz/pascallinxweiler/kaname:X.Y.Z`, `:X.Y` and `:latest` +3. creates a Gitea release with the CHANGELOG section as notes + +Requirements: an `act_runner` registered for the repo/user with Docker access, and a repo secret +`REGISTRY_TOKEN` (personal access token with *package: read and write*). + +On the server, use `deploy/compose.yaml` (pulls the released image instead of building): + +```bash +# in a folder with deploy/compose.yaml and a filled-in .env next to it +docker compose pull && docker compose up -d +``` + +Pin a version with `KANAME_VERSION=0.4.0` in `.env`; the running version is shown next to the app +name in the header. + ## Local development ```bash diff --git a/deploy/compose.yaml b/deploy/compose.yaml new file mode 100644 index 0000000..011d77d --- /dev/null +++ b/deploy/compose.yaml @@ -0,0 +1,49 @@ +# Production compose for the server: runs the released image from the Gitea registry. +# (The compose.yaml in the repo root builds the image locally instead.) +# +# cp ../.env.example .env # fill in, AUTH_URL = public URL +# docker compose pull && docker compose up -d +# +# Pin a version with KANAME_VERSION=0.4.0 in .env (default: latest). + +name: kaname + +x-app: &app + image: git.linxweiler.xyz/pascallinxweiler/kaname:${KANAME_VERSION:-latest} + env_file: .env + environment: + DATABASE_URL: file:/data/app.db + MODELS_DIR: /models + HF_HOME: /data/hf-home + restart: unless-stopped + init: true + +services: + worker: + <<: *app + command: ["node", "dist/worker.mjs"] + volumes: + - data:/data + - models:/models + stop_grace_period: 20s + healthcheck: + test: ["CMD-SHELL", "find /tmp/kaname-worker-alive -mmin -1 | grep -q ."] + interval: 10s + timeout: 5s + start_period: 30s + retries: 3 + + web: + <<: *app + command: ["node_modules/.bin/next", "start"] + ports: + - "${WEB_PORT:-3000}:3000" + volumes: + - data:/data + depends_on: + worker: + condition: service_healthy + +volumes: + data: # SQLite + hf home; keep on local disk (SQLite and NFS don't mix) + models: # downloaded models; will become an NFS mount from TrueNAS diff --git a/scripts/release-notes.mjs b/scripts/release-notes.mjs new file mode 100644 index 0000000..a53183c --- /dev/null +++ b/scripts/release-notes.mjs @@ -0,0 +1,58 @@ +#!/usr/bin/env node +// Release helpers for CI (no dependencies). +// +// node scripts/release-notes.mjs notes print the CHANGELOG section for +// node scripts/release-notes.mjs publish create the Gitea release for $GITHUB_REF_NAME +// +// `publish` uses the Gitea Actions environment: GITHUB_SERVER_URL, GITHUB_REPOSITORY, +// GITHUB_REF_NAME (the tag), IMAGE (registry/owner/name) and TOKEN (API token). + +import { readFileSync } from "node:fs"; + +export function changelogSection(markdown, version) { + const lines = markdown.split(/\r?\n/); + const start = lines.findIndex((l) => l.startsWith(`## [${version}]`)); + if (start === -1) return null; + let end = lines.findIndex((l, i) => i > start && l.startsWith("## ")); + if (end === -1) end = lines.length; + return lines + .slice(start + 1, end) + .join("\n") + .trim(); +} + +async function publish() { + const { GITHUB_SERVER_URL: server, GITHUB_REPOSITORY: repo, GITHUB_REF_NAME: tag, IMAGE, TOKEN } = process.env; + if (!server || !repo || !tag || !IMAGE || !TOKEN) throw new Error("missing CI environment variables"); + const version = tag.replace(/^v/, ""); + const notes = changelogSection(readFileSync("CHANGELOG.md", "utf8"), version); + if (!notes) throw new Error(`CHANGELOG.md has no section for ${version}`); + + const body = `${notes}\n\n### Docker image\n\n\`\`\`\n${IMAGE}:${version}\n\`\`\`\n`; + const res = await fetch(`${server}/api/v1/repos/${repo}/releases`, { + method: "POST", + headers: { Authorization: `token ${TOKEN}`, "Content-Type": "application/json" }, + body: JSON.stringify({ tag_name: tag, name: tag, body, draft: false, prerelease: false }), + }); + if (res.status === 409) { + console.log(`Release ${tag} already exists, leaving it as is.`); + return; + } + if (!res.ok) throw new Error(`Creating release failed: ${res.status} ${await res.text()}`); + console.log(`Created release ${tag}.`); +} + +const [cmd, arg] = process.argv.slice(2); +if (cmd === "notes") { + const section = changelogSection(readFileSync("CHANGELOG.md", "utf8"), arg); + if (!section) { + console.error(`No CHANGELOG section for ${arg}`); + process.exit(1); + } + console.log(section); +} else if (cmd === "publish") { + publish().catch((err) => { + console.error(err.message); + process.exit(1); + }); +} diff --git a/src/app/(app)/layout.tsx b/src/app/(app)/layout.tsx index f00b8c0..b3add42 100644 --- a/src/app/(app)/layout.tsx +++ b/src/app/(app)/layout.tsx @@ -15,8 +15,9 @@ export default async function AppLayout({ children }: LayoutProps<"/">) {
- + Model Manager + {process.env.APP_VERSION ?? "dev"}