Merge pull request #1395 from lugeng/fix-load-metadata
dockerfile build: fix not exit when meet error in load config metadatav0.8
commit
2aa3e0bd42
|
@ -249,33 +249,34 @@ func Dockerfile2LLB(ctx context.Context, dt []byte, opt ConvertOpt) (*llb.State,
|
|||
ResolveMode: opt.ImageResolveMode.String(),
|
||||
LogName: fmt.Sprintf("%s load metadata for %s", prefix, d.stage.BaseName),
|
||||
})
|
||||
if err == nil { // handle the error while builder is actually running
|
||||
var img Image
|
||||
if err := json.Unmarshal(dt, &img); err != nil {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var img Image
|
||||
if err := json.Unmarshal(dt, &img); err != nil {
|
||||
return err
|
||||
}
|
||||
img.Created = nil
|
||||
// if there is no explicit target platform, try to match based on image config
|
||||
if d.platform == nil && platformOpt.implicitTarget {
|
||||
p := autoDetectPlatform(img, *platform, platformOpt.buildPlatforms)
|
||||
platform = &p
|
||||
}
|
||||
d.image = img
|
||||
if dgst != "" {
|
||||
ref, err = reference.WithDigest(ref, dgst)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
img.Created = nil
|
||||
// if there is no explicit target platform, try to match based on image config
|
||||
if d.platform == nil && platformOpt.implicitTarget {
|
||||
p := autoDetectPlatform(img, *platform, platformOpt.buildPlatforms)
|
||||
platform = &p
|
||||
}
|
||||
d.image = img
|
||||
if dgst != "" {
|
||||
ref, err = reference.WithDigest(ref, dgst)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
d.stage.BaseName = ref.String()
|
||||
if len(img.RootFS.DiffIDs) == 0 {
|
||||
isScratch = true
|
||||
// schema1 images can't return diffIDs so double check :(
|
||||
for _, h := range img.History {
|
||||
if !h.EmptyLayer {
|
||||
isScratch = false
|
||||
break
|
||||
}
|
||||
}
|
||||
d.stage.BaseName = ref.String()
|
||||
if len(img.RootFS.DiffIDs) == 0 {
|
||||
isScratch = true
|
||||
// schema1 images can't return diffIDs so double check :(
|
||||
for _, h := range img.History {
|
||||
if !h.EmptyLayer {
|
||||
isScratch = false
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ func toEnvMap(args []instructions.KeyValuePairOptional, env []string) map[string
|
|||
|
||||
func TestDockerfileParsing(t *testing.T) {
|
||||
t.Parallel()
|
||||
df := `FROM busybox
|
||||
df := `FROM scratch
|
||||
ENV FOO bar
|
||||
COPY f1 f2 /sub/
|
||||
RUN ls -l
|
||||
|
@ -34,7 +34,7 @@ RUN ls -l
|
|||
_, _, err := Dockerfile2LLB(appcontext.Context(), []byte(df), ConvertOpt{})
|
||||
assert.NoError(t, err)
|
||||
|
||||
df = `FROM busybox AS foo
|
||||
df = `FROM scratch AS foo
|
||||
ENV FOO bar
|
||||
FROM foo
|
||||
COPY --from=foo f1 /
|
||||
|
@ -43,7 +43,7 @@ COPY --from=0 f2 /
|
|||
_, _, err = Dockerfile2LLB(appcontext.Context(), []byte(df), ConvertOpt{})
|
||||
assert.NoError(t, err)
|
||||
|
||||
df = `FROM busybox AS foo
|
||||
df = `FROM scratch AS foo
|
||||
ENV FOO bar
|
||||
FROM foo
|
||||
COPY --from=foo f1 /
|
||||
|
@ -59,13 +59,13 @@ COPY --from=0 f2 /
|
|||
})
|
||||
assert.Error(t, err)
|
||||
|
||||
df = `FROM busybox
|
||||
df = `FROM scratch
|
||||
ADD http://github.com/moby/buildkit/blob/master/README.md /
|
||||
`
|
||||
_, _, err = Dockerfile2LLB(appcontext.Context(), []byte(df), ConvertOpt{})
|
||||
assert.NoError(t, err)
|
||||
|
||||
df = `FROM busybox
|
||||
df = `FROM scratch
|
||||
COPY http://github.com/moby/buildkit/blob/master/README.md /
|
||||
`
|
||||
_, _, err = Dockerfile2LLB(appcontext.Context(), []byte(df), ConvertOpt{})
|
||||
|
|
Loading…
Reference in New Issue