diff --git a/cmd/ctr/run.go b/cmd/ctr/run.go index 6e3974eda..1b38b8a57 100644 --- a/cmd/ctr/run.go +++ b/cmd/ctr/run.go @@ -34,6 +34,10 @@ var runCommand = cli.Command{ Name: "tty,t", Usage: "allocate a TTY for the container", }, + cli.StringFlag{ + Name: "rootfs", + Usage: "path to rootfs", + }, cli.StringFlag{ Name: "runtime", Usage: "runtime name (linux, windows, vmware-linux)", @@ -89,7 +93,7 @@ var runCommand = cli.Command{ return errors.Wrap(err, "failed resolving image store") } - if runtime.GOOS != "windows" { + if runtime.GOOS != "windows" && context.String("rootfs") == "" { ref := context.Args().First() image, err := imageStore.Get(ctx, ref) @@ -141,7 +145,7 @@ var runCommand = cli.Command{ // TODO: get the image / rootfs through the API once windows has a snapshotter } - create, err := newCreateRequest(context, &imageConfig.Config, id, tmpDir) + create, err := newCreateRequest(context, &imageConfig.Config, id, tmpDir, context.String("rootfs")) if err != nil { return err } diff --git a/cmd/ctr/run_unix.go b/cmd/ctr/run_unix.go index fc2c91004..51fea5f1d 100644 --- a/cmd/ctr/run_unix.go +++ b/cmd/ctr/run_unix.go @@ -219,7 +219,7 @@ func spec(id string, config *ocispec.ImageConfig, context *cli.Context) (*specs. }, nil } -func customSpec(configPath string) (*specs.Spec, error) { +func customSpec(configPath string, rootfs string) (*specs.Spec, error) { b, err := ioutil.ReadFile(configPath) if err != nil { return nil, err @@ -228,24 +228,28 @@ func customSpec(configPath string) (*specs.Spec, error) { if err := json.Unmarshal(b, &s); err != nil { return nil, err } - if s.Root.Path != rootfsPath { - logrus.Warnf("ignoring Root.Path %q, setting %q forcibly", s.Root.Path, rootfsPath) - s.Root.Path = rootfsPath + if rootfs == "" { + if s.Root.Path != rootfsPath { + logrus.Warnf("ignoring Root.Path %q, setting %q forcibly", s.Root.Path, rootfsPath) + s.Root.Path = rootfsPath + } + } else { + s.Root.Path = rootfs } return &s, nil } -func getConfig(context *cli.Context, imageConfig *ocispec.ImageConfig) (*specs.Spec, error) { +func getConfig(context *cli.Context, imageConfig *ocispec.ImageConfig, rootfs string) (*specs.Spec, error) { config := context.String("runtime-config") if config == "" { return spec(context.String("id"), imageConfig, context) } - return customSpec(config) + return customSpec(config, rootfs) } -func newCreateRequest(context *cli.Context, imageConfig *ocispec.ImageConfig, id, tmpDir string) (*execution.CreateRequest, error) { - s, err := getConfig(context, imageConfig) +func newCreateRequest(context *cli.Context, imageConfig *ocispec.ImageConfig, id, tmpDir string, rootfs string) (*execution.CreateRequest, error) { + s, err := getConfig(context, imageConfig, rootfs) if err != nil { return nil, err } diff --git a/cmd/ctr/run_windows.go b/cmd/ctr/run_windows.go index 2623262dd..27025f4a3 100644 --- a/cmd/ctr/run_windows.go +++ b/cmd/ctr/run_windows.go @@ -85,7 +85,7 @@ func spec(id string, config *ocispec.ImageConfig, context *cli.Context) *specs.S } } -func customSpec(context *cli.Context, configPath string) (*specs.Spec, error) { +func customSpec(context *cli.Context, configPath, rootfs string) (*specs.Spec, error) { b, err := ioutil.ReadFile(configPath) if err != nil { return nil, err @@ -96,7 +96,6 @@ func customSpec(context *cli.Context, configPath string) (*specs.Spec, error) { return nil, err } - rootfs := context.String("rootfs") if rootfs != "" && s.Root.Path != rootfs { logrus.Warnf("ignoring config Root.Path %q, setting %q forcibly", s.Root.Path, rootfs) s.Root.Path = rootfs @@ -104,21 +103,21 @@ func customSpec(context *cli.Context, configPath string) (*specs.Spec, error) { return &s, nil } -func getConfig(context *cli.Context, imageConfig *ocispec.ImageConfig) (*specs.Spec, error) { +func getConfig(context *cli.Context, imageConfig *ocispec.ImageConfig, rootfs string) (*specs.Spec, error) { if config := context.String("runtime-config"); config != "" { - return customSpec(context, config) + return customSpec(context, config, rootfs) } s := spec(context.String("id"), imageConfig, context) - if rootfs := context.String("rootfs"); rootfs != "" { + if rootfs != "" { s.Root.Path = rootfs } return s, nil } -func newCreateRequest(context *cli.Context, imageConfig *ocispec.ImageConfig, id, tmpDir string) (*execution.CreateRequest, error) { - spec, err := getConfig(context, imageConfig) +func newCreateRequest(context *cli.Context, imageConfig *ocispec.ImageConfig, id, tmpDir, rootfs string) (*execution.CreateRequest, error) { + spec, err := getConfig(context, imageConfig, rootfs) if err != nil { return nil, err }