From 1f9973cb3f01336d8d034ed60a7a95a65713a020 Mon Sep 17 00:00:00 2001 From: CrazyMax <1951866+crazy-max@users.noreply.github.com> Date: Thu, 5 Nov 2026 15:03:41 +0100 Subject: [PATCH] build/bake: support configurable image layer compression Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com> --- .github/workflows/.test-bake.yml | 83 +++++++++++++++++++++++++++++++ .github/workflows/.test-build.yml | 83 +++++++++++++++++++++++++++++++ .github/workflows/bake.yml | 74 +++++++++++++++++---------- .github/workflows/build.yml | 72 +++++++++++++++++---------- README.md | 6 +++ test/compression.Dockerfile | 2 + test/docker-bake.hcl | 6 +++ 7 files changed, 273 insertions(+), 53 deletions(-) create mode 100644 test/compression.Dockerfile diff --git a/.github/workflows/.test-bake.yml b/.github/workflows/.test-bake.yml index e5a635fe..c105d382 100644 --- a/.github/workflows/.test-bake.yml +++ b/.github/workflows/.test-bake.yml @@ -839,3 +839,86 @@ jobs: await exec.exec('docker', ['rm', container]); fs.rmSync(directory, {recursive: true, force: true}); } + + bake-compression: + strategy: + matrix: + include: + - variant: default + compression: '' + level: '' + force: false + - variant: zstd + compression: zstd + level: '0' + force: false + - variant: zstd-force + compression: zstd + level: '9' + force: true + uses: ./.github/workflows/bake.yml + permissions: + contents: read + id-token: write + packages: write + with: + compression: ${{ matrix.compression }} + compression-level: ${{ matrix.level }} + force-compression: ${{ matrix.force }} + output: image + push: ${{ github.event_name != 'pull_request' }} + context: test + target: compression + meta-images: ghcr.io/docker/github-builder-test + meta-tags: | + type=raw,value=bake-compression-${{ matrix.variant }}-${{ github.run_id }}-${{ github.run_attempt }} + secrets: + registry-auths: | + - registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + bake-compression-check: + runs-on: ubuntu-26.04 + if: ${{ github.event_name != 'pull_request' }} + needs: + - bake-compression + strategy: + matrix: + include: + - variant: default + base: gzip + added: gzip + - variant: zstd + base: gzip + added: zstd + - variant: zstd-force + base: zstd + added: zstd + steps: + - + name: Check image layer compression + uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 + env: + INPUT_IMAGE: ghcr.io/docker/github-builder-test + INPUT_TAG: bake-compression-${{ matrix.variant }}-${{ github.run_id }}-${{ github.run_attempt }} + INPUT_BASE-COMPRESSION: ${{ matrix.base }} + INPUT_ADDED-COMPRESSION: ${{ matrix.added }} + with: + script: | + const assert = require('node:assert/strict'); + const image = core.getInput('image'); + const inspect = async ref => { + const {stdout} = await exec.getExecOutput('docker', ['buildx', 'imagetools', 'inspect', '--raw', ref], {silent: true}); + return JSON.parse(stdout); + }; + const index = await inspect(`${image}:${core.getInput('tag')}`); + const manifests = index.manifests.filter(manifest => manifest.platform?.os === 'linux'); + assert.deepEqual(manifests.map(manifest => manifest.platform.architecture).sort(), ['amd64', 'arm64']); + for (const {digest} of manifests) { + const {layers} = await inspect(`${image}@${digest}`); + assert.ok(layers.length >= 2, 'Expected base image layers and the fixture layer'); + const expected = layers.map((_, index) => core.getInput(index === layers.length - 1 ? 'added-compression' : 'base-compression')); + const actual = layers.map(layer => layer.mediaType.split('+').pop()); + assert.deepEqual(actual, expected, `Unexpected layer compression for ${image}@${digest}`); + } diff --git a/.github/workflows/.test-build.yml b/.github/workflows/.test-build.yml index 39939cd6..6eb3dcd0 100644 --- a/.github/workflows/.test-build.yml +++ b/.github/workflows/.test-build.yml @@ -848,3 +848,86 @@ jobs: await exec.exec('docker', ['rm', container]); fs.rmSync(directory, {recursive: true, force: true}); } + + build-compression: + strategy: + matrix: + include: + - variant: default + compression: '' + level: '' + force: false + - variant: zstd + compression: zstd + level: '0' + force: false + - variant: zstd-force + compression: zstd + level: '9' + force: true + uses: ./.github/workflows/build.yml + permissions: + contents: read + id-token: write + packages: write + with: + compression: ${{ matrix.compression }} + compression-level: ${{ matrix.level }} + force-compression: ${{ matrix.force }} + output: image + push: ${{ github.event_name != 'pull_request' }} + file: test/compression.Dockerfile + platforms: linux/amd64,linux/arm64 + meta-images: ghcr.io/docker/github-builder-test + meta-tags: | + type=raw,value=build-compression-${{ matrix.variant }}-${{ github.run_id }}-${{ github.run_attempt }} + secrets: + registry-auths: | + - registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + build-compression-check: + runs-on: ubuntu-26.04 + if: ${{ github.event_name != 'pull_request' }} + needs: + - build-compression + strategy: + matrix: + include: + - variant: default + base: gzip + added: gzip + - variant: zstd + base: gzip + added: zstd + - variant: zstd-force + base: zstd + added: zstd + steps: + - + name: Check image layer compression + uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 + env: + INPUT_IMAGE: ghcr.io/docker/github-builder-test + INPUT_TAG: build-compression-${{ matrix.variant }}-${{ github.run_id }}-${{ github.run_attempt }} + INPUT_BASE-COMPRESSION: ${{ matrix.base }} + INPUT_ADDED-COMPRESSION: ${{ matrix.added }} + with: + script: | + const assert = require('node:assert/strict'); + const image = core.getInput('image'); + const inspect = async ref => { + const {stdout} = await exec.getExecOutput('docker', ['buildx', 'imagetools', 'inspect', '--raw', ref], {silent: true}); + return JSON.parse(stdout); + }; + const index = await inspect(`${image}:${core.getInput('tag')}`); + const manifests = index.manifests.filter(manifest => manifest.platform?.os === 'linux'); + assert.deepEqual(manifests.map(manifest => manifest.platform.architecture).sort(), ['amd64', 'arm64']); + for (const {digest} of manifests) { + const {layers} = await inspect(`${image}@${digest}`); + assert.ok(layers.length >= 2, 'Expected base image layers and the fixture layer'); + const expected = layers.map((_, index) => core.getInput(index === layers.length - 1 ? 'added-compression' : 'base-compression')); + const actual = layers.map(layer => layer.mediaType.split('+').pop()); + assert.deepEqual(actual, expected, `Unexpected layer compression for ${image}@${digest}`); + } diff --git a/.github/workflows/bake.yml b/.github/workflows/bake.yml index 46639c10..0b3cb92d 100644 --- a/.github/workflows/bake.yml +++ b/.github/workflows/bake.yml @@ -59,6 +59,19 @@ on: description: "Cache layers to export if cache enabled (min or max)" required: false default: 'min' + compression: + type: string + description: "Image layer compression (uncompressed, gzip, estargz or zstd)" + required: false + compression-level: + type: string + description: "Image layer compression level (0-9 for gzip and estargz, 0-22 for zstd)" + required: false + force-compression: + type: boolean + description: "Recompress existing image layers using the selected compression type" + required: false + default: false context: type: string description: "Context to build from in the Git working tree" @@ -225,6 +238,7 @@ jobs: outputs: sourceDateEpoch: ${{ steps.set.outputs.sourceDateEpoch }} sourceDateCreated: ${{ steps.set.outputs.sourceDateCreated }} + buildOutput: ${{ steps.set.outputs.buildOutput }} includes: ${{ steps.set.outputs.includes }} metaImages: ${{ steps.set.outputs.metaImages }} sign: ${{ steps.set.outputs.sign }} @@ -321,6 +335,10 @@ jobs: id: set uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 env: + INPUT_LOCAL-EXPORT-DIR: ${{ env.LOCAL_EXPORT_DIR }} + INPUT_COMPRESSION: ${{ inputs.compression }} + INPUT_COMPRESSION-LEVEL: ${{ inputs.compression-level }} + INPUT_FORCE-COMPRESSION: ${{ inputs.force-compression }} INPUT_SBOM-IMAGE: ${{ env.SBOM_IMAGE }} INPUT_MATRIX-SIZE-LIMIT: ${{ env.MATRIX_SIZE_LIMIT }} INPUT_META-IMAGES: ${{ inputs.meta-images }} @@ -349,6 +367,7 @@ jobs: const { GitHub } = require('@docker/github-builder-runtime/lib/github/github'); const { MetaImages } = require('@docker/github-builder-runtime/lib/github-builder/meta-images'); const { SourceDateEpoch } = require('@docker/github-builder-runtime/lib/github-builder/source-date-epoch'); + const { BuildOutput } = require('@docker/github-builder-runtime/lib/github-builder/build-output'); const { RunnerMapping } = require('@docker/github-builder-runtime/lib/github-builder/runner-mapping'); const { BakeTargets } = require('@docker/github-builder-runtime/lib/github-builder/bake-targets'); const { BakeVars } = require('@docker/github-builder-runtime/lib/github-builder/bake-vars'); @@ -373,6 +392,10 @@ jobs: const inpSet = Util.getInputList('set', {ignoreComma: true, quote: false}); const inpSign = core.getInput('sign'); const inpSourceDateEpoch = core.getInput('source-date-epoch'); + const inpCompression = core.getInput('compression'); + const inpCompressionLevel = core.getInput('compression-level'); + const inpForceCompression = core.getBooleanInput('force-compression'); + const inpLocalExportDir = core.getInput('local-export-dir'); const inpTarget = core.getInput('target'); const inpGitHubToken = core.getInput('github-token'); const inpProxyNetwork = core.getBooleanInput('buildkit-proxy-network'); @@ -429,7 +452,29 @@ jobs: }).sort(), null, 2)); }); + if (inpCompressionLevel !== '' && (!/^\d+$/.test(inpCompressionLevel) || !Number.isSafeInteger(Number(inpCompressionLevel)))) { + core.setFailed(`Invalid compression-level: ${inpCompressionLevel}`); + return; + } + const metaImages = MetaImages.resolve(inpMetaImages); + let buildOutput = BuildOutput.resolve({ + output: inpOutput, + images: metaImages, + push: inpPush, + localExportDir: inpLocalExportDir, + compression: inpCompression || undefined, + compressionLevel: inpCompressionLevel !== '' ? Number(inpCompressionLevel) : undefined, + forceCompression: inpForceCompression || undefined + }); + if (inpOutput === 'image' && inpSourceDateEpoch !== '') { + buildOutput += ',rewrite-timestamp=true'; + } + await core.group(`Set buildOutput output`, async () => { + core.info(buildOutput); + core.setOutput('buildOutput', buildOutput); + }); + await core.group(`Set metaImages output`, async () => { core.info(JSON.stringify(metaImages, null, 2)); core.setOutput('metaImages', metaImages.join('\n')); @@ -842,9 +887,9 @@ jobs: uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 env: INPUT_SOURCE-DATE-EPOCH: ${{ needs.prepare.outputs.sourceDateEpoch }} + INPUT_BUILD-OUTPUT: ${{ needs.prepare.outputs.buildOutput }} INPUT_PLATFORM: ${{ matrix.platform }} INPUT_SBOM-IMAGE: ${{ env.SBOM_IMAGE }} - INPUT_LOCAL-EXPORT-DIR: ${{ env.LOCAL_EXPORT_DIR }} INPUT_CACHE: ${{ inputs.cache }} INPUT_CACHE-SCOPE: ${{ inputs.cache-scope }} INPUT_CACHE-MODE: ${{ inputs.cache-mode }} @@ -852,13 +897,10 @@ jobs: INPUT_TARGETS: ${{ needs.prepare.outputs.targets }} INPUT_CONTEXT: ${{ inputs.context }} INPUT_FILES: ${{ inputs.files }} - INPUT_OUTPUT: ${{ inputs.output }} - INPUT_PUSH: ${{ inputs.push }} INPUT_SBOM: ${{ inputs.sbom }} INPUT_SET: ${{ inputs.set }} INPUT_TARGET: ${{ inputs.target }} INPUT_VARS: ${{ inputs.vars }} - INPUT_META-IMAGES: ${{ needs.prepare.outputs.metaImages }} INPUT_META-VERSION: ${{ steps.meta.outputs.version }} INPUT_META-TAGS: ${{ steps.meta.outputs.tags }} INPUT_SET-META-ANNOTATIONS: ${{ inputs.set-meta-annotations }} @@ -877,14 +919,12 @@ jobs: const { Util } = require('@docker/github-builder-runtime/lib/util'); const inpSourceDateEpoch = core.getInput('source-date-epoch'); - const rewriteTimestamp = inpSourceDateEpoch !== '' ? ',rewrite-timestamp=true' : ''; const inpPlatform = core.getInput('platform'); const platformPairSuffix = inpPlatform ? `-${inpPlatform.replace(/\//g, '-')}` : ''; core.setOutput('platform-pair-suffix', platformPairSuffix); const inpSbomImage = core.getInput('sbom-image'); - const inpLocalExportDir = core.getInput('local-export-dir'); const inpCache = core.getBooleanInput('cache'); const inpCacheScope = core.getInput('cache-scope'); @@ -893,15 +933,12 @@ jobs: const inpTargets = core.getInput('targets'); const inpContext = core.getInput('context'); const inpFiles = Util.getInputList('files'); - const inpOutput = core.getInput('output'); - const inpPush = core.getBooleanInput('push'); const inpSbom = core.getBooleanInput('sbom'); const inpSet = Util.getInputList('set', {ignoreComma: true, quote: false}); const inpTarget = core.getInput('target'); const inpVars = Util.getInputList('vars', {ignoreComma: true, quote: false}); const inpBuildkitProxyNetwork = core.getBooleanInput('buildkit-proxy-network'); - const inpMetaImages = core.getMultilineInput('meta-images'); const inpMetaVersion = core.getInput('meta-version'); const inpMetaTags = core.getMultilineInput('meta-tags'); const inpSetMetaAnnotations = core.getBooleanInput('set-meta-annotations'); @@ -970,23 +1007,6 @@ jobs: core.setOutput('files', bakeFiles.join(os.EOL)); }); - let outputOverride = ''; - switch (inpOutput) { - case 'image': - if (inpMetaImages.length == 0) { - core.setFailed('meta-images is required when output is image'); - return; - } - outputOverride = `*.output=type=image,"name=${inpMetaImages.join(',')}",oci-artifact=true,push-by-digest=true,name-canonical=true,push=${inpPush}${rewriteTimestamp}`; - break; - case 'local': - outputOverride = `*.output=type=local,platform-split=true,dest=${inpLocalExportDir}`; - break; - default: - core.setFailed(`Invalid output: ${inpOutput}`); - return; - } - let bakeOverrides = []; try { bakeOverrides = inpSet.map(override => renderTemplate(override)); @@ -998,7 +1018,7 @@ jobs: if (inpSourceDateEpoch !== '') { bakeOverrides.push(`*.args.SOURCE_DATE_EPOCH=${inpSourceDateEpoch}`); } - bakeOverrides.push(outputOverride); + bakeOverrides.push(`*.output=${core.getInput('build-output')}`); bakeOverrides.push('*.tags='); if (GitHub.context.payload.repository?.private ?? false) { // if this is a private repository, we set min provenance mode diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9f384559..9c4dabeb 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -67,6 +67,19 @@ on: description: "Cache layers to export if cache enabled (min or max)" required: false default: 'min' + compression: + type: string + description: "Image layer compression (uncompressed, gzip, estargz or zstd)" + required: false + compression-level: + type: string + description: "Image layer compression level (0-9 for gzip and estargz, 0-22 for zstd)" + required: false + force-compression: + type: boolean + description: "Recompress existing image layers using the selected compression type" + required: false + default: false context: type: string description: "Context to build from in the Git working tree" @@ -236,6 +249,7 @@ jobs: outputs: sourceDateEpoch: ${{ steps.set.outputs.sourceDateEpoch }} sourceDateCreated: ${{ steps.set.outputs.sourceDateCreated }} + buildOutput: ${{ steps.set.outputs.buildOutput }} includes: ${{ steps.set.outputs.includes }} metaImages: ${{ steps.set.outputs.metaImages }} sign: ${{ steps.set.outputs.sign }} @@ -323,6 +337,10 @@ jobs: id: set uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 env: + INPUT_LOCAL-EXPORT-DIR: ${{ env.LOCAL_EXPORT_DIR }} + INPUT_COMPRESSION: ${{ inputs.compression }} + INPUT_COMPRESSION-LEVEL: ${{ inputs.compression-level }} + INPUT_FORCE-COMPRESSION: ${{ inputs.force-compression }} INPUT_MATRIX-SIZE-LIMIT: ${{ env.MATRIX_SIZE_LIMIT }} INPUT_META-IMAGES: ${{ inputs.meta-images }} INPUT_RUNNER: ${{ inputs.runner }} @@ -342,6 +360,7 @@ jobs: const { GitHub } = require('@docker/github-builder-runtime/lib/github/github'); const { MetaImages } = require('@docker/github-builder-runtime/lib/github-builder/meta-images'); const { SourceDateEpoch } = require('@docker/github-builder-runtime/lib/github-builder/source-date-epoch'); + const { BuildOutput } = require('@docker/github-builder-runtime/lib/github-builder/build-output'); const { RunnerMapping } = require('@docker/github-builder-runtime/lib/github-builder/runner-mapping'); const { Util } = require('@docker/github-builder-runtime/lib/util'); @@ -360,6 +379,10 @@ jobs: const inpSign = core.getInput('sign'); const inpSourceDateEpoch = core.getInput('source-date-epoch'); const inpGitHubToken = core.getInput('github-token'); + const inpCompression = core.getInput('compression'); + const inpCompressionLevel = core.getInput('compression-level'); + const inpForceCompression = core.getBooleanInput('force-compression'); + const inpLocalExportDir = core.getInput('local-export-dir'); const inpProxyNetwork = core.getBooleanInput('buildkit-proxy-network'); if (inpSourceDateEpoch !== '') { @@ -417,7 +440,29 @@ jobs: core.setOutput('proxyNetwork', proxyNetwork); }); + if (inpCompressionLevel !== '' && (!/^\d+$/.test(inpCompressionLevel) || !Number.isSafeInteger(Number(inpCompressionLevel)))) { + core.setFailed(`Invalid compression-level: ${inpCompressionLevel}`); + return; + } + const metaImages = MetaImages.resolve(inpMetaImages); + let buildOutput = BuildOutput.resolve({ + output: inpOutput, + images: metaImages, + push: inpPush, + localExportDir: inpLocalExportDir, + compression: inpCompression || undefined, + compressionLevel: inpCompressionLevel !== '' ? Number(inpCompressionLevel) : undefined, + forceCompression: inpForceCompression || undefined + }); + if (inpOutput === 'image' && inpSourceDateEpoch !== '') { + buildOutput += ',rewrite-timestamp=true'; + } + await core.group(`Set buildOutput output`, async () => { + core.info(buildOutput); + core.setOutput('buildOutput', buildOutput); + }); + await core.group(`Set metaImages output`, async () => { core.info(JSON.stringify(metaImages, null, 2)); core.setOutput('metaImages', metaImages.join('\n')); @@ -776,7 +821,6 @@ jobs: INPUT_SOURCE-DATE-EPOCH: ${{ needs.prepare.outputs.sourceDateEpoch }} INPUT_PLATFORM: ${{ matrix.platform }} INPUT_SBOM-IMAGE: ${{ env.SBOM_IMAGE }} - INPUT_LOCAL-EXPORT-DIR: ${{ env.LOCAL_EXPORT_DIR }} INPUT_DISTRIBUTE: ${{ inputs.distribute }} INPUT_ANNOTATIONS: ${{ inputs.annotations }} INPUT_BUILD-ARGS: ${{ inputs.build-args }} @@ -787,12 +831,9 @@ jobs: INPUT_BUILD-SECRETS: ${{ secrets.build-secrets }} INPUT_LABELS: ${{ inputs.labels }} INPUT_CONTEXT: ${{ inputs.context }} - INPUT_OUTPUT: ${{ inputs.output }} INPUT_PLATFORMS: ${{ inputs.platforms }} - INPUT_PUSH: ${{ inputs.push }} INPUT_SBOM: ${{ inputs.sbom }} INPUT_TARGET: ${{ inputs.target }} - INPUT_META-IMAGES: ${{ needs.prepare.outputs.metaImages }} INPUT_META-VERSION: ${{ steps.meta.outputs.version }} INPUT_META-TAGS: ${{ steps.meta.outputs.tags }} INPUT_SET-META-ANNOTATIONS: ${{ inputs.set-meta-annotations }} @@ -807,14 +848,12 @@ jobs: const { Util } = require('@docker/github-builder-runtime/lib/util'); const inpSourceDateEpoch = core.getInput('source-date-epoch'); - const rewriteTimestamp = inpSourceDateEpoch !== '' ? ',rewrite-timestamp=true' : ''; const inpPlatform = core.getInput('platform'); const platformPairSuffix = inpPlatform ? `-${inpPlatform.replace(/\//g, '-')}` : ''; core.setOutput('platform-pair-suffix', platformPairSuffix); const inpSbomImage = core.getInput('sbom-image'); - const inpLocalExportDir = core.getInput('local-export-dir'); const inpDistribute = core.getBooleanInput('distribute'); const inpAnnotations = core.getInput('annotations'); @@ -825,14 +864,11 @@ jobs: const inpBuildSecrets = core.getInput('build-secrets', {trimWhitespace: false}); const inpContext = core.getInput('context'); const inpLabels = core.getInput('labels'); - const inpOutput = core.getInput('output'); const inpPlatforms = core.getInput('platforms'); - const inpPush = core.getBooleanInput('push'); const inpSbom = core.getBooleanInput('sbom'); const inpTarget = core.getInput('target'); const inpBuildkitProxyNetwork = core.getBooleanInput('buildkit-proxy-network'); - const inpMetaImages = core.getMultilineInput('meta-images'); const inpMetaVersion = core.getInput('meta-version'); const inpMetaTags = core.getMultilineInput('meta-tags'); const inpSetMetaAnnotations = core.getBooleanInput('set-meta-annotations'); @@ -850,22 +886,6 @@ jobs: const buildContext = await new Build().gitContext({subdir: inpContext, attrs: gitContextAttrs}); core.setOutput('context', buildContext); - switch (inpOutput) { - case 'image': - if (inpMetaImages.length == 0) { - core.setFailed('meta-images is required when output is image'); - return; - } - core.setOutput('output', `type=image,"name=${inpMetaImages.join(',')}",oci-artifact=true,push-by-digest=true,name-canonical=true,push=${inpPush}${rewriteTimestamp}`); - break; - case 'local': - core.setOutput('output', `type=local,platform-split=true,dest=${inpLocalExportDir}`); - break; - default: - core.setFailed(`Invalid output: ${inpOutput}`); - return; - } - if (inpPlatform) { core.setOutput('platform', inpPlatform); } else if (!inpDistribute && inpPlatforms) { @@ -937,7 +957,7 @@ jobs: context: ${{ steps.prepare.outputs.context }} file: ${{ inputs.file }} labels: ${{ steps.prepare.outputs.labels }} - outputs: ${{ steps.prepare.outputs.output }} + outputs: ${{ needs.prepare.outputs.buildOutput }} platforms: ${{ steps.prepare.outputs.platform }} provenance: ${{ steps.prepare.outputs.provenance }} sbom: ${{ steps.prepare.outputs.sbom }} diff --git a/README.md b/README.md index c715bfbc..9e9151fc 100644 --- a/README.md +++ b/README.md @@ -239,6 +239,9 @@ jobs: | `cache` | Bool | `false` | Enable [GitHub Actions cache](https://docs.docker.com/build/cache/backends/gha/) exporter | | `cache-scope` | String | target name or `buildkit` | Which [scope cache object belongs to](https://docs.docker.com/build/cache/backends/gha/#scope) if `cache` is enabled. This is the cache blob prefix name used when pushing cache to GitHub Actions cache backend | | `cache-mode` | String | `min` | [Cache layers to export](https://docs.docker.com/build/cache/backends/#cache-mode) if cache enabled (`min` or `max`). In `min` cache mode, only layers that are exported into the resulting image are cached, while in `max` cache mode, all layers are cached, even those of intermediate steps | +| `compression` | String | | Image layer compression: `uncompressed`, `gzip`, `estargz`, or `zstd`. Only applies to `image` output. | +| `compression-level` | String | | Image layer compression level: `0-9` for `gzip` and `estargz`, `0-22` for `zstd`. Empty uses BuildKit's default. Only applies to `image` output. | +| `force-compression` | Bool | `false` | Recompress existing image layers using the selected compression type. Only applies to `image` output. | | `context` | String | `.` | Context to build from in the Git working tree | | `file` | String | `{context}/Dockerfile` | Path to the Dockerfile | | `labels` | List | | List of labels for an image (for `image` output) | @@ -357,6 +360,9 @@ jobs: | `cache` | Bool | `false` | Enable [GitHub Actions cache](https://docs.docker.com/build/cache/backends/gha/) exporter | | `cache-scope` | String | target name or `buildkit` | Which [scope cache object belongs to](https://docs.docker.com/build/cache/backends/gha/#scope) if `cache` is enabled. This is the cache blob prefix name used when pushing cache to GitHub Actions cache backend | | `cache-mode` | String | `min` | [Cache layers to export](https://docs.docker.com/build/cache/backends/#cache-mode) if cache enabled (`min` or `max`). In `min` cache mode, only layers that are exported into the resulting image are cached, while in `max` cache mode, all layers are cached, even those of intermediate steps | +| `compression` | String | | Image layer compression: `uncompressed`, `gzip`, `estargz`, or `zstd`. Only applies to `image` output. | +| `compression-level` | String | | Image layer compression level: `0-9` for `gzip` and `estargz`, `0-22` for `zstd`. Empty uses BuildKit's default. Only applies to `image` output. | +| `force-compression` | Bool | `false` | Recompress existing image layers using the selected compression type. Only applies to `image` output. | | `context` | String | `.` | Context to build from in the Git working tree | | `files` | List | `{context}/docker-bake.hcl` | List of bake definition files | | `output` | String | | Build output destination (one of [`image`](https://docs.docker.com/build/exporters/image-registry/) or [`local`](https://docs.docker.com/build/exporters/local-tar/)). | diff --git a/test/compression.Dockerfile b/test/compression.Dockerfile new file mode 100644 index 00000000..aea26e33 --- /dev/null +++ b/test/compression.Dockerfile @@ -0,0 +1,2 @@ +FROM alpine +RUN printf 'compression fixture\n' > /compression.txt diff --git a/test/docker-bake.hcl b/test/docker-bake.hcl index 5738269e..d8223efe 100644 --- a/test/docker-bake.hcl +++ b/test/docker-bake.hcl @@ -134,3 +134,9 @@ target "source-date-epoch" { dockerfile = "source-date-epoch.Dockerfile" platforms = ["linux/amd64"] } + +target "compression" { + inherits = ["docker-metadata-action"] + dockerfile = "compression.Dockerfile" + platforms = ["linux/amd64", "linux/arm64"] +}