mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-05-18 00:47:48 +08:00
Merge pull request #2864 from crazy-max/builder-validate-config
builder: validate buildkit configuration
This commit is contained in:
commit
38b71998f5
@ -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,18 @@ 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))
|
||||
|
||||
buildkitdConfUnknownFieldPath := path.Join(dirConf, "buildkitd-unknown-field.toml")
|
||||
require.NoError(t, os.WriteFile(buildkitdConfUnknownFieldPath, []byte(`
|
||||
foo = "bar"
|
||||
`), 0644))
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
@ -157,6 +168,26 @@ insecure-entitlements = [ "network.host", "security.insecure" ]
|
||||
nil,
|
||||
true,
|
||||
},
|
||||
{
|
||||
"error parsing buildkit config",
|
||||
"",
|
||||
"docker-container",
|
||||
nil,
|
||||
buildkitdConfBrokenPath,
|
||||
nil,
|
||||
true,
|
||||
},
|
||||
{
|
||||
"unknown field in buildkit config",
|
||||
"",
|
||||
"docker-container",
|
||||
nil,
|
||||
buildkitdConfUnknownFieldPath,
|
||||
[]string{
|
||||
"--allow-insecure-entitlement=network.host",
|
||||
},
|
||||
false,
|
||||
},
|
||||
}
|
||||
for _, tt := range testCases {
|
||||
tt := tt
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user