Skip to content

Commit c0b6de3

Browse files
authored
Merge pull request moby#3472 from zwpaper/dev-nerdctl
feat: add namespace support for nerdctl container
2 parents 5ab03b4 + 7533a10 commit c0b6de3

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

client/connhelper/nerdctlcontainer/nerdctlcontainer.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,30 @@ func Helper(u *url.URL) (*connhelper.ConnectionHelper, error) {
2525
return &connhelper.ConnectionHelper{
2626
ContextDialer: func(ctx context.Context, addr string) (net.Conn, error) {
2727
// using background context because context remains active for the duration of the process, after dial has completed
28-
return commandconn.New(context.Background(), "nerdctl", []string{"exec", "-i", sp.Container, "buildctl", "dial-stdio"}...)
28+
args := []string{"exec"}
29+
if sp.Namespace != "" {
30+
args = append(args, "--namespace", sp.Namespace)
31+
}
32+
args = append(args, "-i", sp.Container, "buildctl", "dial-stdio")
33+
return commandconn.New(context.Background(), "nerdctl", args...)
2934
},
3035
}, nil
3136
}
3237

3338
// Spec
3439
type Spec struct {
3540
Container string
41+
Namespace string
3642
}
3743

3844
// SpecFromURL creates Spec from URL.
39-
// URL is like nerdctl-container://<container>
45+
// URL is like nerdctl-container://<container>?namespace=<namespace>
4046
// Only <container> part is mandatory.
4147
func SpecFromURL(u *url.URL) (*Spec, error) {
48+
q := u.Query()
4249
sp := Spec{
4350
Container: u.Hostname(),
51+
Namespace: q.Get("namespace"),
4452
}
4553
if sp.Container == "" {
4654
return nil, errors.New("url lacks container name")

cmd/buildctl/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
_ "github.com/moby/buildkit/client/connhelper/dockercontainer"
88
_ "github.com/moby/buildkit/client/connhelper/kubepod"
9+
_ "github.com/moby/buildkit/client/connhelper/nerdctlcontainer"
910
_ "github.com/moby/buildkit/client/connhelper/podmancontainer"
1011
_ "github.com/moby/buildkit/client/connhelper/ssh"
1112
bccommon "github.com/moby/buildkit/cmd/buildctl/common"

0 commit comments

Comments
 (0)