Allow providing a custom storage directory for docker checkpoints

Signed-off-by: boucher <rboucher@gmail.com>
This commit is contained in:
boucher 2016-09-19 12:01:16 -04:00
parent 4b65bdd802
commit 5ddcbc3c00
4 changed files with 61 additions and 19 deletions

View File

@ -12,6 +12,7 @@ import (
type createOptions struct {
container string
checkpoint string
checkpointDir string
leaveRunning bool
}
@ -31,6 +32,7 @@ func newCreateCommand(dockerCli *command.DockerCli) *cobra.Command {
flags := cmd.Flags()
flags.BoolVar(&opts.leaveRunning, "leave-running", false, "leave the container running after checkpoint")
flags.StringVarP(&opts.checkpointDir, "checkpoint-dir", "", "", "use a custom checkpoint storage directory")
return cmd
}
@ -40,6 +42,7 @@ func runCreate(dockerCli *command.DockerCli, opts createOptions) error {
checkpointOpts := types.CheckpointCreateOptions{
CheckpointID: opts.checkpoint,
CheckpointDir: opts.checkpointDir,
Exit: !opts.leaveRunning,
}

View File

@ -6,27 +6,44 @@ import (
"golang.org/x/net/context"
"github.com/docker/docker/api/types"
"github.com/docker/docker/cli"
"github.com/docker/docker/cli/command"
"github.com/spf13/cobra"
)
type listOptions struct {
checkpointDir string
}
func newListCommand(dockerCli *command.DockerCli) *cobra.Command {
return &cobra.Command{
var opts listOptions
cmd := &cobra.Command{
Use: "ls CONTAINER",
Aliases: []string{"list"},
Short: "List checkpoints for a container",
Args: cli.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
return runList(dockerCli, args[0])
return runList(dockerCli, args[0], opts)
},
}
flags := cmd.Flags()
flags.StringVarP(&opts.checkpointDir, "checkpoint-dir", "", "", "use a custom checkpoint storage directory")
return cmd
}
func runList(dockerCli *command.DockerCli, container string) error {
func runList(dockerCli *command.DockerCli, container string, opts listOptions) error {
client := dockerCli.Client()
checkpoints, err := client.CheckpointList(context.Background(), container)
listOpts := types.CheckpointListOptions{
CheckpointDir: opts.checkpointDir,
}
checkpoints, err := client.CheckpointList(context.Background(), container, listOpts)
if err != nil {
return err
}

View File

@ -3,24 +3,42 @@ package checkpoint
import (
"golang.org/x/net/context"
"github.com/docker/docker/api/types"
"github.com/docker/docker/cli"
"github.com/docker/docker/cli/command"
"github.com/spf13/cobra"
)
type removeOptions struct {
checkpointDir string
}
func newRemoveCommand(dockerCli *command.DockerCli) *cobra.Command {
return &cobra.Command{
var opts removeOptions
cmd := &cobra.Command{
Use: "rm CONTAINER CHECKPOINT",
Aliases: []string{"remove"},
Short: "Remove a checkpoint",
Args: cli.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
return runRemove(dockerCli, args[0], args[1])
return runRemove(dockerCli, args[0], args[1], opts)
},
}
flags := cmd.Flags()
flags.StringVarP(&opts.checkpointDir, "checkpoint-dir", "", "", "use a custom checkpoint storage directory")
return cmd
}
func runRemove(dockerCli *command.DockerCli, container string, checkpoint string) error {
func runRemove(dockerCli *command.DockerCli, container string, checkpoint string, opts removeOptions) error {
client := dockerCli.Client()
return client.CheckpointDelete(context.Background(), container, checkpoint)
removeOpts := types.CheckpointDeleteOptions{
CheckpointID: checkpoint,
CheckpointDir: opts.checkpointDir,
}
return client.CheckpointDelete(context.Background(), container, removeOpts)
}

View File

@ -21,6 +21,7 @@ type startOptions struct {
openStdin bool
detachKeys string
checkpoint string
checkpointDir string
containers []string
}
@ -46,6 +47,7 @@ func NewStartCommand(dockerCli *command.DockerCli) *cobra.Command {
if dockerCli.HasExperimental() {
flags.StringVar(&opts.checkpoint, "checkpoint", "", "Restore from this checkpoint")
flags.StringVar(&opts.checkpointDir, "checkpoint-dir", "", "Use a custom checkpoint storage directory")
}
return cmd
@ -113,6 +115,7 @@ func runStart(dockerCli *command.DockerCli, opts *startOptions) error {
statusChan := waitExitOrRemoved(dockerCli, ctx, c.ID, c.HostConfig.AutoRemove)
startOptions := types.ContainerStartOptions{
CheckpointID: opts.checkpoint,
CheckpointDir: opts.checkpointDir,
}
// 4. Start the container.
@ -146,6 +149,7 @@ func runStart(dockerCli *command.DockerCli, opts *startOptions) error {
container := opts.containers[0]
startOptions := types.ContainerStartOptions{
CheckpointID: opts.checkpoint,
CheckpointDir: opts.checkpointDir,
}
return dockerCli.Client().ContainerStart(ctx, container, startOptions)