From 95c487415b2bd6a6acfe0351d580ba5587cb6bdb Mon Sep 17 00:00:00 2001 From: Jan Novak Date: Tue, 11 Aug 2026 19:39:23 +0200 Subject: [PATCH] Add Gitea Actions image-build workflow Distilled from the house pattern across sibling projects: tag push + workflow_dispatch triggers, REGISTRY_TOKEN login, raw docker build/push to gitea.home.hrajfrisbee.cz. Adds a lightweight test gate, an immutable sha-<12> tag, :latest only on real tag pushes, and a concurrency group. Co-Authored-By: Claude --- .gitea/workflows/build.yaml | 76 +++++++++++++++++++ CLAUDE.md | 14 +++- .../2026-08-11-1935-gitea-build-workflow.md | 42 ++++++++++ 3 files changed, 130 insertions(+), 2 deletions(-) create mode 100644 .gitea/workflows/build.yaml create mode 100644 docs/plans-executions/2026-08-11-1935-gitea-build-workflow.md diff --git a/.gitea/workflows/build.yaml b/.gitea/workflows/build.yaml new file mode 100644 index 0000000..66fccac --- /dev/null +++ b/.gitea/workflows/build.yaml @@ -0,0 +1,76 @@ +name: Build and Push + +on: + workflow_dispatch: + inputs: + tag: + description: 'Image tag' + required: true + default: 'latest' + push: + tags: + - '*' + +concurrency: + group: build-${{ github.ref }} + cancel-in-progress: true + +jobs: + check: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version-file: go.mod + cache: true + - name: Vet + run: go vet ./... + - name: Build + run: go build ./... + - name: Test (short) + run: go test -short ./... + + build: + needs: check + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + steps: + - uses: actions/checkout@v4 + + - name: Compute image tags + id: meta + run: | + if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then + TAG="${{ inputs.tag }}" + else + TAG="${{ github.ref_name }}" + fi + echo "tag=$TAG" >> "$GITHUB_OUTPUT" + echo "sha=sha-$(echo '${{ github.sha }}' | cut -c1-12)" >> "$GITHUB_OUTPUT" + + - name: Login to Gitea registry + run: echo "${{ secrets.REGISTRY_TOKEN }}" | docker login -u ${{ github.actor }} --password-stdin gitea.home.hrajfrisbee.cz + + - name: Build and push + run: | + IMAGE=gitea.home.hrajfrisbee.cz/${{ github.repository }} + docker build \ + --build-arg GIT_COMMIT=$(echo '${{ github.sha }}' | cut -c1-12) \ + --label org.opencontainers.image.source=https://gitea.home.hrajfrisbee.cz/${{ github.repository }} \ + --label org.opencontainers.image.created=$(date -u +%Y-%m-%dT%H:%M:%SZ) \ + -t "$IMAGE:${{ steps.meta.outputs.tag }}" \ + -t "$IMAGE:${{ steps.meta.outputs.sha }}" \ + . + docker push "$IMAGE:${{ steps.meta.outputs.tag }}" + docker push "$IMAGE:${{ steps.meta.outputs.sha }}" + + # Only real tag pushes move :latest — an ad-hoc dispatch of an old ref must not clobber it. + - name: Push latest (tag builds only) + if: github.event_name == 'push' + run: | + IMAGE=gitea.home.hrajfrisbee.cz/${{ github.repository }} + docker tag "$IMAGE:${{ steps.meta.outputs.tag }}" "$IMAGE:latest" + docker push "$IMAGE:latest" diff --git a/CLAUDE.md b/CLAUDE.md index 4be0be9..57e257e 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -199,8 +199,18 @@ Always append a `Co-Authored-By` trailer to indicate AI assistance: Co-Authored-By: Claude -TODO: no `.gitea/workflows/` CI pipeline exists yet — add a CI/CD subsection here once -one is set up. +### CI/CD + +`.gitea/workflows/build.yaml` builds the manager image and pushes it to the Gitea +registry. Triggers: any tag push, or manual `workflow_dispatch` with a `tag` input. +A lightweight `check` job (`go vet` / `go build` / `go test -short`) gates the build. + +- Images: `gitea.home.hrajfrisbee.cz/kacerr/egress-proxies-operator:` plus an + immutable `sha-<12-char-commit>` tag on every build; `:latest` moves only on real + tag pushes, never on manual dispatch. +- Requires the `REGISTRY_TOKEN` repo secret (Gitea PAT with `write:package`), + same convention as the other projects on this Gitea instance. +- The commit is baked into the binary via the `GIT_COMMIT` build arg (see Dockerfile). ## Gotchas diff --git a/docs/plans-executions/2026-08-11-1935-gitea-build-workflow.md b/docs/plans-executions/2026-08-11-1935-gitea-build-workflow.md new file mode 100644 index 0000000..17b0c89 --- /dev/null +++ b/docs/plans-executions/2026-08-11-1935-gitea-build-workflow.md @@ -0,0 +1,42 @@ +# Execution: Distilled Gitea Actions image-build workflow + +Plan: `docs/plans/2026-08-11-1935-gitea-build-workflow.md` + +- [x] Step 1 — Create `.gitea/workflows/build.yaml` +- [x] Step 2 — Replace CLAUDE.md CI TODO with a CI/CD subsection +- [ ] Step 3 — Push branch + open MR +- [ ] Step 4 — CHANGELOG entry (after the first successful run is confirmed) + +## Steps 1–2 — workflow + CLAUDE.md + +The workflow distills the house pattern from 9 sibling projects (survey in the plan) +plus improvements none of them combine: an immutable `sha-<12>` tag, a lightweight +test gate, `:latest` moving only on real tag pushes, and a `concurrency` group. + +Work happened in a git worktree off `origin/main` so the main checkout (which had +unrelated uncommitted changes) stayed untouched: + +```bash +git worktree add -b feat/gitea-build-workflow \ + "$SCRATCH/wt-build" origin/main +``` + +Deviation from the plan's assumptions: while planning, `feat/proxy-operator` was +still unmerged and the plan noted `main` lacked `internal/`/`test/`. By execution +time `origin/main` had moved (`076bc66..f7000f7` — the proxy-operator MR merged), +so the branch and its CI gate cover the full operator code. + +Verified the workflow parses and the check-gate commands pass on this exact tree +(ruby stands in for a YAML linter because the system python3 has no `yaml` module): + +```bash +ruby -ryaml -e "YAML.load_file('.gitea/workflows/build.yaml'); puts 'YAML OK'" +go vet ./... && go build ./... && go test -short ./... # all packages ok +``` + +Worth noting: the workflow itself cannot run end-to-end until (a) the MR merges +(it only triggers on tags / manual dispatch, not branch pushes) and (b) the +`REGISTRY_TOKEN` secret is created in this repo's Gitea settings (PAT with +`write:package`). First real verification = manual dispatch with tag +`manual-test`, expecting `manual-test` + `sha-…` in Packages and `:latest` +untouched.