Commit Graph

899 Commits

Author SHA1 Message Date
Tonis Tiigi
d1a3df310d llbsolver: fix recompute test and avoid struct copy
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2024-12-03 12:00:38 -08:00
Jonathan A. Sternberg
c644fb81a8 llbsolver: tie op metadata to the op before recomputing digests
When recomputing digests happens, the metadata is lost. This previously
happened only with sources that were affected by source policies so it
wasn't noticed, but now any LLB Op that is rewritten is affected since
the gogo protobuf switch will cause all digests to be rewritten if the
frontend and buildkit are using different versions.

Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
2024-12-03 13:09:49 -06:00
Tõnis Tiigi
16d3799a19 Merge pull request #5517 from jsternberg/deterministic-llb-for-gateway
gateway: ensure llb digests are deterministic when sent by frontends
2024-11-21 09:53:00 -08:00
Shaun Thompson
c3baf4c24e Merge pull request #5540 from tonistiigi/gc-unreferenced-keys
solver: release unreferenced cache keys after gc
2024-11-21 12:20:05 -05:00
Marat Radchenko
0a5a80cfec Remove pre-Go 1.17 build tags
Signed-off-by: Marat Radchenko <marat@slonopotamus.org>
2024-11-21 10:58:27 +03: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
Tõnis Tiigi
edaa93daac Merge pull request #5524 from jsternberg/json-casing-regression
protobuf: fix casing of json attributes with the switch from gogo
2024-11-19 10:32:04 -08:00
Jonathan A. Sternberg
56ffa9f66b protobuf: fix casing of json attributes with the switch from gogo
With the switch from gogo, the `oneof` fields no longer have their
`json:"name"` fields emitted. Protobuf doesn't formally support these
fields and tells users to use the `protojson` package, but we didn't and
the official format is incompatible with the current format we use.

This adds some custom marshaling code to the already existant custom
unmarshaling code to ensure these fields are marshaled with the correct
casing.

Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
2024-11-15 13:17:42 -06: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
Jonathan A. Sternberg
9f65f8c1fa gateway: ensure llb digests are deterministic when sent by frontends
This ensures different valid protobuf serializations that are sent by
frontends will be rewritten into digests that are normalized for the
buildkit solver.

The most recent example of this is that older frontends would generate
protobuf with gogo and the newer buildkit is using the google protobuf
library. These produce different serializations and cause the solver to
think that identical operations are actually different.

Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
2024-11-14 16:12:28 -06: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
c9a25c4d8a pb: regenerate protobuf
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2024-10-28 12:56:03 -07:00
Tonis Tiigi
630357111a vendor: update fsutil to 397af530
Brings in fix for incorrect timestamps for parent destination directories.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2024-10-28 10:39:39 -07:00
Tõnis Tiigi
2bb7d9cc01 Merge pull request #5401 from jsternberg/scheduler-edge-simplify
solver: simplify edge-related functions in the solver
2024-10-11 10:02:31 -07:00
Tõnis Tiigi
6860c8097d Merge pull request #5359 from tonistiigi/gc-free-max-support
update default and basic gc control to use free and max storage
2024-10-08 08:28:40 -07:00
Jonathan A. Sternberg
37b6f87915 solver: simplify edge-related functions in the solver
Many of the functions in the solver that operated on the edges were very
large which obscured their usage and the overall flow of the scheduler.
This change refactors those functions into separate smaller functions to
make it easier to follow the overall flow of the scheduler.

Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
2024-10-07 12:58:09 -05:00
Tõnis Tiigi
605c4697e4 Merge pull request #5356 from jsternberg/vtproto
protobuf: add vtproto as a supplemental marshaler
2024-10-07 08:35:42 -07: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
Tonis Tiigi
a75b5eb15b add capability to detect if new storage filters are supported
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2024-10-04 17:21:53 -07:00
Tõnis Tiigi
293ef59c73 Merge pull request #5372 from LaurentGoderre/sbom-generator-opts
Added way to configure SBOM scanner
2024-10-04 12:12:32 -07:00
Jonathan A. Sternberg
41a0a0c37d protobuf: add vtproto as a supplemental marshaler
vtproto is an extra protobuf compiler that generates special methods
suffixed with `VT` that create typed and unrolled marshal and unmarshal
functions similar to gogo that can be used for performance sensitive
code. These extensions are optional for code to use but buildkit uses
them.

A codec is also included to utilize vtproto for grpc code. If the
package `github.com/moby/buildkit/util/grpcutil/encoding/proto` is
imported then vtproto will be used if it exists and otherwise it will
use the standard marshaling and unmarshaling methods.

This codec has an important difference from the default codec. The
default codec will always reset messages before unmarshaling. In most
cases, this is unnecessary and is only relevant for `RecvMsg` on
streams. In most cases, if we are passing in an existing message to this
method, we want to reuse the buffers. This codec will always merge the
message when unmarshaling instead of resetting the input message.

Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
2024-10-04 12:52:15 -05:00
Jonathan A. Sternberg
ffd8ff490e protobuf: normalize how protobuf files are generated
The relative paths option for protoc generators doesn't work well when
it comes to dependencies. This simplifies the code generation to avoid
using `go generate` and to use one global command for protoc generation.

This is similar to https://github.com/docker/buildx/pull/2713 since the
same problems with code generation occur here too.

Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
2024-10-03 17:40:53 -05:00
Tõnis Tiigi
c7db68a591 Merge pull request #5375 from tonistiigi/non-octal-chmod-copy
client: allow non-octal chmod config for fileop.copy
2024-10-03 14:34:58 -07:00
Akihiro Suda
ca72046b20 Merge pull request #5362 from tonistiigi/input-digest-validation
llbsolver: add input validation to policy recompute
2024-10-03 13:45:12 +09:00
Tõnis Tiigi
8445ccf1cb Merge pull request #5374 from jsternberg/marshal-constraints-cache
llb: deterministic marshaling for protobuf and store results from multiple constraints
2024-10-02 13:48:25 -07:00
Jonathan A. Sternberg
d59218e6e6 llb: deterministic marshaling for protobuf and store results from multiple constraints
This fixes a problem with the new protobuf marshaling with the standard
library. LLB digests are now forced into deterministic marshaling to
ensure they produce the same digest when marshaled multiple times.

In addition, the marshal cache has also been fixed to work in
multi-threaded frontends with multiple different constraints.
Previously, if an LLB vertex was used in multiple goroutines and
marshaled concurrently, the cache would be broken. This could cause
certain problems when a specific node was used multiple times in the
same LLB tree.

Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
2024-10-02 11:17:45 -05:00
CrazyMax
2c10f56e47 history: remove records without attached blobs at startup
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
2024-10-02 13:12:43 +02:00
Tonis Tiigi
25632fb074 client: allow non-octal chmod config for fileop.copy
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2024-10-01 12:52:38 -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
Tonis Tiigi
7d5a06c4bf llbsolver: add input validation to policy recompute
Similar error already exists in loadLLB but was missing in
newer recomputeDigests code.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2024-09-27 07:17:42 -07: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
ac7caa8f3b chore: use a better root for computing free disk space
We shouldn't use the cachemount root, we should actually properly
use the worker's specified root which is propagated from the config.

Signed-off-by: Justin Chadwell <me@jedevc.com>
2024-09-25 10:49:52 +01:00
Tõnis Tiigi
ad0c36c0f8 Merge pull request #5328 from jsternberg/debug-scheduler-refactor
solver: move scheduler debug statements to their own functions
2024-09-23 13:25:39 -07:00
Jonathan A. Sternberg
2f18b835ce solver: move scheduler debug statements to their own functions
Move scheduler debug statements to their own functions and in their own
file so that scheduler debug statements don't make the scheduler logic
more complex to follow. Some of the scheduler logs can be quite long and
can make it difficult to follow the code logic. This changes these log
statements to `debugSchedulerXXX` where `XXX` is the message that would
be printed.

Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
2024-09-18 15:49:34 -05:00
Tõnis Tiigi
e15601a00f Merge pull request #5339 from jedevc/exec-exit-codes
exec: allow specifying non-zero exit codes for execs
2024-09-17 10:21:13 -07:00
Justin Chadwell
7e6c20a0db exec: allow specifying non-zero exit codes for execs
Signed-off-by: Justin Chadwell <me@jedevc.com>
2024-09-17 11:36:07 +01:00
Tonis Tiigi
1958ae229a solver: fix possible panic from error handler
If error is returned from `Save()`, `rck` is nil and
causes nil dereference panic on accessing `TraceFields` when
printing debug logs.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2024-09-13 15:19:33 -07:00
Jonathan A. Sternberg
ad64996f49 solver: pipe implementation utilizes generics for better typing
This updates the pipe library to use generics for the request payload
and the status value. This allows the solver to put in explicit types
rather than rely on type casting from interfaces which helps with type
safety and understandability.

The status value used by the solver uses the `any` type instead of an
explicit type because the `unpark` method takes a generic list of pipes
and the different pipes have different result types. We can likely
change this in the future or create a discriminated union for the
types that can be used in this package. That is left for future work
because at least the request payload is typed now.

Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
2024-09-12 10:37:12 -05:00
Tonis Tiigi
87e0f4bf08 hack: update golangci-lint to 1.61
Unblock CI with the schema verify error in 1.60

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2024-09-09 14:22:27 -07:00
Tonis Tiigi
610affa5fd exec: fix pruning cache mounts with parent ref on no-cache
On a build with no-cache, cache mounts were not pruned correctly
if the mount was on top of another ref. This also appeared in
Dockerfile when mode/uid/gid was set because implicit parent
ref is created in these cases in order to change the permissions
of a subdir that is used as a cache mount base.

Because it is not possible to know ahead of time what ref
will become the parent of cache mount during build, all cache
mounts matching the ID that have a parent will be pruned.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2024-09-05 18:09:54 -07:00
Tonis Tiigi
df0d9d791d ci: update golangci-lint to v1.60.1
Previous version runs out of memory on go1.23

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2024-08-14 16:29:22 +03:00
Tonis Tiigi
3c87ba1bd5 exec: fix incorrect deps computation for special mounts
Secret, SSH and Tmpfs mounts never have an input vertex
and zero value for input should not be considered and input
at index 0 .

Currently, if for example secret mount had a input=0, it
caused content based checksum from first input(rootfs),
that could take quite a lot of time when image was big
and had lots of files. The computation result was cached
but if there was a cache invalidation in previous commands
it caused checksum to recomputed again for the command with
the secret mount.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2024-08-13 13:09:08 +03:00
thompson-shaun
b9992472a4 Merge pull request #5179 from tonistiigi/executor-err-upt
executor error improvements
2024-08-09 11:27:35 -04:00
Sebastiaan van Stijn
b4a189390e migrate to github.com/moby/sys/userns
Commit 4b85f11164 migrated the use of the
userns package to the github.com/moby/sys/user module.

After further discussion with maintainers, it was decided to move the
userns package to a separate module, as it has no direct relation with
"user" operations (other than having "user" in its name).

This patch migrates our code to use the new module.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-08-08 12:36:57 +02: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
thompson-shaun
7c025bfbbe Merge pull request #5163 from tonistiigi/history-graphstate-errors-internal
solver: mark history and graph concistency errors as internal
2024-07-25 12:08:19 -04:00
Sebastiaan van Stijn
86b550e427 migrate to github.com/moby/sys/user/userns
The userns package in libcontainer was integrated into the moby/sys/user
module at commit [3778ae603c706494fd1e2c2faf83b406e38d687d][1].

The userns package is used in many places, and currently either depends
on runc/libcontainer, or on containerd, both of which have a complex
dependency tree. This patch is part of a series of patches to unify the
implementations, and to migrate toward that implementation to simplify
the dependency tree.

[1]: 3778ae603c

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-07-25 14:11:04 +02:00
Tonis Tiigi
ce9e28281a llbsolver: avoid nil releaser on error
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2024-07-22 17:47:12 -07:00