Skip to content
Open
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
14 changes: 14 additions & 0 deletions .github/workflows/.test-bake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -447,3 +447,17 @@ jobs:
sbom: true
sign: ${{ github.event_name != 'pull_request' }}
target: hello-cross

bake-vars:
uses: ./.github/workflows/bake.yml
permissions:
contents: read
id-token: write
with:
setup-qemu: true
artifact-upload: false
context: test
output: local
target: go
vars: |
XX_VERSION=1.9.0
53 changes: 46 additions & 7 deletions .github/workflows/bake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ on:
description: "Bake target to build"
required: true
default: default
vars:
type: string
description: "Variables to set in the Bake definition as list of key-value pair"
required: false
# docker/metadata-action
set-meta-annotations:
type: boolean
Expand Down Expand Up @@ -189,6 +193,7 @@ jobs:
INPUT_SET: ${{ inputs.set }}
INPUT_SIGN: ${{ inputs.sign }}
INPUT_TARGET: ${{ inputs.target }}
INPUT_VARS: ${{ inputs.vars }}
INPUT_GITHUB-TOKEN: ${{ secrets.github-token || github.token }}
with:
script: |
Expand All @@ -205,6 +210,7 @@ jobs:
const inpDistribute = core.getBooleanInput('distribute');
const inpArtifactUpload = core.getBooleanInput('artifact-upload');
const inpContext = core.getInput('context');
const inpVars = Util.getInputList('vars');
const inpFiles = Util.getInputList('files');
const inpOutput = core.getInput('output');
const inpPush = core.getBooleanInput('push');
Expand Down Expand Up @@ -243,6 +249,21 @@ jobs:
await core.group(`Set bake source`, async () => {
core.info(bakeSource);
});

const envs = Object.assign({},
inpVars ? inpVars.reduce((acc, curr) => {
const [key, ...rest] = curr.split('=');
acc[key] = rest.join('=');
return acc;
}, {}) : {},
{
BUILDKIT_MULTI_PLATFORM: '1',
BUILDX_BAKE_GIT_AUTH_TOKEN: inpGitHubToken
}
);
await core.group(`Set envs`, async () => {
core.info(JSON.stringify(envs, null, 2));
});

let def;
let target;
Expand All @@ -254,8 +275,9 @@ jobs:
overrides: inpSet,
sbom: inpSbom ? `generator=${inpSbomImage}` : 'false',
source: bakeSource,
targets: [inpTarget],
githubToken: inpGitHubToken
targets: [inpTarget]
}, {
env: Object.keys(envs).length > 0 ? envs : undefined
});
if (!def) {
throw new Error('Bake definition not set');
Expand Down Expand Up @@ -495,6 +517,7 @@ jobs:
INPUT_SBOM: ${{ inputs.sbom }}
INPUT_SET: ${{ inputs.set }}
INPUT_TARGET: ${{ inputs.target }}
INPUT_VARS: ${{ inputs.vars }}
INPUT_META-IMAGES: ${{ inputs.meta-images }}
INPUT_SET-META-ANNOTATIONS: ${{ inputs.set-meta-annotations }}
INPUT_SET-META-LABELS: ${{ inputs.set-meta-labels }}
Expand Down Expand Up @@ -526,6 +549,7 @@ jobs:
const inpSbom = core.getBooleanInput('sbom');
const inpSet = Util.getInputList('set', {ignoreComma: true, quote: false});
const inpTarget = core.getInput('target');
const inpVars = Util.getInputList('vars');
const inpMetaImages = core.getMultilineInput('meta-images');
const inpSetMetaAnnotations = core.getBooleanInput('set-meta-annotations');
const inpSetMetaLabels = core.getBooleanInput('set-meta-labels');
Expand All @@ -546,6 +570,22 @@ jobs:
core.setOutput('sbom', sbom);
});

const envs = Object.assign({},
inpVars ? inpVars.reduce((acc, curr) => {
const [key, ...rest] = curr.split('=');
acc[key] = rest.join('=');
return acc;
}, {}) : {},
{
BUILDKIT_MULTI_PLATFORM: '1',
BUILDX_BAKE_GIT_AUTH_TOKEN: inpGitHubToken
}
);
await core.group(`Set envs`, async () => {
core.info(JSON.stringify(envs, null, 2));
core.setOutput('envs', JSON.stringify(envs));
});

let target;
try {
await core.group(`Validating definition`, async () => {
Expand All @@ -555,8 +595,9 @@ jobs:
overrides: inpSet,
sbom: sbom,
source: bakeSource,
targets: [inpTarget],
githubToken: inpGitHubToken
targets: [inpTarget]
}, {
env: Object.keys(envs).length > 0 ? envs : undefined
});
if (!def) {
throw new Error('Bake definition not set');
Expand Down Expand Up @@ -645,9 +686,7 @@ jobs:
targets: ${{ steps.prepare.outputs.target }}
sbom: ${{ steps.prepare.outputs.sbom }}
set: ${{ steps.prepare.outputs.overrides }}
env:
BUILDKIT_MULTI_PLATFORM: 1
BUILDX_BAKE_GIT_AUTH_TOKEN: ${{ secrets.github-token || github.token }}
env: ${{ fromJson(steps.prepare.outputs.envs) }}
-
name: Get image digest
id: get-image-digest
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ on:
| `sign` | String | `auto` | Sign attestation manifest for `image` output or artifacts for `local` output, can be one of `auto`, `true` or `false`. The `auto` mode will enable signing if `push` is enabled for pushing the `image` or if `artifact-upload` is enabled for uploading the `local` build output as GitHub Artifact |
| `target` | String | | Sets the target stage to build |
| `ulimit` | List | | [Ulimit](https://docs.docker.com/engine/reference/commandline/buildx_build/#ulimit) options (e.g., `nofile=1024:1024`) |
| `vars` | List | | [Variables](https://docs.docker.com/build/bake/variables/) to set in the Bake definition as list of key-value pair |
| `set-meta-annotations` | Bool | `false` | Append OCI Image Format Specification annotations generated by `docker/metadata-action` |
| `set-meta-labels` | Bool | `false` | Append OCI Image Format Specification labels generated by `docker/metadata-action` |
| `meta-images` | List | | [List of images](https://github.com/docker/metadata-action?tab=readme-ov-file#images-input) to use as base name for tags (required for image output) |
Expand Down
7 changes: 7 additions & 0 deletions test/docker-bake.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,15 @@ group "grp" {
targets = ["go", "hello"]
}

variable "XX_VERSION" {
default = null
}

target "go" {
inherits = ["docker-metadata-action"]
args = {
XX_VERSION = XX_VERSION
}
dockerfile = "go.Dockerfile"
}

Expand Down
3 changes: 2 additions & 1 deletion test/go.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# syntax=docker/dockerfile:1

ARG GO_VERSION="1.25"
ARG XX_VERSION="1.7.0"

# xx is a helper for cross-compilation
FROM --platform=$BUILDPLATFORM tonistiigi/xx:1.7.0 AS xx
FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION} AS xx

FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-alpine AS base
COPY --from=xx / /
Expand Down
Loading