mirror of
https://github.com/moby/buildkit.git
synced 2026-08-06 07:40:49 +00:00
feat: add namespace support for nerdctl container
Signed-off-by: Wei Zhang <kweizh@gmail.com>
This commit is contained in:
@@ -25,7 +25,12 @@ func Helper(u *url.URL) (*connhelper.ConnectionHelper, error) {
|
||||
return &connhelper.ConnectionHelper{
|
||||
ContextDialer: func(ctx context.Context, addr string) (net.Conn, error) {
|
||||
// using background context because context remains active for the duration of the process, after dial has completed
|
||||
return commandconn.New(context.Background(), "nerdctl", []string{"exec", "-i", sp.Container, "buildctl", "dial-stdio"}...)
|
||||
args := []string{"exec"}
|
||||
if sp.Namespace != "" {
|
||||
args = append(args, "--namespace", sp.Namespace)
|
||||
}
|
||||
args = append(args, "-i", sp.Container, "buildctl", "dial-stdio")
|
||||
return commandconn.New(context.Background(), "nerdctl", args...)
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
@@ -33,14 +38,17 @@ func Helper(u *url.URL) (*connhelper.ConnectionHelper, error) {
|
||||
// Spec
|
||||
type Spec struct {
|
||||
Container string
|
||||
Namespace string
|
||||
}
|
||||
|
||||
// SpecFromURL creates Spec from URL.
|
||||
// URL is like nerdctl-container://<container>
|
||||
// URL is like nerdctl-container://<container>?namespace=<namespace>
|
||||
// Only <container> part is mandatory.
|
||||
func SpecFromURL(u *url.URL) (*Spec, error) {
|
||||
q := u.Query()
|
||||
sp := Spec{
|
||||
Container: u.Hostname(),
|
||||
Namespace: q.Get("namespace"),
|
||||
}
|
||||
if sp.Container == "" {
|
||||
return nil, errors.New("url lacks container name")
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
|
||||
_ "github.com/moby/buildkit/client/connhelper/dockercontainer"
|
||||
_ "github.com/moby/buildkit/client/connhelper/kubepod"
|
||||
_ "github.com/moby/buildkit/client/connhelper/nerdctlcontainer"
|
||||
_ "github.com/moby/buildkit/client/connhelper/podmancontainer"
|
||||
_ "github.com/moby/buildkit/client/connhelper/ssh"
|
||||
bccommon "github.com/moby/buildkit/cmd/buildctl/common"
|
||||
|
||||
Reference in New Issue
Block a user