From 154fed2a06ad747571b1b1978e060cb1e98f57e6 Mon Sep 17 00:00:00 2001 From: tajniak81 <13187254+tajniak81@users.noreply.github.com> Date: Mon, 2 Nov 2026 15:49:22 +0100 Subject: [PATCH] Run the release workflow on Gitea - Images go to the registry of the Gitea that runs the workflow (or the REGISTRY variable), signed in with the REGISTRY_TOKEN secret. A plain http Gitea gets a plain http registry in BuildKit's config, and the credentials are written straight into the client config, since docker login refuses such registries. - The build cache is kept in the registry, not the GitHub Actions cache. - One release job creates the Gitea release through its API once every build has passed, and attaches the Windows and Linux installers. - macOS is left out: Gitea has no hosted Mac runners, so the DMG is built by hand. The docs link comes from the DOCS_URL variable instead of a github.io address. - AppImages are built without FUSE, which runner containers lack. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/release.yml | 148 ++++++++++++++++++++++++------- Docs-Site/guide/configuration.md | 2 +- README.md | 4 +- 3 files changed, 120 insertions(+), 34 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f86b4ab..3661b5d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,8 +1,23 @@ -# Publishes a release: push a tag like v0.1.0. -# Images go to ghcr.io//, for linux/amd64 and -# linux/arm64, tagged with the version (0.1.0, 0.1) and latest. -# Desktop installers (Windows NSIS, macOS DMG, Linux deb, rpm and AppImage) -# are attached to the GitHub release for the tag. +# Publishes a release on Gitea: push a tag like v1.0.0. +# Images go to the registry of the Gitea that runs this workflow, +# //, for linux/amd64 and linux/arm64, tagged +# with the version (1.0.0, 1.0) and latest. Desktop installers (Windows NSIS, +# Linux deb, rpm and AppImage) are attached to the Gitea release for the tag, +# which is made once every build has passed. Gitea has no hosted Mac runners, +# so the macOS DMG is built by hand on a Mac (wails3 task darwin:package:dmg +# in Desktop-App) and attached to the release afterwards. +# +# What the Gitea side needs: +# - Runners with the labels ubuntu-latest (a Docker runner whose jobs can use +# Docker, for the image builds) and windows-latest (a host runner with Git +# Bash on the PATH and NSIS or Chocolatey). +# - Secret REGISTRY_TOKEN: an access token with package write access, for the +# account in variable REGISTRY_USER (the person who pushed the tag when +# unset). +# - Optional variables: REGISTRY (another registry host), DOCS_URL (where +# Help → Documentation goes in the desktop app), and +# DESKTOP_UPDATE_MANIFEST_URL with DESKTOP_UPDATE_PUBLIC_KEY (the desktop +# update feed; without them the build never updates itself, see updates.go). name: Release @@ -16,7 +31,7 @@ on: required: true permissions: - contents: read + contents: write packages: write jobs: @@ -47,18 +62,54 @@ jobs: v="${{ inputs.version || github.ref_name }}" echo "value=${v#v}" >> "$GITHUB_OUTPUT" + # Gitea's own registry has the server's address. A plain http server + # means a plain http registry, which BuildKit must be told about. + - name: Registry + id: registry + env: + REGISTRY: ${{ vars.REGISTRY }} + SERVER_URL: ${{ github.server_url }} + OWNER: ${{ github.repository_owner }} + run: | + host="$REGISTRY" + http=false + if [ -z "$host" ]; then + host="${SERVER_URL#*://}" + case "$SERVER_URL" in http://*) http=true ;; esac + fi + host="${host%/}" + echo "host=$host" >> "$GITHUB_OUTPUT" + echo "http=$http" >> "$GITHUB_OUTPUT" + echo "image=$host/$(echo "$OWNER" | tr '[:upper:]' '[:lower:]')/${{ matrix.name }}" >> "$GITHUB_OUTPUT" + + # docker login refuses a plain http registry unless the runner's Docker + # daemon lists it, so the credentials go straight into the client config + # that buildx reads. + - name: Registry sign-in + env: + HOST: ${{ steps.registry.outputs.host }} + USERNAME: ${{ vars.REGISTRY_USER || github.actor }} + TOKEN: ${{ secrets.REGISTRY_TOKEN }} + run: | + if [ -z "$TOKEN" ]; then + echo "::error::Set the REGISTRY_TOKEN secret (an access token with package write access)." + exit 1 + fi + mkdir -p ~/.docker + auth=$(printf '%s:%s' "$USERNAME" "$TOKEN" | base64 | tr -d '\n') + printf '{"auths":{"%s":{"auth":"%s"}}}\n' "$HOST" "$auth" > ~/.docker/config.json + - uses: docker/setup-qemu-action@v3 - uses: docker/setup-buildx-action@v3 - - uses: docker/login-action@v3 with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} + buildkitd-config-inline: | + [registry."${{ steps.registry.outputs.host }}"] + http = ${{ steps.registry.outputs.http }} - id: meta uses: docker/metadata-action@v5 with: - images: ghcr.io/${{ github.repository_owner }}/${{ matrix.name }} + images: ${{ steps.registry.outputs.image }} tags: | type=semver,pattern={{version}},value=${{ steps.version.outputs.value }} type=semver,pattern={{major}}.{{minor}},value=${{ steps.version.outputs.value }} @@ -68,6 +119,7 @@ jobs: org.opencontainers.image.title=${{ matrix.name }} org.opencontainers.image.licenses=AGPL-3.0-or-later + # The build cache lives next to the image, as its "buildcache" tag. - uses: docker/build-push-action@v6 with: context: ${{ matrix.context }} @@ -77,34 +129,33 @@ jobs: build-args: VERSION=${{ steps.version.outputs.value }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} - cache-from: type=gha,scope=${{ matrix.name }} - cache-to: type=gha,mode=max,scope=${{ matrix.name }} + cache-from: type=registry,ref=${{ steps.registry.outputs.image }}:buildcache + cache-to: type=registry,ref=${{ steps.registry.outputs.image }}:buildcache,mode=max desktop: strategy: fail-fast: false matrix: include: - - os: windows-latest + - os: windows + runner: windows-latest task: windows:package files: Desktop-App/bin/*-installer.exe - - os: macos-latest - task: darwin:package:dmg - files: Desktop-App/bin/*.dmg - - os: ubuntu-latest + - os: linux + runner: ubuntu-latest task: linux:create:deb linux:create:rpm linux:create:appimage files: | Desktop-App/bin/*.deb Desktop-App/bin/*.rpm Desktop-App/bin/*.AppImage - runs-on: ${{ matrix.os }} - permissions: - contents: write + runs-on: ${{ matrix.runner }} defaults: run: shell: bash env: GOWORK: "off" + # Containers have no FUSE; linuxdeploy unpacks itself instead. + APPIMAGE_EXTRACT_AND_RUN: "1" steps: - uses: actions/checkout@v5 - uses: actions/setup-go@v6 @@ -122,11 +173,15 @@ jobs: echo "value=${v#v}" >> "$GITHUB_OUTPUT" - name: Linux packaging dependencies - if: runner.os == 'Linux' + if: matrix.os == 'linux' run: sudo apt-get update && sudo apt-get install -y libgtk-3-dev libwebkit2gtk-4.1-dev libfuse2 rpm - name: NSIS - if: runner.os == 'Windows' - run: choco install nsis -y --no-progress && echo "C:/Program Files (x86)/NSIS" >> "$GITHUB_PATH" + if: matrix.os == 'windows' + run: | + if ! command -v makensis >/dev/null; then + choco install nsis -y --no-progress + fi + echo "C:/Program Files (x86)/NSIS" >> "$GITHUB_PATH" - name: Wails CLI run: go install github.com/wailsapp/wails/v3/cmd/wails3@v3.0.0 @@ -135,13 +190,13 @@ jobs: working-directory: Desktop-App run: node build/set-version.mjs "${{ steps.version.outputs.value }}" - # The update feed and its ed25519 public key are repository variables; - # without them the build never updates itself (see updates.go). - name: Package working-directory: Desktop-App run: | flags="-X main.version=${{ steps.version.outputs.value }}" - flags="$flags -X main.docsURL=https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/" + if [ -n "${{ vars.DOCS_URL }}" ]; then + flags="$flags -X main.docsURL=${{ vars.DOCS_URL }}" + fi if [ -n "${{ vars.DESKTOP_UPDATE_MANIFEST_URL }}" ]; then flags="$flags -X main.updateManifestURL=${{ vars.DESKTOP_UPDATE_MANIFEST_URL }} -X main.updatePublicKey=${{ vars.DESKTOP_UPDATE_PUBLIC_KEY }}" fi @@ -149,10 +204,39 @@ jobs: - uses: actions/upload-artifact@v4 with: - name: desktop-${{ runner.os }} + name: desktop-${{ matrix.os }} path: ${{ matrix.files }} - - name: Attach to the release - if: github.event_name == 'push' - uses: softprops/action-gh-release@v2 + + release: + needs: [images, desktop] + if: github.event_name == 'push' + runs-on: ubuntu-latest + steps: + - uses: actions/download-artifact@v4 with: - files: ${{ matrix.files }} + pattern: desktop-* + path: dist + merge-multiple: true + + # Gitea's release API; a release made earlier for this tag (by hand or + # by a rerun) gets the files added instead of a second release. + - name: Release + env: + API: ${{ github.server_url }}/api/v1/repos/${{ github.repository }} + TOKEN: ${{ secrets.GITHUB_TOKEN }} + TAG: ${{ github.ref_name }} + run: | + auth="Authorization: token $TOKEN" + prerelease=false + case "$TAG" in *-*) prerelease=true ;; esac + id=$(curl -fsS -H "$auth" "$API/releases/tags/$TAG" | jq -r .id) || id="" + if [ -z "$id" ]; then + id=$(jq -n --arg tag "$TAG" --argjson pre "$prerelease" \ + '{tag_name: $tag, name: $tag, prerelease: $pre}' | + curl -fsS -X POST -H "$auth" -H "Content-Type: application/json" -d @- "$API/releases" | jq -r .id) + fi + for f in dist/*; do + name=$(basename "$f") + echo "Attaching $name" + curl -fsS -X POST -H "$auth" -F "attachment=@$f" "$API/releases/$id/assets?name=$name" > /dev/null + done diff --git a/Docs-Site/guide/configuration.md b/Docs-Site/guide/configuration.md index 38db14f..a531992 100644 --- a/Docs-Site/guide/configuration.md +++ b/Docs-Site/guide/configuration.md @@ -51,7 +51,7 @@ Docwell is configured with environment variables, set in `.env` (separate servic | Variable | Default | What it does | | --- | --- | --- | -| `DOCWELL_REGISTRY` | `ghcr.io/docwell` | Where `docker compose pull` gets the images. | +| `DOCWELL_REGISTRY` | `ghcr.io/docwell` | Where `docker compose pull` gets the images. For images released on a Gitea server, `/`. A Gitea served over plain http must be listed under `insecure-registries` in Docker's `daemon.json`. | | `DOCWELL_VERSION` | `latest` | Which release to run, for example `0.1.0`. | ## Volumes diff --git a/README.md b/README.md index 365fb89..d4c28ad 100644 --- a/README.md +++ b/README.md @@ -134,7 +134,9 @@ The documentation site: `npm run dev:docs` (http://localhost:5173) and `npm run ### Releases -Push a tag like `v0.1.0`. The Release workflow builds `docwell-db`, `docwell-server`, `docwell-web` and the all-in-one `docwell` image for `linux/amd64` and `linux/arm64` and pushes them to `ghcr.io//`. The compose files pull from `DOCWELL_REGISTRY` (default `ghcr.io/docwell`) at `DOCWELL_VERSION` (default `latest`). +Push a tag like `v1.0.0` to the Gitea repository. The Release workflow builds `docwell-db`, `docwell-server`, `docwell-web` and the all-in-one `docwell` image for `linux/amd64` and `linux/arm64` and pushes them to that Gitea's container registry, `//`. It also builds the Windows and Linux desktop installers and attaches them to a Gitea release for the tag. The macOS DMG is built by hand on a Mac (`wails3 task darwin:package:dmg` in `Desktop-App`) and attached afterwards. The runners, secret and variables it needs are listed at the top of [.github/workflows/release.yml](.github/workflows/release.yml). + +The compose files pull from `DOCWELL_REGISTRY` (default `ghcr.io/docwell`) at `DOCWELL_VERSION` (default `latest`). For images from a Gitea registry, set `DOCWELL_REGISTRY=/`. ## License