File tree 4 files changed +29
-5
lines changed
4 files changed +29
-5
lines changed Original file line number Diff line number Diff line change @@ -16,4 +16,5 @@ require (
16
16
github.com/vbauerster/mpb v3.4.0+incompatible
17
17
github.com/vrischmann/envconfig v1.3.0
18
18
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f // indirect
19
+ gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
19
20
)
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ package task
3
3
import (
4
4
"encoding/json"
5
5
"fmt"
6
+ "gopkg.in/yaml.v3"
6
7
"io"
7
8
"io/ioutil"
8
9
"os"
@@ -374,13 +375,24 @@ func sanitize(cfg *Config) error {
374
375
return errors .Wrap (err , "read build args file" )
375
376
}
376
377
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" )
381
383
}
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
+ }
382
393
383
- cfg .BuildArgs = append (cfg .BuildArgs , arg )
394
+ cfg .BuildArgs = append (cfg .BuildArgs , arg )
395
+ }
384
396
}
385
397
}
386
398
Original file line number Diff line number Diff line change @@ -152,6 +152,15 @@ func (s *TaskSuite) TestBuildArgsFile() {
152
152
s .NoError (err )
153
153
}
154
154
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
+
155
164
func (s * TaskSuite ) TestBuildArgsStaticAndFile () {
156
165
s .req .Config .ContextDir = "testdata/build-args"
157
166
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