showcase
- v0.2.4
- 37 commits
- 1 branch
- 6 tags
- updated
- CI 2/2
ci: build and publish the amd64 image and Gitea release on version tags
Showing 4 changed files with 114 additions and 40 deletions.
.gitea/workflows/release.ymladded
+48 −0
@@ -0,0 +1,48 @@1# Release: when a tag like v1.2.3 is pushed, build the image for the server2# (linux/amd64), push it as 1.2.3 and latest, and create the Gitea release3# with the image digest and the commits since the previous tag.4#5# Needs a repo secret REGISTRY_TOKEN: a Gitea access token with6# write:package. GITEA_TOKEN is made by Gitea for each run.7name: release89on:10 push:11 tags: ["v*.*.*"]1213permissions:14 contents: write # the Gitea release1516env:17 IMAGE: git.danieldaum.net/daniel/showcase1819jobs:20 release:21 runs-on: ubuntu-latest22 steps:23 - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.024 with:25 fetch-depth: 0 # the previous tag, for the notes2627 - name: Build and push the image28 env:29 TOKEN: ${{ secrets.REGISTRY_TOKEN }}30 run: |31 printf '%s' "$TOKEN" | docker login "${IMAGE%%/*}" -u "$GITHUB_REPOSITORY_OWNER" --password-stdin32 docker build --platform linux/amd64 -t "$IMAGE:${GITHUB_REF_NAME#v}" -t "$IMAGE:latest" .33 docker push "$IMAGE:latest"34 pushed=$(docker push "$IMAGE:${GITHUB_REF_NAME#v}")35 echo "$pushed"36 echo "DIGEST=$(echo "$pushed" | awk '/digest: sha256:/ {print $3}')" >> "$GITHUB_ENV"37 docker logout "${IMAGE%%/*}"3839 - name: Create the Gitea release40 env:41 TOKEN: ${{ secrets.GITEA_TOKEN }}42 run: |43 prev=$(git describe --tags --abbrev=0 "$GITHUB_REF_NAME^" 2>/dev/null || true)44 notes=$(git log --format='- %s' "${prev:+$prev..}$GITHUB_REF_NAME")45 jq -n --arg tag "$GITHUB_REF_NAME" --arg body "$(printf 'Image: `%s@%s`\n\n%s' "$IMAGE" "$DIGEST" "$notes")" \46 '{tag_name: $tag, name: $tag, body: $body}' |47 curl -fsS -o /dev/null -X POST -H "Authorization: token $TOKEN" -H "Content-Type: application/json" \48 --data @- "$GITHUB_SERVER_URL/api/v1/repos/$GITHUB_REPOSITORY/releases"
README.md
+33 −38
@@ -58,69 +58,63 @@ it at danieldaum.net/projects are in [deploy/README.md](deploy/README.md).58585959### Release a version606061A release is a signed git tag `v<version>` and an image62`git.danieldaum.net/daniel/showcase:<version>`, also tagged `latest`.63Versions follow semver: a fix bumps the patch (0.2.0 → 0.2.1), a feature64the minor (0.2.0 → 0.3.0). Run these on the Mac, which has Docker and the65signing key. The examples release 0.2.1.61A release is a git tag `v<version>`, an image62`git.danieldaum.net/daniel/showcase:<version>` (also tagged `latest`) and63a Gitea release. Versions follow semver: a fix bumps the patch (0.2.0 →640.2.1), a feature the minor (0.2.0 → 0.3.0). The examples release 0.2.1.6566You commit, tag and deploy. Pushing the tag starts67[`.gitea/workflows/release.yml`](.gitea/workflows/release.yml), which does68the rest.666967701. **Check and push the commit.**68716972 ```sh7073 just lint && just test71 git status # clean: just release refuses uncommitted changes7274 git log --oneline v0.2.0..HEAD # what goes into the release7375 git push origin main7476 ```7577762. **Tag it.** Annotated and signed (`tag.gpgsign` is on; `-s` says so77 explicitly).782. **Tag it and push the tag** (signed, since `tag.gpgsign` is on).78797980 ```sh8081 git tag -s v0.2.1 -m v0.2.181 git tag -v v0.2.1 # Good "git" signature82 git push origin v0.2.182 git push origin v0.2.1 # starts the release workflow8383 ```84848585 Tagged the wrong commit? Before pushing, `git tag -d v0.2.1` and tag8686 again. Once pushed, leave it and release 0.2.2.8787883. **Build and push the image.**8990 ```sh91 docker login git.danieldaum.net # once; a Gitea token with write:package92 just release 0.2.1 # linux/amd64 + linux/arm64, tags 0.2.1 and latest93 ```883. **The workflow** (Gitea → showcase → Actions) builds the image for the89 server (linux/amd64), pushes it as `0.2.1` and `latest`, and creates90 the Gitea release `v0.2.1` with the image digest and the commits since91 `v0.2.0`.949295 `just release` takes the version without the `v`, and refuses96 uncommitted changes or a HEAD that isn't tagged `v0.2.1`. The Docker97 tags are set at build time and buildx pushes straight to the registry,98 so there's no local image to `docker tag` or `docker push`. To point a99 tag at another version later, for example `latest` back to 0.2.0 after100 a bad release:934. **Deploy.** Pin the digest from the release notes in94 `deploy/compose.yaml` (the `image:` line and the version in the comment95 above it) and commit that. Copy `compose.yaml` to the server and, next96 to it and `config.json`:1019710298 ```sh103 docker buildx imagetools create -t git.danieldaum.net/daniel/showcase:latest git.danieldaum.net/daniel/showcase:0.2.099 docker compose pull && docker compose up -d100 curl -s 127.0.0.1:8080/healthz # "ok" once a build is live104101 ```1051021064. **Write the release** (optional). In Gitea, Releases → New release,107 pick the existing tag `v0.2.1` and paste the `git log` from step 1 as108 notes. It shows on showcase's Releases tab, which only appears once a109 repo has a release. A tag without one is still listed under tags.103**Once, before the first run:** enable Actions for the repo and add a repo104secret `REGISTRY_TOKEN` (Settings → Actions → Secrets): a Gitea access105token with `write:package`. That's the only token to make: `GITEA_TOKEN`,106which writes the release, is made by Gitea for each run. The runner needs107Docker (act_runner gives jobs the host's Docker by default).1101081115. **Deploy.** Pin the new digest in `deploy/compose.yaml` (the `image:`112 line and the version in the comment above it) and commit that:109**Without CI**, from the Mac, after step 2:113110114 ```sh115 crane digest git.danieldaum.net/daniel/showcase:0.2.1116 ```117118 Copy `compose.yaml` to the server and, next to it and `config.json`:111```sh112docker login git.danieldaum.net # once; a Gitea token with write:package113just release 0.2.1 # same image and tags; no Gitea release114crane digest git.danieldaum.net/daniel/showcase:0.2.1115```119116120 ```sh121 docker compose pull && docker compose up -d122 curl -s 127.0.0.1:8080/healthz # "ok" once a build is live123 ```117Use one or the other for a version: a rebuild gets a new digest.124118125119### Container126120@@ -144,6 +138,7 @@ testdata/ sample Gitea JSON and golden output144138docs/ spec and design decisions145139Dockerfile golang build stage, alpine + git runtime, pinned by digest146140deploy/ compose, production config, saturn patch and runbook141.gitea/workflows/ release: builds and pushes the image on a version tag147142```148143149144## Docs
docs/decisions.md
+31 −0
@@ -912,3 +912,34 @@ for the repo tabs; the README box's document tabs are unchanged.912912 phone, so it stays on one line down to 375px screens.913913- Not checked in a real browser in this pass: the numbers come from the914914 font's metrics, not a render.915916## Images built by Gitea Actions917918`.gitea/workflows/release.yml` builds and pushes the image when a tag919`v*.*.*` is pushed, then creates the Gitea release. Tagging and deploying920stay manual: the server runs the digest pinned in `deploy/compose.yaml`,921never `latest`, so nothing reaches it that Daniel didn't pin.922923- **amd64 only.** The server is amd64. The image used to be built for924 arm64 too, because `just release` ran on the Mac (Apple silicon). That925 needed QEMU: Go cross-compiles natively, but the runtime stage's926 `apk add` runs as the target arch. Nothing runs the arm64 image, so it927 and QEMU are gone, here and in `just release`. Locally there's928 `just image` and `just demo`.929- **Plain docker commands**, no actions beyond checkout (pinned to a930 commit). The newest Docker actions need Node 24, and the runner was only931 shown to run Node 20 (`actions/checkout@v4`). The digest comes from932 `docker push`'s output, which every image store prints, rather than933 `docker inspect`.934- **Tokens:** only `REGISTRY_TOKEN` is made by hand (a Gitea token with935 `write:package`), since Gitea's run token isn't known to push packages.936 The release is written with the run token, `GITEA_TOKEN`. Both reach937 the scripts as environment variables, and the tag name is read from938 `$GITHUB_REF_NAME`, so nothing is interpolated into a script.939- **Release notes:** the image with its digest (to pin in compose.yaml)940 and the commit subjects since the previous tag. A release that already941 exists makes the step fail after the image is pushed.942- **Not covered:** tests (`just test` runs before committing) and the943 tag's signature. A signature check was tried and dropped: the workflow944 comes from the tagged commit, so it only stops tags made in Gitea's UI,945 and the digest pin already guards the server.
justfile
+2 −2
@@ -31,11 +31,11 @@ image_name := "git.danieldaum.net/daniel/showcase"3131image tag="dev":3232 docker build -t {{image_name}}:{{tag}} .333334# Push a tagged release: needs Docker, `docker login git.danieldaum.net`, a clean tree and HEAD tagged v<version>34# Push a tagged release by hand, as CI does (linux/amd64, for the server): needs Docker, `docker login git.danieldaum.net`, a clean tree and HEAD tagged v<version>3535release version:3636 git diff --quiet HEAD || { echo "commit first"; exit 1; }3737 test "$(git describe --exact-match --tags HEAD 2>/dev/null)" = "v{{version}}" || { echo "tag HEAD as v{{version}} first"; exit 1; }38 docker buildx build --platform linux/amd64,linux/arm64 -t {{image_name}}:{{version}} -t {{image_name}}:latest --push .38 docker buildx build --platform linux/amd64 -t {{image_name}}:{{version}} -t {{image_name}}:latest --push .39394040# Regenerate the icons from extracted npm packages: material-icon-theme@5.40.0 and @primer/octicons@19.15.04141icons material octicons: