setup workflow
This commit is contained in:
@@ -0,0 +1,141 @@
|
|||||||
|
name: docker-image
|
||||||
|
|
||||||
|
# Reusable workflow: builds one or more images of a repository and tags them all
|
||||||
|
# with the same docker/metadata-action tag set:
|
||||||
|
#
|
||||||
|
# <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)
|
||||||
|
# latest on the default branch
|
||||||
|
#
|
||||||
|
# The tag set is computed once in `meta` and shared by every image of the run, so a
|
||||||
|
# multi-image repo (antispam) gets one timestamp across all images.
|
||||||
|
#
|
||||||
|
# Caller:
|
||||||
|
#
|
||||||
|
# jobs:
|
||||||
|
# test: ...
|
||||||
|
# image:
|
||||||
|
# needs: test
|
||||||
|
# uses: traberph/workflows/.gitea/workflows/docker-image.yaml@main
|
||||||
|
# with:
|
||||||
|
# images: '[{"image": "registry.traberph.de/private/cv"}]'
|
||||||
|
# secrets:
|
||||||
|
# registry-username: ${{ secrets.REGISTRY_USERNAME }}
|
||||||
|
# registry-token: ${{ secrets.REGISTRY_TOKEN }}
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_call:
|
||||||
|
inputs:
|
||||||
|
images:
|
||||||
|
description: >-
|
||||||
|
JSON array of images to build: [{"image": "<registry>/<project>/<name>",
|
||||||
|
"context": ".", "dockerfile": "<context>/Dockerfile"}]. Only "image" is required.
|
||||||
|
type: string
|
||||||
|
required: true
|
||||||
|
registry:
|
||||||
|
description: Registry to log in to.
|
||||||
|
type: string
|
||||||
|
default: registry.traberph.de
|
||||||
|
platforms:
|
||||||
|
type: string
|
||||||
|
default: linux/amd64
|
||||||
|
build-args:
|
||||||
|
description: Newline-separated KEY=value pairs, passed to every image.
|
||||||
|
type: string
|
||||||
|
default: ""
|
||||||
|
push:
|
||||||
|
description: Push the images. Pass false for pull requests.
|
||||||
|
type: boolean
|
||||||
|
default: true
|
||||||
|
cache:
|
||||||
|
description: Keep the layer cache in the registry as <image>:buildcache.
|
||||||
|
type: boolean
|
||||||
|
default: false
|
||||||
|
secrets:
|
||||||
|
registry-username:
|
||||||
|
required: false
|
||||||
|
registry-token:
|
||||||
|
required: false
|
||||||
|
outputs:
|
||||||
|
tag:
|
||||||
|
description: The timestamp tag, <UTC yyyymmddHHMMSS>-<sha7>.
|
||||||
|
value: ${{ jobs.meta.outputs.tag }}
|
||||||
|
version:
|
||||||
|
description: The version metadata-action resolved (1.2.3 on v1.2.3, else the timestamp tag).
|
||||||
|
value: ${{ jobs.meta.outputs.version }}
|
||||||
|
tag-names:
|
||||||
|
description: Newline-separated tag names pushed for every image.
|
||||||
|
value: ${{ jobs.meta.outputs.tag-names }}
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
meta:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
outputs:
|
||||||
|
tag: ${{ steps.tag.outputs.tag }}
|
||||||
|
version: ${{ steps.meta.outputs.version }}
|
||||||
|
tag-names: ${{ steps.meta.outputs.tag-names }}
|
||||||
|
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:
|
||||||
|
include: ${{ fromJSON(inputs.images) }}
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v7
|
||||||
|
|
||||||
|
- id: tags
|
||||||
|
env:
|
||||||
|
IMAGE: ${{ matrix.image }}
|
||||||
|
TAG_NAMES: ${{ needs.meta.outputs.tag-names }}
|
||||||
|
run: |
|
||||||
|
{
|
||||||
|
echo "tags<<EOF"
|
||||||
|
printf '%s\n' "$TAG_NAMES" | sed "/^$/d; s|^|${IMAGE}:|"
|
||||||
|
echo "EOF"
|
||||||
|
} >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
|
- if: contains(inputs.platforms, 'arm')
|
||||||
|
uses: docker/setup-qemu-action@v4
|
||||||
|
- uses: docker/setup-buildx-action@v4
|
||||||
|
|
||||||
|
- if: inputs.push
|
||||||
|
uses: docker/login-action@v4
|
||||||
|
with:
|
||||||
|
registry: ${{ inputs.registry }}
|
||||||
|
username: ${{ secrets.registry-username }}
|
||||||
|
password: ${{ secrets.registry-token }}
|
||||||
|
|
||||||
|
- uses: docker/build-push-action@v7
|
||||||
|
with:
|
||||||
|
context: ${{ matrix.context || '.' }}
|
||||||
|
file: ${{ matrix.dockerfile || format('{0}/Dockerfile', matrix.context || '.') }}
|
||||||
|
platforms: ${{ inputs.platforms }}
|
||||||
|
push: ${{ inputs.push }}
|
||||||
|
tags: ${{ steps.tags.outputs.tags }}
|
||||||
|
labels: ${{ needs.meta.outputs.labels }}
|
||||||
|
build-args: ${{ inputs.build-args }}
|
||||||
|
cache-from: ${{ inputs.cache && format('type=registry,ref={0}:buildcache', matrix.image) || '' }}
|
||||||
|
cache-to: ${{ inputs.cache && inputs.push && format('type=registry,ref={0}:buildcache,mode=max,image-manifest=true,oci-mediatypes=true', matrix.image) || '' }}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
# workflows
|
||||||
|
|
||||||
|
Reusable Gitea Actions workflows for the apps in the cluster.
|
||||||
|
|
||||||
|
## `docker-image.yaml`
|
||||||
|
|
||||||
|
Builds and pushes one or more images with a uniform tag set from
|
||||||
|
[docker/metadata-action](https://github.com/docker/metadata-action):
|
||||||
|
|
||||||
|
| Tag | When |
|
||||||
|
|---|---|
|
||||||
|
| `<UTC yyyymmddHHMMSS>-<sha7>` | every build; Flux `ImagePolicy` sorts on the timestamp |
|
||||||
|
| `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 tag set is computed once per run, so every image of a multi-image repo gets the same tags.
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
jobs:
|
||||||
|
test: ...
|
||||||
|
image:
|
||||||
|
needs: test
|
||||||
|
uses: traberph/workflows/.gitea/workflows/docker-image.yaml@main
|
||||||
|
with:
|
||||||
|
images: '[{"image": "registry.traberph.de/private/cv"}]'
|
||||||
|
platforms: linux/amd64,linux/arm64
|
||||||
|
push: ${{ github.event_name != 'pull_request' }}
|
||||||
|
secrets:
|
||||||
|
registry-username: ${{ secrets.REGISTRY_USERNAME }}
|
||||||
|
registry-token: ${{ secrets.REGISTRY_TOKEN }}
|
||||||
|
```
|
||||||
|
|
||||||
|
Inputs:
|
||||||
|
|
||||||
|
- `images` (required): JSON array of `{"image", "context", "dockerfile"}`; `context` defaults to `.`, `dockerfile` to `<context>/Dockerfile`.
|
||||||
|
- `registry`: registry to log in to (default `registry.traberph.de`).
|
||||||
|
- `platforms`: default `linux/amd64`. QEMU is set up when an `arm` platform is listed.
|
||||||
|
- `build-args`: newline-separated `KEY=value`, passed to every image.
|
||||||
|
- `push`: default `true`.
|
||||||
|
- `cache`: keep the layer cache in the registry as `<image>:buildcache` (default `false`).
|
||||||
|
|
||||||
|
Outputs: `tag` (the timestamp tag), `version`, `tag-names`.
|
||||||
|
|
||||||
|
## Updates
|
||||||
|
|
||||||
|
Renovate (running in the cluster, see `cumulus/apps/base/renovate`) opens PRs for the actions used here; see [`renovate.json`](renovate.json).
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
||||||
|
"extends": ["config:recommended"],
|
||||||
|
"timezone": "Europe/Berlin",
|
||||||
|
"packageRules": [
|
||||||
|
{
|
||||||
|
"description": "Supply-chain buffer: only propose action releases that are a few days old",
|
||||||
|
"matchManagers": ["github-actions"],
|
||||||
|
"minimumReleaseAge": "3 days"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user