Skip to content

Commit 3751bb6

Browse files
committed
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 <noreply@anthropic.com> Signed-off-by: Paul Gaiduk <paulg@zededa.com>
1 parent bdef7e8 commit 3751bb6

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

src/cmd/linuxkit/pkglib/dockerimpl.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,16 @@ func (dr *dockerRunnerImpl) builderEnsureContainer(ctx context.Context, name, im
295295
for range buildKitCheckRetryCount {
296296
var b bytes.Buffer
297297
var cid string
298+
// load config files up front so they are available both when checking
299+
// an existing container and when creating a brand-new one
298300
var filesToLoadIntoContainer map[string][]byte
301+
if configPath != "" {
302+
var err error
303+
filesToLoadIntoContainer, err = confutil.LoadConfigFiles(configPath)
304+
if err != nil {
305+
return nil, fmt.Errorf("failed to load buildkit config file %s: %v", configPath, err)
306+
}
307+
}
299308
if err := dr.command(nil, &b, io.Discard, "--context", dockerContext, "container", "inspect", name); err == nil {
300309
// we already have a container named "linuxkit-builder" in the provided context.
301310
// get its state and config
@@ -315,12 +324,6 @@ func (dr *dockerRunnerImpl) builderEnsureContainer(ctx context.Context, name, im
315324
log.Debugf("checking if configPath %s is correct in container %s", configPath, name)
316325
configPathCorrect = false
317326
var configB bytes.Buffer
318-
// we cannot exactly use the local config file, as it gets modified to get loaded into the container
319-
// so we preprocess it using the same library that would load it up
320-
filesToLoadIntoContainer, err = confutil.LoadConfigFiles(configPath)
321-
if err != nil {
322-
return nil, fmt.Errorf("failed to load buildkit config file %s: %v", configPath, err)
323-
}
324327
if err := dr.command(nil, &configB, io.Discard, "--context", dockerContext, "container", "exec", name, "cat", buildkitConfigPath); err == nil {
325328
// sha256sum the config file to see if it matches the provided configPath
326329
containerConfigFileHash := sha256.Sum256(configB.Bytes())

0 commit comments

Comments
 (0)