228 Commits

Author SHA1 Message Date
Sebastiaan van Stijn
50b548a135 vendor: migrate to github.com/gohugoio/hashstructure
The github.com/mitchellh/hashstructure/v2 module was archived, and
there's a maintained fork in the gohugoio org.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2026-06-17 10:02:52 +02:00
Tõnis Tiigi
c6626669bc Merge pull request #6740 from tonistiigi/exec-net-proxy
solver: add proxy network mode
2026-06-08 10:09:34 -07:00
CrazyMax
bd53b4191f bound telemetry shutdown when trace forwarding stalls
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
2026-06-05 16:48:22 +02:00
Jonathan A. Sternberg
d4ac72d232 control: forward traces in a non-blocking goroutine
Traces are now forwarded in a non-blocking goroutine when sent through
the traces exporter. This prevents traces forwarded from the client from
being stalled while waiting for an upstream uploader to appear.

In addition, adds a shutdown context to `appcontext` that will only
cancel when an interrupt has been received twice. One interrupt will
signal the program should clean up and shut down, the second indicates
we should skip shutdown procedures (more forceful), and the third will
indicate that we should immediately terminate the program.

This gives a bit more of a degree of control to shutdown procedures like
the traces and metrics exporter so there's a difference between forcibly
calling exit and just waiting a long time for the shutdown to happen.

Includes a more aggressive shutdown timeout for `buildctl` that is
similar to the export timeout on `docker-buildx` for the tracing
shutdown as another preventative measure to ensure the CLI hangs up at
an appropriate time interval.

Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
2026-06-05 15:55:22 +02:00
Tonis Tiigi
023022108c buildkitd: add daemon proxy network option
Add a proxyNetwork TOML setting and --proxy-network daemon flag to enable
exec proxy enforcement for every build. Wire the default through controller
and solver setup while preserving per-build enablement.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2026-06-04 11:23:02 -07:00
Tonis Tiigi
3254832159 solver: add proxy network mode
Add a build request option that rewrites default exec networking to an
internal proxy network while preserving explicit none networking.

Route HTTP and HTTPS traffic through a BuildKit-owned proxy namespace, enforce
source policy checks for proxied requests, and inject a temporary CA into Linux
rootfs trust bundles for HTTPS interception.

Share namespace pooling between CNI and proxy providers, and cover proxy mode
with unit and integration tests.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2026-06-04 11:23:00 -07:00
Ava Barron
f3f5f546eb solver/llbsolver: emit native build-completion metrics
Threads the existing OTEL MeterProvider through llbsolver.Opt and emits
three build-event instruments from the recordBuildHistory finalizer:

  - buildkit.builds (counter; labels: status, error_code)
  - buildkit.builds.steps (counter; labels: kind)
  - buildkit.build.duration (Base2 exponential histogram; labels: status)

The duration histogram uses an exponential aggregation, rendered as a
Prometheus native histogram by the existing exporter, to avoid the
"tens of millions of series" cardinality blow-up reported in #5777.

MeterProvider is passed explicitly through the constructor — buildkit
policy (per the #4957 review) prohibits relying on the OTel global
provider in library packages.

error_code uses gRPC codes.Code.String() for a bounded set;
rec.Error.Message is intentionally never used as a label. The frontend
label is intentionally omitted — client.Build clears req.Frontend on
the wire, so the field is empty for every caller that goes through the
gateway-client API (buildctl, buildx). The metric is forward-compatible
with a future buildkit change that populates rec.Frontend on that path.

A follow-up PR will add observable gauges for worker count and cache
state, plus an operator guide at docs/metrics.md.

Refs #1544; addresses discussion #5777.

Signed-off-by: Ava Barron <abarron@coreweave.com>
2026-05-28 12:57:43 -04:00
Tonis Tiigi
98e1113c6d lint: modernize Go lint findings
Update non-generated code for the newer lint recommendations by using typed
atomic values, strings.Cut, and slices.Backward where applicable.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2026-05-14 10:13:21 -07:00
Tõnis Tiigi
4f42761308 Merge pull request #6705 from tonistiigi/provenance-dockerfile-version
provenance: add dockerfile frontend version
2026-05-06 17:57:13 -07:00
Jonathan A. Sternberg
4b9488be47 gateway: reduce potential lock contention in gateway forwarder
There's a large potential for a lock contention issue in the gateway
forwarder's logic. The previous iteration of this would keep a global
mapping of the build ids and, when a forwarder for a build id didn't
exist, the forwarder would wait 3 seconds for the build to register.

The issue with lock contention comes after this. Instead of having a
notification channel that a specific build was ready, the forwarder
would wake up all goroutines that were waiting each time a build was
registered. Since each of those builds took a read lock to check whether
its build was present and registering subsequent builds took a write
lock, it was very easy to end up in a lock contention scenario when
starting many builds at the same time. Then it was easy to hit the 3
second timeout especially when the machine itself was under load.

This changes the notification mechanism so the notify happens per build.
Looking up a build id creates a forwarder registrar with a channel that
can be polled for when the registration is complete. A forwarder will
then only be notified and woken when that specific build id is ready by
the go runtime rather than from the sync condition.

Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
2026-05-06 14:21:50 -05:00
Tonis Tiigi
1890989989 version: expose Dockerfile frontend version
Expose the builtin Dockerfile frontend version in BuildKit version
APIs and buildctl debug output.

Move Dockerfile version logic into frontend/dockerfile/version and
validate that the builtin version constant matches release tags.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2026-05-06 10:42:32 -07:00
Tonis Tiigi
5fde446dee solver: add compatibility-version support
Add solve-wide compatibility-version support for image and oci
exports, with historical goldens and release compatibility tests.

Backfill version 10 for v0.13-v0.14 git artifact behavior, keep
version 20 as current, and reject unsupported zstd on v10.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2026-04-10 09:24:11 -07:00
Tonis Tiigi
f931b7e580 refactor: extract build history into dedicated package
Move build history queue from solver/llbsolver into its own
solver/llbsolver/history package. The history subsystem is
persistence/API concern, not solving logic.

Rename types to avoid stutter with package name:
  HistoryQueue    -> history.Queue
  HistoryQueueOpt -> history.QueueOpt
  NewHistoryQueue -> history.NewQueue

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2026-03-10 21:47:26 -07:00
Jonathan A. Sternberg
2999fdcfae gateway: create interface for reading from container filesystem
This creates an interface that can be used to read the filesystem of a
new container created through the gateway API. These filesystem reading
methods are tied to a specific container that has been created, but
aren't tied to the container itself.

Due to being run inside of buildkit, these containers have access to the
same mounts that a container request would have. This is useful for
features like the file explorer in `buildx dap` because it can access
container filesystem state from stages that error along with ones that
have completed successfully.

Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
2026-01-14 11:52:39 -06:00
Tonis Tiigi
f79f1a98c4 policysession: dynamic source policy support
Add support for dynamic source policies via client session.

Client session can allow or deny specific source or
ask additional metadata information via sourcemetaresolver if
that is needed to make the decision.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2025-11-05 14:28:13 -08:00
Tonis Tiigi
9d6d33dd72 control: handle duplicate inline cache exporter
Inline cache exporter can be set with multiple ways, doesn't
have any attributes and can always only run one time.

Instead of allowing multiple inline exporters where one
gets ignored later when there is an attribute difference, or
erroring when attributes are unset, just ignore the extra ones.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2025-10-06 08:36:32 -07:00
Tonis Tiigi
8ecdc0ad3d provenance: add custom fields support
This allows buildkitd daemon to define additional fields
that are added to all the provenance attestations that
BuildKit creates (by default from /etc/buildkit/provenance.d/).

These custom fields can provide additional context about
the environment BuildKit itself is running (eg. Github workflow)
and are not allowed to collide with the trusted fields created
by BuildKit itself.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2025-09-10 16:56:59 -07: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
CrazyMax
a58f93e7b3 provenance slsa v1
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
2025-06-11 11:12:04 +02:00
Tonis Tiigi
2307fb7d12 allow duration based filters on diskusage requests
Allows similar time-based filter that is allowed for
prune requests so that DiskUsage request can be used to
check which records would be candidates for pruning.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2025-05-18 20:30:18 -07:00
Tonis Tiigi
f1f56c2b77 golangci-lint: v2 upgrade
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2025-05-02 12:19:17 -07:00
Tonis Tiigi
3cabacf36e control: make sure sending nil cache options does not panic
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2025-04-17 10:33:53 -07:00
Tonis Tiigi
58faf412f3 exporter: add session exporter capability
This allows client to defer exporter selection to
the the time where build has completed.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2025-04-10 22:15:19 -07:00
Tonis Tiigi
8244761d21 fix trace blob detected as leaked blob in tests
Trace blob is created 3 seconds after build completion.
If this happens after test has cleaned all history records
and before it checks for leaked blobs, test can report the
trace blob as leaked. In practice it would be cleaned up
next time containerd GC gets triggered.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2025-02-25 09:29:54 -08:00
Tonis Tiigi
05a451e15b add autoallow and entitlements support to CDI devices
Devices can be marked as "automatically allowed" by TOML config
or by the CDI spec of specific file via annotation.

Device that is is not "automatically allowed" needs to be allowed
by the build request by passing entitlement. For example a Dockerfile
may not use a device without use invoking the build permitting it.

--allow device grants access to any device.
--allow device=kind|name grants access to specific device.
--allow device=kind|name,alias=kind|name allows mapping kind to
a specific device or one device to another. Alias is the name requested
by the build and device is the actual device that is being enabled.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2025-02-13 23:17:37 -08:00
Tonis Tiigi
f61e01c14c llbsolver: on-demand CDI devices with automatic setup
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2025-02-11 11:21:48 +01:00
Tonis Tiigi
3adcf53d1a enable CDI by default for buildkitd
Access should be managed by entitlements checks

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2025-02-11 11:21:46 +01:00
Tonis Tiigi
9b39b0d82c allow listing devices
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2025-02-11 11:21:45 +01:00
Tõnis Tiigi
e7185ace0b Merge pull request #5636 from jsternberg/unroll-prune-loop
cache: convert prune loop from recursive invocation to iterative
2025-01-16 14:35:44 -08:00
Marat Radchenko
5be7edb69c Upgrade to containerd 2
Co-authored-by: Derek McGowan <derek@mcg.dev>
Signed-off-by: Marat Radchenko <marat@slonopotamus.org>
2025-01-13 16:42:48 -08:00
Jonathan A. Sternberg
174fb8ad5c cache: convert prune loop from recursive invocation to iterative
The prune logic would prune multiple times because one prune could cause
more things to be capable of pruning and change the logic. This was done
through a recursive invocation.

Since go doesn't have support for function tail calls, this would result
in a new stack entry for each loop. This unrolls the logic so the prune
function is invoked iteratively rather than recursively.

`prune` and `pruneOnce` have also had their names swapped. In general,
`pruneOnce` implies that it runs a single prune while `prune` sounds
like the top level function. The current code had this reversed and
`pruneOnce` would call `prune` and `prune` would call itself
recursively.

I've also updated a section in the controller that invoked prune on each
worker. In older versions of Go, the current version was correct because
those versions of Go would reuse the location for each loop which would
cause goroutines to all reference the same worker instead of different
workers.

Recent versions of Go have changed the behavior so this is no longer
needed.

Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
2025-01-13 10:26:54 -06:00
Tonis Tiigi
7fc428cdfc solver: release unreferenced cache keys after gc
Previously this routine only ran after user ran
prune command or on reboot of the daemon.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2024-11-20 22:49:54 -08:00
Tõnis Tiigi
e853c88d3b Merge pull request #5522 from tonistiigi/history-gracefulstop-fix
history: handle gracefulstop when history is active
2024-11-20 11:48:59 -08:00
Tonis Tiigi
e05a89e0b8 improve stacks of cancels from defers
In this case the current stack trace points to the line
where the context was created. Instead the stack should be
captured when the defer is running so the return path to
the defer call is also part of the stack.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2024-11-19 18:40:00 -08:00
Tonis Tiigi
c45cd8fa16 history: handle gracefulstop when history is active
When GracefulStop is called gRPC waits for current requests to finish
before closing. While this is generally the behavior we want, it is
not always same for the History.Listen endpoint. That endpoint is
usually open even if buildkit is not actively processing any builds,
because client may be waiting for new events.

The new logic is that if GracefulStop will happen, history will
close active listeners if there are no active builds. If there are
active builds then active listeners will be closed after all the
active builds have completed their finalizers.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2024-11-15 10:58:48 -08:00
Tonis Tiigi
65f5dad9ff fix gc after delete history records
Current implementation based on leases.SynchronousDelete only works
with the containerd worker and is ignored otherwise. This means that
blobs referenced by history records were left on disc until the
periodic background GC was initialized later.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2024-11-12 17:43:55 -08:00
Tonis Tiigi
d45a506aac cache: rename new prune/gc control fields
Naming that was chosen during review was
reservedSpace, maxUsedSpace and minFreeSpace.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2024-10-04 17:23:04 -07:00
Laurent Goderre
2782f14746 Added way to configure SBOM scanner
Signed-off-by: Laurent Goderre <laurent.goderre@docker.com>
2024-09-30 16:11:32 -04:00
Jonathan A. Sternberg
1a3fc0aa15 protobuf: remove gogoproto
Remove gogoproto in favor of the standard protobuf compiler. This
removes any nonstandard extensions that were part of gogoproto such as
the custom types.

Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
2024-09-26 12:57:45 -05:00
Justin Chadwell
6382cf9e80 config: allow configuring free gc policies
Signed-off-by: Justin Chadwell <me@jedevc.com>
2024-09-25 10:48:59 +01:00
Alberto Garcia Hierro
892e756394 debug: add trace flight recorder
Use golang.org/x/exp/trace to implement an trace recorder that saves the trace
to a circular buffer and can be retrieved at any time.

Debug endpoints have been added under /debug/flight to start and stop the trace
as well as to set its period.

Due to golang.org/x/exp/trace, the minimum go version has been bumped to 1.22

Signed-off-by: Alberto Garcia Hierro <damaso.hierro@docker.com>
2024-09-23 21:01:19 +01:00
Tonis Tiigi
13bd25cd58 db: move DB dependencies to transactor interface
This allows more flexible control over DB transactions
and compaction.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2024-07-25 12:55:16 -07:00
Tonis Tiigi
3139b164d5 solver: allow finalizing history record traces
Client can send a finalize update to build record that
will complete saving the traces and block until the record
has been updated. If no request is sent then the traces will be
sent after a 3 second timeout as before.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2024-07-02 00:08:20 -07:00
CrazyMax
6b6fa9d5fa history: fix empty Exporters attribute
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
2024-06-11 17:09:54 +02:00
Tonis Tiigi
03c7a6d769 lint: fix some testifylint warnings
This does not cover all warning yet but split
into chunks to ease review.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2024-05-30 11:32:55 -07:00
Tonis Tiigi
30c069cb03 replace resolveimageconfig with generic sourcemetaresolver
This is more versatile function that works for any source,
not just images.

It can be used together with a policy that switches
between input and output source as well as for adding
additional metadata for other sources in the future.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2024-02-11 22:06:23 -08:00
Tonis Tiigi
5d7d85f5a0 pb: add extra validation to protobuf types
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
(cherry picked from commit 838635998dcae34bbde59e3eab129ab85bd37bef)
2024-01-31 12:37:27 -08:00
Justin Chadwell
6337e81b37 chore: close solver resources on shutdown
The solver has a Close method to shutdown the scheduler, which releases
a goroutine. We should call it on shutdown.

While in the area, we can also close the sysSampler.

Signed-off-by: Justin Chadwell <me@jedevc.com>
2024-01-26 15:15:03 +00:00
Justin Chadwell
cfd320c5b7 control: fix typo in exporter slice comment
Signed-off-by: Justin Chadwell <me@jedevc.com>
2024-01-05 16:09:38 +00:00
Justin Chadwell
1c1777b7c0 exporter: use implicit ids for exporters
We can derive exporter ids from their place in the exporter array in a
SolveRequest - this removes the need to manually generate and handle
multiple sets of IDs.

Signed-off-by: Justin Chadwell <me@jedevc.com>
2024-01-05 12:04:28 +00:00