Commit Graph

416 Commits

Author SHA1 Message Date
Tõnis Tiigi
6997850e16 Merge pull request #4281 from jsternberg/duplicate-mount-integration-test
solver: use toSelectors to filter root paths instead of custom logic
2023-12-05 23:19:15 -08:00
Justin Chadwell
62205f47a3 chore: tidy up removal of digest algorithm
In these cases, we can just call digest.Encoded(), instead of needing to
play around with removing the prefix.

Signed-off-by: Justin Chadwell <me@jedevc.com>
2023-12-05 18:05:32 +00:00
Jonathan A. Sternberg
091fb2c80d solver: use toSelectors to filter root paths instead of custom logic
This updates #4270 to add an integration test and also merge some of the
logic for how the selectors are created. Now, `toSelectors` will perform
the root path detection instead of some custom logic in `getMountDeps`.

`dedupePaths` has also been updated to check if the number of paths is 1
or less so it can avoid an allocation when the function is a no-op.

Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
2023-12-04 14:02:16 -06:00
CrazyMax
9d39af0e62 llbsolver: fix possible panic when setting event to nil
When a record is marked for deletion the event is set to nil
but we don't check if it's nil when sending events which could
cause a panic.

Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
2023-11-29 17:48:53 +01:00
Jonathan A. Sternberg
94af8de274 dockerfile: remove duplicate layer chains from provenance attestation
When a step in the dockerfile is a dependency of multiple other steps in
the dockerfile, the provenance attestation would record the layer chain
for that step multiple times even with the same layer chain.

This is because the provenance attestation reuses the exporter mechanic
and the exporter mechanic would need to visit this same step multiple
times to produce the appropriate cache entries.

Since these duplicate layer chains aren't intentional, this modifies the
provenance attestation capture to detect these duplicates and remove
them.

Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
2023-11-22 10:17:42 -06:00
Jonathan A. Sternberg
40fb5ce649 llbsolver: unmarshal protobuf objects into the provenance attestation correctly
This modifies how build steps are unmarshaled from JSON into the
provenance attestation. The current method doesn't correctly handle
protobuf attributes that are used with `oneof`.

Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
2023-11-13 09:57:30 -06:00
Paul "TBBle" Hampson
98e0d8dcff Whenever copying OCI Platform data, include OSVersion and OSFeatures
Trivially created by looking for every reference to .Variant and adding
OSVersion and OSFeatures, except the ones related to the string
representation of a Platform instance.

I then went through and ensured every assignment of OSFeatures that
might leak out, i.e., not local-only or for marhsalling purposes, uses
the append-to-nil idiom to avoid sharing the slice storage and allowing
accidental mutation after-the-fact.

Signed-off-by: Paul "TBBle" Hampson <Paul.Hampson@Pobox.com>
2023-11-03 12:19:29 +09:00
Sebastiaan van Stijn
253c678a3f migrate to github.com/moby/sys/user
This migrates uses of github.com/opencontainers/runc/libcontainer/user
to the new github.com/moby/sys/user module, which was extracted from
runc at commit [opencontainers/runc@a3a0ec4].

This is the initial release of the module, which is a straight copy, but
some changes may be made in the next release (such as fixing camel-casing
in some fields and functions (Uid -> UID).

[opencontainers/runc@a3a0ec4]: a3a0ec48c4

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-10-26 23:31:02 +02:00
Tõnis Tiigi
ef9ae3a4a2 Merge pull request #4362 from tonistiigi/history-listener-hang
llbsolver: fix possible deadlock in history listen
2023-10-23 15:00:56 -07:00
Tonis Tiigi
1ed9931af1 llbsolver: fix possible deadlock in history listen
The events for currently active builds were sent through
pubsub channel instead of directly to the current request,
like it was done for completed builds for example.

This meant that if there are more active builds running
than the pubsub channel buffer (32) the sends will block.
Because the history API mutex is held in this process it
will eventually block the requests for builds that try to
update their history records.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2023-10-20 15:00:38 -07:00
Gabriel Adrian Samfira
2585dd955d Fix linting issue
Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
2023-10-17 15:06:41 +03:00
Gabriel Adrian Samfira
2f3bda8ecb Use snapshot.Mountable as an argument type to readUser
Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
2023-10-17 15:06:41 +03:00
Gabriel Adrian Samfira
fe3ca93c09 Move readUser code outside of the file package
Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
2023-10-17 15:06:41 +03:00
Gabriel Adrian Samfira
8a369a9eba Remove the need for an exported Executor field
Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
2023-10-17 15:06:41 +03:00
Gabriel Adrian Samfira
b8c7bd5f5a Implement readUser on Windows
Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
2023-10-17 15:06:40 +03:00
Jonathan A. Sternberg
dc608427ea solver: correctly set the content selector with multiple bind mounts references
Correctly set the content based selector when multiple bind mounts refer
to the same source. Previously, a selector that referred to the root
filesystem would be ignored. This is because a blank selector refers to
the root filesystem.

When two bind mounts referred to the same dependency, one mount would
add a selector while the other would be skipped. This caused the cache
key to be only computed based on the more narrow filesystem which caused
erroneous cache hits.

Now, the creation of the selector includes the root filesystem for
consideration. It fills in `/` as the selector and then removes it later
so that we don't narrow the selection in an invalid way.

Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
2023-09-25 13:51:07 -05:00
Tõnis Tiigi
fca54c908e Merge pull request #4192 from goller/fix/merge-diff-cachemap-digest
fix: use sha256 for merge/diff op cache maps
2023-09-12 13:09:57 -07:00
Sebastiaan van Stijn
2d3722e50a migrate to github.com/distribution/reference v0.5.0
The "reference" package was moved to a separate module, which was extracted
from b9b19409cf

Also updating docker/docker, which also switched to this new module;

vendor: github.com/docker/docker 032797ea4bcb (v25.0.0-dev)

full diff: afd4805278...032797ea4b

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-09-05 15:29:27 +02:00
Chris Goller
a49c9c0b63 fix: use sha256 for merge/diff op cache maps
The digest of the merge/diff ops' CacheMap
would be json strings like:

```
{"Type":"buildkit.merge.v0","Merge":{"inputs":[{"input":0},{"input":1}]}}
```

rather than a sha256.

Signed-off-by: Chris Goller <goller@gmail.com>
2023-09-01 20:09:50 -05:00
Tõnis Tiigi
4376f3861b Merge pull request #4051 from jake-ciolek/with-allow-not-found-bug
file: Fix incorrect handling of non-existent files in llbsolver's rmPath
2023-08-23 17:49:34 -07:00
Justin Chadwell
c08f767e26 solver: fix possible race for provenance ResolveImageConfig
ResolveImageConfig can be called concurrently - for example, by
dockerfile2llb during conversion, we loop through each stage and resolve
the base image for that stage.

In the case that two calls to ResolveImageConfig finish at roughly the
same time, we can hit an edge case where we attempt to modify the
bridge's image records at the same time.

To fix this, we just need to use the bridge's mutex to prevent
concurrent access here.

This should fix the following stack trace found in CI:

    sandbox.go:144: goroutine 1079 [running]:
    sandbox.go:144: github.com/moby/buildkit/solver/llbsolver.(*provenanceBridge).ResolveImageConfig(0xc000431e00, {0x1c2b040?, 0xc0008e5b30?}, {0xc00094ba00?, 0xc0003728f0?}, {0x0, 0xc0006cb580, {0x19ba868, 0x7}, {0xc0008f7500, ...}, ...})
    sandbox.go:144: 	/src/solver/llbsolver/provenance.go:139 +0x1fb
    sandbox.go:144: github.com/moby/buildkit/frontend/dockerfile/dockerfile2llb.toDispatchState.func3.1()
    sandbox.go:144: 	/src/frontend/dockerfile/dockerfile2llb/convert.go:405 +0x5fe
    sandbox.go:144: golang.org/x/sync/errgroup.(*Group).Go.func1()
    sandbox.go:144: 	/src/vendor/golang.org/x/sync/errgroup/errgroup.go:75 +0x64
    sandbox.go:144: created by golang.org/x/sync/errgroup.(*Group).Go
    sandbox.go:144: 	/src/vendor/golang.org/x/sync/errgroup/errgroup.go:72 +0xa5
    --- FAIL: TestIntegration/TestNoCache/worker=oci-rootless/frontend=builtin (4.45s)

No other explanation for this failure makes sense - `b` cannot be `nil`
at this point, since a call to `b.llbBridge.ResolveImageConfig` has just
succeeded (also because that would be very strange).

Signed-off-by: Justin Chadwell <me@jedevc.com>
2023-08-17 13:39:00 +01:00
Alex Suraci
6b27487fec source: make sources pluggable
Sources are a pretty neat extension point, except there are a few code
paths that hard-code against each type. This moves code around and
adjusts interfaces so that Source implementations are self-contained and
merely need to be registered with the source.Manager.

Signed-off-by: Alex Suraci <suraci.alex@gmail.com>
2023-08-16 09:57:55 +01:00
Erik Sipsma
45b19d34ef Improve cache related trace logging.
This adds trace logs to the solver's cache manager to assist debugging
cache misses+hits.

It also replace the LazyStackTrace struct with a function that returns a
stack trace string only if trace level is enabled, an empty string
otherwise. This makes it easier to use with logrus hooks that pass the
fields around to different goroutines without needing to try to "unlazy"
the fields first.

Signed-off-by: Erik Sipsma <erik@sipsma.dev>
2023-08-07 07:25:40 -07:00
Justin Chadwell
3ac85c9daf chore: clean up file copy logic backend logic
This avoids duplication of the AttemptUnpackDockerCompatability
handling.

Signed-off-by: Justin Chadwell <me@jedevc.com>
2023-07-26 11:27:34 +01:00
Jakub Ciolek
ce439567a4 file: Fix incorrect handling of non-existent files in llbsolver's rmPath
The os.RemoveAll() call returns nil if the path doesn't exist. When the
rmPath function is called with allowNotFound set to false, it doesn't change the
behaviour of the function.

Change the code so if allowNotFound is set to false, we first check
whether the file exists. If it doesn't exist, return an error.

Add tests for three relevant cases.

Signed-off-by: Jakub Ciolek <jakub@ciolek.dev>
2023-07-23 15:28:09 +02:00
Sebastiaan van Stijn
ce332e1952 executor/resource: stub out NewSysSampler on Windows
Commit 509cfa3916 introduced the SysSampler,
which measures resource consumption. However, for this it depends on
prometheus' procfs. That package does not have build-tags but is a Linux-only
implementation, which (by default) attempts to access `/proc`;
https://github.com/prometheus/procfs/blob/v0.9.0/fs.go#L26-L33
https://github.com/prometheus/procfs/blob/v0.9.0/internal/fs/fs.go#L23-L24

This patch splits the implementation of "resource" into platform-specific
files, and stubs out the NewSysSampler() on non-Linux platforms.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-07-20 14:28:53 +02:00
Tonis Tiigi
22d84461e4 llbsolver: fix policy rule ordering
The older of rules in policy matters. Eg. in [DENY *, ALLOW ref]
mixing the order would deny all sources so map can't be used
to deduplicate the rules.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2023-07-12 10:09:45 -07:00
Tõnis Tiigi
595bfa218f Merge pull request #3908 from gabriel-samfira/handle-platform-file-paths
Handle file paths base on target platform
2023-07-10 13:57:23 -07:00
Gabriel Adrian Samfira
f1657ecc14 Fix various nits
Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
2023-07-10 22:58:36 +03:00
Brian Goff
330cf7ae7d Fix ResolveImageConfig to evaluate source policy
Before this change, ResolveImageConfig was unaware of source policies.
This means that:

1. Images for denied sources may be resolved
2. Image configs may get pulled for sources that are later converted to
   a different image

The update makes it so the image resolver first runs a given ref through
the source policy and uses any mutated ref for the actual resolve
(instead of the original ref).
It also returns the mutated ref so it can be used correctly by the
frontend (e.g. don't want to do llb.Image(oldRef@resolvedDigest)).

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2023-07-10 17:44:50 +00:00
Gabriel Adrian Samfira
b29ec0b04e Remove nil pointer check and extra NormalizePath
Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
2023-07-03 08:11:52 -07:00
Gabriel Adrian Samfira
236d00b59a Use current OS as a default
Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
2023-07-03 08:11:52 -07:00
Gabriel Adrian Samfira
686a84b428 Handle file paths base on target platform
This change properly handles paths on different platforms. In short, this
change checks the target platform we're building an image for and applies
normalization steps to make sure the file paths are valid. This makes buildkit
properly handle paths on both *nix systems and on Windows.

Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
2023-07-03 08:11:49 -07:00
Tõnis Tiigi
402b1f8320 Merge pull request #3972 from tonistiigi/fix-layer-labels
containerimage: keep layer labels for exported images
2023-06-29 14:46:41 -07:00
Tonis Tiigi
8ffc03b8f0 move flightcontrol to use generics
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2023-06-28 23:44:05 -07:00
Tonis Tiigi
20b3cea734 containerimage: keep layer labels for exported images
When moving blobs to history namespace also move the blobs
the labels point to, but don't move actual image layers.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2023-06-28 23:38:16 -07:00
Tõnis Tiigi
62bdf9689b Merge pull request #3945 from tonistiigi/fix-missing-provenance
handle missing provenance for non-evaluated result
2023-06-28 11:27:50 -07:00
Tõnis Tiigi
12070ca97a Merge pull request #3446 from jedevc/sbom-image-resolve-mode
Propogate image-resolve-mode for SBOM generator image
2023-06-28 09:48:13 -07:00
Justin Chadwell
a609d2ea2f sbom: propogate image-resolve-mode for generator image
Signed-off-by: Justin Chadwell <me@jedevc.com>
2023-06-28 11:23:02 +01:00
Tonis Tiigi
60b3aa72a0 handle missing provenance for non-evaluated result
If resultProxy has been created but the result has not been
evaluated then it shouldn't show missing provenance error
for that result.

This patch works together with previous one that fixes
error reporting on provenance creation.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2023-06-27 22:44:55 -07:00
Tonis Tiigi
3279d2620e gateway: enable named contexts for gateway frontend
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2023-06-27 22:41:58 -07:00
Tonis Tiigi
509cfa3916 llbsolver: add systemusage samples to provenance attestation
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2023-06-08 15:52:02 -07:00
Tonis Tiigi
32dcdff1a0 resources: store sys cpu usage per step
This can be used to convert step usage to relative units.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2023-06-08 15:51:35 -07:00
Tonis Tiigi
6a2f92d08f resources: add sampler for periodic stat reads
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2023-06-08 15:51:35 -07:00
Tonis Tiigi
6e87e4b455 resources: add build step resource tracking via cgroups
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2023-06-08 15:51:31 -07:00
Alex Couture-Beil
1c551a45b0 llbsolver: set temporary lease in Commit context
The temporary lease must be passed via the context for the call to
w.Commit() to prevent the cleanup of metadata resources before they are
fully referenced.

This fixes https://github.com/moby/buildkit/issues/3921

Signed-off-by: Alex Couture-Beil <alex@earthly.dev>
2023-06-06 18:52:21 -07:00
Justin Chadwell
7af75e706c solver: move AddBuildConfig into llbsolver package
The data structures used by llbsolver shouldn't be bundled into the same
package as the actual creation of the build config.

As it was, it wasn't possible to use the data structures (in tests,
external libraries using buildkit, etc) without pulling in more of
buildkit than was probably intended.

Signed-off-by: Justin Chadwell <me@jedevc.com>
2023-06-01 11:25:25 +01:00
Justin Chadwell
667bb725f5 solver: mark locally loaded images as such
Signed-off-by: Justin Chadwell <me@jedevc.com>
2023-05-31 10:54:55 +01:00
Justin Chadwell
ff5baa0f5f solver: merge local and remote images into single list
This also allows us to specify that local images should be generated
with exactly the same specification as remote images, but with the
pkg:oci scheme instead of pkg:docker.

Signed-off-by: Justin Chadwell <me@jedevc.com>
2023-05-31 10:54:55 +01:00
Justin Chadwell
80ea813b03 purl: allow RefToPURL to take a type parameter
Signed-off-by: Justin Chadwell <me@jedevc.com>
2023-05-31 10:54:54 +01:00