mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-05-18 00:47:48 +08:00
builder: validate buildkit configuration
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
This commit is contained in:
parent
f3f5e760b3
commit
07db2be2f0
@ -29,7 +29,10 @@ func TestCsvToMap(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestParseBuildkitdFlags(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 enables additional debug logging
|
||||||
debug = true
|
debug = true
|
||||||
# insecure-entitlements allows insecure entitlements, disabled by default.
|
# insecure-entitlements allows insecure entitlements, disabled by default.
|
||||||
@ -37,10 +40,18 @@ insecure-entitlements = [ "network.host", "security.insecure" ]
|
|||||||
[log]
|
[log]
|
||||||
# log formatter: json or text
|
# log formatter: json or text
|
||||||
format = "text"
|
format = "text"
|
||||||
`
|
`), 0644))
|
||||||
dirConf := t.TempDir()
|
|
||||||
buildkitdConfPath := path.Join(dirConf, "buildkitd-conf.toml")
|
buildkitdConfBrokenPath := path.Join(dirConf, "buildkitd-conf-broken.toml")
|
||||||
require.NoError(t, os.WriteFile(buildkitdConfPath, []byte(buildkitdConf), 0644))
|
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 {
|
testCases := []struct {
|
||||||
name string
|
name string
|
||||||
@ -157,6 +168,26 @@ insecure-entitlements = [ "network.host", "security.insecure" ]
|
|||||||
nil,
|
nil,
|
||||||
true,
|
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 {
|
for _, tt := range testCases {
|
||||||
tt := tt
|
tt := tt
|
||||||
|
@ -9,6 +9,7 @@ import (
|
|||||||
|
|
||||||
"github.com/docker/cli/cli/command"
|
"github.com/docker/cli/cli/command"
|
||||||
"github.com/docker/docker/pkg/ioutils"
|
"github.com/docker/docker/pkg/ioutils"
|
||||||
|
"github.com/moby/buildkit/cmd/buildkitd/config"
|
||||||
"github.com/pelletier/go-toml"
|
"github.com/pelletier/go-toml"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
fs "github.com/tonistiigi/fsutil/copy"
|
fs "github.com/tonistiigi/fsutil/copy"
|
||||||
@ -151,7 +152,11 @@ func LoadConfigTree(fp string) (*toml.Tree, error) {
|
|||||||
defer f.Close()
|
defer f.Close()
|
||||||
t, err := toml.LoadReader(f)
|
t, err := toml.LoadReader(f)
|
||||||
if err != nil {
|
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
|
return t, nil
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user