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
}
d.stage.BaseName = reference.TagNameOnly(ref).String()
var isScratch bool
if metaResolver != nil && reachable {
dgst, dt, err := metaResolver.ResolveImageConfig(ctx, d.stage.BaseName)
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()
_ = ref
if len(img.RootFS.DiffIDs) == 0 {
isScratch = true
}
}
}
d.state = llb.Image(d.stage.BaseName, dfCmd(d.stage.SourceCode))
if isScratch {
d.state = llb.Scratch()
} else {
d.state = llb.Image(d.stage.BaseName, dfCmd(d.stage.SourceCode))
}
return nil
})
}(i, d)

View File

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