Skip to content

remotecache/s3: honor compression attributes - #7121

Merged
crazy-max merged 3 commits into
moby:masterfrom
ernetas:s3-cache-compression
Sep 23, 2026
Merged

crazy-max merged 3 commits into
moby:masterfrom
ernetas:s3-cache-compression

Conversation

@ernetas

@ernetas ernetas commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

--export-cache type=s3 silently ignores compression, compression-level and force-compression: the exporter returns a hardcoded compression.New(compression.Default) from Config(), so every layer is exported as gzip.

buildctl build ... \
  --export-cache type=s3,region=eu-west-1,bucket=my_bucket,compression=zstd,force-compression=true
# layers are still application/vnd.oci.image.layer.v1.tar+gzip

That value was never deliberate. e3f6d7b added Config() to the Exporter interface and wired compression.ParseAttributes into registry and local, leaving a placeholder returning the default in gha and inline; the s3 backend landed two months later in 09c5a7c and, having to satisfy the now-mandatory method, copied that placeholder rather than the registry implementation. Nothing in the s3 format is tied to gzip — Finalize already records the real media type of every layer and the importer reads it back, so blobs of any supported compression round-trip.

Changes

remotecache/s3: honor compression attributes — parse the attributes in ResolveCacheExporterFunc and return them from Config(), the same way registry and local do. Tests: a table test over the parsing (each valid value, and the error each invalid one produces), plus two integration tests that export, re-import, and assert the cache manifest records the requested media type and that the uploaded blobs really are in that format:

  • testZstdS3CacheImportExport also exports llb.Image("busybox").Run(...) under a second manifest name. That build is what pins force-compression — the first only creates layers born in the requested compression, while this one has to convert the gzip base image layers.
  • testUncompressedS3CacheImportExport covers the other end of the range, where the blob digest equals the diffID and the media type carries no compression suffix.

test: isolate mc config dir for minio servers — a prerequisite. mc keeps its aliases in a single folder defaulting to $HOME/.mc and NewMinioServer registers an alias there per server, so concurrent servers race while rewriting it: mc mb intermittently created the bucket on another test's server and the export then failed with NoSuchBucket. Each server now gets its own folder through MC_CONFIG_DIR, set in the environment rather than passed as --config-dir so that no invocation can miss it — mc treats <alias>/<bucket> of an unknown alias as a local path and silently succeeds.

README documents the three attributes, with a caveat that estargz layers are recorded as plain gzip in the s3 manifest and so cannot be lazily pulled from s3: LayerAnnotations has nowhere to keep their eStargz annotations.

Testing

$ go test ./cache/remotecache/s3/            # and with AWS_PROFILE=nonexistent
ok  	github.com/moby/buildkit/cache/remotecache/s3

$ TESTPKGS=./client TESTFLAGS="--run TestIntegration/Test.*S3CacheImportExport -v" ./hack/test integration
DONE 28 tests in 14.439s   # 9 workers, all pass, 0 skips

Both new integration tests fail without the Config() change, e.g.:

--- FAIL: TestIntegration/TestUncompressedS3CacheImportExport/worker=oci
    layer sha256:3a4bc23… has media type "application/vnd.oci.image.layer.v1.tar+gzip", expected uncompressed

Notes

  • Behavior change: an invalid compression, compression-level or force-compression value on type=s3 now fails when the exporter is resolved — before any build work, and regardless of ignore-error — instead of being silently ignored. This matches registry and local.
  • azblob and gha still carry the same placeholder; the gha one is noted in Support ZSTD compression in s3 remote cache #3071. Left out here to keep the change focused.

Fixes #3071

@ernetas

ernetas commented Sep 21, 2026

Copy link
Copy Markdown
Contributor Author

@tonistiigi sorry, didn't see that this was already approved before pushing. Do you want me to drop minio test changes?

@crazy-max crazy-max added this to the v0.34.0 milestone Sep 23, 2026

@crazy-max crazy-max left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you check CI, seems there are some lint issues. Also can you rebase with master

mc stores its aliases in a single configuration folder that defaults to
$HOME/.mc. NewMinioServer registers an alias there for every server it
starts, so two servers running at the same time race each other while
rewriting that file: one invocation can drop the alias another one just
registered, and a subsequent mc call then either fails outright or
resolves the alias to the wrong server. In the latter case the bucket
gets created on a different server than the one the test handed to
buildkitd, which later fails the export with NoSuchBucket.

Only a single test used a minio server so far, so the aliases never
overlapped in practice. Point the mc invocations of every server at
their own folder through MC_CONFIG_DIR so that additional parallel tests
keep working. Setting it in the environment rather than passing
--config-dir makes it impossible for an invocation to miss it, which
matters because mc treats "<alias>/<bucket>" of an unknown alias as a
local path and silently succeeds. As the folder is a t.TempDir(), the
alias no longer needs a random name or an explicit cleanup.

Signed-off-by: Ernestas Lukoševičius <ernetas@gmail.com>
The s3 cache exporter returned a hardcoded compression.New(compression.
Default) from Config(), so compression, compression-level and
force-compression passed to --export-cache type=s3 were silently ignored
and every layer was always exported as gzip.

That value was never a deliberate choice for this backend. e3f6d7b
added Config() to the Exporter interface to make the compression
selectable, and wired compression.ParseAttributes into the registry and
local backends while leaving a placeholder returning the default in gha
and inline. The s3 backend was added two months later in 09c5a7c and
copied that placeholder instead of the registry implementation.

Nothing in the s3 cache format is tied to gzip. Finalize already records
the real media type of every layer in the cache manifest and the importer
reads it back, so blobs of any supported compression round-trip.

Parse the attributes in ResolveCacheExporterFunc and return them from
Config(), the same way the registry and local backends do.

Fixes moby#3071

Signed-off-by: Ernestas Lukoševičius <ernetas@gmail.com>
NewMinioServer runs mc alias set and mc mb through integration.RunCmd,
which is a plain cmd.Run on t.Context(). That context is only canceled
once the test function returns, so unlike everything else the test does
these two calls are not covered by the sandbox timeout: a wedged server
keeps the test running until the whole test binary hits its go test
deadline, and the test that hung is never reported. They are the only
RunCmd callers in the tree; every other wait in the harness is bounded.

Give each one-shot invocation a 30s deadline of its own and report which
one expired. mc admin trace is a long-running stream and keeps using
t.Context(). A failure of mc itself still surfaces as its own error
rather than as a timeout.

Signed-off-by: Ernestas Lukoševičius <ernetas@gmail.com>
@ernetas
ernetas force-pushed the s3-cache-compression branch from a77ccc3 to bfdbe22 Compare September 23, 2026 13:09
@crazy-max
crazy-max merged commit e1d0ff6 into moby:master Sep 23, 2026
249 of 250 checks passed
@ernetas
ernetas deleted the s3-cache-compression branch September 23, 2026 13:59
markharding pushed a commit to futo-org/Harbor that referenced this pull request Oct 13, 2026
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [moby/buildkit](https://github.com/moby/buildkit) | final | minor | `v0.33.0-rootless` → `v0.34.0-rootless` |

---

### Release Notes

<details>
<summary>moby/buildkit</summary>

### [`v0.34.0`](https://github.com/moby/buildkit/releases/tag/v0.34.0)

[Compare Source](moby/buildkit@v0.33.1...v0.34.0)

buildkit 0.34.0

Welcome to the v0.34.0 release of buildkit!

Please try out the release binaries and report any issues at
<https://github.com/moby/buildkit/issues>.

##### Contributors

- Tõnis Tiigi
- CrazyMax
- Sebastiaan van Stijn
- Akihiro Suda
- Ernestas Lukoševičius
- Alexandre Rodrigues
- Kamil Monicz
- okhowang(王沛文)
- Alex G. Wolff
- Ben Harris
- Guthrie McAfee Armstrong
- Jonathan A. Sternberg
- KR Ravindra
- MohammadHasan Akbari
- MsfPablo
- Paul Schroeder
- Ruzan Sasuri
- Sterling Greene
- Suhail Hany
- ZRHann

##### Notable changes

- Built-in Dockerfile frontend has been updated to v1.28.0 [changelog](https://github.com/moby/buildkit/releases/tag/dockerfile%2F1.28.0)
- BoltDB databases now support compaction to periodically reduce database size and compress them on disk. This feature is currently opt-in and can be enabled with TOML configuration. The intention is to enable it by default in future releases. [#&#8203;7138](moby/buildkit#7138) [#&#8203;7248](moby/buildkit#7248)
- Local and tar exporters now support the `src` option for specifying the subdirectory to export. [#&#8203;7226](moby/buildkit#7226)
- Provenance attestation now contains information about the target platform of the build. [#&#8203;7227](moby/buildkit#7227)
- Unpack exporter option is not supported in rewrite-timestamp mode. [#&#8203;6939](moby/buildkit#6939)
- Reduce BoltDB database size and performance overhead [#&#8203;6882](moby/buildkit#6882)
- Transient registry token failures are now retried. [#&#8203;7155](moby/buildkit#7155)
- Add protection to using concurrent local cache exports with `reset` option. [#&#8203;7153](moby/buildkit#7153)
- NewContainer API in Gateway now preserves the platform information of the created container. [#&#8203;7083](moby/buildkit#7083)
- Enable configuring Hyper-V isolation mode for Windows containers. [#&#8203;7067](moby/buildkit#7067)
- S3 remote cache backend now supports compression options. [#&#8203;7121](moby/buildkit#7121)
- Session authentication timeout is now configurable from TOML configuration. [#&#8203;7225](moby/buildkit#7225)
- Startup performance of internal databases has been improved by creating a BoltDB freelist on graceful shutdown [#&#8203;7249](moby/buildkit#7249)
- Improve recovery from database open failures in more internal databases. [#&#8203;7137](moby/buildkit#7137)
- Buildkitd now supports defining the configuration path with an environment variable. [#&#8203;7144](moby/buildkit#7144)
- Original messages from GitHub cache backend are now preserved. [#&#8203;7232](moby/buildkit#7232)
- Avoid panic from misconfigured GC policy. [#&#8203;7209](moby/buildkit#7209)
- Fix issue where some cache records could remain in use after build completion with an error. [#&#8203;7223](moby/buildkit#7223)
- Fix possible cache export failure with parallel requests. [#&#8203;7145](moby/buildkit#7145)
- Fix incorrect backslash escaping in RUN step progress output. [#&#8203;7188](moby/buildkit#7188)
- Fix encoding of some material URLs with custom ports in the provenance attestation. [#&#8203;5641](moby/buildkit#5641)
- Fix possible "ref locked: unavailable" errors on parallel builds export step. [#&#8203;7182](moby/buildkit#7182)
- Fix possible build errors when using `SOURCE_DATE_EPOCH` together with subdir Git sources. [#&#8203;7183](moby/buildkit#7183)
- Fix possible EBUSY errors from overlay filesystem on some systems. [#&#8203;7167](moby/buildkit#7167)
- Fix bug that could cause some internal database indexes to never get released. [#&#8203;7135](moby/buildkit#7135)
- Fix handling of IPv6 hosts without an explicit port. [#&#8203;7164](moby/buildkit#7164)
- Fix possible build error when canceling QEMU emulated build step. [#&#8203;7092](moby/buildkit#7092)
- Fix using normalized variant of platform identifier in annotation key [#&#8203;7244](moby/buildkit#7244)
- Fix possible storage reference leak when canceling build in the middle of exec step [#&#8203;7247](moby/buildkit#7247)
- Fix possible deadlock on large bidirectional stdio streams [#&#8203;7240](moby/buildkit#7240)
- Fix possible hang on container output writer error [#&#8203;7243](moby/buildkit#7243)

##### Dependency Changes

- **github.com/aws/aws-sdk-go-v2**                                                  v1.43.8 -> v1.47.0
- **github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream**                         v1.7.18 -> v1.7.20
- **github.com/aws/aws-sdk-go-v2/config**                                           v1.32.39 -> v1.33.4
- **github.com/aws/aws-sdk-go-v2/credentials**                                      v1.19.38 -> v1.20.4
- **github.com/aws/aws-sdk-go-v2/feature/ec2/imds**                                 v1.18.39 -> v1.20.0
- **github.com/aws/aws-sdk-go-v2/internal/configsources**                           v1.4.39 -> v1.5.3
- **github.com/aws/aws-sdk-go-v2/internal/endpoints/v2**                            v2.7.39 -> v2.8.3
- **github.com/aws/aws-sdk-go-v2/internal/v4a**                                     v1.4.40 -> v1.5.3
- **github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding**                 v1.13.18 -> v1.13.19
- **github.com/aws/aws-sdk-go-v2/service/internal/presigned-url**                   v1.13.39 -> v1.14.3
- **github.com/aws/aws-sdk-go-v2/service/signin**                                   v1.5.8 -> v1.10.0
- **github.com/aws/aws-sdk-go-v2/service/sso**                                      v1.33.8 -> v1.38.0
- **github.com/aws/aws-sdk-go-v2/service/ssooidc**                                  v1.38.8 -> v1.43.0
- **github.com/aws/aws-sdk-go-v2/service/sts**                                      v1.45.8 -> v1.50.0
- **github.com/aws/smithy-go**                                                      v1.27.10 -> v1.28.2
- **github.com/containerd/containerd/api**                                          v1.11.1 -> v1.12.0
- **github.com/containerd/containerd/v2**                                           v2.3.6 -> v2.4.1
- **github.com/containerd/go-cni**                                                  v1.1.13 -> v1.1.14
- **github.com/containerd/log/otel**                                                v0.1.0 **_new_**
- **github.com/containerd/ttrpc**                                                   v1.2.9 -> v1.2.10
- **github.com/containernetworking/cni**                                            v1.3.0 -> v1.3.1
- **github.com/cyphar/filepath-securejoin**                                         v0.6.1 -> v0.7.0
- **github.com/docker/cli**                                                         v29.7.2 -> v29.8.2
- **github.com/docker/docker-credential-helpers**                                   v0.9.8 -> v0.9.9
- **github.com/docker/go-metrics**                                                  v0.0.1 -> v0.1.0
- **github.com/fsnotify/fsnotify**                                                  v1.9.0 -> v1.10.1
- **github.com/go-openapi/analysis**                                                v0.25.2 -> v0.25.5
- **github.com/go-openapi/jsonpointer**                                             v0.23.1 -> v1.0.0
- **github.com/go-openapi/jsonreference**                                           v0.21.6 -> v1.0.0
- **github.com/go-openapi/loads**                                                   v0.24.0 -> v0.25.0
- **github.com/go-openapi/runtime**                                                 v0.32.4 -> v0.33.0
- **github.com/go-openapi/spec**                                                    v0.22.6 -> v0.22.9
- **github.com/go-openapi/strfmt**                                                  v0.26.4 -> v0.27.0
- **github.com/go-openapi/swag**                                                    v0.26.1 -> v0.28.0
- **github.com/go-openapi/swag/cmdutils**                                           v0.26.1 -> v0.28.0
- **github.com/go-openapi/swag/conv**                                               v0.27.0 -> v0.28.0
- **github.com/go-openapi/swag/fileutils**                                          v0.26.1 -> v0.28.0
- **github.com/go-openapi/swag/jsonutils**                                          v0.26.1 -> v0.28.0
- **github.com/go-openapi/swag/loading**                                            v0.26.1 -> v0.28.0
- **github.com/go-openapi/swag/mangling**                                           v0.26.1 -> v0.28.0
- **github.com/go-openapi/swag/netutils**                                           v0.26.1 -> v0.28.0
- **github.com/go-openapi/swag/pools**                                              v0.28.0 **_new_**
- **github.com/go-openapi/swag/stringutils**                                        v0.26.1 -> v0.28.0
- **github.com/go-openapi/swag/typeutils**                                          v0.27.0 -> v0.28.0
- **github.com/go-openapi/swag/yamlutils**                                          v0.26.1 -> v0.28.0
- **github.com/go-openapi/validate**                                                v0.26.0 -> v0.26.1
- **github.com/gofrs/flock**                                                        v0.13.0 -> v0.13.1
- **github.com/grpc-ecosystem/grpc-gateway/v2**                                     v2.29.0 -> v2.30.0
- **github.com/klauspost/compress**                                                 v1.19.2 -> v1.20.1
- **github.com/moby/policy-helpers**                                                [`dd6c549`](moby/buildkit@dd6c5499c491) -> [`bd98f47`](moby/buildkit@bd98f4747414)
- **github.com/moby/profiles/seccomp**                                              v0.2.3 -> v0.2.4
- **github.com/moby/sys/userns**                                                    v0.2.0 -> v0.2.1
- **github.com/package-url/packageurl-go**                                          v0.1.1 -> v0.1.7
- **github.com/prometheus/client_model**                                            v0.6.2 -> v0.6.3
- **github.com/prometheus/common**                                                  v0.70.1 -> v0.71.0
- **github.com/sirupsen/logrus**                                                    v1.10.1 -> v1.10.2
- **github.com/tonistiigi/go-actions-cache**                                        [`54bc28c`](moby/buildkit@54bc28c26fd2) -> [`afe8013`](moby/buildkit@afe8013b5ac4)
- **github.com/urfave/cli/v3**                                                      v3.9.0 -> v3.11.0
- **go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc**   v0.70.0 -> v0.71.0
- **go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace**  v0.70.0 -> v0.71.0
- **go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp**                 v0.70.0 -> v0.71.0
- **go.opentelemetry.io/otel**                                                      v1.45.0 -> v1.46.0
- **go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc**             v1.45.0 -> v1.46.0
- **go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp**             v1.45.0 -> v1.46.0
- **go.opentelemetry.io/otel/exporters/otlp/otlptrace**                             v1.45.0 -> v1.46.0
- **go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc**               v1.45.0 -> v1.46.0
- **go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp**               v1.45.0 -> v1.46.0
- **go.opentelemetry.io/otel/exporters/prometheus**                                 v0.67.0 -> v0.68.0
- **go.opentelemetry.io/otel/metric**                                               v1.45.0 -> v1.46.0
- **go.opentelemetry.io/otel/sdk**                                                  v1.45.0 -> v1.46.0
- **go.opentelemetry.io/otel/sdk/metric**                                           v1.45.0 -> v1.46.0
- **go.opentelemetry.io/otel/trace**                                                v1.45.0 -> v1.46.0
- **google.golang.org/genproto/googleapis/api**                                     [`6ac0973`](moby/buildkit@6ac0973c030d) -> [`da73d73`](moby/buildkit@da73d73af1c5)
- **google.golang.org/genproto/googleapis/rpc**                                     [`6ac0973`](moby/buildkit@6ac0973c030d) -> [`da73d73`](moby/buildkit@da73d73af1c5)
- **google.golang.org/grpc**                                                        v1.83.2 -> v1.84.0
- **tags.cncf.io/container-device-interface**                                       v1.1.0 -> v1.1.1
- **tags.cncf.io/container-device-interface/specs-go**                              v1.1.0 -> v1.1.1

Previous release can be found at [v0.33.1](https://github.com/moby/buildkit/releases/tag/v0.33.1)

### [`v0.33.1`](https://github.com/moby/buildkit/releases/tag/v0.33.1)

[Compare Source](moby/buildkit@v0.33.0...v0.33.1)

Welcome to the v0.33.1 release of buildkit!

Please try out the release binaries and report any issues at
<https://github.com/moby/buildkit/issues>.

##### Contributors

- Tõnis Tiigi
- CrazyMax
- Sebastiaan van Stijn

##### Notable Changes

- Built-in Dockerfile frontend has been updated to v1.27.1 [changelog](https://github.com/moby/buildkit/releases/tag/dockerfile%2F1.27.1).
- Fix proxy CA cleanup so build steps cannot redirect it outside the build rootfs, block it with a special file, or succeed when cleanup fails. GHSA-2f5p-x9ph-g97x
- Fix a daemon panic when a build requests CDI devices while CDI support is disabled. Optional devices are ignored; required devices produce an error. GHSA-r456-g3gm-cvxf
- Verify container blob contents against their claimed digest before caching them. This protects shared caches from unverified blobs supplied through the low-level LLB API. GHSA-p3rc-w3hc-pqvv
- Verify applied image layer DiffIDs, bind lazy stargz snapshots to their verified TOC digest, and isolate legacy layer snapshots. Image source cache keys no longer rely on unverified DiffIDs. GHSA-f2v9-hprr-32q3
- Prevent malicious external frontends from crashing the daemon through gateway container lifecycle races or malformed requests and definitions. GHSA-4hgw-qrhw-fhg8
- Reject special files in daemon-side snapshot reads and replace existing special files safely in LLB `mkfile` operations. GHSA-9728-qjrv-2xh2
- Reject malformed LLB file operations with invalid symlink owner inputs instead of allowing a daemon panic. GHSA-fjj4-h6vf-m9hj
- Reject malformed LLB merge operations with mismatched input counts instead of allowing a daemon panic. GHSA-cv6p-7w7g-xjwq
- Limit Dockerfile, `.dockerignore`, gateway file, and nested LLB definition reads to prevent oversized inputs from exhausting daemon memory. GHSA-mgqf-486f-49vp
- Apply source policies to Git bundle locators and reject Git full remote URLs that do not match the source identifier. GHSA-66hf-6vf5-87hc

##### Dependency Changes

- **github.com/containerd/containerd/v2**  v2.3.4 -> v2.3.6
- **golang.org/x/crypto**                  v0.55.0 -> v0.56.0

Previous release can be found at [v0.33.0](https://github.com/moby/buildkit/releases/tag/v0.33.0)

</details>

---

### Configuration

📅 **Schedule**: (UTC)

- Branch creation
  - "before 9am on tuesday"
- Automerge
  - At any time (no schedule defined)

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Mend Renovate CLI](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0NC4xMzMuMCIsInVwZGF0ZWRJblZlciI6IjQ0LjE1NS4xIiwidGFyZ2V0QnJhbmNoIjoiZGV2ZWxvcCIsImxhYmVscyI6WyJkZXBlbmRlbmNpZXMiLCJyZW5vdmF0ZSJdfQ==-->

Reviewed-on: https://code.futo.org/harbor/harbor/pulls/1830
Reviewed-by: Thomas de Zeeuw <thomas@futo.org>
crohr added a commit to runs-on/buildkit that referenced this pull request Nov 3, 2026
The gha cache exporter returned a hardcoded compression.New(compression.Default)
from Config(), so compression, compression-level and force-compression set on
--export-cache type=gha were silently ignored, and every new layer was
exported as gzip. moby#7121 fixed the same bug in the s3 exporter.

Parse the attributes when resolving the exporter and return them from
Config(), as the s3 exporter does. Finalize already records each layer's media
type in the cache config and the importer reads it back, so zstd and
uncompressed blobs round-trip. The importer shares getConfig and keeps
ignoring these attributes. NewExporter keeps the default compression.

Signed-off-by: Cyril Rohr <hey@cyrilrohr.com>
crazy-max added a commit to crazy-max/docker-docs that referenced this pull request Nov 23, 2026
Follow up on moby/buildkit#7121.

Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support ZSTD compression in s3 remote cache

3 participants