File tree Expand file tree Collapse file tree 4 files changed +29
-5
lines changed
Expand file tree Collapse file tree 4 files changed +29
-5
lines changed Original file line number Diff line number Diff line change @@ -16,4 +16,5 @@ require (
1616 github.com/vbauerster/mpb v3.4.0+incompatible
1717 github.com/vrischmann/envconfig v1.3.0
1818 golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f // indirect
19+ gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
1920)
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 "io/ioutil"
89 "os"
@@ -374,13 +375,24 @@ func sanitize(cfg *Config) error {
374375 return errors .Wrap (err , "read build args file" )
375376 }
376377
377- for _ , arg := range strings .Split (string (buildArgs ), "\n " ) {
378- if len (arg ) == 0 {
379- // skip blank lines
380- continue
378+ if strings .HasSuffix (cfg .BuildArgsFile , ".yml" ) || strings .HasSuffix (cfg .BuildArgsFile , ".yaml" ) {
379+ var buildArgsData map [string ]string
380+ err = yaml .Unmarshal (buildArgs , & buildArgsData )
381+ if err != nil {
382+ return errors .Wrap (err , "read build args yaml file" )
381383 }
384+ for key , arg := range buildArgsData {
385+ cfg .BuildArgs = append (cfg .BuildArgs , key + "=" + arg )
386+ }
387+ } else {
388+ for _ , arg := range strings .Split (string (buildArgs ), "\n " ) {
389+ if len (arg ) == 0 {
390+ // skip blank lines
391+ continue
392+ }
382393
383- cfg .BuildArgs = append (cfg .BuildArgs , arg )
394+ cfg .BuildArgs = append (cfg .BuildArgs , arg )
395+ }
384396 }
385397 }
386398
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