ctr: move unpack to snapshot command
Signed-off-by: Jess Valarezo <valarezo.jessica@gmail.com>
This commit is contained in:
parent
456d3f4475
commit
e4da49c44c
@ -8,9 +8,11 @@ import (
|
|||||||
"text/tabwriter"
|
"text/tabwriter"
|
||||||
|
|
||||||
"github.com/containerd/containerd/cmd/ctr/commands"
|
"github.com/containerd/containerd/cmd/ctr/commands"
|
||||||
|
"github.com/containerd/containerd/log"
|
||||||
"github.com/containerd/containerd/mount"
|
"github.com/containerd/containerd/mount"
|
||||||
"github.com/containerd/containerd/progress"
|
"github.com/containerd/containerd/progress"
|
||||||
"github.com/containerd/containerd/snapshot"
|
"github.com/containerd/containerd/snapshot"
|
||||||
|
digest "github.com/opencontainers/go-digest"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
)
|
)
|
||||||
@ -31,6 +33,7 @@ var Command = cli.Command{
|
|||||||
commitCommand,
|
commitCommand,
|
||||||
infoCommand,
|
infoCommand,
|
||||||
setLabelCommand,
|
setLabelCommand,
|
||||||
|
unpackCommand,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -382,6 +385,49 @@ var setLabelCommand = cli.Command{
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var unpackCommand = cli.Command{
|
||||||
|
Name: "unpack",
|
||||||
|
Usage: "unpack applies layers from a manifest to a snapshot",
|
||||||
|
ArgsUsage: "[flags] <digest>",
|
||||||
|
Flags: commands.SnapshotterFlags,
|
||||||
|
Action: func(context *cli.Context) error {
|
||||||
|
dgst, err := digest.Parse(context.Args().First())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
client, ctx, cancel, err := commands.NewClient(context)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer cancel()
|
||||||
|
log.G(ctx).Debugf("unpacking layers from manifest %s", dgst.String())
|
||||||
|
// TODO: Support unpack by name
|
||||||
|
images, err := client.ListImages(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
var unpacked bool
|
||||||
|
for _, image := range images {
|
||||||
|
if image.Target().Digest == dgst {
|
||||||
|
fmt.Printf("unpacking %s (%s)...", dgst, image.Target().MediaType)
|
||||||
|
if err := image.Unpack(ctx, context.String("snapshotter")); err != nil {
|
||||||
|
fmt.Println()
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
fmt.Println("done")
|
||||||
|
unpacked = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !unpacked {
|
||||||
|
return errors.New("manifest not found")
|
||||||
|
}
|
||||||
|
// TODO: Get rootfs from Image
|
||||||
|
//log.G(ctx).Infof("chain ID: %s", chainID.String())
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
type snapshotTreeNode struct {
|
type snapshotTreeNode struct {
|
||||||
Name string
|
Name string
|
||||||
Parent string
|
Parent string
|
||||||
|
@ -81,7 +81,6 @@ containerd CLI
|
|||||||
images.Command,
|
images.Command,
|
||||||
namespacesCmd.Command,
|
namespacesCmd.Command,
|
||||||
pprofCommand,
|
pprofCommand,
|
||||||
rootfsCommand,
|
|
||||||
runCommand,
|
runCommand,
|
||||||
snapshot.Command,
|
snapshot.Command,
|
||||||
tasksCommand,
|
tasksCommand,
|
||||||
|
@ -1,62 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/containerd/containerd/cmd/ctr/commands"
|
|
||||||
"github.com/containerd/containerd/log"
|
|
||||||
digest "github.com/opencontainers/go-digest"
|
|
||||||
"github.com/urfave/cli"
|
|
||||||
)
|
|
||||||
|
|
||||||
var rootfsCommand = cli.Command{
|
|
||||||
Name: "rootfs",
|
|
||||||
Usage: "setup a rootfs",
|
|
||||||
Subcommands: []cli.Command{
|
|
||||||
rootfsUnpackCommand,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
var rootfsUnpackCommand = cli.Command{
|
|
||||||
Name: "unpack",
|
|
||||||
Usage: "unpack applies layers from a manifest to a snapshot",
|
|
||||||
ArgsUsage: "[flags] <digest>",
|
|
||||||
Flags: commands.SnapshotterFlags,
|
|
||||||
Action: func(context *cli.Context) error {
|
|
||||||
dgst, err := digest.Parse(context.Args().First())
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
client, ctx, cancel, err := commands.NewClient(context)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer cancel()
|
|
||||||
log.G(ctx).Debugf("unpacking layers from manifest %s", dgst.String())
|
|
||||||
// TODO: Support unpack by name
|
|
||||||
images, err := client.ListImages(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
var unpacked bool
|
|
||||||
for _, image := range images {
|
|
||||||
if image.Target().Digest == dgst {
|
|
||||||
fmt.Printf("unpacking %s (%s)...", dgst, image.Target().MediaType)
|
|
||||||
if err := image.Unpack(ctx, context.String("snapshotter")); err != nil {
|
|
||||||
fmt.Println()
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
fmt.Println("done")
|
|
||||||
unpacked = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !unpacked {
|
|
||||||
return errors.New("manifest not found")
|
|
||||||
}
|
|
||||||
// TODO: Get rootfs from Image
|
|
||||||
//log.G(ctx).Infof("chain ID: %s", chainID.String())
|
|
||||||
return nil
|
|
||||||
},
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user