projects

showcase

A public git mirror

ci: manual release runs; push via the tailnet registry name

daniel daum committed parent 3ed9da7 commit 5b15ad4

Showing 3 changed files with 57 additions and 19 deletions.

.gitea/workflows/release.yml +35 −13
@@ -2,6 +2,9 @@22# (linux/amd64), push it as 1.2.3 and latest, and create the Gitea release33# with the image digest and the commits since the previous tag.44#5# To run it by hand (Actions → release → Run workflow), name an existing6# tag: its code is built with this workflow, and its release is updated.7#58# Needs a repo secret REGISTRY_TOKEN: a Gitea access token with69# write:package. GITEA_TOKEN is made by Gitea for each run.710name: release@@ -9,41 +12,60 @@ name: release912on:1013  push:1114    tags: ["v*.*.*"]15  workflow_dispatch:16    inputs:17      tag:18        description: Existing tag to release, like v1.2.319        required: true12201321permissions:1422  contents: write # the Gitea release152324# The push goes through the Docker daemon on the runner's host, so the image25# needs a name that host resolves: Gitea's tailnet name, not the address the26# runner uses for Gitea (GITHUB_SERVER_URL, a Docker network name here).27env:28  IMAGE: code.aardvark-halibut.ts.net/daniel/showcase291630jobs:1731  release:1832    runs-on: ubuntu-latest33    env:34      TAG: ${{ inputs.tag || github.ref_name }}1935    steps:2036      - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.02137        with:38          ref: refs/tags/${{ env.TAG }}2239          fetch-depth: 0 # the previous tag, for the notes23402441      - name: Build and push the image2542        env:2643          TOKEN: ${{ secrets.REGISTRY_TOKEN }}2744        run: |28          # Gitea's own host is the registry: <host>/daniel/showcase29          host=${GITHUB_SERVER_URL#*://}30          IMAGE=${host%/}/$GITHUB_REPOSITORY31          echo "IMAGE=$IMAGE" >> "$GITHUB_ENV"45          [[ $TAG =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]] || { echo "::error::$TAG isn't a tag like v1.2.3"; exit 1; }3246          printf '%s' "$TOKEN" | docker login "${IMAGE%%/*}" -u "$GITHUB_REPOSITORY_OWNER" --password-stdin33          docker build --platform linux/amd64 -t "$IMAGE:${GITHUB_REF_NAME#v}" -t "$IMAGE:latest" .47          docker build --platform linux/amd64 -t "$IMAGE:${TAG#v}" -t "$IMAGE:latest" .3448          docker push "$IMAGE:latest"35          pushed=$(docker push "$IMAGE:${GITHUB_REF_NAME#v}")49          pushed=$(docker push "$IMAGE:${TAG#v}")3650          echo "$pushed"3751          echo "DIGEST=$(echo "$pushed" | awk '/digest: sha256:/ {print $3}')" >> "$GITHUB_ENV"3852          docker logout "${IMAGE%%/*}"395340      - name: Create the Gitea release54      # a rerun rebuilds the image with a new digest, so it updates the release55      - name: Create or update the Gitea release4156        env:4257          TOKEN: ${{ secrets.GITEA_TOKEN }}4358        run: |44          prev=$(git describe --tags --abbrev=0 "$GITHUB_REF_NAME^" 2>/dev/null || true)45          notes=$(git log --format='- %s' "${prev:+$prev..}$GITHUB_REF_NAME")46          jq -n --arg tag "$GITHUB_REF_NAME" --arg body "$(printf 'Image: `%s@%s`\n\n%s' "$IMAGE" "$DIGEST" "$notes")" \47            '{tag_name: $tag, name: $tag, body: $body}' |48            curl -fsS -o /dev/null -X POST -H "Authorization: token $TOKEN" -H "Content-Type: application/json" \49              --data @- "$GITHUB_SERVER_URL/api/v1/repos/$GITHUB_REPOSITORY/releases"59          # the job container reaches Gitea at the runner's address for it60          api=$GITHUB_SERVER_URL/api/v1/repos/$GITHUB_REPOSITORY/releases61          prev=$(git describe --tags --abbrev=0 "$TAG^" 2>/dev/null || true)62          notes=$(git log --format='- %s' "${prev:+$prev..}$TAG")63          body=$(jq -n --arg tag "$TAG" --arg body "$(printf 'Image: `%s@%s`\n\n%s' "$IMAGE" "$DIGEST" "$notes")" \64            '{tag_name: $tag, name: $tag, body: $body}')65          if id=$(curl -fsS -H "Authorization: token $TOKEN" "$api/tags/$TAG" | jq -e .id); then66            method=PATCH url=$api/$id67          else68            method=POST url=$api69          fi70          curl -fsS -o /dev/null -X "$method" -H "Authorization: token $TOKEN" -H "Content-Type: application/json" \71            --data "$body" "$url"
README.md +5 −0
@@ -90,6 +90,11 @@ the rest.9090   the Gitea release `v0.2.1` with the image digest and the commits since9191   `v0.2.0`.929293   To run it by hand, for example after a failed run: Actions → release →94   Run workflow, on `main`, with the tag (`v0.2.1`). It builds that tag's95   code with the workflow on `main`, so a fixed workflow works for an96   older tag, and it updates the tag's release with the new digest.9793984. **Deploy.** Pin the digest from the release notes in9499   `deploy/compose.yaml` (the `image:` line and the version in the comment95100   above it) and commit that. Copy `compose.yaml` to the server and, next
docs/decisions.md +17 −6
@@ -938,13 +938,24 @@ never `latest`, so nothing reaches it that Daniel didn't pin.938938  `$GITHUB_REF_NAME`, so nothing is interpolated into a script.939939- **Registry host:** Gitea moved to the tailnet940940  (`code.aardvark-halibut.ts.net`), and `git.danieldaum.net/v2/` now941  answers 404. The workflow takes the registry host from942  `$GITHUB_SERVER_URL`, Gitea's own address, so it follows Gitea if it943  moves again. The justfile, compose.yaml and the docs name the tailnet944  host. The pinned 0.1.0 digest is the same there (checked with crane).941  answers 404. The workflow, the justfile, compose.yaml and the docs name942  the tailnet host. The pinned 0.1.0 digest is the same there (checked943  with crane).944  - Not `$GITHUB_SERVER_URL`: that's the runner's address for Gitea,945    `http://gitea:3000` (a Docker network name), which works inside the946    job container but not for the push. `docker push` is done by the947    Docker daemon on the runner's host, which resolves names like the948    host does. So that host must resolve and reach the tailnet name.949    The Gitea API call (the release) does run in the job container and950    keeps using `$GITHUB_SERVER_URL`.951- **Manual runs:** `workflow_dispatch` takes an existing tag. The952  workflow comes from the branch it runs on and checks out953  `refs/tags/<tag>`, so a fixed workflow can release a tag whose own run954  failed. The tag must look like `v1.2.3`; anything else stops the run.945955- **Release notes:** the image with its digest (to pin in compose.yaml)946  and the commit subjects since the previous tag. A release that already947  exists makes the step fail after the image is pushed.956  and the commit subjects since the previous tag. A rerun rebuilds the957  image with a new digest, so an existing release is updated (PATCH)958  instead of created.948959- **Not covered:** tests (`just test` runs before committing) and the949960  tag's signature. A signature check was tried and dropped: the workflow950961  comes from the tagged commit, so it only stops tags made in Gitea's UI,