From 2ca6441dd5ce63020444d717dbf7014c18b51e5d Mon Sep 17 00:00:00 2001 From: CrazyMax <1951866+crazy-max@users.noreply.github.com> Date: Wed, 23 Apr 2025 10:14:10 +0200 Subject: [PATCH] DOCKER_BUILD_EXPORT_LEGACY env var to opt-in for legacy export Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com> --- .github/workflows/ci.yml | 29 +++++++++++++++++++++++++++++ README.md | 1 + src/main.ts | 10 +++++++++- 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e9d7706..ea557d9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1464,6 +1464,35 @@ jobs: env: DOCKER_BUILD_RECORD_RETENTION_DAYS: ${{ matrix.days }} + export-legacy: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + legacy: + - false + - true + steps: + - + name: Checkout + uses: actions/checkout@v4 + with: + path: action + - + 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 + uses: ./action + with: + file: ./test/Dockerfile + env: + DOCKER_BUILD_EXPORT_LEGACY: ${{ matrix.legacy }} + checks: runs-on: ubuntu-latest strategy: diff --git a/README.md b/README.md index fb60ea6..82e672a 100644 --- a/README.md +++ b/README.md @@ -277,6 +277,7 @@ The following outputs are available: | `DOCKER_BUILD_SUMMARY` | Bool | `true` | If `false`, [build summary](https://docs.docker.com/build/ci/github-actions/build-summary/) generation is disabled | | `DOCKER_BUILD_RECORD_UPLOAD` | Bool | `true` | If `false`, build record upload as [GitHub artifact](https://docs.github.com/en/actions/using-workflows/storing-workflow-data-as-artifacts) is disabled | | `DOCKER_BUILD_RECORD_RETENTION_DAYS` | Number | | Duration after which build record artifact will expire in days. Defaults to repository/org [retention settings](https://docs.github.com/en/actions/learn-github-actions/usage-limits-billing-and-administration#artifact-and-log-retention-policy) if unset or `0` | +| `DOCKER_BUILD_EXPORT_LEGACY` | Bool | `false` | If `true`, exports build using legacy export-build tool instead of [`buildx history export` command](https://docs.docker.com/reference/cli/docker/buildx/history/export/) | ## Troubleshooting diff --git a/src/main.ts b/src/main.ts index 538ec08..442027a 100644 --- a/src/main.ts +++ b/src/main.ts @@ -200,7 +200,8 @@ actionsToolkit.run( const buildxHistory = new BuildxHistory(); const exportRes = await buildxHistory.export({ - refs: stateHelper.buildRef ? [stateHelper.buildRef] : [] + refs: stateHelper.buildRef ? [stateHelper.buildRef] : [], + useContainer: buildExportLegacy() }); core.info(`Build record written to ${exportRes.dockerbuildFilename} (${Util.formatFileSize(exportRes.dockerbuildSize)})`); @@ -294,3 +295,10 @@ function buildRecordRetentionDays(): number | undefined { return res; } } + +function buildExportLegacy(): boolean { + if (process.env.DOCKER_BUILD_EXPORT_LEGACY) { + return Util.parseBool(process.env.DOCKER_BUILD_EXPORT_LEGACY); + } + return false; +}