Files
meshcore-exporter/.gitea/workflows/image.yml
T
renovate-bot 21e22caa61
pr-check / build (pull_request) Successful in 28s
pr-check / dependencies (pull_request) Successful in 5s
ci / test (push) Successful in 1m51s
ci / test (pull_request) Successful in 1m55s
Update https://git.rfa.cz/tth-pub/ci-actions action to v14
2026-11-05 15:00:22 +00:00

148 lines
5.4 KiB
YAML

# Container image git.rfa.cz/tth-pub/meshcore-exporter, one single-platform
# tag per architecture (latest-amd64, latest-arm64): `docker pull` from this
# registry is unreliable on combined multi-arch manifests. Only the commit tag
# is pushed first; latest-<arch> moves after the Trivy gate.
#
# A tag vX.Y.Z (must equal __version__) also gets X.Y.Z-<arch> images and a
# release with the pull commands and the Grafana dashboard attached.
#
# Secret REGISTRY_TOKEN: a Gitea token with packages:write.
name: image
"on":
push:
branches: [main]
tags: ["v*"]
schedule:
- cron: "40 4 * * 1" # weekly: base image security updates
workflow_dispatch:
inputs:
skip_trivy:
description: "skip the Trivy gate (EMERGENCY, logged)"
type: boolean
default: false
env:
IMAGE: git.rfa.cz/tth-pub/meshcore-exporter
jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
arch: [amd64, arm64]
steps:
- uses: actions/checkout@v7
- name: Trivy config
uses: https://git.rfa.cz/tth-pub/ci-actions/trivy-gate@v14
with:
scan-type: fs
scanners: misconfig
mode: warn
- name: Tag matches __version__
if: startsWith(github.ref, 'refs/tags/v')
run: |
set -euo pipefail
v=$(sed -n 's/^__version__ = "\(.*\)"$/\1/p' meshcore_exporter.py)
[ "v$v" = "${GITHUB_REF_NAME}" ] ||
{ echo "::error::tag ${GITHUB_REF_NAME} but __version__ = $v"; exit 1; }
- uses: docker/setup-qemu-action@v4
- uses: docker/setup-buildx-action@v4
- uses: docker/login-action@v4
with:
registry: git.rfa.cz
username: ${{ gitea.actor }}
password: ${{ secrets.REGISTRY_TOKEN }}
- name: Build date
id: date
run: echo "day=$(date -u +%F)" >> "$GITHUB_OUTPUT"
- name: Build and push the commit tag
uses: docker/build-push-action@v7
with:
context: .
push: true
pull: true
provenance: false
platforms: linux/${{ matrix.arch }}
build-args: OS_UPDATES=${{ steps.date.outputs.day }}
tags: ${{ env.IMAGE }}:${{ github.sha }}-${{ matrix.arch }}
cache-from: type=registry,ref=${{ env.IMAGE }}:buildcache-${{ matrix.arch }}
cache-to: type=registry,ref=${{ env.IMAGE }}:buildcache-${{ matrix.arch }},mode=max
# The runner cannot execute foreign binaries (no binfmt): exec format
# error on arm64. The code is pure Python, so amd64 covers it.
- name: Smoke test (--help, --version)
if: matrix.arch == 'amd64'
run: |
set -euo pipefail
img="$IMAGE:${{ github.sha }}-${{ matrix.arch }}"
docker run --rm --platform "linux/${{ matrix.arch }}" "$img" --version
docker run --rm --platform "linux/${{ matrix.arch }}" "$img" --help | grep -q -- --repeaters
- name: Trivy gate
uses: https://git.rfa.cz/tth-pub/ci-actions/trivy-gate@v14
with:
image: ${{ env.IMAGE }}:${{ github.sha }}-${{ matrix.arch }}
username: ${{ gitea.actor }}
password: ${{ secrets.REGISTRY_TOKEN }}
platform: linux/${{ matrix.arch }}
mode: block
skip: ${{ inputs.skip_trivy && 'true' || 'false' }}
# Pull, tag, push: latest-<arch> stays a plain single-platform manifest
# like the commit tag. `imagetools create` would wrap it in an OCI
# index, the kind of manifest `docker pull` from this registry is
# unreliable on.
- name: Move latest-${{ matrix.arch }}
run: |
set -euo pipefail
src="$IMAGE:${{ github.sha }}-${{ matrix.arch }}"
docker pull -q --platform "linux/${{ matrix.arch }}" "$src"
docker tag "$src" "$IMAGE:latest-${{ matrix.arch }}"
docker push -q "$IMAGE:latest-${{ matrix.arch }}"
if [[ "$GITHUB_REF" == refs/tags/v* ]]; then
ver="${GITHUB_REF_NAME#v}-${{ matrix.arch }}"
docker tag "$src" "$IMAGE:$ver"
docker push -q "$IMAGE:$ver"
fi
release:
needs: build
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- name: Release with the dashboard attached
env:
TOKEN: ${{ github.token }}
run: |
set -euo pipefail
api="${GITHUB_SERVER_URL}/api/v1/repos/${GITHUB_REPOSITORY}"
auth="header = \"Authorization: token $TOKEN\""
ver="${GITHUB_REF_NAME#v}"
body=$(cat <<EOF2
Images (one per architecture):
docker pull $IMAGE:$ver-amd64
docker pull $IMAGE:$ver-arm64
Docker stack: \`MC_VERSION=$ver\` in \`stack/.env\` pins this version.
Grafana: import the attached \`meshcore-repeater.json\`.
Setup and configuration: README.md.
EOF2
)
jq -n --arg t "$GITHUB_REF_NAME" --arg n "meshcore-exporter $ver" --arg b "$body" \
'{tag_name: $t, name: $n, body: $b}' >"$RUNNER_TEMP/rel.json"
id=$(curl -sSf --config - -X POST -H 'Content-Type: application/json' \
--data-binary "@$RUNNER_TEMP/rel.json" "$api/releases" <<<"$auth" | jq -r .id)
curl -sSf --config - -X POST -F "attachment=@dashboards/meshcore-repeater.json" \
"$api/releases/$id/assets?name=meshcore-repeater.json" <<<"$auth" >/dev/null
echo "release $GITHUB_REF_NAME (id $id)"