Skip to content
Merged
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
20 changes: 20 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -867,3 +867,23 @@ jobs:
files: |
./test/config.hcl
call: check

attest-override:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v5
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
version: ${{ inputs.buildx-version || env.BUILDX_VERSION }}
driver-opts: |
image=${{ inputs.buildkit-image || env.BUILDKIT_IMAGE }}
-
name: Build and push
uses: ./
with:
workdir: ./test/attest
source: .
24 changes: 18 additions & 6 deletions __tests__/context.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,9 @@ describe('getArgs', () => {
[
'bake',
'--metadata-file', metadataJson,
"--provenance", `mode=min,inline-only=true,builder-id=https://github.com/docker/build-push-action/actions/runs/123456789/attempts/1`,
'--set', `lint.attest=type=provenance,mode=min,inline-only=true,builder-id=https://github.com/docker/build-push-action/actions/runs/123456789/attempts/1`,
'--set', `validate-docs.attest=type=provenance,mode=min,inline-only=true,builder-id=https://github.com/docker/build-push-action/actions/runs/123456789/attempts/1`,
'--set', `validate-vendor.attest=type=provenance,mode=min,inline-only=true,builder-id=https://github.com/docker/build-push-action/actions/runs/123456789/attempts/1`,
],
undefined
],
Expand Down Expand Up @@ -311,7 +313,9 @@ describe('getArgs', () => {
'--set', '*.platform=linux/amd64,linux/ppc64le,linux/s390x',
'--set', `*.output=type=image,"name=moby/buildkit:v0.11.0,moby/buildkit:latest",push=true`,
'--metadata-file', metadataJson,
'--provenance', `mode=min,inline-only=true,builder-id=https://github.com/docker/build-push-action/actions/runs/123456789/attempts/1`,
'--set', `lint.attest=type=provenance,mode=min,inline-only=true,builder-id=https://github.com/docker/build-push-action/actions/runs/123456789/attempts/1`,
'--set', `validate-docs.attest=type=provenance,mode=min,inline-only=true,builder-id=https://github.com/docker/build-push-action/actions/runs/123456789/attempts/1`,
'--set', `validate-vendor.attest=type=provenance,mode=min,inline-only=true,builder-id=https://github.com/docker/build-push-action/actions/runs/123456789/attempts/1`,
'image-all'
],
undefined
Expand All @@ -332,7 +336,9 @@ describe('getArgs', () => {
'bake',
'--set', `*.labels.foo=bar=#baz`,
'--metadata-file', metadataJson,
'--provenance', `mode=min,inline-only=true,builder-id=https://github.com/docker/build-push-action/actions/runs/123456789/attempts/1`,
'--set', `lint.attest=type=provenance,mode=min,inline-only=true,builder-id=https://github.com/docker/build-push-action/actions/runs/123456789/attempts/1`,
'--set', `validate-docs.attest=type=provenance,mode=min,inline-only=true,builder-id=https://github.com/docker/build-push-action/actions/runs/123456789/attempts/1`,
'--set', `validate-vendor.attest=type=provenance,mode=min,inline-only=true,builder-id=https://github.com/docker/build-push-action/actions/runs/123456789/attempts/1`,
'image-all'
],
undefined
Expand All @@ -352,7 +358,9 @@ describe('getArgs', () => {
'https://github.com/docker/build-push-action.git#refs/heads/master',
'--file', './foo.hcl',
'--metadata-file', metadataJson,
'--provenance', `mode=min,inline-only=true,builder-id=https://github.com/docker/build-push-action/actions/runs/123456789/attempts/1`,
'--set', `lint.attest=type=provenance,mode=min,inline-only=true,builder-id=https://github.com/docker/build-push-action/actions/runs/123456789/attempts/1`,
'--set', `validate-docs.attest=type=provenance,mode=min,inline-only=true,builder-id=https://github.com/docker/build-push-action/actions/runs/123456789/attempts/1`,
'--set', `validate-vendor.attest=type=provenance,mode=min,inline-only=true,builder-id=https://github.com/docker/build-push-action/actions/runs/123456789/attempts/1`
],
undefined
],
Expand All @@ -371,7 +379,9 @@ describe('getArgs', () => {
'bake',
'--allow', 'network.host',
'--metadata-file', metadataJson,
"--provenance", `mode=min,inline-only=true,builder-id=https://github.com/docker/build-push-action/actions/runs/123456789/attempts/1`
'--set', `lint.attest=type=provenance,mode=min,inline-only=true,builder-id=https://github.com/docker/build-push-action/actions/runs/123456789/attempts/1`,
'--set', `validate-docs.attest=type=provenance,mode=min,inline-only=true,builder-id=https://github.com/docker/build-push-action/actions/runs/123456789/attempts/1`,
'--set', `validate-vendor.attest=type=provenance,mode=min,inline-only=true,builder-id=https://github.com/docker/build-push-action/actions/runs/123456789/attempts/1`
],
undefined
],
Expand All @@ -391,7 +401,9 @@ describe('getArgs', () => {
'https://github.com/docker/build-push-action.git#refs/heads/master:subdir',
'--file', './foo.hcl',
'--metadata-file', metadataJson,
'--provenance', `mode=min,inline-only=true,builder-id=https://github.com/docker/build-push-action/actions/runs/123456789/attempts/1`,
'--set', `lint.attest=type=provenance,mode=min,inline-only=true,builder-id=https://github.com/docker/build-push-action/actions/runs/123456789/attempts/1`,
'--set', `validate-docs.attest=type=provenance,mode=min,inline-only=true,builder-id=https://github.com/docker/build-push-action/actions/runs/123456789/attempts/1`,
'--set', `validate-vendor.attest=type=provenance,mode=min,inline-only=true,builder-id=https://github.com/docker/build-push-action/actions/runs/123456789/attempts/1`
],
undefined
],
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

22 changes: 14 additions & 8 deletions src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,22 @@ async function getBakeArgs(inputs: Inputs, definition: BakeDefinition, toolkit:
if (inputs.provenance) {
args.push('--provenance', inputs.provenance);
} else if (!noDefaultAttestations() && (await toolkit.buildkit.versionSatisfies(inputs.builder, '>=0.11.0')) && !Bake.hasDockerExporter(definition, inputs.load)) {
// if provenance not specified and BuildKit version compatible for
// check if provenance attestation is already specified in the bake
// definition and if not specified and BuildKit version compatible for
// attestation, set default provenance. Also needs to make sure user
// doesn't want to explicitly load the image to docker.
if (GitHub.context.payload.repository?.private ?? false) {
// if this is a private repository, we set the default provenance
// attributes being set in buildx: https://github.com/docker/buildx/blob/fb27e3f919dcbf614d7126b10c2bc2d0b1927eb6/build/build.go#L603
args.push('--provenance', Build.resolveProvenanceAttrs(`mode=min,inline-only=true`));
} else {
// for a public repository, we set max provenance mode.
args.push('--provenance', Build.resolveProvenanceAttrs(`mode=max`));
for (const targetName in definition.target) {
const target = definition.target[targetName];
if (!Array.isArray(target.attest) || !target.attest.some(attest => attest?.type === 'provenance')) {
if (GitHub.context.payload.repository?.private ?? false) {
// if this is a private repository, we set the default provenance
// attributes being set in buildx: https://github.com/docker/buildx/blob/fb27e3f919dcbf614d7126b10c2bc2d0b1927eb6/build/build.go#L603
args.push('--set', `${targetName}.attest=type=provenance,${Build.resolveProvenanceAttrs(`mode=min,inline-only=true`)}`);
} else {
// for a public repository, we set max provenance mode.
args.push('--set', `${targetName}.attest=type=provenance,${Build.resolveProvenanceAttrs(`mode=max`)}`);
}
}
}
}
if (inputs.sbom) {
Expand Down
10 changes: 10 additions & 0 deletions test/attest/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# syntax=docker/dockerfile:1

FROM busybox AS t1
RUN echo "Hello t1"

FROM busybox AS t2
RUN echo "Hello t2"

FROM busybox AS t3
RUN echo "Hello t3"
17 changes: 17 additions & 0 deletions test/attest/docker-bake.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
group "default" {
targets = ["t1", "t2", "t3"]
}

target "t1" {
target = "t1"
}

target "t2" {
target = "t2"
attest = ["type=provenance,mode=min"]
}

target "t3" {
target = "t3"
attest = ["type=sbom"]
}
Comment on lines +1 to +17
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested in https://github.com/docker/bake-action/actions/runs/19702226697/job/56441006449#step:4:234

  {
    "group": {
      "default": {
        "targets": [
          "t1",
          "t2",
          "t3"
        ]
      }
    },
    "target": {
      "t1": {
        "attest": [
          {
            "builder-id": "https://github.com/docker/bake-action/actions/runs/19702226697/attempts/1",
            "mode": "max",
            "type": "provenance"
          }
        ],
        "context": ".",
        "dockerfile": "Dockerfile",
        "target": "t1"
      },
      "t2": {
        "attest": [
          {
            "mode": "min",
            "type": "provenance"
          }
        ],
        "context": ".",
        "dockerfile": "Dockerfile",
        "target": "t2"
      },
      "t3": {
        "attest": [
          {
            "type": "sbom"
          },
          {
            "builder-id": "https://github.com/docker/bake-action/actions/runs/19702226697/attempts/1",
            "mode": "max",
            "type": "provenance"
          }
        ],
        "context": ".",
        "dockerfile": "Dockerfile",
        "target": "t3"
      }
    }
  }

Loading