Skip to content

Commit

Permalink
inspect: display buildkit daemon configuration file
Browse files Browse the repository at this point in the history
Signed-off-by: CrazyMax <[email protected]>
  • Loading branch information
crazy-max committed Sep 11, 2024
1 parent 40f444f commit 0b94e96
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
8 changes: 8 additions & 0 deletions commands/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,14 @@ func runInspect(ctx context.Context, dockerCli command.Cli, in inspectOptions) e
fmt.Fprintf(w, "\tKeep Bytes:\t%s\n", units.BytesSize(float64(rule.KeepBytes)))
}
}
if debug.IsEnabled() {
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)
}
}
}
}
}
}
Expand Down
68 changes: 68 additions & 0 deletions tests/inspect.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package tests

import (
"os"
"path"
"strings"
"testing"

Expand All @@ -19,6 +21,7 @@ var inspectTests = []func(t *testing.T, sb integration.Sandbox){
testInspect,
testInspectBuildkitdFlags,
testInspectNetworkHostEntitlement,
testInspectBuildkitdConf,
}

func testInspect(t *testing.T, sb integration.Sandbox) {
Expand Down Expand Up @@ -109,3 +112,68 @@ func testInspectNetworkHostEntitlement(t *testing.T, sb integration.Sandbox) {
}
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, "--debug"))
require.NoError(t, err, out)

var fileContent string
var foundFile bool
for _, line := range strings.Split(out, "\n") {
if strings.HasPrefix(line, "File#buildkitd.toml:") {
foundFile = true
continue
}
if foundFile {
line = strings.TrimSpace(line)
if strings.HasPrefix(line, ">") {
fileContent += strings.TrimPrefix(strings.TrimPrefix(line, ">"), "> ") + "\n"
} else {
break
}
}
}
if !foundFile {
require.Fail(t, "File#buildkitd.toml not found in inspect output")
}
require.Equal(t, expectedContent, fileContent, "File#buildkitd.toml content mismatch")
}

0 comments on commit 0b94e96

Please sign in to comment.