Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/actionlint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,10 @@ self-hosted-runner:
labels:
- ubuntu-26.04
- ubuntu-26.04-arm

paths:
.github/workflows/**/*.{yml,yaml}:
ignore:
# actionlint 1.7.12 doesn't know GitHub's "$/" self-repository syntax yet: rhysd/actionlint#711
- 'reusable workflow call "\$/.+" at "uses" is not following the format'
- 'specifying action "\$/.+" in invalid format because ref is missing'
230 changes: 230 additions & 0 deletions .github/workflows/bake.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,230 @@
name: Bake

on:
workflow_call:
inputs:
files:
description: >-
The consumer's bake files (multiline). The workflow reads its own bake/specs.hcl first, at the version of
this workflow, so the bake files can use its functions without a copy of it.
type: string
default: docker-bake.hcl
targets:
description: Bake targets or groups to build (multiline). Defaults to the "default" group.
type: string
required: false
version:
description: >-
The VERSION bake variable. Defaults to the tag without its leading "v" on a tag push, "pr-<number>" on a
pull request, the branch name on a branch push, "nightly" on a schedule and the dispatch tag on
workflow_dispatch.
type: string
required: false
dispatch-tag:
description: Tag published by a workflow_dispatch run. Lowercased.
type: string
default: latest
push:
description: >-
"true" or "false". Defaults to pushing, except for pull requests from dependabot or from a fork, pushes to
a dependabot branch, and events the tag rules don't cover.
type: string
required: false
runners:
description: >-
JSON object mapping a platform to its runner, merged over the default
{"linux/amd64": "ubuntu-26.04", "linux/arm64": "ubuntu-26.04-arm"}.
type: string
required: false
disable-apparmor:
description: Disable AppArmor on the build runners before building.
type: boolean
default: false
timeout-minutes:
description: Timeout of each build job.
type: number
default: 60
secrets:
build-secrets:
description: >-
Build secrets as "NAME=value" lines. Each one is masked and exported as an environment variable to the
build, where the bake file refers to it with secret = ["id=<id>,env=NAME"].
required: false
outputs:
version:
description: The VERSION the images were built with.
value: ${{ jobs.plan.outputs.version }}
push:
description: Whether the images were pushed ("true" or "false").
value: ${{ jobs.plan.outputs.push }}

permissions: {}

jobs:

plan:
name: Plan
runs-on: ubuntu-26.04
timeout-minutes: 10
permissions:
contents: read
outputs:
version: ${{ steps.plan.outputs.version }}
push: ${{ steps.plan.outputs.push }}
matrix: ${{ steps.plan.outputs.matrix }}
steps:

- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false

- name: Plan
id: plan
uses: $/bake/plan
with:
files: ${{ inputs.files }}
targets: ${{ inputs.targets }}
version: ${{ inputs.version }}
dispatch-tag: ${{ inputs.dispatch-tag }}
push: ${{ inputs.push }}
runners: ${{ inputs.runners }}

- name: Upload the bake definition
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: bake-definition
path: ${{ runner.temp }}/bake/*.json
if-no-files-found: error
retention-days: 1

build:
name: Build ${{ matrix.platform }}
needs: plan
runs-on: ${{ matrix.runner }}
timeout-minutes: ${{ inputs.timeout-minutes }}
permissions:
contents: read
packages: write
strategy:
fail-fast: false
matrix:
include: ${{ fromJSON(needs.plan.outputs.matrix) }}
steps:

- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false

- name: Download the bake definition
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: bake-definition
path: ${{ runner.temp }}/bake

- name: Export the build secrets
env:
BUILD_SECRETS: ${{ secrets.build-secrets }}
run: |
while IFS= read -r line; do
[ -z "${line//[[:space:]]/}" ] && continue
if [[ ! $line =~ ^[A-Za-z_][A-Za-z0-9_]*= ]]; then
echo "::error::build-secrets lines must be NAME=value, with a NAME of letters, digits and underscores."
exit 1
fi
value="${line#*=}"
[ -n "$value" ] && echo "::add-mask::$value"
# The random delimiter keeps a value from ending the block early or injecting more variables.
delimiter="EOF_$(openssl rand -hex 16)"
printf '%s<<%s\n%s\n%s\n' "${line%%=*}" "$delimiter" "$value" "$delimiter" >> "$GITHUB_ENV"
done <<< "$BUILD_SECRETS"

- name: Log in to the Container registry
if: ${{ needs.plan.outputs.push == 'true' }}
uses: docker/login-action@8aa5831fb8d48d8f76594c7ddde61ae58019f550 # v4.8.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Disable AppArmor
if: ${{ inputs.disable-apparmor }}
uses: cisagov/action-disable-apparmor@437d94f26a2e4bf8c03acfb500a6afc688b497db # v1.0.0

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1

- name: Build
id: bake
uses: docker/bake-action@59cb1203cd42bcefd40a1b6d73b589e48c86040e # v7.5.0
env:
BUILDX_NO_DEFAULT_ATTESTATIONS: 1
with:
source: .
files: ${{ runner.temp }}/bake/definition-${{ matrix.slug }}.json

- name: Save the build metadata
if: ${{ needs.plan.outputs.push == 'true' }}
env:
METADATA: ${{ steps.bake.outputs.metadata }}
SLUG: ${{ matrix.slug }}
run: |
mkdir -p "$RUNNER_TEMP/metadata"
printf '%s\n' "$METADATA" > "$RUNNER_TEMP/metadata/$SLUG.json"

- name: Upload the build metadata
if: ${{ needs.plan.outputs.push == 'true' }}
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: bake-metadata-${{ matrix.slug }}
path: ${{ runner.temp }}/metadata/${{ matrix.slug }}.json
if-no-files-found: error
retention-days: 1

publish:
name: Publish
needs: [plan, build]
if: ${{ needs.plan.outputs.push == 'true' }}
runs-on: ubuntu-26.04
timeout-minutes: 15
permissions:
packages: write
steps:

- name: Download the bake definition
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: bake-definition
path: ${{ runner.temp }}/bake

- name: Download the build metadata
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
pattern: bake-metadata-*
path: ${{ runner.temp }}/metadata
merge-multiple: true

- name: Log in to the Container registry
uses: docker/login-action@8aa5831fb8d48d8f76594c7ddde61ae58019f550 # v4.8.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Create the manifests
uses: $/bake/publish

status:
name: Image
needs: [plan, build, publish]
if: ${{ always() }}
runs-on: ubuntu-26.04
timeout-minutes: 5
steps:
- name: Check the results
env:
NEEDS: ${{ toJSON(needs) }}
run: |
jq -r 'to_entries[] | "\(.key): \(.value.result)"' <<< "$NEEDS"
jq -e '.plan.result == "success" and all(.[]; .result == "success" or .result == "skipped")' <<< "$NEEDS" > /dev/null
40 changes: 40 additions & 0 deletions .github/workflows/cleanup-e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Clean up the e2e images

on:
schedule:
- cron: '23 4 * * *'
workflow_dispatch:
inputs:
dry-run:
description: Only list what would be deleted
type: boolean
default: false

permissions: {}

concurrency:
group: ${{ github.workflow }}

jobs:

cleanup:
name: Clean up
runs-on: ubuntu-26.04
timeout-minutes: 15
permissions:
contents: read
packages: write
pull-requests: read
steps:

- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false

- name: Delete the images of closed pull requests
env:
GH_TOKEN: ${{ github.token }}
PACKAGES: github-actions/e2e github-actions/e2e-cli
DRY_RUN: ${{ inputs.dry-run || false }}
run: bake/test/cleanup-e2e.sh
6 changes: 6 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,9 @@ jobs:
persist-credentials: false
- name: Run the specs.hcl fixture tests
run: bake/test/run.sh
- name: Run the plan tests
run: bake/test/vars.sh
- name: Run shellcheck
run: >-
docker run --rm --volume "$PWD:/mnt" --workdir /mnt koalaman/shellcheck:v0.11.0
bake/*/*.sh bake/test/*.sh
Loading
Loading