mirror of
https://github.com/moby/buildkit.git
synced 2026-08-04 14:50:21 +00:00
This reverts commit f2c770e45e.
This patch reworks the attestations code back out of the Refs map. The
logic for this change is that the loss-of-granularity in the data
structure for the protobuf requires convoluted logic in the exporter to
be able to determine the correct multi-platform behaviour.
Prior to attestations, Refs directly mapped each platform to a
reference. Attestations changed this structure, which means that there
is no longer a concrete way to determine if a reference should be
exported with multi-platform semantics or not (e.g. should a local
export with a single platform be flat/nested, should an image export use
an oci manifest or an oci index).
This patch restores the previous semantics, moving the attestion refs
back, pushing the attestations back down into a separate struct. This
has the disadvantage of requiring the result.Attestation struct to be
generic, however, this does simplify some of the helper methods around
it.
By changing this logic, we're able to simplify a few key pieces of
logic:
- Fewer version interop concerns. Because we're not changing the
structure of Ref/Refs between buildkit versions, mixing frontends and
buildkit versions will *always* produce the expected result. If a
frontend attaches attestations they won't be transmitted at all
automatically. Additionally, because attestations can also be attached
to a single Ref, the frontend doesn't need to force an index in the
future.
- Less complex exporter logic, we don't need to any magic around
detecting the user intention with regards to multi-platform exports,
we simply follow the previous semantics of len(res.Refs) > 0. We only
need the small snippet that ensures that the inline-only attestations
don't get attached to a single manifest, to keep the docker load case
working.
- Some simplification of the SBOM scanner code, we can return an
Attestation[llb.State], which we can then easily Convert into an
actual Attestation[Ref].
The patch looks large, but most of the changes are mostly just function
signature changes - the meat of the changes is in the rework of the
platform detection code. This is so we can support the use case of Ref +
Attestations, Refs + Attestations (multi-platform=false) and Refs +
Attestations (multi-platform=true).
Signed-off-by: Justin Chadwell <me@jedevc.com>
32 lines
845 B
Go
32 lines
845 B
Go
package llbsolver
|
|
|
|
import (
|
|
"context"
|
|
|
|
cacheconfig "github.com/moby/buildkit/cache/config"
|
|
"github.com/moby/buildkit/frontend"
|
|
"github.com/moby/buildkit/session"
|
|
"github.com/moby/buildkit/solver"
|
|
"github.com/moby/buildkit/solver/llbsolver/provenance"
|
|
"github.com/moby/buildkit/worker"
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
type Result struct {
|
|
*frontend.Result
|
|
Provenance *provenance.Result
|
|
}
|
|
|
|
type Attestation = frontend.Attestation
|
|
|
|
func workerRefResolver(refCfg cacheconfig.RefConfig, all bool, g session.Group) func(ctx context.Context, res solver.Result) ([]*solver.Remote, error) {
|
|
return func(ctx context.Context, res solver.Result) ([]*solver.Remote, error) {
|
|
ref, ok := res.Sys().(*worker.WorkerRef)
|
|
if !ok {
|
|
return nil, errors.Errorf("invalid result: %T", res.Sys())
|
|
}
|
|
|
|
return ref.GetRemotes(ctx, true, refCfg, all, g)
|
|
}
|
|
}
|