protobuf: remove gogoproto

Removes gogo/protobuf from buildx and updates to a version of
moby/buildkit where gogo is removed.

This also changes how the proto files are generated. This is because
newer versions of protobuf are more strict about name conflicts. If two
files have the same name (even if they are relative paths) and are used
in different protoc commands, they'll conflict in the registry.

Since protobuf file generation doesn't work very well with
`paths=source_relative`, this removes the `go:generate` expression and
just relies on the dockerfile to perform the generation.

Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
This commit is contained in:
Jonathan A. Sternberg
2024-10-02 15:51:59 -05:00
parent 8e47387d02
commit b35a0f4718
592 changed files with 46288 additions and 110420 deletions

View File

@ -2,34 +2,43 @@ package llb
import (
"io"
"maps"
"sync"
cerrdefs "github.com/containerd/errdefs"
"github.com/containerd/platforms"
"github.com/moby/buildkit/solver/pb"
digest "github.com/opencontainers/go-digest"
"google.golang.org/protobuf/proto"
)
// Definition is the LLB definition structure with per-vertex metadata entries
// Corresponds to the Definition structure defined in solver/pb.Definition.
type Definition struct {
Def [][]byte
Metadata map[digest.Digest]pb.OpMetadata
Metadata map[digest.Digest]OpMetadata
Source *pb.Source
Constraints *Constraints
}
func (def *Definition) ToPB() *pb.Definition {
metas := make(map[string]*pb.OpMetadata, len(def.Metadata))
for dgst, meta := range def.Metadata {
metas[string(dgst)] = meta.ToPB()
}
return &pb.Definition{
Def: def.Def,
Source: def.Source,
Metadata: maps.Clone(def.Metadata),
Metadata: metas,
}
}
func (def *Definition) FromPB(x *pb.Definition) {
def.Def = x.Def
def.Source = x.Source
def.Metadata = maps.Clone(x.Metadata)
def.Metadata = make(map[digest.Digest]OpMetadata, len(x.Metadata))
for dgst, meta := range x.Metadata {
def.Metadata[digest.Digest(dgst)] = NewOpMetadata(meta)
}
}
func (def *Definition) Head() (digest.Digest, error) {
@ -40,14 +49,14 @@ func (def *Definition) Head() (digest.Digest, error) {
last := def.Def[len(def.Def)-1]
var pop pb.Op
if err := (&pop).Unmarshal(last); err != nil {
if err := proto.Unmarshal(last, &pop); err != nil {
return "", err
}
if len(pop.Inputs) == 0 {
return "", nil
}
return pop.Inputs[0].Digest, nil
return digest.Digest(pop.Inputs[0].Digest), nil
}
func WriteTo(def *Definition, w io.Writer) error {
@ -65,7 +74,7 @@ func ReadFrom(r io.Reader) (*Definition, error) {
return nil, err
}
var pbDef pb.Definition
if err := pbDef.Unmarshal(b); err != nil {
if err := proto.Unmarshal(b, &pbDef); err != nil {
return nil, err
}
var def Definition
@ -104,27 +113,41 @@ func MarshalConstraints(base, override *Constraints) (*pb.Op, *pb.OpMetadata) {
Constraints: &pb.WorkerConstraints{
Filter: c.WorkerConstraints,
},
}, &c.Metadata
}, c.Metadata.ToPB()
}
type MarshalCache struct {
digest digest.Digest
dt []byte
md *pb.OpMetadata
srcs []*SourceLocation
constraints *Constraints
cache sync.Map
}
func (mc *MarshalCache) Cached(c *Constraints) bool {
return mc.dt != nil && mc.constraints == c
func (mc *MarshalCache) Load(c *Constraints) (digest.Digest, []byte, *pb.OpMetadata, []*SourceLocation, error) {
v, ok := mc.cache.Load(c)
if !ok {
return "", nil, nil, nil, cerrdefs.ErrNotFound
}
res := v.(*marshalCacheResult)
return res.digest, res.dt, res.md, res.srcs, nil
}
func (mc *MarshalCache) Load() (digest.Digest, []byte, *pb.OpMetadata, []*SourceLocation, error) {
return mc.digest, mc.dt, mc.md, mc.srcs, nil
func (mc *MarshalCache) Store(dt []byte, md *pb.OpMetadata, srcs []*SourceLocation, c *Constraints) (digest.Digest, []byte, *pb.OpMetadata, []*SourceLocation, error) {
res := &marshalCacheResult{
digest: digest.FromBytes(dt),
dt: dt,
md: md,
srcs: srcs,
}
mc.cache.Store(c, res)
return res.digest, res.dt, res.md, res.srcs, nil
}
func (mc *MarshalCache) Store(dt []byte, md *pb.OpMetadata, srcs []*SourceLocation, c *Constraints) {
mc.digest = digest.FromBytes(dt)
mc.dt = dt
mc.md = md
mc.constraints = c
mc.srcs = srcs
type marshalCacheResult struct {
digest digest.Digest
dt []byte
md *pb.OpMetadata
srcs []*SourceLocation
}
func deterministicMarshal[Message proto.Message](m Message) ([]byte, error) {
return proto.MarshalOptions{Deterministic: true}.Marshal(m)
}