Skip to content

Commit c7e7f44

Browse files
authored
Merge pull request moby#4194 from jedevc/fix-dockerfile2llb-example
dockerfile2llb: prevent panic in ./examples/dockerfile2llb helper
2 parents 4dcd141 + bd9e78a commit c7e7f44

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

frontend/dockerfile/dockerfile2llb/convert.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,9 @@ func toDispatchState(ctx context.Context, dt []byte, opt ConvertOpt) (*dispatchS
573573
return nil, err
574574
}
575575
buildContext.Output = bctx.Output()
576+
} else {
577+
bctx := dockerui.DefaultMainContext(opts...)
578+
buildContext.Output = bctx.Output()
576579
}
577580

578581
defaults := []llb.ConstraintsOpt{

frontend/dockerfile/dockerfile2llb/convert_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package dockerfile2llb
22

33
import (
4+
"context"
45
"testing"
56

67
"github.com/moby/buildkit/frontend/dockerfile/instructions"
@@ -85,6 +86,20 @@ COPY --from=0 f2 /
8586
assert.Error(t, err)
8687
}
8788

89+
func TestDockerfileParsingMarshal(t *testing.T) {
90+
t.Parallel()
91+
df := `FROM scratch
92+
ENV FOO bar
93+
COPY f1 f2 /sub/
94+
RUN ls -l
95+
`
96+
state, _, _, err := Dockerfile2LLB(appcontext.Context(), []byte(df), ConvertOpt{})
97+
assert.NoError(t, err)
98+
99+
_, err = state.Marshal(context.TODO())
100+
assert.NoError(t, err)
101+
}
102+
88103
func TestAddEnv(t *testing.T) {
89104
// k exists in env as key
90105
// override = true

frontend/dockerui/config.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,15 @@ func (bc *Client) IsNoCache(name string) bool {
494494
return false
495495
}
496496

497+
func DefaultMainContext(opts ...llb.LocalOption) *llb.State {
498+
opts = append([]llb.LocalOption{
499+
llb.SharedKeyHint(DefaultLocalNameContext),
500+
WithInternalName("load build context"),
501+
}, opts...)
502+
st := llb.Local(DefaultLocalNameContext, opts...)
503+
return &st
504+
}
505+
497506
func WithInternalName(name string) llb.ConstraintsOpt {
498507
return llb.WithCustomName("[internal] " + name)
499508
}

0 commit comments

Comments
 (0)