Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for build arg files in yaml format. #123

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ require (
github.com/vbauerster/mpb v3.4.0+incompatible
github.com/vrischmann/envconfig v1.3.0
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
)
22 changes: 17 additions & 5 deletions task.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package task
import (
"encoding/json"
"fmt"
"gopkg.in/yaml.v3"
"io"
"io/ioutil"
"os"
Expand Down Expand Up @@ -374,13 +375,24 @@ func sanitize(cfg *Config) error {
return errors.Wrap(err, "read build args file")
}

for _, arg := range strings.Split(string(buildArgs), "\n") {
if len(arg) == 0 {
// skip blank lines
continue
if strings.HasSuffix(cfg.BuildArgsFile, ".yml") || strings.HasSuffix(cfg.BuildArgsFile, ".yaml") {
var buildArgsData map[string]string
err = yaml.Unmarshal(buildArgs, &buildArgsData)
if err != nil {
return errors.Wrap(err, "read build args yaml file")
}
for key, arg := range buildArgsData {
cfg.BuildArgs = append(cfg.BuildArgs, key + "=" + arg)
}
} else {
for _, arg := range strings.Split(string(buildArgs), "\n") {
if len(arg) == 0 {
// skip blank lines
continue
}

cfg.BuildArgs = append(cfg.BuildArgs, arg)
cfg.BuildArgs = append(cfg.BuildArgs, arg)
}
}
}

Expand Down
9 changes: 9 additions & 0 deletions task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,15 @@ func (s *TaskSuite) TestBuildArgsFile() {
s.NoError(err)
}

func (s *TaskSuite) TestBuildArgsYamlFile() {
s.req.Config.ContextDir = "testdata/build-args"
s.req.Config.BuildArgsFile = "testdata/build-args/build_args_file.yaml"

// the Dockerfile itself asserts that the arg has been received
_, err := s.build()
s.NoError(err)
}

func (s *TaskSuite) TestBuildArgsStaticAndFile() {
s.req.Config.ContextDir = "testdata/build-args"
s.req.Config.BuildArgs = []string{"some_arg=some_value"}
Expand Down
2 changes: 2 additions & 0 deletions testdata/build-args/build_args_file.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
some_arg: some_value
some_other_arg: some_other_value