gateway: fix returning nil references
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>docker-18.09
parent
fc5d833cc1
commit
46e816965b
|
@ -24,7 +24,7 @@ func (f *dfFrontend) Solve(ctx context.Context, llbBridge frontend.FrontendLLBBr
|
|||
|
||||
defer func() {
|
||||
for _, r := range c.refs {
|
||||
if c.final != r || retErr != nil {
|
||||
if r != nil && (c.final != r || retErr != nil) {
|
||||
r.Release(context.TODO())
|
||||
}
|
||||
}
|
||||
|
@ -38,5 +38,5 @@ func (f *dfFrontend) Solve(ctx context.Context, llbBridge frontend.FrontendLLBBr
|
|||
return nil, nil, errors.Errorf("invalid empty return") // shouldn't happen
|
||||
}
|
||||
|
||||
return c.final, c.exporterAttr, nil
|
||||
return c.final.ImmutableRef, c.exporterAttr, nil
|
||||
}
|
||||
|
|
|
@ -1,11 +1,14 @@
|
|||
package dockerfile
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/moby/buildkit/cache"
|
||||
"github.com/moby/buildkit/frontend"
|
||||
"github.com/moby/buildkit/frontend/gateway/client"
|
||||
"github.com/moby/buildkit/session"
|
||||
"github.com/moby/buildkit/solver/pb"
|
||||
"github.com/pkg/errors"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
|
@ -16,7 +19,7 @@ func llbBridgeToGatewayClient(ctx context.Context, llbBridge frontend.FrontendLL
|
|||
type bridgeClient struct {
|
||||
frontend.FrontendLLBBridge
|
||||
opts map[string]string
|
||||
final cache.ImmutableRef
|
||||
final *ref
|
||||
sid string
|
||||
exporterAttr map[string][]byte
|
||||
refs []*ref
|
||||
|
@ -56,5 +59,8 @@ type ref struct {
|
|||
}
|
||||
|
||||
func (r *ref) ReadFile(ctx context.Context, fp string) ([]byte, error) {
|
||||
if r.ImmutableRef == nil {
|
||||
return nil, errors.Wrapf(os.ErrNotExist, "%s no found", fp)
|
||||
}
|
||||
return cache.ReadFile(ctx, r.ImmutableRef, fp)
|
||||
}
|
||||
|
|
|
@ -145,7 +145,7 @@ func (gf *gatewayFrontend) Solve(ctx context.Context, llbBridge frontend.Fronten
|
|||
|
||||
defer func() {
|
||||
for _, r := range lbf.refs {
|
||||
if lbf.lastRef != r || retErr != nil {
|
||||
if r != nil && (lbf.lastRef != r || retErr != nil) {
|
||||
r.Release(context.TODO())
|
||||
}
|
||||
}
|
||||
|
@ -278,6 +278,9 @@ func (lbf *llbBrideForwarder) Solve(ctx context.Context, req *pb.SolveRequest) (
|
|||
lbf.lastRef = ref
|
||||
lbf.exporterAttr = exp
|
||||
}
|
||||
if ref == nil {
|
||||
id = ""
|
||||
}
|
||||
return &pb.SolveResponse{Ref: id}, nil
|
||||
}
|
||||
func (lbf *llbBrideForwarder) ReadFile(ctx context.Context, req *pb.ReadFileRequest) (*pb.ReadFileResponse, error) {
|
||||
|
@ -285,7 +288,9 @@ func (lbf *llbBrideForwarder) ReadFile(ctx context.Context, req *pb.ReadFileRequ
|
|||
if !ok {
|
||||
return nil, errors.Errorf("no such ref: %v", req.Ref)
|
||||
}
|
||||
|
||||
if ref == nil {
|
||||
return nil, errors.Wrapf(os.ErrNotExist, "%s no found", req.FilePath)
|
||||
}
|
||||
dt, err := cache.ReadFile(ctx, ref, req.FilePath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -51,6 +51,9 @@ func (c *grpcClient) Solve(ctx context.Context, def *opspb.Definition, frontend
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if resp.Ref == "" {
|
||||
return nil, nil
|
||||
}
|
||||
return &reference{id: resp.Ref, c: c}, nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue