one image per call, timestamp tag from commit time

Gitea 1.27.0 panics expanding a called workflow whose matrix comes from
inputs, and the caller run is never created. Build one image per call
instead; the commit time keeps the tag identical across calls.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-16 19:29:22 +02:00
co-authored by Claude Opus 5.5
parent 9998d345d7
commit f55707417f
2 changed files with 89 additions and 89 deletions
+48 -71
View File
@@ -1,25 +1,29 @@
name: image name: image
# Reusable workflow: builds one or more images of a repository and tags them all # Reusable workflow: builds one image and tags it with the docker/metadata-action tag set
# with the same docker/metadata-action tag set: # shared by every repo:
# #
# <UTC yyyymmddHHMMSS>-<sha7> every build (Flux image automation sorts on it) # <UTC yyyymmddHHMMSS>-<sha7> every build (Flux image automation sorts on it)
# 1.2.3, 1.2, 1 on a v1.2.3 git tag (no "1" while major is 0) # 1.2.3, 1.2, 1 on a v1.2.3 git tag (no "1" while major is 0)
# latest on the default branch # latest on the default branch
# #
# The tag set is computed once in `meta` and shared by every image of the run, so a # The timestamp is the commit time, not the build time, so the tag depends only on the
# multi-image repo (antispam) gets one timestamp across all images. # commit: a repo with several images calls this once per image (the calls run in
# parallel) and all of them get the same tag. Rebuilding a commit re-pushes its tag.
# #
# Images go to <registry>/<project>/<image>, and to docker.io/<dockerhub-username>/<image> # Images go to <registry>/<project>/<image>, and to docker.io/<dockerhub-username>/<image>
# when the Docker Hub secrets are passed. # when the Docker Hub secrets are passed.
# #
# One image per call: Gitea 1.27.0 can't expand a matrix built from inputs in a called
# workflow (the run is silently not created).
#
# Caller: # Caller:
# #
# jobs: # jobs:
# test: ... # test: ...
# image: # image:
# needs: test # needs: test
# uses: traberph/ci/.gitea/workflows/image.yaml@main # uses: traberph/ci/.gitea/workflows/image.yaml@v1.0.0
# with: # with:
# project: private # project: private
# image: cv # image: cv
@@ -43,7 +47,7 @@ on:
image: image:
description: Image name, in Harbor and on Docker Hub. description: Image name, in Harbor and on Docker Hub.
type: string type: string
default: "" required: true
context: context:
type: string type: string
default: "." default: "."
@@ -51,21 +55,15 @@ on:
description: Defaults to <context>/Dockerfile. description: Defaults to <context>/Dockerfile.
type: string type: string
default: "" default: ""
images:
description: >-
Several images instead of image/context/dockerfile, as a JSON array:
[{"image": "<name>", "context": ".", "dockerfile": "<context>/Dockerfile"}].
type: string
default: ""
platforms: platforms:
type: string type: string
default: linux/amd64,linux/arm64 default: linux/amd64,linux/arm64
build-args: build-args:
description: Newline-separated KEY=value pairs, passed to every image. description: Newline-separated KEY=value pairs.
type: string type: string
default: "" default: ""
push: push:
description: Push the images. Pass false for pull requests. description: Push the image. Pass false for pull requests.
type: boolean type: boolean
default: true default: true
cache: cache:
@@ -77,7 +75,7 @@ on:
required: false required: false
registry-token: registry-token:
required: false required: false
# Optional: with both set, every image is also pushed to docker.io/<dockerhub-username>/<image>. # Optional: with both set, the image is also pushed to docker.io/<dockerhub-username>/<image>.
dockerhub-username: dockerhub-username:
required: false required: false
dockerhub-token: dockerhub-token:
@@ -85,80 +83,59 @@ on:
outputs: outputs:
tag: tag:
description: The timestamp tag, <UTC yyyymmddHHMMSS>-<sha7>. description: The timestamp tag, <UTC yyyymmddHHMMSS>-<sha7>.
value: ${{ jobs.meta.outputs.tag }} value: ${{ jobs.build.outputs.tag }}
version: version:
description: The version metadata-action resolved (1.2.3 on v1.2.3, else the timestamp tag). description: The version metadata-action resolved (1.2.3 on v1.2.3, else the timestamp tag).
value: ${{ jobs.meta.outputs.version }} value: ${{ jobs.build.outputs.version }}
tag-names: tags:
description: Newline-separated tag names pushed for every image. description: Newline-separated full image references that were pushed.
value: ${{ jobs.meta.outputs.tag-names }} value: ${{ jobs.build.outputs.tags }}
jobs: jobs:
meta: build:
runs-on: ubuntu-latest runs-on: ubuntu-latest
outputs: outputs:
tag: ${{ steps.tag.outputs.tag }} tag: ${{ steps.ts.outputs.tag }}
version: ${{ steps.meta.outputs.version }} version: ${{ steps.meta.outputs.version }}
tag-names: ${{ steps.meta.outputs.tag-names }} tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
steps:
# No `images`: metadata-action emits bare tag names, the build job prefixes them.
- id: meta
uses: docker/metadata-action@v6
with:
flavor: latest=false
tags: |
type=raw,value={{date 'YYYYMMDDHHmmss' tz='UTC'}}-{{sha}},priority=1000
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}},enable=${{ !startsWith(github.ref, 'refs/tags/v0.') }}
type=raw,value=latest,enable={{is_default_branch}}
- id: tag
env:
TAG_NAMES: ${{ steps.meta.outputs.tag-names }}
run: |
tag="$(printf '%s\n' "$TAG_NAMES" | grep -E '^[0-9]{14}-[0-9a-f]{7}$')"
echo "tag=${tag}" >> "$GITHUB_OUTPUT"
printf 'Tags:\n%s\n' "$TAG_NAMES"
build:
needs: meta
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
# A single image/context/dockerfile becomes a one-entry list.
include: ${{ fromJSON(inputs.images || format('[{{"image":"{0}","context":"{1}","dockerfile":"{2}"}}]', inputs.image, inputs.context, inputs.dockerfile)) }}
env: env:
IMAGE: ${{ inputs.registry }}/${{ inputs.project }}/${{ matrix.image }} IMAGE: ${{ inputs.registry }}/${{ inputs.project }}/${{ inputs.image }}
# Secrets can't be used in `if:` directly, env can. # Secrets can't be used in `if:` directly, env can.
DOCKERHUB: ${{ secrets.dockerhub-username != '' && secrets.dockerhub-token != '' }} DOCKERHUB: ${{ secrets.dockerhub-username != '' && secrets.dockerhub-token != '' }}
DOCKERHUB_USERNAME: ${{ secrets.dockerhub-username }} DOCKERHUB_USERNAME: ${{ secrets.dockerhub-username }}
steps: steps:
- uses: actions/checkout@v7 - uses: actions/checkout@v7
- id: tags - id: ts
env:
NAME: ${{ matrix.image }}
TAG_NAMES: ${{ needs.meta.outputs.tag-names }}
run: | run: |
if [ -z "${NAME}" ]; then ts="$(TZ=UTC git log -1 --format=%cd --date=format-local:%Y%m%d%H%M%S)"
echo "::error::set the image input (or images)" # same as metadata-action's {{sha}}
exit 1 sha="$(echo "${GITHUB_SHA}" | cut -c1-7)"
fi
images="${IMAGE}" images="${IMAGE}"
if [ "${DOCKERHUB}" = "true" ]; then if [ "${DOCKERHUB}" = "true" ]; then
images="${images} docker.io/${DOCKERHUB_USERNAME}/${NAME}" images="${images}
docker.io/${DOCKERHUB_USERNAME}/${{ inputs.image }}"
fi fi
{ {
echo "tags<<EOF" echo "ts=${ts}"
for image in ${images}; do echo "tag=${ts}-${sha}"
printf '%s\n' "$TAG_NAMES" | sed "/^$/d; s|^|${image}:|" echo "images<<EOF"
done echo "${images}"
echo "EOF" echo "EOF"
} >> "$GITHUB_OUTPUT" } >> "$GITHUB_OUTPUT"
- id: meta
uses: docker/metadata-action@v6
with:
images: ${{ steps.ts.outputs.images }}
flavor: latest=false
tags: |
type=raw,value=${{ steps.ts.outputs.ts }}-{{sha}}
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}},enable=${{ !startsWith(github.ref, 'refs/tags/v0.') }}
type=raw,value=latest,enable={{is_default_branch}}
- if: contains(inputs.platforms, 'arm') - if: contains(inputs.platforms, 'arm')
uses: docker/setup-qemu-action@v4 uses: docker/setup-qemu-action@v4
- uses: docker/setup-buildx-action@v4 - uses: docker/setup-buildx-action@v4
@@ -178,12 +155,12 @@ jobs:
- uses: docker/build-push-action@v7 - uses: docker/build-push-action@v7
with: with:
context: ${{ matrix.context || '.' }} context: ${{ inputs.context }}
file: ${{ matrix.dockerfile || format('{0}/Dockerfile', matrix.context || '.') }} file: ${{ inputs.dockerfile || format('{0}/Dockerfile', inputs.context) }}
platforms: ${{ inputs.platforms }} platforms: ${{ inputs.platforms }}
push: ${{ inputs.push }} push: ${{ inputs.push }}
tags: ${{ steps.tags.outputs.tags }} tags: ${{ steps.meta.outputs.tags }}
labels: ${{ needs.meta.outputs.labels }} labels: ${{ steps.meta.outputs.labels }}
build-args: ${{ inputs.build-args }} build-args: ${{ inputs.build-args }}
cache-from: ${{ inputs.cache && format('type=registry,ref={0}:buildcache', env.IMAGE) || '' }} cache-from: ${{ inputs.cache && format('type=registry,ref={0}:buildcache', env.IMAGE) || '' }}
cache-to: ${{ inputs.cache && inputs.push && format('type=registry,ref={0}:buildcache,mode=max,image-manifest=true,oci-mediatypes=true', env.IMAGE) || '' }} cache-to: ${{ inputs.cache && inputs.push && format('type=registry,ref={0}:buildcache,mode=max,image-manifest=true,oci-mediatypes=true', env.IMAGE) || '' }}
+41 -18
View File
@@ -1,21 +1,23 @@
# ci # ci
Reusable Gitea Actions workflows for the apps in the cluster. Needs Gitea 1.27 or later, which Reusable Gitea Actions workflows for the apps in the cluster. Needs Gitea 1.27 or later, which
expands called workflows on the server, so each image builds as its own job, in parallel across expands called workflows on the server into their own jobs. The repository is public so every
the runners. The repository is public so every repo can call it. repo can call it.
## `image.yaml` ## `image.yaml`
Builds and pushes one or more images with a uniform tag set from Builds and pushes one image with a uniform tag set from
[docker/metadata-action](https://github.com/docker/metadata-action): [docker/metadata-action](https://github.com/docker/metadata-action):
| Tag | When | | Tag | When |
|---|---| |---|---|
| `<UTC yyyymmddHHMMSS>-<sha7>` | every build; Flux `ImagePolicy` sorts on the timestamp | | `<UTC yyyymmddHHMMSS>-<sha7>` | every build; the timestamp is the **commit** time, Flux `ImagePolicy` sorts on it |
| `1.2.3`, `1.2`, `1` | on a `v1.2.3` git tag (`1` is skipped while the major is `0`; pre-releases only get the full version) | | `1.2.3`, `1.2`, `1` | on a `v1.2.3` git tag (`1` is skipped while the major is `0`; pre-releases only get the full version) |
| `latest` | on the default branch | | `latest` | on the default branch |
The tag set is computed once per run, so every image of a multi-image repo gets the same tags. The tags depend only on the commit, not on when it was built. A repo with several images calls
the workflow once per image (the calls run as separate jobs, in parallel) and every image gets the
same tags; rebuilding a commit re-pushes its tags instead of producing a newer one.
If the `dockerhub-username` and `dockerhub-token` secrets are passed, every image is also pushed with the same tags to `docker.io/<dockerhub-username>/<image>`, e.g. `registry.traberph.de/public/homepage` → `docker.io/traberph/homepage`. Only pass them for public images: Docker Hub creates new repositories as public by default. If the `dockerhub-username` and `dockerhub-token` secrets are passed, every image is also pushed with the same tags to `docker.io/<dockerhub-username>/<image>`, e.g. `registry.traberph.de/public/homepage` → `docker.io/traberph/homepage`. Only pass them for public images: Docker Hub creates new repositories as public by default.
@@ -24,7 +26,7 @@ jobs:
test: ... test: ...
image: image:
needs: test needs: test
uses: traberph/ci/.gitea/workflows/image.yaml@main uses: traberph/ci/.gitea/workflows/image.yaml@v1.0.0
with: with:
project: public project: public
image: homepage image: homepage
@@ -40,24 +42,45 @@ Inputs:
- `registry`: default `registry.traberph.de`. - `registry`: default `registry.traberph.de`.
- `project` (required): Harbor project, e.g. `public` or `private`. - `project` (required): Harbor project, e.g. `public` or `private`.
- `image`: image name, used in Harbor (`<registry>/<project>/<image>`) and on Docker Hub. - `image` (required): image name, used in Harbor (`<registry>/<project>/<image>`) and on Docker Hub.
- `context`: default `.`. - `context`: default `.`.
- `dockerfile`: default `<context>/Dockerfile`. - `dockerfile`: default `<context>/Dockerfile`.
- `images`: several images instead of `image`/`context`/`dockerfile`, as a JSON array of `{"image", "context", "dockerfile"}`:
```yaml
project: uni-spam
images: |
[
{"image": "inference", "context": "services/inference"},
{"image": "webapp", "context": "services/webapp/frontend"}
]
```
- `platforms`: default `linux/amd64,linux/arm64`. QEMU is set up when an `arm` platform is listed. - `platforms`: default `linux/amd64,linux/arm64`. QEMU is set up when an `arm` platform is listed.
- `build-args`: newline-separated `KEY=value`, passed to every image. - `build-args`: newline-separated `KEY=value`.
- `push`: default `true`. - `push`: default `true`.
- `cache`: keep the layer cache in Harbor as `<image>:buildcache` (default `false`). - `cache`: keep the layer cache in Harbor as `<image>:buildcache` (default `false`).
Outputs: `tag` (the timestamp tag), `version`, `tag-names`. Outputs: `tag` (the timestamp tag), `version`, `tags` (the full image references).
Several images: one job per image, e.g.
```yaml
jobs:
inference:
uses: traberph/ci/.gitea/workflows/image.yaml@v1.0.0
with: {project: uni-spam, image: inference, context: services/inference}
secrets: ...
webapp:
uses: traberph/ci/.gitea/workflows/image.yaml@v1.0.0
with: {project: uni-spam, image: webapp, context: services/webapp/frontend}
secrets: ...
```
A matrix over images inside the called workflow (`matrix: ${{ fromJSON(inputs.…) }}`) does not
work on Gitea 1.27.0: its parser panics while expanding the call and the run is never created.
## Versions
Callers pin a release tag (`@v1.0.0`). Renovate in the calling repos proposes new tags; it needs
a rule pointing `traberph/ci` at this Gitea:
```json
{
"matchDepNames": ["traberph/ci"],
"overrideDatasource": "gitea-tags",
"registryUrls": ["https://git.traberph.de"]
}
```
## Updates ## Updates