Skip to content

Commit

Permalink
driver: docker-container driver uses --config correctly in rootless mode
Browse files Browse the repository at this point in the history
The `docker-container` driver relies on the default config file location
for buildkit when writing the configuration file. When run in a rootless
version of docker (dind), the default location is different.

Instead of trying to figure out where the appropriate default location
is, this just writes the files to the same location and sets the
`--config` parameter explicitly. This flag is placed first so a
user-specified config option in `--buildkitd-flags` will take precedence
over the implicit config parameter.

Signed-off-by: Jonathan A. Sternberg <[email protected]>
  • Loading branch information
jsternberg committed Oct 20, 2023
1 parent 48f9b86 commit a0b218f
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions driver/docker-container/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ import (
)

const (
volumeStateSuffix = "_state"
volumeStateSuffix = "_state"
buildkitdConfigFile = "buildkitd.toml"
)

type Driver struct {
Expand Down Expand Up @@ -114,9 +115,7 @@ func (d *Driver) create(ctx context.Context, l progress.SubLogger) error {
Image: imageName,
Env: d.env,
}
if d.InitConfig.BuildkitFlags != nil {
cfg.Cmd = d.InitConfig.BuildkitFlags
}
cfg.Cmd = getBuildkitFlags(d.InitConfig)

useInit := true // let it cleanup exited processes created by BuildKit's container API
if err := l.Wrap("creating container "+d.Name, func() error {
Expand Down Expand Up @@ -487,3 +486,14 @@ func writeConfigFiles(m map[string][]byte) (_ string, err error) {
}
return tmpDir, nil
}

func getBuildkitFlags(initConfig driver.InitConfig) []string {
flags := initConfig.BuildkitFlags
if _, ok := initConfig.Files[buildkitdConfigFile]; ok {
// Be explicit with the config file if it exists.
newFlags := make([]string, 0, len(flags)+2)
newFlags = append(newFlags, "--config", path.Join("/etc/buildkit", buildkitdConfigFile))
flags = append(newFlags, flags...)
}
return flags
}

0 comments on commit a0b218f

Please sign in to comment.