Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f1d384c8f5 | ||
|
|
b1403046e5 | ||
|
|
e15f7896cb | ||
|
|
192cc26ca1 |
@@ -11,8 +11,11 @@ name: image
|
||||
# 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>
|
||||
# when the Docker Hub secrets are passed.
|
||||
# Images go to <registry>/<project>/<image>, and to
|
||||
# docker.io/<dockerhub-username>/<project>-<image> (or <dockerhub-image>) when the Docker Hub
|
||||
# secrets are passed.
|
||||
#
|
||||
# After a push, the compressed size per platform is printed to the log and the job summary.
|
||||
#
|
||||
# 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).
|
||||
@@ -45,9 +48,13 @@ on:
|
||||
type: string
|
||||
required: true
|
||||
image:
|
||||
description: Image name, in Harbor and on Docker Hub.
|
||||
description: Image name in Harbor, and on Docker Hub as <project>-<image>.
|
||||
type: string
|
||||
required: true
|
||||
dockerhub-image:
|
||||
description: Docker Hub repository name, defaults to <project>-<image>.
|
||||
type: string
|
||||
default: ""
|
||||
context:
|
||||
type: string
|
||||
default: "."
|
||||
@@ -70,15 +77,16 @@ on:
|
||||
type: string
|
||||
default: "true"
|
||||
cache:
|
||||
description: Keep the layer cache in Harbor as <image>:buildcache, "true" or "false".
|
||||
description: Keep the layer cache in Harbor as <image>:buildcache, "true" (default) or "false".
|
||||
type: string
|
||||
default: "false"
|
||||
default: "true"
|
||||
secrets:
|
||||
registry-username:
|
||||
required: false
|
||||
registry-token:
|
||||
required: false
|
||||
# Optional: with both set, the image is also pushed to docker.io/<dockerhub-username>/<image>.
|
||||
# Optional: with both set, the image is also pushed to
|
||||
# docker.io/<dockerhub-username>/<dockerhub-image>.
|
||||
dockerhub-username:
|
||||
required: false
|
||||
dockerhub-token:
|
||||
@@ -106,6 +114,7 @@ jobs:
|
||||
# Secrets can't be used in `if:` directly, env can.
|
||||
DOCKERHUB: ${{ secrets.dockerhub-username != '' && secrets.dockerhub-token != '' }}
|
||||
DOCKERHUB_USERNAME: ${{ secrets.dockerhub-username }}
|
||||
DOCKERHUB_IMAGE: ${{ inputs.dockerhub-image || format('{0}-{1}', inputs.project, inputs.image) }}
|
||||
steps:
|
||||
- uses: actions/checkout@v7
|
||||
|
||||
@@ -117,7 +126,7 @@ jobs:
|
||||
images="${IMAGE}"
|
||||
if [ "${DOCKERHUB}" = "true" ]; then
|
||||
images="${images}
|
||||
docker.io/${DOCKERHUB_USERNAME}/${{ inputs.image }}"
|
||||
docker.io/${DOCKERHUB_USERNAME}/${DOCKERHUB_IMAGE}"
|
||||
fi
|
||||
{
|
||||
echo "ts=${ts}"
|
||||
@@ -156,7 +165,8 @@ jobs:
|
||||
username: ${{ secrets.dockerhub-username }}
|
||||
password: ${{ secrets.dockerhub-token }}
|
||||
|
||||
- uses: docker/build-push-action@v7
|
||||
- id: build
|
||||
uses: docker/build-push-action@v7
|
||||
with:
|
||||
context: ${{ inputs.context }}
|
||||
file: ${{ inputs.dockerfile || format('{0}/Dockerfile', inputs.context) }}
|
||||
@@ -167,3 +177,30 @@ jobs:
|
||||
build-args: ${{ inputs.build-args }}
|
||||
cache-from: ${{ inputs.cache == 'true' && format('type=registry,ref={0}:buildcache', env.IMAGE) || '' }}
|
||||
cache-to: ${{ inputs.cache == 'true' && inputs.push == 'true' && format('type=registry,ref={0}:buildcache,mode=max,image-manifest=true,oci-mediatypes=true', env.IMAGE) || '' }}
|
||||
|
||||
# Compressed size per platform (sum of the layer sizes, what a pull downloads), read
|
||||
# back from the registry. Only after a push: a multi-platform build isn't kept locally.
|
||||
- if: inputs.push == 'true'
|
||||
env:
|
||||
DIGEST: ${{ steps.build.outputs.digest }}
|
||||
PLATFORMS: ${{ inputs.platforms }}
|
||||
run: |
|
||||
raw="$(docker buildx imagetools inspect --raw "${IMAGE}@${DIGEST}")"
|
||||
# a single-platform push without attestations is a plain manifest, not an index
|
||||
if echo "${raw}" | jq -e '.manifests' >/dev/null; then
|
||||
list="$(echo "${raw}" | jq -r '.manifests[]
|
||||
| select(.annotations["vnd.docker.reference.type"] != "attestation-manifest")
|
||||
| "\(.platform.os)/\(.platform.architecture)\(if .platform.variant then "/" + .platform.variant else "" end) \(.digest)"')"
|
||||
else
|
||||
list="${PLATFORMS} ${DIGEST}"
|
||||
fi
|
||||
{
|
||||
echo "### ${IMAGE}"
|
||||
echo ""
|
||||
echo "| Platform | Compressed size |"
|
||||
echo "|---|---|"
|
||||
echo "${list}" | while read -r platform digest; do
|
||||
bytes="$(docker buildx imagetools inspect --raw "${IMAGE}@${digest}" | jq '[.layers[].size] | add')"
|
||||
echo "| ${platform} | $(numfmt --to=iec --suffix=B "${bytes}") |"
|
||||
done
|
||||
} | tee -a "${GITHUB_STEP_SUMMARY:-/dev/null}"
|
||||
|
||||
@@ -4,10 +4,83 @@ Reusable Gitea Actions workflows for the apps in the cluster. Needs Gitea 1.27 o
|
||||
expands called workflows on the server into their own jobs. The repository is public so every
|
||||
repo can call it.
|
||||
|
||||
## Usage
|
||||
|
||||
Add a workflow with the same name as the shared one, `.gitea/workflows/image.yaml`, to the
|
||||
calling repo and set `project` and `image`:
|
||||
|
||||
```yaml
|
||||
name: Build image
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
tags: ["v*"]
|
||||
paths-ignore: ["**.md"]
|
||||
pull_request:
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
# Tags and build steps are shared across repos, see traberph/ci.
|
||||
image:
|
||||
uses: traberph/ci/.gitea/workflows/image.yaml@v1.0.0
|
||||
with:
|
||||
project: public
|
||||
image: interval-viz
|
||||
push: ${{ github.event_name != 'pull_request' }}
|
||||
secrets:
|
||||
registry-username: ${{ secrets.REGISTRY_USERNAME }}
|
||||
registry-token: ${{ secrets.REGISTRY_TOKEN }}
|
||||
```
|
||||
|
||||
This builds `registry.traberph.de/public/interval-viz` on every push, pull request and manual
|
||||
run, and pushes it except for pull requests. The repo needs the `REGISTRY_USERNAME` and
|
||||
`REGISTRY_TOKEN` secrets (a Harbor robot account with push access to the project).
|
||||
|
||||
To run tests first, add a `test` job and set `needs: test` on `image`.
|
||||
|
||||
## `image.yaml`
|
||||
|
||||
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).
|
||||
|
||||
### Inputs
|
||||
|
||||
- `registry`: default `registry.traberph.de`.
|
||||
- `project` (required): Harbor project, e.g. `public` or `private`.
|
||||
- `image` (required): image name in Harbor (`<registry>/<project>/<image>`).
|
||||
- `dockerhub-image`: Docker Hub repository name, default `<project>-<image>`. See
|
||||
[Docker Hub](#docker-hub).
|
||||
- `context`: default `.`.
|
||||
- `dockerfile`: default `<context>/Dockerfile`.
|
||||
- `platforms`: default `linux/amd64,linux/arm64`. QEMU is set up when an `arm` platform is listed.
|
||||
- `build-args`: newline-separated `KEY=value`.
|
||||
- `push`: `"true"` (default) or `"false"`.
|
||||
- `cache`: `"true"` (default) or `"false"`. Keeps the layer cache in Harbor as
|
||||
`<image>:buildcache`: every build reads it, only pushing builds write it. The tag lives next to
|
||||
the image, so a Harbor tag retention rule on the project has to keep it (e.g. exclude
|
||||
`buildcache`).
|
||||
|
||||
`push` and `cache` are strings, not booleans: on Gitea 1.27 with gitea/runner v2.0.1 every boolean
|
||||
input of a called workflow arrives as `false`. An expression like
|
||||
`${{ github.event_name != 'pull_request' }}` works as is.
|
||||
|
||||
### Secrets
|
||||
|
||||
- `registry-username`, `registry-token`: login for `registry`, only needed when pushing.
|
||||
- `dockerhub-username`, `dockerhub-token` (optional): see [Docker Hub](#docker-hub).
|
||||
|
||||
### Outputs
|
||||
|
||||
`tag` (the timestamp tag), `version`, `tags` (the full image references).
|
||||
|
||||
### Image size
|
||||
|
||||
After a push, the compressed size of each platform (the sum of its layer sizes, what a pull
|
||||
downloads) is read back from the registry and printed to the log and the job summary. Builds
|
||||
with `push: "false"` skip it: a multi-platform build isn't kept locally.
|
||||
|
||||
### Tags
|
||||
|
||||
| Tag | When |
|
||||
|---|---|
|
||||
@@ -15,44 +88,30 @@ Builds and pushes one image with a uniform tag set from
|
||||
| `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 |
|
||||
|
||||
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.
|
||||
The tags depend only on the commit, not on when it was built: 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.
|
||||
### Docker Hub
|
||||
|
||||
If `dockerhub-username` and `dockerhub-token` are passed, the image is also pushed with the same
|
||||
tags to `docker.io/<dockerhub-username>/<project>-<image>`, e.g.
|
||||
`registry.traberph.de/public/homepage` → `docker.io/traberph/public-homepage`. Docker Hub has no
|
||||
projects, so the project goes into the name. Set `dockerhub-image` to use another name, e.g.
|
||||
`dockerhub-image: homepage` → `docker.io/traberph/homepage`. Only pass the secrets for public
|
||||
images: Docker Hub creates new repositories as public by default.
|
||||
|
||||
```yaml
|
||||
jobs:
|
||||
test: ...
|
||||
image:
|
||||
needs: test
|
||||
uses: traberph/ci/.gitea/workflows/image.yaml@v1.0.0
|
||||
with:
|
||||
project: public
|
||||
image: homepage
|
||||
push: ${{ github.event_name != 'pull_request' }}
|
||||
secrets:
|
||||
registry-username: ${{ secrets.REGISTRY_USERNAME }}
|
||||
registry-token: ${{ secrets.REGISTRY_TOKEN }}
|
||||
dockerhub-username: ${{ secrets.DOCKERHUB_USERNAME }} # optional
|
||||
dockerhub-token: ${{ secrets.DOCKERHUB_TOKEN }} # optional
|
||||
dockerhub-username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
dockerhub-token: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
```
|
||||
|
||||
Inputs:
|
||||
### Several images
|
||||
|
||||
- `registry`: default `registry.traberph.de`.
|
||||
- `project` (required): Harbor project, e.g. `public` or `private`.
|
||||
- `image` (required): image name, used in Harbor (`<registry>/<project>/<image>`) and on Docker Hub.
|
||||
- `context`: default `.`.
|
||||
- `dockerfile`: default `<context>/Dockerfile`.
|
||||
- `platforms`: default `linux/amd64,linux/arm64`. QEMU is set up when an `arm` platform is listed.
|
||||
- `build-args`: newline-separated `KEY=value`.
|
||||
- `push`: default `true`.
|
||||
- `cache`: keep the layer cache in Harbor as `<image>:buildcache` (default `false`).
|
||||
|
||||
Outputs: `tag` (the timestamp tag), `version`, `tags` (the full image references).
|
||||
|
||||
Several images: one job per image, e.g.
|
||||
Call the workflow once per image. The calls run as separate jobs in parallel, and every image of
|
||||
a commit gets the same tags:
|
||||
|
||||
```yaml
|
||||
jobs:
|
||||
@@ -69,19 +128,29 @@ jobs:
|
||||
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
|
||||
## Versions and Renovate
|
||||
|
||||
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:
|
||||
Callers pin a release tag (`@v1.0.0`). The self-hosted Renovate in the cluster (see
|
||||
`cumulus/apps/base/renovate`) monitors the calling repos itself, so they need no Renovate
|
||||
workflow, only a `renovate.json`. Renovate looks up `traberph/ci` on github.com by default, so the
|
||||
config has to point it at this Gitea:
|
||||
|
||||
```json
|
||||
{
|
||||
"matchDepNames": ["traberph/ci"],
|
||||
"overrideDatasource": "gitea-tags",
|
||||
"registryUrls": ["https://git.traberph.de"]
|
||||
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
||||
"extends": ["config:recommended"],
|
||||
"timezone": "Europe/Berlin",
|
||||
"packageRules": [
|
||||
{
|
||||
"description": "The shared image workflow lives on this Gitea, not on github.com",
|
||||
"matchDepNames": ["traberph/ci"],
|
||||
"overrideDatasource": "gitea-tags",
|
||||
"registryUrls": ["https://git.traberph.de"]
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
## Updates
|
||||
Renovate then opens a PR in the calling repo for each new release tag of this repo.
|
||||
|
||||
Renovate (running in the cluster, see `cumulus/apps/base/renovate`) opens PRs for the actions used here; see [`renovate.json`](renovate.json).
|
||||
The actions used in this repo are kept up to date the same way; see [`renovate.json`](renovate.json).
|
||||
|
||||
Reference in New Issue
Block a user