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

@ -13,9 +13,6 @@ import (
"time"
distreference "github.com/distribution/reference"
"github.com/gogo/googleapis/google/rpc"
gogotypes "github.com/gogo/protobuf/types"
"github.com/golang/protobuf/ptypes/any"
"github.com/moby/buildkit/client/llb"
"github.com/moby/buildkit/client/llb/sourceresolver"
"github.com/moby/buildkit/frontend/gateway/client"
@ -36,6 +33,7 @@ import (
"google.golang.org/grpc/codes"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/proto"
)
const frontendPrefix = "BUILDKIT_FRONTEND_OPT_"
@ -196,10 +194,10 @@ func (c *grpcClient) Run(ctx context.Context, f client.BuildFunc) (retError erro
if retError != nil {
st, _ := status.FromError(grpcerrors.ToGRPC(ctx, retError))
stp := st.Proto()
req.Error = &rpc.Status{
req.Error = &spb.Status{
Code: stp.Code,
Message: stp.Message,
Details: convertToGogoAny(stp.Details),
Details: stp.Details,
}
}
if _, err := c.client.Return(ctx, req); err != nil && retError == nil {
@ -251,8 +249,8 @@ func (c *grpcClient) Run(ctx context.Context, f client.BuildFunc) (retError erro
// defaultCaps returns the capabilities that were implemented when capabilities
// support was added. This list is frozen and should never be changed.
func defaultCaps() []apicaps.PBCap {
return []apicaps.PBCap{
func defaultCaps() []*apicaps.PBCap {
return []*apicaps.PBCap{
{ID: string(pb.CapSolveBase), Enabled: true},
{ID: string(pb.CapSolveInlineReturn), Enabled: true},
{ID: string(pb.CapResolveImage), Enabled: true},
@ -262,8 +260,8 @@ func defaultCaps() []apicaps.PBCap {
// defaultLLBCaps returns the LLB capabilities that were implemented when capabilities
// support was added. This list is frozen and should never be changed.
func defaultLLBCaps() []apicaps.PBCap {
return []apicaps.PBCap{
func defaultLLBCaps() []*apicaps.PBCap {
return []*apicaps.PBCap{
{ID: string(opspb.CapSourceImage), Enabled: true},
{ID: string(opspb.CapSourceLocal), Enabled: true},
{ID: string(opspb.CapSourceLocalUnique), Enabled: true},
@ -331,7 +329,7 @@ func (c *grpcClient) requestForRef(ref client.Reference) (*pb.SolveRequest, erro
func (c *grpcClient) Warn(ctx context.Context, dgst digest.Digest, msg string, opts client.WarnOpts) error {
_, err := c.client.Warn(ctx, &pb.WarnRequest{
Digest: dgst,
Digest: string(dgst),
Level: int64(opts.Level),
Short: []byte(msg),
Info: opts.SourceInfo,
@ -346,7 +344,7 @@ func (c *grpcClient) Solve(ctx context.Context, creq client.SolveRequest) (res *
if creq.Definition != nil {
for _, md := range creq.Definition.Metadata {
for cap := range md.Caps {
if err := c.llbCaps.Supports(cap); err != nil {
if err := c.llbCaps.Supports(apicaps.CapID(cap)); err != nil {
return nil, err
}
}
@ -538,7 +536,7 @@ func (c *grpcClient) ResolveSourceMetadata(ctx context.Context, op *opspb.Source
}
if resp.Image != nil {
r.Image = &sourceresolver.ResolveImageResponse{
Digest: resp.Image.Digest,
Digest: digest.Digest(resp.Image.Digest),
Config: resp.Image.Config,
}
}
@ -576,7 +574,7 @@ func (c *grpcClient) resolveImageConfigViaSourceMetadata(ctx context.Context, re
}
ref = strings.TrimPrefix(resp.Source.Identifier, "docker-image://")
ref = strings.TrimPrefix(ref, "oci-layout://")
return ref, resp.Image.Digest, resp.Image.Config, nil
return ref, digest.Digest(resp.Image.Digest), resp.Image.Config, nil
}
func (c *grpcClient) ResolveImageConfig(ctx context.Context, ref string, opt sourceresolver.Opt) (string, digest.Digest, []byte, error) {
@ -622,7 +620,7 @@ func (c *grpcClient) ResolveImageConfig(ctx context.Context, ref string, opt sou
// This could occur if the version of buildkitd is too old.
newRef = ref
}
return newRef, resp.Digest, resp.Config, nil
return newRef, digest.Digest(resp.Digest), resp.Config, nil
}
func (c *grpcClient) BuildOpts() client.BuildOpts {
@ -646,7 +644,7 @@ func (c *grpcClient) CurrentFrontend() (*llb.State, error) {
return nil, err
}
var def opspb.Definition
if err := def.Unmarshal(dt); err != nil {
if err := proto.Unmarshal(dt, &def); err != nil {
return nil, err
}
op, err := llb.NewDefinitionOp(&def)
@ -1095,7 +1093,7 @@ func (ctr *container) Start(ctx context.Context, req client.StartRequest) (clien
exitError = grpcerrors.FromGRPC(status.ErrorProto(&spb.Status{
Code: exit.Error.Code,
Message: exit.Error.Message,
Details: convertGogoAny(exit.Error.Details),
Details: exit.Error.Details,
}))
if exit.Code != pb.UnknownExitStatus {
exitError = &pb.ExitError{ExitCode: exit.Code, Err: exitError}
@ -1260,6 +1258,7 @@ func grpcClientConn(ctx context.Context) (context.Context, *grpc.ClientConn, err
grpc.WithDefaultCallOptions(grpc.MaxCallSendMsgSize(16 << 20)),
}
//nolint:staticcheck // ignore SA1019 NewClient has different behavior and needs to be tested
cc, err := grpc.DialContext(ctx, "localhost", dialOpts...)
if err != nil {
return ctx, nil, errors.Wrap(err, "failed to create grpc client")
@ -1285,21 +1284,24 @@ type conn struct {
func (s *conn) LocalAddr() net.Addr {
return dummyAddr{}
}
func (s *conn) RemoteAddr() net.Addr {
return dummyAddr{}
}
func (s *conn) SetDeadline(t time.Time) error {
return nil
}
func (s *conn) SetReadDeadline(t time.Time) error {
return nil
}
func (s *conn) SetWriteDeadline(t time.Time) error {
return nil
}
type dummyAddr struct {
}
type dummyAddr struct{}
func (d dummyAddr) Network() string {
return "pipe"
@ -1346,19 +1348,3 @@ func workers() []client.WorkerInfo {
func product() string {
return os.Getenv("BUILDKIT_EXPORTEDPRODUCT")
}
func convertGogoAny(in []*gogotypes.Any) []*any.Any {
out := make([]*any.Any, len(in))
for i := range in {
out[i] = &any.Any{TypeUrl: in[i].TypeUrl, Value: in[i].Value}
}
return out
}
func convertToGogoAny(in []*any.Any) []*gogotypes.Any {
out := make([]*gogotypes.Any, len(in))
for i := range in {
out[i] = &gogotypes.Any{TypeUrl: in[i].TypeUrl, Value: in[i].Value}
}
return out
}