Skip to content

Commit b57f321

Browse files
Merge pull request moby#26709 from boucher/checkpoint-dir
Allow providing a custom storage directory for docker checkpoints
2 parents 9e436c9 + bd7d512 commit b57f321

File tree

24 files changed

+167
-57
lines changed

24 files changed

+167
-57
lines changed

api/server/router/checkpoint/backend.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ import "github.com/docker/docker/api/types"
55
// Backend for Checkpoint
66
type Backend interface {
77
CheckpointCreate(container string, config types.CheckpointCreateOptions) error
8-
CheckpointDelete(container string, checkpointID string) error
9-
CheckpointList(container string) ([]types.Checkpoint, error)
8+
CheckpointDelete(container string, config types.CheckpointDeleteOptions) error
9+
CheckpointList(container string, config types.CheckpointListOptions) ([]types.Checkpoint, error)
1010
}

api/server/router/checkpoint/checkpoint_routes.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ func (s *checkpointRouter) getContainerCheckpoints(ctx context.Context, w http.R
3535
return err
3636
}
3737

38-
checkpoints, err := s.backend.CheckpointList(vars["name"])
38+
checkpoints, err := s.backend.CheckpointList(vars["name"], types.CheckpointListOptions{
39+
CheckpointDir: r.Form.Get("dir"),
40+
})
41+
3942
if err != nil {
4043
return err
4144
}
@@ -48,7 +51,11 @@ func (s *checkpointRouter) deleteContainerCheckpoint(ctx context.Context, w http
4851
return err
4952
}
5053

51-
err := s.backend.CheckpointDelete(vars["name"], vars["checkpoint"])
54+
err := s.backend.CheckpointDelete(vars["name"], types.CheckpointDeleteOptions{
55+
CheckpointDir: r.Form.Get("dir"),
56+
CheckpointID: vars["checkpoint"],
57+
})
58+
5259
if err != nil {
5360
return err
5461
}

api/server/router/container/backend.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ type stateBackend interface {
3939
ContainerResize(name string, height, width int) error
4040
ContainerRestart(name string, seconds *int) error
4141
ContainerRm(name string, config *types.ContainerRmConfig) error
42-
ContainerStart(name string, hostConfig *container.HostConfig, validateHostname bool, checkpoint string) error
42+
ContainerStart(name string, hostConfig *container.HostConfig, validateHostname bool, checkpoint string, checkpointDir string) error
4343
ContainerStop(name string, seconds *int) error
4444
ContainerUnpause(name string) error
4545
ContainerUpdate(name string, hostConfig *container.HostConfig, validateHostname bool) (types.ContainerUpdateResponse, error)

api/server/router/container/container_routes.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,9 @@ func (s *containerRouter) postContainersStart(ctx context.Context, w http.Respon
155155
}
156156

157157
checkpoint := r.Form.Get("checkpoint")
158+
checkpointDir := r.Form.Get("checkpoint-dir")
158159
validateHostname := versions.GreaterThanOrEqualTo(version, "1.24")
159-
if err := s.backend.ContainerStart(vars["name"], hostConfig, validateHostname, checkpoint); err != nil {
160+
if err := s.backend.ContainerStart(vars["name"], hostConfig, validateHostname, checkpoint, checkpointDir); err != nil {
160161
return err
161162
}
162163

api/types/client.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,20 @@ import (
1212

1313
// CheckpointCreateOptions holds parameters to create a checkpoint from a container
1414
type CheckpointCreateOptions struct {
15-
CheckpointID string
16-
Exit bool
15+
CheckpointID string
16+
CheckpointDir string
17+
Exit bool
18+
}
19+
20+
// CheckpointListOptions holds parameters to list checkpoints for a container
21+
type CheckpointListOptions struct {
22+
CheckpointDir string
23+
}
24+
25+
// CheckpointDeleteOptions holds parameters to delete a checkpoint from a container
26+
type CheckpointDeleteOptions struct {
27+
CheckpointID string
28+
CheckpointDir string
1729
}
1830

1931
// ContainerAttachOptions holds parameters to attach to a container.
@@ -77,7 +89,8 @@ type ContainerRemoveOptions struct {
7789

7890
// ContainerStartOptions holds parameters to start containers.
7991
type ContainerStartOptions struct {
80-
CheckpointID string
92+
CheckpointID string
93+
CheckpointDir string
8194
}
8295

8396
// CopyToContainerOptions holds information

builder/builder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ type Backend interface {
124124
// ContainerKill stops the container execution abruptly.
125125
ContainerKill(containerID string, sig uint64) error
126126
// ContainerStart starts a new container
127-
ContainerStart(containerID string, hostConfig *container.HostConfig, validateHostname bool, checkpoint string) error
127+
ContainerStart(containerID string, hostConfig *container.HostConfig, validateHostname bool, checkpoint string, checkpointDir string) error
128128
// ContainerWait stops processing until the given container is stopped.
129129
ContainerWait(containerID string, timeout time.Duration) (int, error)
130130
// ContainerUpdateCmdOnBuild updates container.Path and container.Args

builder/dockerfile/internals.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ func (b *Builder) run(cID string) (err error) {
537537
}
538538
}()
539539

540-
if err := b.docker.ContainerStart(cID, nil, true, ""); err != nil {
540+
if err := b.docker.ContainerStart(cID, nil, true, "", ""); err != nil {
541541
close(finished)
542542
if cancelErr := <-cancelErrCh; cancelErr != nil {
543543
logrus.Debugf("Build cancelled (%v) and got an error from ContainerStart: %v",

cli/command/checkpoint/create.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ import (
1010
)
1111

1212
type createOptions struct {
13-
container string
14-
checkpoint string
15-
leaveRunning bool
13+
container string
14+
checkpoint string
15+
checkpointDir string
16+
leaveRunning bool
1617
}
1718

1819
func newCreateCommand(dockerCli *command.DockerCli) *cobra.Command {
@@ -31,6 +32,7 @@ func newCreateCommand(dockerCli *command.DockerCli) *cobra.Command {
3132

3233
flags := cmd.Flags()
3334
flags.BoolVar(&opts.leaveRunning, "leave-running", false, "leave the container running after checkpoint")
35+
flags.StringVarP(&opts.checkpointDir, "checkpoint-dir", "", "", "use a custom checkpoint storage directory")
3436

3537
return cmd
3638
}
@@ -39,8 +41,9 @@ func runCreate(dockerCli *command.DockerCli, opts createOptions) error {
3941
client := dockerCli.Client()
4042

4143
checkpointOpts := types.CheckpointCreateOptions{
42-
CheckpointID: opts.checkpoint,
43-
Exit: !opts.leaveRunning,
44+
CheckpointID: opts.checkpoint,
45+
CheckpointDir: opts.checkpointDir,
46+
Exit: !opts.leaveRunning,
4447
}
4548

4649
err := client.CheckpointCreate(context.Background(), opts.container, checkpointOpts)

cli/command/checkpoint/list.go

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,44 @@ import (
66

77
"golang.org/x/net/context"
88

9+
"github.com/docker/docker/api/types"
910
"github.com/docker/docker/cli"
1011
"github.com/docker/docker/cli/command"
1112
"github.com/spf13/cobra"
1213
)
1314

15+
type listOptions struct {
16+
checkpointDir string
17+
}
18+
1419
func newListCommand(dockerCli *command.DockerCli) *cobra.Command {
15-
return &cobra.Command{
20+
var opts listOptions
21+
22+
cmd := &cobra.Command{
1623
Use: "ls CONTAINER",
1724
Aliases: []string{"list"},
1825
Short: "List checkpoints for a container",
1926
Args: cli.ExactArgs(1),
2027
RunE: func(cmd *cobra.Command, args []string) error {
21-
return runList(dockerCli, args[0])
28+
return runList(dockerCli, args[0], opts)
2229
},
2330
}
31+
32+
flags := cmd.Flags()
33+
flags.StringVarP(&opts.checkpointDir, "checkpoint-dir", "", "", "use a custom checkpoint storage directory")
34+
35+
return cmd
36+
2437
}
2538

26-
func runList(dockerCli *command.DockerCli, container string) error {
39+
func runList(dockerCli *command.DockerCli, container string, opts listOptions) error {
2740
client := dockerCli.Client()
2841

29-
checkpoints, err := client.CheckpointList(context.Background(), container)
42+
listOpts := types.CheckpointListOptions{
43+
CheckpointDir: opts.checkpointDir,
44+
}
45+
46+
checkpoints, err := client.CheckpointList(context.Background(), container, listOpts)
3047
if err != nil {
3148
return err
3249
}

cli/command/checkpoint/remove.go

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,42 @@ package checkpoint
33
import (
44
"golang.org/x/net/context"
55

6+
"github.com/docker/docker/api/types"
67
"github.com/docker/docker/cli"
78
"github.com/docker/docker/cli/command"
89
"github.com/spf13/cobra"
910
)
1011

12+
type removeOptions struct {
13+
checkpointDir string
14+
}
15+
1116
func newRemoveCommand(dockerCli *command.DockerCli) *cobra.Command {
12-
return &cobra.Command{
17+
var opts removeOptions
18+
19+
cmd := &cobra.Command{
1320
Use: "rm CONTAINER CHECKPOINT",
1421
Aliases: []string{"remove"},
1522
Short: "Remove a checkpoint",
1623
Args: cli.ExactArgs(2),
1724
RunE: func(cmd *cobra.Command, args []string) error {
18-
return runRemove(dockerCli, args[0], args[1])
25+
return runRemove(dockerCli, args[0], args[1], opts)
1926
},
2027
}
28+
29+
flags := cmd.Flags()
30+
flags.StringVarP(&opts.checkpointDir, "checkpoint-dir", "", "", "use a custom checkpoint storage directory")
31+
32+
return cmd
2133
}
2234

23-
func runRemove(dockerCli *command.DockerCli, container string, checkpoint string) error {
35+
func runRemove(dockerCli *command.DockerCli, container string, checkpoint string, opts removeOptions) error {
2436
client := dockerCli.Client()
25-
return client.CheckpointDelete(context.Background(), container, checkpoint)
37+
38+
removeOpts := types.CheckpointDeleteOptions{
39+
CheckpointID: checkpoint,
40+
CheckpointDir: opts.checkpointDir,
41+
}
42+
43+
return client.CheckpointDelete(context.Background(), container, removeOpts)
2644
}

0 commit comments

Comments
 (0)