ProofedMesh/.forgejo/workflows/build-images.yml
CTO (Paperclip) d6efabd96f
All checks were successful
validate / JSON Schema (ajv) (push) Successful in 21s
build-images / signing-service image (push) Successful in 25s
validate / DB (migrate up/down dry-run) (push) Successful in 25s
validate / Go (vet + test) (push) Successful in 1m15s
validate / Rego (opa fmt + opa test) (push) Successful in 14s
ci(images): pass Harbor secrets as env vars so robot $ is not expanded (DEV-617)
Harbor robot usernames are of the form `robot$basicstack+forgejo-ci`.
Forgejo Actions substitutes `${{ secrets.HARBOR_USERNAME }}` into the
`run:` script before bash runs it, so `set -u` sees the resulting
`robot$basicstack+forgejo-ci` and dies with "basicstack: parameter
not set" trying to expand `$basicstack`. Pass the Harbor credentials
as env vars on the step; bash then reads them from the environment as
plain strings instead of parsing them for parameter expansion.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-10-25 20:17:41 +00:00

103 lines
4.2 KiB
YAML

name: build-images
# Build + push container images for ProofedMesh services on every push to
# main. PRs run the build to catch Dockerfile breakage but do not push.
#
# The repository is sha256 — same gotchas as validate.yml apply: no
# actions/checkout, clone manually from a trixie/alpine container with
# git ≥ 2.42.
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
signing-service:
name: signing-service image
runs-on: ubuntu-latest
container:
image: debian:trixie-slim
options: --user 0:0
env:
REGISTRY: harbor.basicstack.de
IMAGE_REPO: harbor.basicstack.de/basicstack/signing-service
# The signing-service Dockerfile uses `RUN --mount=type=cache` which
# the legacy Docker builder rejects; the Debian `docker-buildx`
# package registers the buildx CLI plugin at
# `/usr/libexec/docker/cli-plugins/docker-buildx`, and setting
# `DOCKER_BUILDKIT=1` routes `docker build` through BuildKit so the
# `# syntax=docker/dockerfile:1.7` frontend handles `--mount`.
DOCKER_BUILDKIT: "1"
steps:
- name: Install git + buildx client + ca-certs
run: |
set -euo pipefail
apt-get update
# Debian trixie: `docker.io` only installs the daemon; the CLI
# (`/usr/bin/docker`) ships in `docker-cli`, which is a Recommends
# and therefore excluded by `--no-install-recommends`. The
# buildx plugin ships separately in `docker-buildx` and is
# required because the signing-service Dockerfile uses
# `RUN --mount=type=cache` (BuildKit-only syntax).
apt-get install -y --no-install-recommends \
git curl ca-certificates docker.io docker-cli docker-buildx
git --version
docker --version
docker buildx version
- name: Clone repository (sha256-aware)
run: |
set -euo pipefail
git clone --depth=1 --branch="${GITHUB_REF_NAME}" \
"https://x-access-token:${GITHUB_TOKEN}@forgejo.basicstack.de/${GITHUB_REPOSITORY}.git" \
"${GITHUB_WORKSPACE}"
cd "${GITHUB_WORKSPACE}"
git log -1 --oneline
- name: Resolve tags
id: tags
working-directory: ${{ github.workspace }}
run: |
set -euo pipefail
SHA="$(git rev-parse --short HEAD)"
echo "sha=${SHA}" >> "${GITHUB_OUTPUT}"
echo "image_sha=${IMAGE_REPO}:${SHA}" >> "${GITHUB_OUTPUT}"
echo "image_main=${IMAGE_REPO}:main" >> "${GITHUB_OUTPUT}"
- name: Build image
working-directory: ${{ github.workspace }}
run: |
set -euo pipefail
# Explicit `docker buildx build` so BuildKit frontend features
# (`# syntax=`, `--mount=type=cache`) work on any docker-cli
# version regardless of whether `docker build` is aliased to
# buildx. The default `docker` driver loads the result into the
# local daemon, so the subsequent `docker push` finds the tags.
docker buildx build \
--load \
-f services/signing-service/Dockerfile \
-t "${{ steps.tags.outputs.image_sha }}" \
-t "${{ steps.tags.outputs.image_main }}" \
.
- name: Login to Harbor (push jobs only)
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
# Harbor robot usernames contain `$` (e.g. `robot$basicstack+ci`),
# so inlining `${{ secrets.HARBOR_USERNAME }}` directly in the
# `run:` script makes bash expand `$basicstack` (and die under
# `set -u`). Pass the secrets as env vars so the shell only sees
# them as plain strings.
env:
HARBOR_USERNAME: ${{ secrets.HARBOR_USERNAME }}
HARBOR_PASSWORD: ${{ secrets.HARBOR_PASSWORD }}
run: |
set -eu
echo "${HARBOR_PASSWORD}" | \
docker login "${REGISTRY}" --username "${HARBOR_USERNAME}" --password-stdin
- name: Push image (main only)
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
run: |
set -eu
docker push "${{ steps.tags.outputs.image_sha }}"
docker push "${{ steps.tags.outputs.image_main }}"