Commit Graph

91 Commits

Author SHA1 Message Date
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
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
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
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
Justin Chadwell
130b7d142a chore: remove impossible err check
`err` is not set in this conditional branch, so the err check is
unneccessary and so can be removed.

Signed-off-by: Justin Chadwell <me@jedevc.com>
2024-04-02 10:44:53 +01: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
Tõnis Tiigi
1981eb123d Merge pull request #4601 from tonistiigi/0131-fix-validate-nil
Add more validations for nil values
2024-01-31 14:07:20 -08:00
Tonis Tiigi
65c3c9c135 llbsolver: make sure interactive container API validates entitlements
Ensure interactive calls validate same conditions that
the build requests do. Refactor of the build side is to ensure
we use the same validation function for both cases. There
was no validation issue with the LLB validation.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
(cherry picked from commit d1970522d7145be5f4a1f1a028b1910bb527126c)
2024-01-31 12:38:25 -08:00
Tonis Tiigi
0c5daa2327 gateway: pass executor with build and not access worker directly
Running interactive container APIs was done by giving
the gateway implementation access to worker controller
directly, but it should be passed with a build job instead.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
(cherry picked from commit 0971dffaab93d91e51af984b44c745b35b3c5b4d)
2024-01-31 12:38:19 -08:00
Tonis Tiigi
e11862c24d sourcepolicy: add validations for nil values
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
(cherry picked from commit 4e2569e796aae398648082689d70ca1d4f4f74a8)
2024-01-31 12:37:22 -08: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
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
6a2f92d08f resources: add sampler for periodic stat reads
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2023-06-08 15:51:35 -07:00
Kohei Tokunaga
085bd8af7f Fix cache cannot reuse lazy layers
Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
2023-01-24 16:23:56 +09:00
Brian Goff
c7a54c7453 sourcepolicy: cleanup uneccessary interfaces
These were just there while figuring out how things would work and are
not needed now.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2022-12-13 13:02:14 -08:00
Brian Goff
7a08c9dbdf sourcepolicy: Add support for frontend policies
Allows frontends to pass in a list of policies in the solve request.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2022-12-13 13:02:12 -08:00
Brian Goff
7526659ab0 Update source pinning to use proposed policy
Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2022-12-13 13:01:54 -08:00
Akihiro Suda
0d3f71ee18 llbsolver: support pinning sources
Alternative to PR 2816 ("dockerfile: support Dockerfile.pin for pinning sources")

This version is implemented on the llbsolver side and agnostic to the LLB frontends.
See `solver/llbsolver/vertex.go:loadLLB()`.

See `docs/build-repro.md` for the usage.

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2022-12-13 13:01:54 -08:00
Tonis Tiigi
9acc6d30eb refactor buildinfo into provenance capture
Change how provenance information is captured from builds.

While previously frontend passed the buildinfo
sources with metadata, now all information is captured
through buildkit. A frontend does not need to implement
buildinfo and can't set incorrect/incomplete buildinfo
for a build result.

All LLB operations can now collect as much provenance
info as they like that will be used when making the
attestation. Previously this was limited to a single Pin
value. For example now we also detect secrets and SSH IDs
that the build uses, or if it accesses network, if local
sources are used etc.. The new design makes sure this
can be easily extended in the future.

Provenance capture can now detect builds that do
multiple separate subsolves in sequence. For example,
first subsolve gathers the sources for the build and
second one builds from immutable sources without a
network connection. If first solve does not participate
in final build result it does not end up in provenance.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2022-11-15 19:37:03 -08:00
Justin Chadwell
d709afdb96 solver: always respect value of evaluate field
Always use the value of the evaluate field to force result generation,
which previously was not performed for frontends. This improves API
consistency, and ensures the value is used regardless of whether
the solver uses a frontend, or a raw definition.

Signed-off-by: Justin Chadwell <me@jedevc.com>
2022-10-12 07:40:10 +01:00
Tõnis Tiigi
46c8b9ee45 Merge pull request #2982 from jonnystoten/remove-legacy-cache-options
Stop using legacy cache import/export in client
2022-08-25 18:29:47 -07:00
Justin Chadwell
c5c3159aa8 solver: add new generic results package
The Result struct in this package is intended to replace the various
Result structs across the codebase, including:

- frontend.Result
- client.Result/gateway.Result
- exporter.Source

These Results are all fundamentally the same, and share the same logic,
with the only difference being the type used in the Ref/Refs properties.

Since these were all separate, we easily encounter the following
problems:

- Repetition of struct and method declarations.

  Each separate Result type required it's own properties and methods to
  be redeclared. Sometimes these were consistent with each other, and
  other times they were not. Unifying all Results together ensures a
  lack of duplication, and means that changing the structure of the Result
  will not require extensive changes throughout every single declaration.

- Complex conversion between Result types.

  At gateway and api boundaries, we are required to convert each Result
  into a Result of a different type. Previously, this has been a lengthly
  and error prone conversion, requiring knowledge of the exact structure
  of the Result, so as to allow traversal. By unifying Results, we can
  implement a ConvertResult function to convert from types of Result[A]
  to types of Result[B] given a function from A to B, which cleanly
  encapsulates the structure of the Result.

- Complex conversion to the protobuf gateway api types.

  At the gateway api, we have to convert to pb.Results. Previously, we
  had to include logic to convert to and from both frontend.Result and
  client.Result. With a generic Result, we can simple convert to a
  Result[pb.Ref] and then have one single set of methods to convert
  Result[pb.Ref] to a pb.Result.

These problems have been an issue for some time, however, recently with
the addition of attestations, the problem has grown, since the amount of
logic required at conversion boundaries has massively increased.

This patch intends to simplify all of the above, and reduce line-count
and code complexity by using the new-ish go generics features. Care has
been taken to ensure that this patch is as small as possible, and
affects as few Go APIs as possible. This is ensured by using type aliases
for the Result type to re-create the various previous Results, e.g.
frontend.Result/client.Result/exporter.Source, so that little code in
packages that utilize these Results need to be changed. The only major
changes take place at conversion boundaries, where, for the most part,
the code is simplified.

One major caveat is that the result package is made significantly more
complex, due to the generic code, and the need for reflection to perform
comparisons of any types to nil, as interfaces such solver.ResultProxy
(used as a Ref type) do not implement the comparable interface, which is
a limitation of the current go language spec (hopefully to be resolved
in the future).

Signed-off-by: Justin Chadwell <me@jedevc.com>
2022-08-24 16:28:14 -07:00
Justin Chadwell
863d9d7351 gateway: clone ResultProxy at gateway boundaries
Previously, a frontend returning two identical references caused a
double-release error, as the gateway expects each ref to be unique.
However, there are scenarios where a frontend might reasonably be
expected to provide identical refs, e.g. for 2 platforms that have
binary compatibility, or for the upcoming attestations use-case.

To solve this issue, we refactor the ResultProxy implementation to
support cloning via splits.

Additionally, we then use the new splitting functionality in the gateway
and forwarder (e.g. dockerfile) frontends, and ensure that the same
ResultProxy is never returned twice in a result. This means that
identical refs over the wire are translated into the correct
shared-memory structures.

Signed-off-by: Justin Chadwell <me@jedevc.com>
2022-07-29 11:37:57 +01:00
Jonny Stoten
3b8298b67a Add context to errors setting up caches
Signed-off-by: Jonny Stoten <jonny.stoten@docker.com>
2022-07-26 12:55:21 +01:00
Tonis Tiigi
6644f165cc fix cancellation error not being detected and erroneously cached
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2022-06-23 08:25:21 -07:00
David Gageot
1245e43085 Enable gosimple linter
Signed-off-by: David Gageot <david.gageot@doctolib.com>
2022-04-23 23:57:16 +02:00
CrazyMax
49aa39c018 buildinfo: merge build sources for deps
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
2022-03-09 18:52:11 +01:00
CrazyMax
a3da60d114 fix nil pointer dereference in bridge result
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
2022-02-18 19:54:25 +01:00
CrazyMax
9cd97fb726 buildinfo: check nil attrs
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
2022-02-14 22:55:37 +01:00
CrazyMax
cdaafb9303 buildinfo: use metadata to set frontend build sources
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
2022-02-14 21:55:20 +01:00
CrazyMax
b2e5d1938d buildinfo: set frontend attrs to bridge result
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
2022-02-14 21:55:20 +01:00
CrazyMax
b4e37a867f buildinfo: refactor
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
2022-02-14 21:55:18 +01:00
Tonis Tiigi
872518e334 update warning type definition
Detail is now an array and URL is a separate field.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2021-12-13 21:38:20 -08:00
Tonis Tiigi
71316c6f29 split warning message into short and detail
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2021-12-02 18:17:35 -08:00
Tonis Tiigi
7ee783e90c add source mapping support to warnings
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2021-11-30 21:58:37 -08:00
Tonis Tiigi
6cad384e93 support setting warnings from frontends
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2021-11-24 00:19:43 -08:00
CrazyMax
d81e79540b update to github.com/mitchellh/hashstructure v2.0.2
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
2021-11-09 09:56:10 +01:00
CrazyMax
5fcc94454f Generate and embed build sources
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
2021-09-18 01:39:35 +02:00
Morlay
18b49fd7dc refactor to use util/bklog instead of using logurs directly
Signed-off-by: Morlay <morlay.null@gmail.com>
2021-07-13 11:42:31 +08:00
Tonis Tiigi
4e4152832c dockerfile: remove unnecessary error wrappings
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2021-07-02 17:29:32 -07:00
Erik Sipsma
b85ef15689 Remove unneeded Finalize method from ImmutableRef.
Finalize was only used outside the cache package in one place, which
called it with the commit arg set to false. The code path followed
when commit==false turned out to essentially be a no-op because
it set "retain cache" to true if it was already set to true.

It was thus safe to remove the only external call to it and remove it
from the interface. This should be helpful for future efforts to
simplify the equal{Mutable,Immutable} fields in cacheRecord, which exist
due to the "lazy commit" feature that Finalize is tied into.

Signed-off-by: Erik Sipsma <erik@sipsma.dev>
2021-07-01 17:54:59 +00:00
Tonis Tiigi
df3a9cad23 make sure execerror is released on cancellation
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2020-11-25 15:50:10 -08:00
Edgar Lee
372df78cc8 Guarantee err results are released when result proxy is released
Signed-off-by: Edgar Lee <edgarl@netflix.com>
2020-11-25 11:26:53 -08:00
Edgar Lee
1240dd7795 Return committed readonly inputs and actives in exec error in MountIDs
Signed-off-by: Edgar Lee <edgarl@netflix.com>
2020-11-16 13:21:23 -08:00
Edgar Lee
bcff7baf60 Allow scratch mounts with gateway.RunContainer
- Plumb default worker by adding GetDefault() to frontend.WorkerInfos
- To avoid cyclic dependency, refactor frontend.WorkerInfos to worker.Infos
- Refactor gateway.NewContainer to share code with llbsolver/ops/exec.go

Signed-off-by: Edgar Lee <edgarl@netflix.com>
2020-11-13 22:05:13 -08:00
Edgar Lee
7ce58c31ba Plumb op metadata to recreate failed ops with gateway exec
Signed-off-by: Edgar Lee <edgarl@netflix.com>
2020-11-13 22:05:13 -08:00
Tonis Tiigi
bdcee17437 executor: change mount to struct
Allows readonly passed cleanly.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2020-11-02 22:20:51 -08:00
Tonis Tiigi
e3b05289d8 add session injection to remote loading
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2020-11-02 22:20:44 -08:00
Cory Bennett
03e1c199a3 remove SessonManager from FrontendLLBBridge, adding as arg to Frontend.Solve
Signed-off-by: Cory Bennett <cbennett@netflix.com>
2020-10-02 01:59:05 +00:00
Cory Bennett
3cc8aa0649 move ExecOps mounting logic into new package so logic can be reused from gateway exec
Signed-off-by: Cory Bennett <cbennett@netflix.com>
2020-09-15 07:01:42 +00:00