Skip to content

Commit

Permalink
builder: validate buildkit configuration
Browse files Browse the repository at this point in the history
Signed-off-by: CrazyMax <[email protected]>
  • Loading branch information
crazy-max committed Dec 16, 2024
1 parent 695200c commit 861f42a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
25 changes: 20 additions & 5 deletions builder/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,24 @@ func TestCsvToMap(t *testing.T) {
}

func TestParseBuildkitdFlags(t *testing.T) {
buildkitdConf := `
dirConf := t.TempDir()

buildkitdConfPath := path.Join(dirConf, "buildkitd-conf.toml")
require.NoError(t, os.WriteFile(buildkitdConfPath, []byte(`
# debug enables additional debug logging
debug = true
# insecure-entitlements allows insecure entitlements, disabled by default.
insecure-entitlements = [ "network.host", "security.insecure" ]
[log]
# log formatter: json or text
format = "text"
`
dirConf := t.TempDir()
buildkitdConfPath := path.Join(dirConf, "buildkitd-conf.toml")
require.NoError(t, os.WriteFile(buildkitdConfPath, []byte(buildkitdConf), 0644))
`), 0644))

buildkitdConfBrokenPath := path.Join(dirConf, "buildkitd-conf-broken.toml")
require.NoError(t, os.WriteFile(buildkitdConfBrokenPath, []byte(`
[worker.oci]
gc = "maybe"
`), 0644))

testCases := []struct {
name string
Expand Down Expand Up @@ -157,6 +163,15 @@ insecure-entitlements = [ "network.host", "security.insecure" ]
nil,
true,
},
{
"error parsing buildkit config",
"",
"docker-container",
nil,
buildkitdConfBrokenPath,
nil,
true,
},
}
for _, tt := range testCases {
tt := tt
Expand Down
7 changes: 6 additions & 1 deletion util/confutil/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/docker/cli/cli/command"
"github.com/docker/docker/pkg/ioutils"
"github.com/moby/buildkit/cmd/buildkitd/config"
"github.com/pelletier/go-toml"
"github.com/pkg/errors"
fs "github.com/tonistiigi/fsutil/copy"
Expand Down Expand Up @@ -151,7 +152,11 @@ func LoadConfigTree(fp string) (*toml.Tree, error) {
defer f.Close()
t, err := toml.LoadReader(f)
if err != nil {
return t, errors.Wrap(err, "failed to parse config")
return t, errors.Wrap(err, "failed to parse buildkit config")
}
var bkcfg config.Config
if err = t.Unmarshal(&bkcfg); err != nil {
return t, errors.Wrap(err, "failed to parse buildkit config")
}
return t, nil
}

0 comments on commit 861f42a

Please sign in to comment.