dockerfile: detect empty images early

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
docker-18.09
Tonis Tiigi 2018-05-22 15:58:22 -07:00
parent 8084e8cde9
commit eefc49ff72
2 changed files with 13 additions and 3 deletions

View File

@ -156,6 +156,7 @@ func Dockerfile2LLB(ctx context.Context, dt []byte, opt ConvertOpt) (*llb.State,
return err return err
} }
d.stage.BaseName = reference.TagNameOnly(ref).String() d.stage.BaseName = reference.TagNameOnly(ref).String()
var isScratch bool
if metaResolver != nil && reachable { if metaResolver != nil && reachable {
dgst, dt, err := metaResolver.ResolveImageConfig(ctx, d.stage.BaseName) dgst, dt, err := metaResolver.ResolveImageConfig(ctx, d.stage.BaseName)
if err == nil { // handle the error while builder is actually running if err == nil { // handle the error while builder is actually running
@ -173,9 +174,16 @@ func Dockerfile2LLB(ctx context.Context, dt []byte, opt ConvertOpt) (*llb.State,
} }
d.stage.BaseName = ref.String() d.stage.BaseName = ref.String()
_ = ref _ = ref
if len(img.RootFS.DiffIDs) == 0 {
isScratch = true
} }
} }
}
if isScratch {
d.state = llb.Scratch()
} else {
d.state = llb.Image(d.stage.BaseName, dfCmd(d.stage.SourceCode)) d.state = llb.Image(d.stage.BaseName, dfCmd(d.stage.SourceCode))
}
return nil return nil
}) })
}(i, d) }(i, d)

View File

@ -88,10 +88,12 @@ func (b *llbBridge) Solve(ctx context.Context, req frontend.SolveRequest) (res s
if !ok { if !ok {
return nil, nil, errors.Errorf("invalid reference for exporting: %T", res.Sys()) return nil, nil, errors.Errorf("invalid reference for exporting: %T", res.Sys())
} }
if wr.ImmutableRef != nil {
if err := wr.ImmutableRef.Finalize(ctx); err != nil { if err := wr.ImmutableRef.Finalize(ctx); err != nil {
return nil, nil, err return nil, nil, err
} }
} }
}
return return
} }