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

@ -8,6 +8,7 @@ import (
digest "github.com/opencontainers/go-digest"
ocispecs "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/pkg/errors"
"google.golang.org/protobuf/proto"
)
// DefinitionOp implements llb.Vertex using a marshalled definition.
@ -19,7 +20,7 @@ type DefinitionOp struct {
mu sync.Mutex
ops map[digest.Digest]*pb.Op
defs map[digest.Digest][]byte
metas map[digest.Digest]pb.OpMetadata
metas map[digest.Digest]*pb.OpMetadata
sources map[digest.Digest][]*SourceLocation
platforms map[digest.Digest]*ocispecs.Platform
dgst digest.Digest
@ -29,7 +30,7 @@ type DefinitionOp struct {
// NewDefinitionOp returns a new operation from a marshalled definition.
func NewDefinitionOp(def *pb.Definition) (*DefinitionOp, error) {
if def == nil {
if def.IsNil() {
return nil, errors.New("invalid nil input definition to definition op")
}
@ -40,7 +41,7 @@ func NewDefinitionOp(def *pb.Definition) (*DefinitionOp, error) {
var dgst digest.Digest
for _, dt := range def.Def {
var op pb.Op
if err := (&op).Unmarshal(dt); err != nil {
if err := proto.Unmarshal(dt, &op); err != nil {
return nil, errors.Wrap(err, "failed to parse llb proto op")
}
dgst = digest.FromBytes(dt)
@ -89,14 +90,19 @@ func NewDefinitionOp(def *pb.Definition) (*DefinitionOp, error) {
var index pb.OutputIndex
if dgst != "" {
index = ops[dgst].Inputs[0].Index
dgst = ops[dgst].Inputs[0].Digest
index = pb.OutputIndex(ops[dgst].Inputs[0].Index)
dgst = digest.Digest(ops[dgst].Inputs[0].Digest)
}
metas := make(map[digest.Digest]*pb.OpMetadata, len(def.Metadata))
for k, v := range def.Metadata {
metas[digest.Digest(k)] = v
}
return &DefinitionOp{
ops: ops,
defs: defs,
metas: def.Metadata,
metas: metas,
sources: srcs,
platforms: platforms,
dgst: dgst,
@ -163,7 +169,7 @@ func (d *DefinitionOp) Marshal(ctx context.Context, c *Constraints) (digest.Dige
defer d.mu.Unlock()
meta := d.metas[d.dgst]
return d.dgst, d.defs[d.dgst], &meta, d.sources[d.dgst], nil
return d.dgst, d.defs[d.dgst], meta, d.sources[d.dgst], nil
}
func (d *DefinitionOp) Output() Output {
@ -207,7 +213,7 @@ func (d *DefinitionOp) Inputs() []Output {
for _, input := range op.Inputs {
var vtx *DefinitionOp
d.mu.Lock()
if existingIndexes, ok := d.loadInputCache(input.Digest); ok {
if existingIndexes, ok := d.loadInputCache(digest.Digest(input.Digest)); ok {
if int(input.Index) < len(existingIndexes) && existingIndexes[input.Index] != nil {
vtx = existingIndexes[input.Index]
}
@ -218,19 +224,19 @@ func (d *DefinitionOp) Inputs() []Output {
defs: d.defs,
metas: d.metas,
platforms: d.platforms,
dgst: input.Digest,
index: input.Index,
dgst: digest.Digest(input.Digest),
index: pb.OutputIndex(input.Index),
inputCache: d.inputCache,
sources: d.sources,
}
existingIndexes, _ := d.loadInputCache(input.Digest)
existingIndexes, _ := d.loadInputCache(digest.Digest(input.Digest))
indexDiff := int(input.Index) - len(existingIndexes)
if indexDiff >= 0 {
// make room in the slice for the new index being set
existingIndexes = append(existingIndexes, make([]*DefinitionOp, indexDiff+1)...)
}
existingIndexes[input.Index] = vtx
d.storeInputCache(input.Digest, existingIndexes)
d.storeInputCache(digest.Digest(input.Digest), existingIndexes)
}
d.mu.Unlock()