Skip to content

feat!: add the bake.yml reusable workflow - #83

Draft
Ilyes512 wants to merge 13 commits into
4.0/specs-hclfrom
4.0/bake-workflow
Draft

Ilyes512 wants to merge 13 commits into
4.0/specs-hclfrom
4.0/bake-workflow

Conversation

@Ilyes512

@Ilyes512 Ilyes512 commented Nov 9, 2026 •

Copy link
Copy Markdown
Member

One call builds and publishes every target in a consumer's bake files: plan → build (one job per platform) → publish → status (Image).

  • plan works out VERSION, push and the other bake variables once, runs bake --print and freezes the result as an artifact: the printed JSON as it is, and one definition per platform with only the targets that list it, pushed by digest and without tags. Every platform and the publish job therefore see identical tags and labels. It reads bake/specs.hcl from this repository, at the version of the workflow, before the consumer's bake files, so consumers don't keep a copy. It fails early when a target has no platforms, has no tags for an event it would push, or needs a runner that isn't mapped.
  • build builds every target in its platform's frozen definition in one docker/bake-action run, pushes by digest and uploads bake's metadata. Cache scope is per image, target and platform. Default attestations are off, and attest in HCL opts in.
  • publish reads the tags, labels and digests from the frozen definition and the build jobs' metadata, and runs imagetools create per target, with the labels as index: and manifest-descriptor: annotations. It does no checkout.
  • push follows the event: no push for dependabot PRs (also when re-run), fork PRs, dependabot/* branches, or events the tag rules don't cover.
  • Security: build-secrets is a secret, not an input; each line must be NAME=value and its value is masked. All inputs go through env:. permissions are set per job, all actions are pinned by SHA, and checkout uses persist-credentials: false.
  • Runners: ubuntu-26.04 / ubuntu-26.04-arm by default; the runners input overrides them.

Scripts. The plan and publish logic lives in two composite actions under bake/ (plan, publish), called with GitHub's $/ self-repository syntax, so it always runs at the same commit as bake.yml. The build job's two small steps, exporting the build secrets and saving bake's metadata, are inline. The artifacts have fixed names (bake-definition, bake-metadata-<platform>): a repository calls bake.yml once per run.

specs.hcl changes on top of #82. The REPOSITORY_NAME, REPOSITORY_DESCRIPTION and LICENSES variables are gone: there is no GitHub API lookup, a target passes its own title and description, and an empty one is left out. IS_STABLE is no longer a variable either: specs.hcl works it out from EVENT, REF_TYPE and VERSION, with the fixtures unchanged apart from the removed labels.

$/ across repositories. GitHub's docs don't say what $/ resolves to inside a reusable workflow called from another repository. A test from a scratch branch in specsnl/utils, pinned to this branch's commit, settled it: every job, Publish included, downloaded specsnl/github-actions@<that commit>. utils has no specs.hcl, and the build published both platforms with the expected labels. The branch and its run were only for the test, and the branch has been removed.

actionlint 1.7.12 knows neither the $/ syntax nor the 26.04 labels yet (rhysd/actionlint#711), so .github/actionlint.yaml declares the labels (added in #82) and ignores only the two $/ format errors.

Tests (task test, and lint.yml):

  • bake/test/vars.sh runs bake/plan/vars.sh for 18 GitHub contexts.
  • test-bake.yml runs the workflow on a test image. On a pull request from this repository and on a push to main it pushes, and its Verify job checks the platforms and annotations of the published indexes; a manual run pushes only with push on. A load: true job covers the PR-style test.
  • cleanup-e2e.yml runs every night and deletes the pr-<N> test images of closed pull requests, and the untagged platform images no tag refers to any more (only those older than a day, so a run that is still publishing keeps them). A manual run can be a dry run.
  • Shellcheck lints the scripts (task lint).

Part of the 4.0.0 stack (bake variant of the plan in #80). Merge bottom to top: #82 → #83 → #84 → #85 → #86 → #88.

One call builds and publishes everything a consumer's docker-bake.hcl
defines:

- plan works out the version, the push decision and the other bake
  variables once, runs docker buildx bake --print and freezes the
  result, so every later job sees identical tags and labels (created
  included).
- build runs once per platform, building every target for that platform
  in one bake invocation, and pushes by digest.
- publish merges the digests per target with imagetools create and
  copies the labels onto the index and its descriptors.
- status reports the result as a single "Image" check.

push now follows the event instead of github.actor: no push for
dependabot pull requests (also when a person re-runs them), pull
requests from forks, dependabot branches, or events the tag rules don't
cover. Build secrets come in through one build-secrets secret. Every
input reaches the scripts through env, and every action is pinned by
commit SHA.

The plan job warns when the consumer's vendored specs.hcl differs from
bake/specs.hcl at this version, by comparing it with SPECS_HCL_SHA256;
lint.yml checks that hash, and tests the plan job's version and push
rules. test-bake.yml runs the workflow on a test image (pushing only on
a manual run), and builds, loads and runs one target the way a
consumer's pull request test would.
They reach bake as REPOSITORY_NAME, REPOSITORY_DESCRIPTION and LICENSES,
the fallbacks specs_labels uses for the title, description and licenses
labels, so a migrated image keeps the labels metadata-action gave it.
The repository is read once from the GitHub API with the token's
contents: read; an unrecognised license (NOASSERTION) is left out.

SPECS_HCL_SHA256 follows the specs.hcl change.
Every scripted step of bake.yml is now a script in a small composite
action under bake/ (plan, narrow, secrets, digests, publish), called with
the $/ self-repository syntax so it runs at the same commit as bake.yml.
The larger jq programs live in .jq files next to the scripts, and the
scripts share their output helpers in bake/lib.sh.

The plan action reads bake/specs.hcl from its own checkout before the
caller's bake files, so consumers no longer keep a copy of it. The
specs-file input, SPECS_HCL_SHA256 and its check are gone; a local build
fetches specs.hcl at the commit the caller pins bake.yml to.

The tests now run the scripts directly: vars.sh for the plan variables,
secrets.sh for the build secrets parsing, and pipeline.sh for freeze,
narrow, digests and publish end to end, against golden files and with a
docker that only records the imagetools calls. Shellcheck lints the
scripts, locally and in CI.
…en files

test-bake.yml now pushes on pull requests from this repository and checks the published indexes, which replaces bake/test/pipeline.sh and its 1,080 lines of expected output.
The plan job writes bake --print as bake.json and a definition per platform next to it, so the narrow and digests actions go. The build jobs upload bake's metadata as is, and publish reads the tags, labels and digests from bake.json and that metadata.
A repository calls bake.yml once per run, so the per-call artifact prefix and the output that carried it go.
The caller already controls its own workflow, so refusing names like PATH protects nothing. The step keeps the NAME=value check and the masking, and lib.sh moves next to the plan scripts, its only users.
… labels

The plan job no longer reads the repository from the GitHub API. Targets pass their title and description to specs_labels, and an empty one is left out like any other empty value.
specs.hcl derives it from EVENT, REF_TYPE and VERSION, so the tag rules live in one place and a local build no longer needs IS_STABLE set to preview a release.
cleanup-e2e.yml removes the pr-<N> images test-bake.yml published once the pull request is closed, and the untagged platform images nothing refers to any more.
imagetools inspect right after imagetools create can get a 404 from GHCR, which failed a publish that had succeeded.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant