File tree Expand file tree Collapse file tree 4 files changed +29
-6
lines changed
Expand file tree Collapse file tree 4 files changed +29
-6
lines changed Original file line number Diff line number Diff 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)
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ package task
33import (
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
Original file line number Diff line number Diff 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+
155164func (s * TaskSuite ) TestBuildArgsStaticAndFile () {
156165 s .req .Config .ContextDir = "testdata/build-args"
157166 s .req .Config .BuildArgs = []string {"some_arg=some_value" }
Original file line number Diff line number Diff line change 1+ some_arg : some_value
2+ some_other_arg : some_other_value
You can’t perform that action at this time.
0 commit comments