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 <noreply@anthropic.com>
This commit is contained in:
1 parent
c7cb6ed433
commit
30b01d7bca
7 files changed
+203
-1
No files matched your search
@@ -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
|
||||
@@ -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
|
||||
|
||||
@@ -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 \
|
||||
|
||||
@@ -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: `<AUTH_URL>/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
|
||||
|
||||
@@ -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
|
||||
@@ -0,0 +1,58 @@
|
||||
#!/usr/bin/env node
|
||||
// Release helpers for CI (no dependencies).
|
||||
//
|
||||
// node scripts/release-notes.mjs notes <version> print the CHANGELOG section for <version>
|
||||
// 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);
|
||||
});
|
||||
}
|
||||
@@ -15,8 +15,9 @@ export default async function AppLayout({ children }: LayoutProps<"/">) {
|
||||
<div className="flex min-h-screen flex-col">
|
||||
<header className="border-b">
|
||||
<div className="mx-auto flex h-14 max-w-6xl items-center gap-6 px-4">
|
||||
<Link href="/" className="font-semibold">
|
||||
<Link href="/" className="flex items-baseline gap-1.5 font-semibold">
|
||||
Model Manager
|
||||
<span className="text-xs font-normal text-muted-foreground">{process.env.APP_VERSION ?? "dev"}</span>
|
||||
</Link>
|
||||
<nav className="flex items-center gap-4 text-sm text-muted-foreground">
|
||||
<Link href="/" className="hover:text-foreground">
|
||||
|
||||
Reference in new issue
Block a user