Skip to content

Commit

Permalink
containerd: support custom shim path
Browse files Browse the repository at this point in the history
Like CRI, we should support custom shim paths. We can just add this as a
new config field "path" under the runtime object.

While "name" can be either the name of a custom shim (from which a path
is derived), or a path itself, if configured as a path, no options can
be provided - this is because to derive the type for the options struct,
we need the name to be a member of a well-known set (currently runc and
hcs).

With this patch, it's now possible to configure a runtime with a custom
shim at a non-default path, and include it's options (which was
previously not possible to do in buildkit).

Signed-off-by: Justin Chadwell <me@jedevc.com>
  • Loading branch information
jedevc committed Nov 7, 2023
1 parent 116d015 commit 148e1ea
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/buildkitd/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ type ContainerdConfig struct {

type ContainerdRuntime struct {
Name string `toml:"name"`
Path string `toml:"path"`
Options map[string]interface{} `toml:"options"`
}

Expand Down
2 changes: 2 additions & 0 deletions cmd/buildkitd/config/load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ platforms=["linux/amd64"]
address="containerd.sock"
[worker.containerd.runtime]
name="exotic"
path="/usr/bin/exotic"
options.foo="bar"
[[worker.containerd.gcpolicy]]
all=true
Expand Down Expand Up @@ -107,6 +108,7 @@ searchDomains=["example.com"]
require.Equal(t, 0, len(cfg.Workers.OCI.GCPolicy))
require.Equal(t, "non-default", cfg.Workers.Containerd.Namespace)
require.Equal(t, "exotic", cfg.Workers.Containerd.Runtime.Name)
require.Equal(t, "/usr/bin/exotic", cfg.Workers.Containerd.Runtime.Path)
require.Equal(t, "bar", cfg.Workers.Containerd.Runtime.Options["foo"])
require.Equal(t, 3, len(cfg.Workers.Containerd.GCPolicy))

Expand Down
1 change: 1 addition & 0 deletions cmd/buildkitd/main_containerd_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ func containerdWorkerInitializer(c *cli.Context, common workerInitializerOpt) ([

runtime = &containerd.RuntimeInfo{
Name: cfg.Runtime.Name,
Path: cfg.Runtime.Path,
Options: opts,
}
}
Expand Down
1 change: 1 addition & 0 deletions docs/buildkitd.toml.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ insecure-entitlements = [ "network.host", "security.insecure" ]
# configure the containerd runtime
[worker.containerd.runtime]
name = "io.containerd.runc.v2"
path = "/path/to/containerd/runc/shim"
options = { BinaryName = "runc" }

[[worker.containerd.gcpolicy]]
Expand Down
4 changes: 4 additions & 0 deletions executor/containerdexecutor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ type OnCreateRuntimer interface {

type RuntimeInfo struct {
Name string
Path string
Options any
}

Expand Down Expand Up @@ -179,6 +180,9 @@ func (w *containerdExecutor) Run(ctx context.Context, id string, root executor.M
if err != nil {
return nil, err
}
if w.runtime != nil && w.runtime.Path != "" {
taskOpts = append(taskOpts, containerd.WithRuntimePath(w.runtime.Path))
}
task, err := container.NewTask(ctx, cio.NewCreator(cioOpts...), taskOpts...)
if err != nil {
return nil, err
Expand Down

0 comments on commit 148e1ea

Please sign in to comment.