640 Commits

Author SHA1 Message Date
CrazyMax
41ec37ec87 vendor: update github.com/aws/aws-sdk-go-v2 modules to latest
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
2026-06-09 11:46:10 +02:00
Tõnis Tiigi
fdbf563f59 Merge pull request #6821 from tonistiigi/fix-failed-to-commit
Fix failed to commit on during finalize error
2026-06-08 11:11:25 -07:00
Sebastiaan van Stijn
94dcaca630 update protoc to v3.14.0
Updating to the lowest release that includes [protobuf@dfab275], which
removed use of the github.com/golang/protobuf/ptypes/timestamp.Timestamp
type alias (deprecated).

[protobuf@dfab275]: dfab275eca

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2026-06-05 18:01:59 +02:00
Bjorn Neergaard
c9f1690554 all: use well-known zstd mediaType constants
When support for zstd was introduced, these mediaTypes were not yet
available in released versions of their respective Go packages. That is
no longer the case.

Signed-off-by: Bjorn Neergaard <bjorn.neergaard@docker.com>
2026-06-02 23:11:12 -07:00
Brian Goff
c78752e9c1 cache: tighten parent lock scope in parentRefs.release
The layerParent and diffParents cases locked each parent's mutex and
deferred the unlock to the end of the function, so the lock was held
longer than the release it protects -- and in the diffParents case the
lower parent's lock was still held while the upper parent was locked and
released.

Unlock each parent immediately after releasing it so the lock is held
only for that parent's release, matching the mergeParents case in the
same switch which already does this. This narrows the lock scope and
avoids holding one parent's lock while acquiring another's.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2026-06-01 20:54:08 -07:00
Tonis Tiigi
bd3608ddc9 lint: update golangci-lint to v2.12.2
Update golangci-lint and adjust code for new gosec diagnostics. Use
root-scoped filesystem operations where appropriate, preserve explicit
user path behavior for SSH keys, and avoid background contexts in
request-scoped cleanup paths.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2026-05-14 10:13:15 -07:00
Jonathan A. Sternberg
80e934d8b3 remotecache: propagate details field from registry when included
Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
2026-05-11 12:37:43 -05:00
Vladimir Kuznichenkov
b0e7d805e6 s3cache: Fix data race in readerAtCloser
readerAtCloser implements io.ReaderAt, whose documented contract
explicitly allows concurrent callers:

    Clients of ReadAt can execute parallel ReadAt calls on the same
    input source.

However the type has no synchronization protecting its mutable state
(rc, ra, offset, closed). When used as the body of an S3 upload via
manager.Uploader, the AWS SDK v2 upload manager spawns DefaultUpload-
Concurrency=5 worker goroutines, each given an io.NewSectionReader
slice that shares the same underlying body. Each worker's Read
eventually becomes a concurrent ReadAt on the same *readerAtCloser
at a different offset, racing on the close-then-reopen path.

Under the race detector this produces DATA RACE warnings on rc,
offset and ra. Without the race detector it intermittently crashes
buildkitd with a nil pointer dereference at the hrs.rc.Read(p) call
in the io.ReaderAt fallback branch, when one goroutine nils rc
between a peer's nil-check and Read dispatch. The crash kills the
buildkit daemon and cannot be recovered by the buildctl client.

The bug reliably reproduces whenever a cache layer exceeds the
default 5 MiB part size, i.e. essentially every real-world Docker
image build that exports cache to S3.

PR #5597 added an offset parameter to s3Client.getReader and reduced
the frequency of close-reopen on the common sequential-read path,
but did not address the underlying thread-safety violation. This
commit takes the minimum-risk correctness fix: serialize ReadAt and
Close with a sync.Mutex so the io.ReaderAt contract is honoured and
the existing close-reopen logic remains correct under concurrent
callers.

Under the mutex this becomes serialised per readerAtCloser: correct,
but potentially slower for a single large blob that is being
re-exported from S3 back to S3. This is not a global BuildKit lock:
different cache layers can still upload in parallel, but one blob
backed by this reader loses multipart read parallelism and still
pays the reopen churn. A proper follow-up would also eliminate the
shared-state optimisation that causes the thrashing, for example by
having ReaderAt open an independent reader per call (stateless), or
by keeping a small pool of per-offset readers. That optimisation
can be follow-up work after this correctness fix, or part of the
#3993 refactor (which would also need a mutex added to the
replacement contentutil.readerAt).

Closes #6674

Signed-off-by: Vladimir Kuznichenkov <vova@kuzaxak.dev>
2026-04-10 09:02:11 +03:00
Jiří Moravčík
2828e47139 cache: add retry_mode and retry_max_attempts options to s3 cache
Add configurable retry behavior for the S3 cache.
Users can now set `retry_mode` (standard/adaptive) and
`retry_max_attempts` to tune AWS SDK retry settings for their
environment. When not specified, the AWS SDK defaults apply
(standard mode, 3 max attempts).

Signed-off-by: Jiří Moravčík <jiri.moravcik@gmail.com>
2026-04-06 23:23:18 +02:00
Dmitrii Kostyrev
dc552cb6e5 Introduce disable_accept_encoding flag in s3 cache.
Signed-off-by: Dmitrii Kostyrev <dkostyrev@joom.com>
2026-04-02 14:26:51 +01:00
Tõnis Tiigi
c0a4bd9e75 Merge pull request #6566 from tonistiigi/generics-typed-utils
util: use generics based helper packages for type safety
2026-03-10 09:06:08 -07:00
Tonis Tiigi
481132ff14 refactor: deduplicate NopWriteCloser into util/iohelper
Replace duplicate nopCloser, nopWriteCloser, and bufferCloser
type definitions across test and production code with the
shared iohelper.NopWriteCloser type.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2026-03-09 22:16:14 -07:00
Tonis Tiigi
0a402db53c refactor: add typed sync.Pool wrapper to eliminate any
Introduce util/pools.Pool[T] as a generic typed wrapper
around sync.Pool. Migrate existing pool usages in
contenthash, converter, and overlay packages to use the
new wrapper, removing unchecked type assertions at each
call site.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2026-03-09 22:15:43 -07:00
Sebastiaan van Stijn
1a05836d25 worker: remove automatic migration of legacy v1 cache
This removes the MigrateV2 function, which was added in BuildKit v0.7.0
(Docker v20.10.0) in 31a9aeea88. That was
in 2019, which is now over 6 Years ago, so it's very unlikely for old
files to be still present.

Removing this code would impact users migrating from Docker 19.03 or
older, which are versions that reached EOL many years ago, so very
unlikely.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2026-02-14 12:28:42 +01:00
CrazyMax
18ad342e57 Merge pull request #6460 from tonistiigi/golint-v2.8.0-update
hack: golangci v2.8.0 and gopls v0.38.0 update
2026-01-14 15:44:19 +01:00
CrazyMax
85b330feab Merge pull request #6459 from tonistiigi/v0.27-deps-updates
v0.27 dependency updates
2026-01-14 11:09:27 +01:00
Tonis Tiigi
a8b83196f3 ci: update golangci to v2.8.0
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2026-01-13 22:09:20 -08:00
Tonis Tiigi
ddeb26c5e1 vendor: update outdated patch versions of dependencies
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2026-01-13 22:08:15 -08:00
Amr Mahdi
87b57a2ff2 registry remotecache: push cache blobs in parallel
Registry cache blob pushing was sequential, copying one layer at a time. This
uses images.Dispatch to push all cache layer blobs in parallel, similar
to how image export already handles layer pushing.

The blobs are collected upfront, pushed concurrently, then
added to the cache manifest in order after all pushes complete.

Signed-off-by: Amr Mahdi <amrmahdi@meta.com>
2026-01-13 16:49:43 -08:00
Tõnis Tiigi
cc0fbe984f Merge pull request #6397 from tonistiigi/gha-signed-cache
gha: add signed cache support
2026-01-06 14:58:42 -08:00
Tõnis Tiigi
e79956392a Merge pull request #6387 from jedevc/cache-mounts-over-session
Cache local mounts for filesystem access APIs
2026-01-05 18:08:11 -08:00
Tonis Tiigi
c2027e194d gha: add signed cache support
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2026-01-05 18:00:24 -08:00
Tonis Tiigi
9a3333c4d2 resolver: auth refactor for better readability
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2025-12-10 18:08:59 -08:00
Justin Chadwell
7aaa7974dd gateway: cache local mounts from fs operations
Previously, each call to `ReadFile`/`ReadDir`/`StatFile` would trigger
an entire `Mount`+`Unmount` operation. This could result in terrible
performance for repeated filesystem accesses - potentially worse that
one `Mount`+`Unmount` per file, if the file is read in ranges.

To resolve this, we now directly store the `localMounter` in the
gateway, and rely on the fact that repeated calls to it return the same
value. These mounts will only be removed when the gateway itself is
released.

Signed-off-by: Justin Chadwell <me@jedevc.com>
2025-12-04 11:33:42 +00:00
CrazyMax
ccf4af8dd6 cache(s3): request checksum calculation when required
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
2025-11-20 10:51:15 +01:00
Tonis Tiigi
09426caaae vendor: update containerd to v2.2.0-rc.0
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2025-11-03 11:11:53 -08:00
Jonathan A. Sternberg
ac10b4193f frontend: add required paths to LLB and use it with --parents
This adds an additional `RequiredPaths` that is primarily intended for
use with `COPY --parents`. This parameter specifies expected directories
or files that should exist when performing the checksum. A not found
error will be produced if one of these paths is missing.

This fixes an issue with `COPY --parents` where a non existent directory
that was intended to be copied would be ignored.

Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
2025-10-13 14:38:38 -05:00
Akihiro Suda
7cf577a2f7 Merge pull request #6238 from jsternberg/exclude-pattern-too-broad-cache-key
contenthash: change how checksum is calculated with wildcards and patterns
2025-10-10 09:01:32 +09:00
Tonis Tiigi
687fb282e4 client: add test for deleted blobs in remote cache
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2025-10-06 07:58:39 -07:00
Tonis Tiigi
99c6887ddf remotecache: skip result on not-found error
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2025-10-02 23:06:07 -07:00
Jonathan A. Sternberg
9403302103 contenthash: change how checksum is calculated with wildcards and patterns
This changes the way the checksum is calculated for content that has
wildcards or include/exclude paths. The previous method would result in
a different checksum with the same file contents but different patterns
due to a different method of hashing the data.

This normalizes the way the data is hashed to use similar methods. The
wildcard path now strips the prefix from the path instead of using the
base path. It no longer adds an additional zero byte between entries but
instead uses the zero byte from the directory path key.

Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
2025-09-23 15:32:51 -05:00
Tõnis Tiigi
f319a773e8 Merge pull request #6220 from jsternberg/copy-broken-symlink-with-exclude
contenthash: do not follow nested symlinks when computing checksum
2025-09-19 15:52:04 -07:00
Jonathan A. Sternberg
74d1779103 contenthash: do not follow nested symlinks when computing checksum
Nested symlinks were not intended to be followed after the first level
of wildcard expansion. When include/exclude patterns were used or a
wildcard was present higher up in the tree, we would erroneously follow
ALL symlinks to compute the hash.

When a symlink was broken, this would result in an error. We weren't
supposed to be following the symlinks at all.

This fixes things by changing `includedPaths` to also return whether a
path should follow links. If a parent directory exists for the path,
then the symlink is not followed.

Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
2025-09-12 18:02:22 -05:00
Tonis Tiigi
292043fcaa remotecache: fix missing skipped result on diffop tests
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2025-09-11 13:08:18 -07:00
Tonis Tiigi
e4ee7622d1 remotecache: fix possible panic when merging loop candidates
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2025-09-11 13:08:11 -07:00
Tonis Tiigi
6c0aa8c8f1 remotecache: use bestResult to determine what result to export
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2025-09-11 13:08:10 -07:00
Tonis Tiigi
846a4ccd13 remotecache: add merge keys for loops
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2025-09-11 13:08:10 -07:00
Tonis Tiigi
a12ea755c0 remotecache: fix remote selector candidates matching
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2025-09-11 13:08:10 -07:00
Tonis Tiigi
2d7ef04dfd remotecache: refactor to new cache export interface
This is a complete refactor of the cache export Go interface.

Main aspect is to provide a strictly ordered walk of the
cache tree instead of previous one where modification could be
added to cache tree at any time by any component.

This should address subtle concurrency issues and remove
large parts of complicated (and likely buggy) normalization
and deduplication steps.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2025-09-11 13:08:10 -07:00
Jonathan A. Sternberg
f4339fd00b tools: utilize the new tool functionality introduced in go 1.24
Removes the `tools/tools.go` file used as a hack to get `go.mod` to
track tools in favor of the new method introduced in go 1.24 of being
formally supported in the `go.mod` file. This will allow the tools to be
managed with the new `go get tool` and `go install tool` commands.

Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
2025-09-10 10:08:03 -05:00
CrazyMax
d31230ea96 lint: gopls fixes
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
2025-09-09 14:13:04 +02:00
Sebastiaan van Stijn
8322c04df8 replace github.com/hashicorp/go-multierror with errors.Join
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-20 16:24:49 +02:00
Tõnis Tiigi
3cad6c06a2 Merge pull request #6076 from tonistiigi/cache-debuginfo-db-remote
debug: allow debug from remote cache config
2025-08-13 15:05:11 +03:00
Tõnis Tiigi
cea1cadf80 Merge pull request #6092 from Fricounet/fricounet/upstream/fix-digest-duplication
[cache] Fix descriptor duplication in getAvailableBlobs
2025-08-12 12:12:31 +03:00
Baptiste Girard-Carrabin
786d74c3ef [cache] Fix descriptor duplication in getAvailableBlobs
The walkBlob function was called with a function having a side effect: appending a descriptor to a list. However, the function could be called multiple times for the same descriptor (once in `walkBlob` and once in `walkBlobVariantsOnly` in that case) leading to duplicate entries in the final list.
Instead, we will check each time we want to add an element, that it's not already in the list using slice.ContainsFunc.
This should be fine from a performance perspective as the list is small (at most 2 compressions in the vast majority of cases).

Signed-off-by: Baptiste Girard-Carrabin <baptiste.girardcarrabin@datadoghq.com>
2025-08-11 16:33:55 +02:00
Tonis Tiigi
4b822e9762 debug: allow debug from remote cache config
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2025-08-11 13:12:50 +03:00
Kohei Tokunaga
a6f4cc55a1 TestGetRemotes: fix race of laziness check
Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
2025-07-18 23:33:45 +09:00
Tonis Tiigi
4c9d94f93c add cache key debuginfo lookup
This allows opt-in to cache key debug database on
daemon startup.

If enabled, all cache keys generated by builds are
saved into this database together with the plaintexts
of the original data so a reverse lookup can be performed
later to compare two checksums and find out their original
difference. If checksum contains other checksums internally
then these are saved as well. For storage constraints, the
plaintext of file content is not saved but the metadata
portion can be still looked up.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2025-06-30 23:29:36 -07:00
Jonathan A. Sternberg
450362ac36 contenthash: unconditionally clear ModeIrregular during content hash
Go 1.23 changed the behavior of `os.Stat` to set `ModeIrregular` when it
encountered a mount point reparse point on Windows. These were
previously labeled as symlinks.

We attempted to fix this by clearing `ModeIrregular` during checksum
generation, but we only cleared it in the case where `ModeIrregular` and
at least one other mode type was set.

After reviewing the original solution and issue, I believe that this was
too conservative. The original issue seems to indicate that only the
`ModeIrregular` bit was set so the condition would not have triggered
and cleared it properly. I thought mount points would have both
`ModeDir` and `ModeIrregular` set, but they only seem to have
`ModeIrregular` set.

This unconditionally clears the bit similar to socket files which should
properly fix the issue on Windows.

Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
2025-06-11 09:45:21 -05:00
CrazyMax
1bd26bf901 Merge pull request #5977 from austinvazquez/update-runtime-components-05162025
Dockerfile: update container runtime components
2025-05-28 11:23:34 +02:00