Commit Graph

518 Commits

Author SHA1 Message Date
Tõnis Tiigi
c574c5874b Merge pull request #4908 from tonistiigi/platforms-verify
verifier: verify platforms of the build result
2024-05-31 08:18:08 -07:00
Tõnis Tiigi
843be8670c Merge pull request #4932 from tonistiigi/testifylint-fixes1
lint: fix some testifylint warnings
2024-05-31 07:48:54 -07:00
Tonis Tiigi
fbd08c6a42 allow skipping backlinks where walking cache chains for provenance
Backlink walking should not be needed to determine layers for
current build and should be safe to skip. This improves performance
of provenance creation for certain builds.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2024-05-30 21:26:38 -07: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
acb1bed96c verifier: verify platforms of the build result
Check that the result returned from the frontend
matches the user request conventions and show a
warning if it doesn't.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2024-05-30 11:05:52 -07:00
Tonis Tiigi
7b52fed89f llbsolver: create single temp lease for exports for performance
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2024-05-23 09:49:20 -07:00
Dennis Haney
bf1da9647c fix: 20 sec timeout for write to disc too short
20 sec stall on an platter old hdd is not unexpected.
Nor is 20s write on a low-tier cloud environment drive unexpected.

300s should however be enough to tell the difference between crappy hardware and actual failure.

fixes #4327

Signed-off-by: Dennis Haney <davh@davh.dk>
2024-05-22 06:38:04 +02:00
Tõnis Tiigi
3fd813cfa5 Merge pull request #4833 from crazy-max/provenance-infer-builder-id
solver: infer builder id from user input for provenance in build record
2024-04-12 14:41:46 -07:00
Akihiro Suda
5a19fb4759 Merge pull request #4829 from tonistiigi/gopls-linters
add extra linters from gopls
2024-04-12 06:25:34 +09:00
Tõnis Tiigi
76c742232c Merge pull request #4825 from profnandaa/fix-4696-normalize-path-function
fix: use unix path separator since windows path already normalized
2024-04-11 12:38:59 -07:00
Anthony Nandaa
018155fa68 fix: use unix path separator since path already normalized
In the case for Windows, this line at
frontend/dockerfile/dockerfile2llb/convert.go#L1142
```go
dest += string(filepath.Separator)
```
was adding the `\\` to a path that is already normalized
to unix-format, hence ending up with dest paths like
`/\\` for `C:\\` and `/test\\` for `C:\\test\\`.

the src paths are well normalized too at ~L1290.

This change removes the block of code and instead
does the "/" appending using the keepSlash logic
that is in system.NormalizePath called in
pathRelativeToWorkingDir() function before.

fixes #4696

Signed-off-by: Anthony Nandaa <profnandaa@gmail.com>
2024-04-11 18:25:10 +03:00
CrazyMax
8769cd5e3c solver: infer builder id from user input for provenance in build record
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
2024-04-11 15:18:34 +02:00
Tonis Tiigi
a07a92e157 lint: unusedparams fixes for windows
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2024-04-09 07:23:16 -07:00
Tonis Tiigi
1f9988911f lint: unusedparams fixes
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2024-04-09 07:23:16 -07:00
Tonis Tiigi
eb942eae5b unify ReadAt to ReadCloser conversion
Also removes dependency from pkg/ioutils

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2024-04-05 16:24:40 -07:00
Erik Sipsma
7bc06cb0b7 add support for AlwaysReplaceExistingDestPaths in llb copy
Signed-off-by: Erik Sipsma <erik@sipsma.dev>
2024-04-02 12:11:06 -07: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
Jonathan A. Sternberg
0e1cf1ce35 tracing: refactor the trace recorder
The trace recorder is now a separate entity and does not wrap another
span exporter. It is added as another span processor to the underlying
tracer provider so the two can be disconnected from each other and this
removes the need to use `detect.Exporter()` to find the TraceRecorder
along with the need to invoke flush manually.

The trace recorder is wrapped with a simple span processor instead of
the batch one. That makes the flushing irrelevant for this purpose.

The trace recorder itself is also modified to avoid leaking goroutines
and respecting context cancellations.

This is part of a general refactor of the detect package to separate the
buildkit-specific functionality from the external exporter detection.

Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
2024-03-27 16:00:26 -05:00
Justin Chadwell
d0b170ceb8 solver: stub out sysSampler close
Follow-up to ce332e1952 - this didn't
resolve the access to sysSampler.Close, we need to stub this one out as
well!

Signed-off-by: Justin Chadwell <me@jedevc.com>
2024-03-18 14:44:33 +01:00
Tonis Tiigi
a7d1ccab27 file: fix idmap passed to unpack when userns enabled
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2024-02-28 17:01:17 -08:00
Tonis Tiigi
e91834d3c8 file: use best-effort xattr behavior on unpacking
Default changed in Moby25 archive package. Setting this
bool restores the previous behavior.

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2024-02-28 16:34:28 -08:00
CrazyMax
94e2370023 provenance: move types to a dedicated package
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
2024-02-25 20:39:50 +01:00
CrazyMax
db304eb931 Merge pull request #4675 from tonistiigi/log-remove
remove accidental debug log
2024-02-21 07:57:07 +01:00
Tonis Tiigi
7bd28836ae remove accidental debug log
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2024-02-20 21:43:57 -08:00
Akihiro Suda
f668293668 secret mount: avoid setting noexec when an exec bit it set
Fix issue 4668

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2024-02-20 06:57:26 +09: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
Justin Chadwell
ed2efe3e9c test: add new content-cache exec mount tests
These test all of the new behavior:

- Checks for old default no content cache
- Checks for old read-only and no-output allowed content cache
- Checks for new root selector allowed content cache
- Checks for new caller options that allow enabling/disabling it

Signed-off-by: Justin Chadwell <me@jedevc.com>
2024-02-06 11:44:25 +00:00
Justin Chadwell
0eb25a6bf7 exec: allow caller-controlled content-based cache
This allows LLB-directed content-based cache enablement for each mount.

Some mounts may not be explicitly unabled (because it would be unsafe) -
for these cases we explicitly error out.

Signed-off-by: Justin Chadwell <me@jedevc.com>
2024-02-06 11:44:25 +00:00
Justin Chadwell
ab17c1dd93 exec: allow content-cache for root selected mounts
These mounts are actually safe, as suggested by Erik on slack:

> Is it correct that this wouldn’t be a problem in the case where the
> selector of the mount is just “/“? Because then there’s no “hidden”
> files.
>
> If so, maybe there’s a path to enabling content cache for rw mounts
> that are from “/“. Then you could also get the same end behavior by
> not using selectors and instead always copying the subdir you want to
> mount to scratch.

This patch adds a check for this case, and explicitly enables
content-based cache for these cases.

Co-authored-by: Erik Sipsma <erik@sipsma.dev>
Signed-off-by: Justin Chadwell <me@jedevc.com>
2024-02-06 11:18:57 +00:00
Justin Chadwell
98bfcf44ce exec: refactor content-based cache detection
This refactors the content-based cache to be that little bit tidier. In
addition to adding comments that explain *why* we're even bothering,
this restructures the code to avoid being unclear.

To explain the changes in a little more detail (since it's not
abundantly clear why this translation is valid), the initial condition
looks like:

	if (!m.Readonly || m.Dest == pb.RootMount) && m.Output != -1 {
		deps[m.Input].NoContentBasedHash = true

We can apply De Morgan's law recursively to invert the condition and the
result:

	deps[m.Input].NoContentBasedHash = true
	if (m.Readonly && m.Dest != pb.RootMount) || m.Output == -1 {
		deps[m.Input].NoContentBasedHash = false

With all the juggling of NoContentBasedCache, we invert the variable
name to be ContentBasedCache (and invert everywhere it's used as well):

	if (m.Readonly && m.Dest != pb.RootMount) || m.Output == -1 {
		deps[m.Input].ContentBasedHash = true

This reads a bit easier, but now we split this into two separate
branches for readability (and so we can comment each one in more detail
separately):

	if m.Readonly && m.Dest != pb.RootMount {
		deps[m.Input].ContentBasedHash = true
	}
	if m.Output == -1 {
		deps[m.Input].ContentBasedHash = true
	}

While this has been the behavior for ages, I think it makes sense to
deliberately this behavior slightly. It doesn't make sense to me that we
should only disallow read-only root mounts, but no-output root mounts
are allowed - there's no reason these shouldn't behave identically, by
splitting these out:

	if m.Readonly {
		deps[m.Input].ContentBasedHash = true
	}
	if m.Output == -1 {
		deps[m.Input].ContentBasedHash = true
	}

	if m.Dest == pb.RootMount {
		deps[m.Input].ContentBasedHash = false
	}

There is a small chance that this is a breaking change for some users,
however, 1. SkipOutput (-1) is very rare and not often used in the wild
(except for dockerfiles, where it's only used for non-root mounts), and 2.
will only cause a cache miss.

Signed-off-by: Justin Chadwell <me@jedevc.com>
2024-02-06 11:18:55 +00: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
Tõnis Tiigi
0fecf46d6f Merge pull request #4589 from jedevc/cachechains-readability
chore: start to improve cachechains readability
2024-01-28 17:26:47 -08:00
Tõnis Tiigi
4438f4f75c Merge pull request #4585 from cpuguy83/exclude_cachemount_id_from_cachemap
Do not include a cache mount's ID in the ExecOp's cachemap
2024-01-26 11:37:05 -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
8d6199a27c chore: update CacheExporterTarget docs
Signed-off-by: Justin Chadwell <me@jedevc.com>
2024-01-25 17:33:20 +00:00
Brian Goff
584ec40085 Do not include a cache mount's ID in the ExecOp's cachemap
A cache ID should not have any impact on whether or not a step should be
re-run any more than the content of that cache does (or rather,
doesn't).

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2024-01-25 16:53:51 +00:00
Justin Chadwell
a1826acd72 history: wrap os.ErrNotExist errors
While debugging around, I found some instances of os.ErrNotExist
appearing in the logs from the history API - however, no stack traces
were available, since they're not wrapped.

This patch just adds wrapping for them, with some additional debbuging
info.

Signed-off-by: Justin Chadwell <me@jedevc.com>
2024-01-22 13:27:52 +00:00
Justin Chadwell
cb7d240ffb solver: ensure each ref in the result map is evaluated
There was a typo in d709afdb96.

Signed-off-by: Justin Chadwell <me@jedevc.com>
2024-01-11 11:26:07 +00:00
Tõnis Tiigi
d2b7b92a38 Merge pull request #4526 from jedevc/fix-scratch-multiplatform
Fix scratch multi-platform images
2024-01-09 11:15:05 -08:00
Justin Chadwell
7c0f37b09b solver: avoid discarding nil refs entry
This is possible with llb.Scratch in a multi-platform build. We were
accidentally discarding the nil entries in Refs.

Instead, we just skip over nil refs. This isn't ideal - we *should* be
able generate provenance for a nil ref. However, 1. this isn't handled
for llb.Scratch as a single-platform result, and 2. this is tricky,
since the ResultProxy is nil at this point (so there's no ID to match
on). This should be ok for a quick fix, but we can come back and fix
this later.

Signed-off-by: Justin Chadwell <me@jedevc.com>
2024-01-05 15:17:04 +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
Justin Chadwell
7fb54984ea control: add multiple exporters
This patch adds support for multiple exporters at the control API, and
propogates the resulting required changes through the client and the
solver.

A few notable changes:
- Each exporter instance now has an associated identifier
- Build records in the build history now have multiple possible
  descriptors to built content
- Exporter responses are all merged together (like we currently do with
  multiple cache exporters). We likely will need to revisit this design
  later, since now cache exporters do not line up one-to-one with
  exporters.

For backwards compatability, new clients will continue to produce
requests that contain the now deprecated exporter fields, as well as the
new ones. New servers will attempt to use deprecated fields if they
are present.

Co-authored-by: a-palchikov <deemok@gmail.com>
Co-authored-by: fahed dorgaa <fahed.dorgaa@gmail.com>
Signed-off-by: Justin Chadwell <me@jedevc.com>
2024-01-05 12:04:28 +00:00
Justin Chadwell
4c93f9d9bd exporter: pass inline cache directly to exporter
This preps for the case where a single exporter source does not map
neatly onto a single inline cache - such as introducing multiple
exporters.

We also introduce laziness here - each exporter chooses to attempt
extracting the inline cache on demand, which ensures that we avoid
creating inline caches for exporters that do not support them.

Co-authored-by: a-palchikov <deemok@gmail.com>
Co-authored-by: fahed dorgaa <fahed.dorgaa@gmail.com>
Signed-off-by: Justin Chadwell <me@jedevc.com>
2024-01-05 12:04:26 +00:00
Justin Chadwell
9c5816a317 chore: remove function indirection for cache exporters
Signed-off-by: Justin Chadwell <me@jedevc.com>
2024-01-05 12:03:39 +00:00
Tõnis Tiigi
f84cfe3d6a Merge pull request #4460 from jsternberg/otel-metrics
util: expose otel metrics through grpc and prometheus
2023-12-12 14:03:41 -08:00
Jonathan A. Sternberg
7de2e4fb32 util: expose otel metrics through grpc and prometheus
This exposes the otel metrics through the environment variables for the
otel collector or through the prometheus `/metrics` endpoint through the
debug address.

This also adds metrics for the grpc endpoints from the opentelemetry
libraries.

For the opentelemetry collector, the metric temporality is delta which
reduces the amount of data that goes over the wire overall. Prometheus
metrics are cumulative because prometheus metrics require that.

Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
2023-12-12 08:59:01 -06:00
Tõnis Tiigi
7eb2c8e067 Merge pull request #4457 from tonistiigi/cancel-cause
replace context.WithCancel with WithCancelCause
2023-12-11 17:39:43 -08:00