fix when --config provided, don't need Image/RootFS
Signed-off-by: Lifubang <lifubang@aliyun.com>
This commit is contained in:
		@@ -53,11 +53,22 @@ var createCommand = cli.Command{
 | 
				
			|||||||
	Flags:     append(commands.SnapshotterFlags, commands.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     string
 | 
				
			||||||
			ref = context.Args().First()
 | 
								ref    string
 | 
				
			||||||
 | 
								config = context.IsSet("config")
 | 
				
			||||||
		)
 | 
							)
 | 
				
			||||||
		if ref == "" {
 | 
					
 | 
				
			||||||
			return errors.New("image ref must be provided")
 | 
							if config {
 | 
				
			||||||
 | 
								id = context.Args().First()
 | 
				
			||||||
 | 
								if context.NArg() > 1 {
 | 
				
			||||||
 | 
									return errors.New("with spec config file, only container id should be provided")
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								id = context.Args().Get(1)
 | 
				
			||||||
 | 
								ref = context.Args().First()
 | 
				
			||||||
 | 
								if ref == "" {
 | 
				
			||||||
 | 
									return errors.New("image ref must be provided")
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if id == "" {
 | 
							if id == "" {
 | 
				
			||||||
			return errors.New("container id must be provided")
 | 
								return errors.New("container id must be provided")
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -110,15 +110,26 @@ var Command = cli.Command{
 | 
				
			|||||||
	Action: func(context *cli.Context) error {
 | 
						Action: func(context *cli.Context) error {
 | 
				
			||||||
		var (
 | 
							var (
 | 
				
			||||||
			err error
 | 
								err error
 | 
				
			||||||
 | 
								id  string
 | 
				
			||||||
 | 
								ref string
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			id     = context.Args().Get(1)
 | 
					 | 
				
			||||||
			ref    = context.Args().First()
 | 
					 | 
				
			||||||
			tty    = context.Bool("tty")
 | 
								tty    = context.Bool("tty")
 | 
				
			||||||
			detach = context.Bool("detach")
 | 
								detach = context.Bool("detach")
 | 
				
			||||||
 | 
								config = context.IsSet("config")
 | 
				
			||||||
		)
 | 
							)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if ref == "" {
 | 
							if config {
 | 
				
			||||||
			return errors.New("image ref must be provided")
 | 
								id = context.Args().First()
 | 
				
			||||||
 | 
								if context.NArg() > 1 {
 | 
				
			||||||
 | 
									return errors.New("with spec config file, only container id should be provided")
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								id = context.Args().Get(1)
 | 
				
			||||||
 | 
								ref = context.Args().First()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								if ref == "" {
 | 
				
			||||||
 | 
									return errors.New("image ref must be provided")
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if id == "" {
 | 
							if id == "" {
 | 
				
			||||||
			return errors.New("container id must be provided")
 | 
								return errors.New("container id must be provided")
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -34,10 +34,14 @@ import (
 | 
				
			|||||||
// 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 (
 | 
				
			||||||
		ref  = context.Args().First()
 | 
							id     string
 | 
				
			||||||
		id   = context.Args().Get(1)
 | 
							Config = context.IsSet("config")
 | 
				
			||||||
		args = context.Args()[2:]
 | 
					 | 
				
			||||||
	)
 | 
						)
 | 
				
			||||||
 | 
						if Config {
 | 
				
			||||||
 | 
							id = context.Args().First()
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							id = context.Args().Get(1)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if raw := context.String("checkpoint"); raw != "" {
 | 
						if raw := context.String("checkpoint"); raw != "" {
 | 
				
			||||||
		im, err := client.GetImage(ctx, raw)
 | 
							im, err := client.GetImage(ctx, raw)
 | 
				
			||||||
@@ -53,9 +57,14 @@ func NewContainer(ctx gocontext.Context, client *containerd.Client, context *cli
 | 
				
			|||||||
		spec  containerd.NewContainerOpts
 | 
							spec  containerd.NewContainerOpts
 | 
				
			||||||
	)
 | 
						)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if context.IsSet("config") {
 | 
						if Config {
 | 
				
			||||||
		opts = append(opts, oci.WithSpecFromFile(context.String("config")))
 | 
							opts = append(opts, oci.WithSpecFromFile(context.String("config")))
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
 | 
							var (
 | 
				
			||||||
 | 
								ref = context.Args().First()
 | 
				
			||||||
 | 
								//for container's id is Args[1]
 | 
				
			||||||
 | 
								args = context.Args()[2:]
 | 
				
			||||||
 | 
							)
 | 
				
			||||||
		opts = append(opts, oci.WithDefaultSpec(), oci.WithDefaultUnixDevices)
 | 
							opts = append(opts, oci.WithDefaultSpec(), oci.WithDefaultUnixDevices)
 | 
				
			||||||
		opts = append(opts, oci.WithEnv(context.StringSlice("env")))
 | 
							opts = append(opts, oci.WithEnv(context.StringSlice("env")))
 | 
				
			||||||
		opts = append(opts, withMounts(context))
 | 
							opts = append(opts, withMounts(context))
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user