diff --git a/builder/builder_test.go b/builder/builder_test.go index 130a4a01df7..669574b826f 100644 --- a/builder/builder_test.go +++ b/builder/builder_test.go @@ -29,7 +29,10 @@ 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. @@ -37,10 +40,13 @@ 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 @@ -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 diff --git a/util/confutil/config.go b/util/confutil/config.go index c3814c22ee2..ebd42b2a278 100644 --- a/util/confutil/config.go +++ b/util/confutil/config.go @@ -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" @@ -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 }