Skip to content

Commit fceb601

Browse files
featheredtoasttaylorsilva
authored andcommitted
Add support for build arg files in yaml format.
Adds key/value yaml files as possible input for build arg file. This allows for multiline args support in files. Signed-off-by: Jeff Wong <awole20@gmail.com>
1 parent a7b2102 commit fceb601

File tree

4 files changed

+29
-6
lines changed

4 files changed

+29
-6
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,5 @@ require (
3838
golang.org/x/sync v0.8.0 // indirect
3939
golang.org/x/sys v0.26.0 // indirect
4040
golang.org/x/term v0.25.0 // indirect
41-
gopkg.in/yaml.v3 v3.0.1 // indirect
41+
gopkg.in/yaml.v3 v3.0.1
4242
)

task.go

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package task
33
import (
44
"encoding/json"
55
"fmt"
6+
"gopkg.in/yaml.v3"
67
"io"
78
"os"
89
"os/exec"
@@ -373,13 +374,24 @@ func sanitize(cfg *Config) error {
373374
return errors.Wrap(err, "read build args file")
374375
}
375376

376-
for _, arg := range strings.Split(string(buildArgs), "\n") {
377-
if len(arg) == 0 {
378-
// skip blank lines
379-
continue
377+
if strings.HasSuffix(cfg.BuildArgsFile, ".yml") || strings.HasSuffix(cfg.BuildArgsFile, ".yaml") {
378+
var buildArgsData map[string]string
379+
err = yaml.Unmarshal(buildArgs, &buildArgsData)
380+
if err != nil {
381+
return errors.Wrap(err, "read build args yaml file")
380382
}
383+
for key, arg := range buildArgsData {
384+
cfg.BuildArgs = append(cfg.BuildArgs, key + "=" + arg)
385+
}
386+
} else {
387+
for _, arg := range strings.Split(string(buildArgs), "\n") {
388+
if len(arg) == 0 {
389+
// skip blank lines
390+
continue
391+
}
381392

382-
cfg.BuildArgs = append(cfg.BuildArgs, arg)
393+
cfg.BuildArgs = append(cfg.BuildArgs, arg)
394+
}
383395
}
384396
}
385397

task_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,15 @@ func (s *TaskSuite) TestBuildArgsFile() {
152152
s.NoError(err)
153153
}
154154

155+
func (s *TaskSuite) TestBuildArgsYamlFile() {
156+
s.req.Config.ContextDir = "testdata/build-args"
157+
s.req.Config.BuildArgsFile = "testdata/build-args/build_args_file.yaml"
158+
159+
// the Dockerfile itself asserts that the arg has been received
160+
_, err := s.build()
161+
s.NoError(err)
162+
}
163+
155164
func (s *TaskSuite) TestBuildArgsStaticAndFile() {
156165
s.req.Config.ContextDir = "testdata/build-args"
157166
s.req.Config.BuildArgs = []string{"some_arg=some_value"}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
some_arg: some_value
2+
some_other_arg: some_other_value

0 commit comments

Comments
 (0)