Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions pkg/stacker/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,14 @@ func (c *Converter) convertCommand(cmd *Command) error {
c.env = map[string]string{}
}

// Dockerfile ENV defines build and runtime variables.
// For equivalent in stacker, also add them to layer's
// Environment(runtime).
//
if layer.Environment == nil {
layer.Environment = map[string]string{}
}

// parser returns key, value, sep for ENV since v0.16.1
// https://github.com/moby/buildkit/commit/6cfa4599029db7f2e6e83feaaa33984785ddd147
if len(cmd.Value) < 3 {
Expand Down Expand Up @@ -207,11 +215,8 @@ func (c *Converter) convertCommand(cmd *Command) error {
}
}

if c.env == nil {
c.env = map[string]string{}
}

c.env[key] = val
layer.Environment[key] = val
}
case "workdir":
layer.Run = append(layer.Run, fmt.Sprintf("mkdir -p %s", cmd.Value[0]))
Expand Down
9 changes: 7 additions & 2 deletions pkg/stacker/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,13 @@ func TestConverterConvertCommandErrors(t *testing.T) {
},
{
name: "invalid env",
c: NewConverter(&ConvertArgs{}),
cmd: &Command{Cmd: "env", Original: "ENV FOO", Value: []string{"FOO"}},
c: func() *Converter {
c := NewConverter(&ConvertArgs{})
c.currLayer = "layer"
c.output[c.currLayer] = &types.Layer{}
return c
}(),
cmd: &Command{Cmd: "env", Original: "ENV FOO", Value: []string{"FOO"}},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't quite follow two things.

  1. if this test is named 'invalid env' ; what it is testing?
  2. Why is this hunk needed vs the original relating to the "invalid env" scenario?

I apologize here, I should study the test case here; but if you already know I'd appreciate some background on what this change is doing.

Lastly; I was hoping to see a test that demonstrates the failure so it's easy to reason about the fix.

},
{
name: "invalid arg",
Expand Down