Commit Graph

518 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
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
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
605c4697e4 Merge pull request #5356 from jsternberg/vtproto
protobuf: add vtproto as a supplemental marshaler
2024-10-07 08:35:42 -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
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
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
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
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
Tonis Tiigi
304b6ecedc ops: improve error messages from fileop
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2024-07-22 15:14:05 -07:00
CrazyMax
1aa17c046a history api: save number of warnings to build record
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
2024-07-18 13:40:23 +02:00
Tonis Tiigi
5149ea81e9 solver: mark history and graph concistency errors as internal
Error during creating history or failure in graph concistency
checks are signs of either bugs or system configuration issue. This
makes sure that gRPC error code in the API error based on these
cases has correct value to signify it.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2024-07-17 16:28:41 -07:00
Tonis Tiigi
d7b3e02a55 lint: finish up testifylint
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2024-07-12 16:03:18 -07:00
Tonis Tiigi
3d00c54779 llbsolver: fix possible early delete of external error
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2024-07-10 00:09:47 -07:00
Tonis Tiigi
76945ca7d4 llbsolver: make sure stoptrace called on bolt error
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2024-07-08 20:34:18 -07:00
Sebastiaan van Stijn
175973babc switch to github.com/containerd/platforms module
Switch to use github.com/containerd/platforms module, because containerd's
platforms package has moved to a separate module. This allows updating the
platforms parsing independent of the containerd module itself.

The package in containerd is deprecated, but kept as an alias to provide
compatibility between codebases.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-07-02 22:59:12 +02: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
Tonis Tiigi
6e38854262 llbsolver: move typed error to own blob in history
Avoid putting big error metadata to main history record
and instead write it to a separate blob.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2024-07-01 21:48:12 -07:00
Tõnis Tiigi
ff1674a396 Merge pull request #5031 from tonistiigi/context-withoutcancel
ensure context.WithoutCancel in defer funcs
2024-06-18 12:56:04 -07:00
Tonis Tiigi
4103099d94 ensure context.WithoutCancel in defer funcs
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2024-06-12 19:18:32 -07:00
Tonis Tiigi
dfc35271ae simplify with maps pkg functions
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2024-06-12 18:33:30 -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
fc936ae3d7 lint: more testifylint fixes
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2024-06-10 21:16:51 -07:00
Tonis Tiigi
031b3162ed llbsolver: add more otel spans for export and history
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2024-06-05 19:52:49 -07:00
Sebastiaan van Stijn
0f89a763aa vendor: github.com/containerd/containerd v1.7.18
Update to containerd 1.7.18, which now migrated to the errdefs module. The
existing errdefs package is now an alias for the module, and should no longer
be used directly.

This patch:

- updates the containerd dependency: https://github.com/containerd/containerd/compare/v1.7.17...v1.7.18
- replaces uses of the old package in favor of the new module
- adds a linter check to prevent accidental re-introduction of the old package
- adds a linter check to enforce using an alias, to prevent accidental use
  of the errdefs package in BuildKit or Moby.
- adds a linter check to prevent using the "log" package, which was also
  migrated to a separate module.

There are still some uses of the old package in (indirect) dependencies,
which should go away over time.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-05 08:54:22 +02:00