Add diff service implementation
Add snapshot subcommand to ctr for creating diffs of RW layers. Signed-off-by: Derek McGowan <derek@mcgstyle.net>
This commit is contained in:
@@ -61,6 +61,7 @@ containerd client
|
||||
execCommand,
|
||||
pauseCommand,
|
||||
resumeCommand,
|
||||
snapshotCommand,
|
||||
versionCommand,
|
||||
}
|
||||
app.Commands = append(app.Commands, extraCmds...)
|
||||
|
||||
@@ -54,6 +54,10 @@ var runCommand = cli.Command{
|
||||
Name: "net-host",
|
||||
Usage: "enable host networking for the container",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "keep",
|
||||
Usage: "keep container after running",
|
||||
},
|
||||
},
|
||||
Action: func(context *cli.Context) error {
|
||||
var (
|
||||
@@ -110,7 +114,11 @@ var runCommand = cli.Command{
|
||||
return err
|
||||
}
|
||||
|
||||
mounts, err = snapshotter.Prepare(ctx, id, identity.ChainID(diffIDs).String())
|
||||
if context.Bool("readonly") {
|
||||
mounts, err = snapshotter.View(ctx, id, identity.ChainID(diffIDs).String())
|
||||
} else {
|
||||
mounts, err = snapshotter.Prepare(ctx, id, identity.ChainID(diffIDs).String())
|
||||
}
|
||||
if err != nil {
|
||||
if !snapshot.IsExist(err) {
|
||||
return err
|
||||
@@ -192,10 +200,12 @@ var runCommand = cli.Command{
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := containers.Delete(ctx, &execution.DeleteRequest{
|
||||
ID: response.ID,
|
||||
}); err != nil {
|
||||
return err
|
||||
if !context.Bool("keep") {
|
||||
if _, err := containers.Delete(ctx, &execution.DeleteRequest{
|
||||
ID: response.ID,
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if status != 0 {
|
||||
return cli.NewExitError("", int(status))
|
||||
|
||||
50
cmd/ctr/snapshot.go
Normal file
50
cmd/ctr/snapshot.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/containerd/containerd/rootfs"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
var snapshotCommand = cli.Command{
|
||||
Name: "snapshot",
|
||||
Usage: "snapshot a container into an archive",
|
||||
ArgsUsage: "",
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "id",
|
||||
Usage: "id of the container",
|
||||
},
|
||||
},
|
||||
Action: func(clicontext *cli.Context) error {
|
||||
id := clicontext.String("id")
|
||||
if id == "" {
|
||||
return errors.New("container id must be provided")
|
||||
}
|
||||
|
||||
snapshotter, err := getSnapshotter(clicontext)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
differ, err := getDiffService(clicontext)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
contentRef := fmt.Sprintf("diff-%s", id)
|
||||
|
||||
d, err := rootfs.Diff(context.TODO(), id, contentRef, snapshotter, differ)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// TODO: Track progress
|
||||
fmt.Printf("%s %s\n", d.MediaType, d.Digest)
|
||||
|
||||
return nil
|
||||
},
|
||||
}
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
contentapi "github.com/containerd/containerd/api/services/content"
|
||||
diffapi "github.com/containerd/containerd/api/services/diff"
|
||||
"github.com/containerd/containerd/api/services/execution"
|
||||
imagesapi "github.com/containerd/containerd/api/services/images"
|
||||
snapshotapi "github.com/containerd/containerd/api/services/snapshot"
|
||||
@@ -21,6 +22,7 @@ import (
|
||||
"github.com/containerd/containerd/content"
|
||||
"github.com/containerd/containerd/images"
|
||||
contentservice "github.com/containerd/containerd/services/content"
|
||||
"github.com/containerd/containerd/services/diff"
|
||||
imagesservice "github.com/containerd/containerd/services/images"
|
||||
snapshotservice "github.com/containerd/containerd/services/snapshot"
|
||||
"github.com/containerd/containerd/snapshot"
|
||||
@@ -62,6 +64,14 @@ func getImageStore(clicontext *cli.Context) (images.Store, error) {
|
||||
return imagesservice.NewStoreFromClient(imagesapi.NewImagesClient(conn)), nil
|
||||
}
|
||||
|
||||
func getDiffService(context *cli.Context) (diff.DiffService, error) {
|
||||
conn, err := getGRPCConnection(context)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return diff.NewDiffServiceFromClient(diffapi.NewDiffClient(conn)), nil
|
||||
}
|
||||
|
||||
func getVersionService(context *cli.Context) (versionservice.VersionClient, error) {
|
||||
conn, err := getGRPCConnection(context)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user