From 3751bb6d79f2121eea4b0328c15de4d15ca4d760 Mon Sep 17 00:00:00 2001 From: Paul Gaiduk Date: Thu, 12 Mar 2026 20:28:03 +0100 Subject: [PATCH] pkg build: fix builder config and certs not copied into new containers LoadConfigFiles() was only called inside the container-inspect block, so filesToLoadIntoContainer was never populated when no builder container existed yet. The subsequent copyFilesToContainer() call received a nil map, sending an empty tar archive and leaving /etc/buildkit/ empty inside the newly created container. Move the LoadConfigFiles() call before the inspect check so the config and certificate data is always available when creating a fresh builder. Co-Authored-By: Claude Signed-off-by: Paul Gaiduk --- src/cmd/linuxkit/pkglib/dockerimpl.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/cmd/linuxkit/pkglib/dockerimpl.go b/src/cmd/linuxkit/pkglib/dockerimpl.go index dfead49c2..f943c696d 100644 --- a/src/cmd/linuxkit/pkglib/dockerimpl.go +++ b/src/cmd/linuxkit/pkglib/dockerimpl.go @@ -295,7 +295,16 @@ func (dr *dockerRunnerImpl) builderEnsureContainer(ctx context.Context, name, im for range buildKitCheckRetryCount { var b bytes.Buffer var cid string + // load config files up front so they are available both when checking + // an existing container and when creating a brand-new one var filesToLoadIntoContainer map[string][]byte + if configPath != "" { + var err error + filesToLoadIntoContainer, err = confutil.LoadConfigFiles(configPath) + if err != nil { + return nil, fmt.Errorf("failed to load buildkit config file %s: %v", configPath, err) + } + } if err := dr.command(nil, &b, io.Discard, "--context", dockerContext, "container", "inspect", name); err == nil { // we already have a container named "linuxkit-builder" in the provided context. // get its state and config @@ -315,12 +324,6 @@ func (dr *dockerRunnerImpl) builderEnsureContainer(ctx context.Context, name, im log.Debugf("checking if configPath %s is correct in container %s", configPath, name) configPathCorrect = false var configB bytes.Buffer - // we cannot exactly use the local config file, as it gets modified to get loaded into the container - // so we preprocess it using the same library that would load it up - filesToLoadIntoContainer, err = confutil.LoadConfigFiles(configPath) - if err != nil { - return nil, fmt.Errorf("failed to load buildkit config file %s: %v", configPath, err) - } if err := dr.command(nil, &configB, io.Discard, "--context", dockerContext, "container", "exec", name, "cat", buildkitConfigPath); err == nil { // sha256sum the config file to see if it matches the provided configPath containerConfigFileHash := sha256.Sum256(configB.Bytes())