mirror of https://github.com/docker/buildx.git
inspect: display buildkit daemon configuration file
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
This commit is contained in:
parent
40f444f4b8
commit
528181c759
|
@ -126,6 +126,12 @@ func runInspect(ctx context.Context, dockerCli command.Cli, in inspectOptions) e
|
||||||
fmt.Fprintf(w, "\tKeep Bytes:\t%s\n", units.BytesSize(float64(rule.KeepBytes)))
|
fmt.Fprintf(w, "\tKeep Bytes:\t%s\n", units.BytesSize(float64(rule.KeepBytes)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for f, dt := range nodes[i].Files {
|
||||||
|
fmt.Fprintf(w, "File#%s:\n", f)
|
||||||
|
for _, line := range strings.Split(string(dt), "\n") {
|
||||||
|
fmt.Fprintf(w, "\t> %s\n", line)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
package tests
|
package tests
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
|
"path"
|
||||||
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
@ -19,6 +22,7 @@ var inspectTests = []func(t *testing.T, sb integration.Sandbox){
|
||||||
testInspect,
|
testInspect,
|
||||||
testInspectBuildkitdFlags,
|
testInspectBuildkitdFlags,
|
||||||
testInspectNetworkHostEntitlement,
|
testInspectNetworkHostEntitlement,
|
||||||
|
testInspectBuildkitdConf,
|
||||||
}
|
}
|
||||||
|
|
||||||
func testInspect(t *testing.T, sb integration.Sandbox) {
|
func testInspect(t *testing.T, sb integration.Sandbox) {
|
||||||
|
@ -109,3 +113,68 @@ func testInspectNetworkHostEntitlement(t *testing.T, sb integration.Sandbox) {
|
||||||
}
|
}
|
||||||
require.Fail(t, "network.host insecure entitlement not found in inspect output")
|
require.Fail(t, "network.host insecure entitlement not found in inspect output")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testInspectBuildkitdConf(t *testing.T, sb integration.Sandbox) {
|
||||||
|
if !isDockerContainerWorker(sb) {
|
||||||
|
t.Skip("only testing with docker-container worker")
|
||||||
|
}
|
||||||
|
|
||||||
|
buildkitdConf := `
|
||||||
|
# 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"
|
||||||
|
`
|
||||||
|
|
||||||
|
expectedContent := `debug = true
|
||||||
|
insecure-entitlements = ["network.host", "security.insecure"]
|
||||||
|
|
||||||
|
[log]
|
||||||
|
format = "text"
|
||||||
|
`
|
||||||
|
|
||||||
|
var builderName string
|
||||||
|
t.Cleanup(func() {
|
||||||
|
if builderName == "" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
out, err := rmCmd(sb, withArgs(builderName))
|
||||||
|
require.NoError(t, err, out)
|
||||||
|
})
|
||||||
|
|
||||||
|
dirConf := t.TempDir()
|
||||||
|
buildkitdConfPath := path.Join(dirConf, "buildkitd-conf.toml")
|
||||||
|
require.NoError(t, os.WriteFile(buildkitdConfPath, []byte(buildkitdConf), 0644))
|
||||||
|
|
||||||
|
out, err := createCmd(sb, withArgs("--driver", "docker-container", "--buildkitd-config="+buildkitdConfPath))
|
||||||
|
require.NoError(t, err, out)
|
||||||
|
builderName = strings.TrimSpace(out)
|
||||||
|
|
||||||
|
out, err = inspectCmd(sb, withArgs(builderName))
|
||||||
|
require.NoError(t, err, out)
|
||||||
|
|
||||||
|
var fileLines []string
|
||||||
|
var fileFound bool
|
||||||
|
var reConfLine = regexp.MustCompile(`^[\s\t]*>\s(.*)`)
|
||||||
|
for _, line := range strings.Split(out, "\n") {
|
||||||
|
if strings.HasPrefix(line, "File#buildkitd.toml:") {
|
||||||
|
fileFound = true
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if fileFound {
|
||||||
|
if matches := reConfLine.FindStringSubmatch(line); len(matches) > 1 {
|
||||||
|
fileLines = append(fileLines, matches[1])
|
||||||
|
} else {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !fileFound {
|
||||||
|
require.Fail(t, "File#buildkitd.toml not found in inspect output")
|
||||||
|
}
|
||||||
|
require.Equal(t, expectedContent, strings.Join(fileLines, "\n"), "File#buildkitd.toml content mismatch")
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue