commit
f7cf4823f7
|
@ -475,7 +475,16 @@ func (lbf *llbBridgeForwarder) Solve(ctx context.Context, req *pb.SolveRequest)
|
|||
}
|
||||
ids[k] = id
|
||||
}
|
||||
pbRes.Result = &pb.Result_Refs{Refs: &pb.RefMap{Refs: ids}}
|
||||
|
||||
if req.AllowResultArrayRef {
|
||||
refMap := make(map[string]*pb.Ref, len(res.Refs))
|
||||
for k, id := range ids {
|
||||
refMap[k] = pb.NewRef(id)
|
||||
}
|
||||
pbRes.Result = &pb.Result_Refs{Refs: &pb.RefMap{Refs: refMap}}
|
||||
} else {
|
||||
pbRes.Result = &pb.Result_RefsDeprecated{RefsDeprecated: &pb.RefMapDeprecated{Refs: ids}}
|
||||
}
|
||||
} else {
|
||||
id := identity.NewID()
|
||||
if res.Ref == nil {
|
||||
|
@ -484,7 +493,12 @@ func (lbf *llbBridgeForwarder) Solve(ctx context.Context, req *pb.SolveRequest)
|
|||
lbf.refs[id] = res.Ref
|
||||
}
|
||||
defaultID = id
|
||||
pbRes.Result = &pb.Result_Ref{Ref: id}
|
||||
|
||||
if req.AllowResultArrayRef {
|
||||
pbRes.Result = &pb.Result_Ref{Ref: pb.NewRef(id)}
|
||||
} else {
|
||||
pbRes.Result = &pb.Result_RefDeprecated{RefDeprecated: id}
|
||||
}
|
||||
}
|
||||
lbf.mu.Unlock()
|
||||
|
||||
|
@ -635,16 +649,42 @@ func (lbf *llbBridgeForwarder) Return(ctx context.Context, in *pb.ReturnRequest)
|
|||
}
|
||||
|
||||
switch res := in.Result.Result.(type) {
|
||||
case *pb.Result_RefDeprecated:
|
||||
var ids []string
|
||||
if res.RefDeprecated != "" {
|
||||
ids = append(ids, res.RefDeprecated)
|
||||
}
|
||||
|
||||
ref, err := lbf.convertRef(ids)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
r.Ref = ref
|
||||
case *pb.Result_RefsDeprecated:
|
||||
m := map[string]solver.CachedResult{}
|
||||
for k, v := range res.RefsDeprecated.Refs {
|
||||
var ids []string
|
||||
if v != "" {
|
||||
ids = append(ids, v)
|
||||
}
|
||||
|
||||
ref, err := lbf.convertRef(ids)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
m[k] = ref
|
||||
}
|
||||
r.Refs = m
|
||||
case *pb.Result_Ref:
|
||||
ref, err := lbf.convertRef(res.Ref)
|
||||
ref, err := lbf.convertRef(res.Ref.Ids)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
r.Ref = ref
|
||||
case *pb.Result_Refs:
|
||||
m := map[string]solver.CachedResult{}
|
||||
for k, v := range res.Refs.Refs {
|
||||
ref, err := lbf.convertRef(v)
|
||||
for k, ref := range res.Refs.Refs {
|
||||
ref, err := lbf.convertRef(ref.Ids)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -656,16 +696,24 @@ func (lbf *llbBridgeForwarder) Return(ctx context.Context, in *pb.ReturnRequest)
|
|||
}
|
||||
}
|
||||
|
||||
func (lbf *llbBridgeForwarder) convertRef(id string) (solver.CachedResult, error) {
|
||||
if id == "" {
|
||||
func (lbf *llbBridgeForwarder) convertRef(ids []string) (solver.CachedResult, error) {
|
||||
if len(ids) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
if len(ids) > 1 {
|
||||
return nil, errors.Errorf("return reference has multi-result array")
|
||||
}
|
||||
|
||||
lbf.mu.Lock()
|
||||
defer lbf.mu.Unlock()
|
||||
|
||||
id := ids[0]
|
||||
r, ok := lbf.refs[id]
|
||||
if !ok {
|
||||
return nil, errors.Errorf("return reference %s not found", id)
|
||||
}
|
||||
|
||||
return r, nil
|
||||
}
|
||||
|
||||
|
|
|
@ -105,14 +105,14 @@ func (c *grpcClient) Run(ctx context.Context, f client.BuildFunc) (retError erro
|
|||
Metadata: res.Metadata,
|
||||
}
|
||||
if res.Refs != nil {
|
||||
m := map[string]string{}
|
||||
m := map[string]*pb.Ref{}
|
||||
for k, r := range res.Refs {
|
||||
id, err := convertRef(r)
|
||||
if err != nil {
|
||||
retError = err
|
||||
continue
|
||||
}
|
||||
m[k] = 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: id}
|
||||
pbRes.Result = &pb.Result_Ref{Ref: pb.NewRef(id)}
|
||||
}
|
||||
}
|
||||
if retError == nil {
|
||||
|
@ -280,10 +280,11 @@ func (c *grpcClient) Solve(ctx context.Context, creq client.SolveRequest) (*clie
|
|||
}
|
||||
|
||||
req := &pb.SolveRequest{
|
||||
Definition: creq.Definition,
|
||||
Frontend: creq.Frontend,
|
||||
FrontendOpt: creq.FrontendOpt,
|
||||
AllowResultReturn: true,
|
||||
Definition: creq.Definition,
|
||||
Frontend: creq.Frontend,
|
||||
FrontendOpt: creq.FrontendOpt,
|
||||
AllowResultReturn: true,
|
||||
AllowResultArrayRef: true,
|
||||
// old API
|
||||
ImportCacheRefsDeprecated: legacyRegistryCacheImports,
|
||||
// new API
|
||||
|
@ -310,18 +311,37 @@ func (c *grpcClient) Solve(ctx context.Context, creq client.SolveRequest) (*clie
|
|||
} else {
|
||||
res.Metadata = resp.Result.Metadata
|
||||
switch pbRes := resp.Result.Result.(type) {
|
||||
case *pb.Result_Ref:
|
||||
if id := pbRes.Ref; id != "" {
|
||||
case *pb.Result_RefDeprecated:
|
||||
if id := pbRes.RefDeprecated; id != "" {
|
||||
res.SetRef(&reference{id: id, c: c})
|
||||
}
|
||||
case *pb.Result_Refs:
|
||||
for k, v := range pbRes.Refs.Refs {
|
||||
case *pb.Result_RefsDeprecated:
|
||||
for k, v := range pbRes.RefsDeprecated.Refs {
|
||||
ref := &reference{id: v, c: c}
|
||||
if v == "" {
|
||||
ref = nil
|
||||
}
|
||||
res.AddRef(k, ref)
|
||||
}
|
||||
case *pb.Result_Ref:
|
||||
ids := pbRes.Ref.Ids
|
||||
if len(ids) > 0 {
|
||||
if len(ids) > 1 {
|
||||
return nil, errors.Errorf("solve returned multi-result array")
|
||||
}
|
||||
res.SetRef(&reference{id: ids[0], c: c})
|
||||
}
|
||||
case *pb.Result_Refs:
|
||||
for k, v := range pbRes.Refs.Refs {
|
||||
var ref *reference
|
||||
if len(v.Ids) > 0 {
|
||||
if len(v.Ids) > 1 {
|
||||
return nil, errors.Errorf("solve returned multi-result array")
|
||||
}
|
||||
ref = &reference{id: v.Ids[0], c: c}
|
||||
}
|
||||
res.AddRef(k, ref)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -30,16 +30,28 @@ service LLBBridge {
|
|||
|
||||
message Result {
|
||||
oneof result {
|
||||
string ref = 1;
|
||||
RefMap refs = 2;
|
||||
// Deprecated non-array refs.
|
||||
string refDeprecated = 1;
|
||||
RefMapDeprecated refsDeprecated = 2;
|
||||
|
||||
Ref ref = 3;
|
||||
RefMap refs = 4;
|
||||
}
|
||||
map<string, bytes> metadata = 10;
|
||||
}
|
||||
|
||||
message RefMap {
|
||||
message RefMapDeprecated {
|
||||
map<string, string> refs = 1;
|
||||
}
|
||||
|
||||
message Ref {
|
||||
repeated string ids = 1;
|
||||
}
|
||||
|
||||
message RefMap {
|
||||
map<string, Ref> refs = 1;
|
||||
}
|
||||
|
||||
message ReturnRequest {
|
||||
Result result = 1;
|
||||
google.rpc.Status error = 2;
|
||||
|
@ -70,6 +82,7 @@ message SolveRequest {
|
|||
// for each of the ImportCacheRefs entry to CacheImports for compatibility. (planned to be removed)
|
||||
repeated string ImportCacheRefsDeprecated = 4;
|
||||
bool allowResultReturn = 5;
|
||||
bool allowResultArrayRef = 6;
|
||||
|
||||
// apicaps.CapSolveInlineReturn deprecated
|
||||
bool Final = 10;
|
||||
|
|
|
@ -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
|
||||
}
|
Loading…
Reference in New Issue