Files
moby/client/checkpoint_create.go
Sebastiaan van Stijn a8afc2c6fb api/types/checkpoint: move checkpoint options to client
Move the option-types to the client and in some cases create a
copy for the backend. These types are used to construct query-
args, and not marshaled to JSON, and can be replaced with functional
options in the client.

The CreateOptions type was used both as options-struct for the client,
and as struct to marshal/unmarshal the request. For this type, a copy
is created in the Client and a new `checkpoint.CreateRequest` is added
in the API.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-09-05 10:20:06 +02:00

32 lines
843 B
Go

package client
import (
"context"
"github.com/moby/moby/api/types/checkpoint"
)
// CheckpointCreateOptions holds parameters to create a checkpoint from a container.
type CheckpointCreateOptions struct {
CheckpointID string
CheckpointDir string
Exit bool
}
// CheckpointCreate creates a checkpoint from the given container.
func (cli *Client) CheckpointCreate(ctx context.Context, containerID string, options CheckpointCreateOptions) error {
containerID, err := trimID("container", containerID)
if err != nil {
return err
}
requestBody := checkpoint.CreateRequest{
CheckpointID: options.CheckpointID,
CheckpointDir: options.CheckpointDir,
Exit: options.Exit,
}
resp, err := cli.post(ctx, "/containers/"+containerID+"/checkpoints", nil, requestBody, nil)
defer ensureReaderClosed(resp)
return err
}