Merge pull request #2411 from flx42/move-containerflags
Move ContainerFlags to "commands" package
This commit is contained in:
commit
1ac546b3c4
@ -21,6 +21,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/containerd/containerd"
|
"github.com/containerd/containerd"
|
||||||
@ -63,6 +64,67 @@ var (
|
|||||||
Usage: "refresh token for authorization server",
|
Usage: "refresh token for authorization server",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ContainerFlags are cli flags specifying container options
|
||||||
|
ContainerFlags = []cli.Flag{
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "config,c",
|
||||||
|
Usage: "path to the runtime-specific spec config file",
|
||||||
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "checkpoint",
|
||||||
|
Usage: "provide the checkpoint digest to restore the container",
|
||||||
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "cwd",
|
||||||
|
Usage: "specify the working directory of the process",
|
||||||
|
},
|
||||||
|
cli.StringSliceFlag{
|
||||||
|
Name: "env",
|
||||||
|
Usage: "specify additional container environment variables (i.e. FOO=bar)",
|
||||||
|
},
|
||||||
|
cli.StringSliceFlag{
|
||||||
|
Name: "label",
|
||||||
|
Usage: "specify additional labels (i.e. foo=bar)",
|
||||||
|
},
|
||||||
|
cli.StringSliceFlag{
|
||||||
|
Name: "mount",
|
||||||
|
Usage: "specify additional container mount (ex: type=bind,src=/tmp,dst=/host,options=rbind:ro)",
|
||||||
|
},
|
||||||
|
cli.BoolFlag{
|
||||||
|
Name: "net-host",
|
||||||
|
Usage: "enable host networking for the container",
|
||||||
|
},
|
||||||
|
cli.BoolFlag{
|
||||||
|
Name: "privileged",
|
||||||
|
Usage: "run privileged container",
|
||||||
|
},
|
||||||
|
cli.BoolFlag{
|
||||||
|
Name: "read-only",
|
||||||
|
Usage: "set the containers filesystem as readonly",
|
||||||
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "runtime",
|
||||||
|
Usage: "runtime name (io.containerd.runtime.v1.linux, io.containerd.runtime.v1.windows, io.containerd.runtime.v1.com.vmware.linux)",
|
||||||
|
Value: fmt.Sprintf("io.containerd.runtime.v1.%s", runtime.GOOS),
|
||||||
|
},
|
||||||
|
cli.BoolFlag{
|
||||||
|
Name: "tty,t",
|
||||||
|
Usage: "allocate a TTY for the container",
|
||||||
|
},
|
||||||
|
cli.StringSliceFlag{
|
||||||
|
Name: "with-ns",
|
||||||
|
Usage: "specify existing Linux namespaces to join at container runtime (format '<nstype>:<path>')",
|
||||||
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "pid-file",
|
||||||
|
Usage: "file path to write the task's pid",
|
||||||
|
},
|
||||||
|
cli.IntFlag{
|
||||||
|
Name: "gpus",
|
||||||
|
Usage: "add gpus to the container",
|
||||||
|
},
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
// ObjectWithLabelArgs returns the first arg and a LabelArgs object
|
// ObjectWithLabelArgs returns the first arg and a LabelArgs object
|
||||||
|
33
cmd/ctr/commands/commands_unix.go
Normal file
33
cmd/ctr/commands/commands_unix.go
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
// +build !windows
|
||||||
|
|
||||||
|
/*
|
||||||
|
Copyright The containerd Authors.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package commands
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/urfave/cli"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
ContainerFlags = append(ContainerFlags, cli.BoolFlag{
|
||||||
|
Name: "rootfs",
|
||||||
|
Usage: "use custom rootfs that is not managed by containerd snapshotter",
|
||||||
|
}, cli.BoolFlag{
|
||||||
|
Name: "no-pivot",
|
||||||
|
Usage: "disable use of pivot-root (linux only)",
|
||||||
|
})
|
||||||
|
}
|
@ -49,7 +49,7 @@ var createCommand = cli.Command{
|
|||||||
Name: "create",
|
Name: "create",
|
||||||
Usage: "create container",
|
Usage: "create container",
|
||||||
ArgsUsage: "[flags] Image|RootFS CONTAINER",
|
ArgsUsage: "[flags] Image|RootFS CONTAINER",
|
||||||
Flags: append(commands.SnapshotterFlags, run.ContainerFlags...),
|
Flags: append(commands.SnapshotterFlags, commands.ContainerFlags...),
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(context *cli.Context) error {
|
||||||
var (
|
var (
|
||||||
id = context.Args().Get(1)
|
id = context.Args().Get(1)
|
||||||
|
@ -22,7 +22,6 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"runtime"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/containerd/console"
|
"github.com/containerd/console"
|
||||||
@ -38,67 +37,6 @@ import (
|
|||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ContainerFlags are cli flags specifying container options
|
|
||||||
var ContainerFlags = []cli.Flag{
|
|
||||||
cli.StringFlag{
|
|
||||||
Name: "config,c",
|
|
||||||
Usage: "path to the runtime-specific spec config file",
|
|
||||||
},
|
|
||||||
cli.StringFlag{
|
|
||||||
Name: "checkpoint",
|
|
||||||
Usage: "provide the checkpoint digest to restore the container",
|
|
||||||
},
|
|
||||||
cli.StringFlag{
|
|
||||||
Name: "cwd",
|
|
||||||
Usage: "specify the working directory of the process",
|
|
||||||
},
|
|
||||||
cli.StringSliceFlag{
|
|
||||||
Name: "env",
|
|
||||||
Usage: "specify additional container environment variables (i.e. FOO=bar)",
|
|
||||||
},
|
|
||||||
cli.StringSliceFlag{
|
|
||||||
Name: "label",
|
|
||||||
Usage: "specify additional labels (i.e. foo=bar)",
|
|
||||||
},
|
|
||||||
cli.StringSliceFlag{
|
|
||||||
Name: "mount",
|
|
||||||
Usage: "specify additional container mount (ex: type=bind,src=/tmp,dst=/host,options=rbind:ro)",
|
|
||||||
},
|
|
||||||
cli.BoolFlag{
|
|
||||||
Name: "net-host",
|
|
||||||
Usage: "enable host networking for the container",
|
|
||||||
},
|
|
||||||
cli.BoolFlag{
|
|
||||||
Name: "privileged",
|
|
||||||
Usage: "run privileged container",
|
|
||||||
},
|
|
||||||
cli.BoolFlag{
|
|
||||||
Name: "read-only",
|
|
||||||
Usage: "set the containers filesystem as readonly",
|
|
||||||
},
|
|
||||||
cli.StringFlag{
|
|
||||||
Name: "runtime",
|
|
||||||
Usage: "runtime name (io.containerd.runtime.v1.linux, io.containerd.runtime.v1.windows, io.containerd.runtime.v1.com.vmware.linux)",
|
|
||||||
Value: fmt.Sprintf("io.containerd.runtime.v1.%s", runtime.GOOS),
|
|
||||||
},
|
|
||||||
cli.BoolFlag{
|
|
||||||
Name: "tty,t",
|
|
||||||
Usage: "allocate a TTY for the container",
|
|
||||||
},
|
|
||||||
cli.StringSliceFlag{
|
|
||||||
Name: "with-ns",
|
|
||||||
Usage: "specify existing Linux namespaces to join at container runtime (format '<nstype>:<path>')",
|
|
||||||
},
|
|
||||||
cli.StringFlag{
|
|
||||||
Name: "pid-file",
|
|
||||||
Usage: "file path to write the task's pid",
|
|
||||||
},
|
|
||||||
cli.IntFlag{
|
|
||||||
Name: "gpus",
|
|
||||||
Usage: "add gpus to the container",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
func loadSpec(path string, s *specs.Spec) error {
|
func loadSpec(path string, s *specs.Spec) error {
|
||||||
raw, err := ioutil.ReadFile(path)
|
raw, err := ioutil.ReadFile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -181,7 +119,7 @@ var Command = cli.Command{
|
|||||||
Name: "fifo-dir",
|
Name: "fifo-dir",
|
||||||
Usage: "directory used for storing IO FIFOs",
|
Usage: "directory used for storing IO FIFOs",
|
||||||
},
|
},
|
||||||
}, append(commands.SnapshotterFlags, ContainerFlags...)...),
|
}, append(commands.SnapshotterFlags, commands.ContainerFlags...)...),
|
||||||
Action: func(context *cli.Context) error {
|
Action: func(context *cli.Context) error {
|
||||||
var (
|
var (
|
||||||
err error
|
err error
|
||||||
|
@ -31,16 +31,6 @@ import (
|
|||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
|
||||||
ContainerFlags = append(ContainerFlags, cli.BoolFlag{
|
|
||||||
Name: "rootfs",
|
|
||||||
Usage: "use custom rootfs that is not managed by containerd snapshotter",
|
|
||||||
}, cli.BoolFlag{
|
|
||||||
Name: "no-pivot",
|
|
||||||
Usage: "disable use of pivot-root (linux only)",
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewContainer creates a new container
|
// NewContainer creates a new container
|
||||||
func NewContainer(ctx gocontext.Context, client *containerd.Client, context *cli.Context) (containerd.Container, error) {
|
func NewContainer(ctx gocontext.Context, client *containerd.Client, context *cli.Context) (containerd.Container, error) {
|
||||||
var (
|
var (
|
||||||
|
Loading…
Reference in New Issue
Block a user