From 71d914d1b4ffd4b6aadb4bc645f286d3b79d41bc Mon Sep 17 00:00:00 2001 From: Joy Latten Date: Fri, 17 Jul 2026 19:29:12 +0000 Subject: [PATCH] fix: stacker convert should include ENV vars into the runtime config. Dockerfile ENV defines variables for both build and runtime. Stacker convert, converts ENV for build, but does not include runtime. Stacker uses "environment:" in yaml to define variables for runtime. So, include the ENV variables there so they will show up in the config when running the container. Signed-off-by: Joy Latten --- pkg/stacker/convert.go | 13 +++++++++---- pkg/stacker/convert_test.go | 9 +++++++-- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/pkg/stacker/convert.go b/pkg/stacker/convert.go index ebacaf5f..f270e82d 100644 --- a/pkg/stacker/convert.go +++ b/pkg/stacker/convert.go @@ -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 { @@ -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])) diff --git a/pkg/stacker/convert_test.go b/pkg/stacker/convert_test.go index 720beacd..827e05dd 100644 --- a/pkg/stacker/convert_test.go +++ b/pkg/stacker/convert_test.go @@ -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"}}, }, { name: "invalid arg",