From 7562a6638ac7552170c275c4d6dcfa1946df496c Mon Sep 17 00:00:00 2001 From: Edgar Lee Date: Thu, 5 Dec 2019 11:08:12 -0800 Subject: [PATCH] Fix empty string id in result ref Signed-off-by: Edgar Lee --- frontend/gateway/gateway.go | 4 ++-- frontend/gateway/grpcclient/client.go | 4 ++-- frontend/gateway/pb/ref.go | 9 +++++++++ 3 files changed, 13 insertions(+), 4 deletions(-) create mode 100644 frontend/gateway/pb/ref.go diff --git a/frontend/gateway/gateway.go b/frontend/gateway/gateway.go index 3727b98e..392ee261 100644 --- a/frontend/gateway/gateway.go +++ b/frontend/gateway/gateway.go @@ -479,7 +479,7 @@ func (lbf *llbBridgeForwarder) Solve(ctx context.Context, req *pb.SolveRequest) if req.AllowResultArrayRef { refMap := make(map[string]*pb.Ref, len(res.Refs)) for k, id := range ids { - refMap[k] = &pb.Ref{Ids: []string{id}} + refMap[k] = pb.NewRef(id) } pbRes.Result = &pb.Result_Refs{Refs: &pb.RefMap{Refs: refMap}} } else { @@ -495,7 +495,7 @@ func (lbf *llbBridgeForwarder) Solve(ctx context.Context, req *pb.SolveRequest) defaultID = id if req.AllowResultArrayRef { - pbRes.Result = &pb.Result_Ref{Ref: &pb.Ref{Ids: []string{id}}} + pbRes.Result = &pb.Result_Ref{Ref: pb.NewRef(id)} } else { pbRes.Result = &pb.Result_RefDeprecated{RefDeprecated: id} } diff --git a/frontend/gateway/grpcclient/client.go b/frontend/gateway/grpcclient/client.go index ae1eaab5..b7dba2b7 100644 --- a/frontend/gateway/grpcclient/client.go +++ b/frontend/gateway/grpcclient/client.go @@ -112,7 +112,7 @@ func (c *grpcClient) Run(ctx context.Context, f client.BuildFunc) (retError erro retError = err continue } - m[k] = &pb.Ref{Ids: []string{id}} + m[k] = pb.NewRef(id) } pbRes.Result = &pb.Result_Refs{Refs: &pb.RefMap{Refs: m}} } else { @@ -120,7 +120,7 @@ func (c *grpcClient) Run(ctx context.Context, f client.BuildFunc) (retError erro if err != nil { retError = err } else { - pbRes.Result = &pb.Result_Ref{Ref: &pb.Ref{Ids: []string{id}}} + pbRes.Result = &pb.Result_Ref{Ref: pb.NewRef(id)} } } if retError == nil { diff --git a/frontend/gateway/pb/ref.go b/frontend/gateway/pb/ref.go new file mode 100644 index 00000000..882fae57 --- /dev/null +++ b/frontend/gateway/pb/ref.go @@ -0,0 +1,9 @@ +package moby_buildkit_v1_frontend + +func NewRef(id string) *Ref { + var ref Ref + if id != "" { + ref.Ids = append(ref.Ids, id) + } + return &ref +}