docker

package module
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 14, 2024 License: MIT Imports: 17 Imported by: 19

README

Docker sdk wrapper

This package provides a wrapper for the docker sdk, creating and running commands in containers.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrorImageDoesNotExist returned when inspecting an image that does not exist on the system.
	ErrorImageDoesNotExist = fmt.Errorf("no such image")
)

Functions

This section is empty.

Types

type Command

type Command []string

func (Command) String

func (c Command) String() string

type Container

type Container interface {
	// ID the id of the container.
	ID() string
	// Create the container, call Start to start it.
	Create(ctx context.Context, w Wrapper) error
	// Start the container.
	Start(ctx context.Context, w Wrapper, timeout time.Duration) error
	// Stop sends SIGINT to the container.
	Stop(ctx context.Context, w Wrapper) error
	// Kill sends SIGKILL to the container.
	Kill(ctx context.Context, w Wrapper) error
	// Wait for the container to stop running, see dockercontainer.WaitCondition.
	Wait(ctx context.Context, w Wrapper) error
	// Remove the container.
	Remove(ctx context.Context, w Wrapper) error
	// Exec execute a Command in the running container.
	Exec(ctx context.Context, w Wrapper, cmd Command) (Exec, error)
	// ExecWithoutTTY execute a Command in the running container without tty.
	ExecWithoutTTY(ctx context.Context, w Wrapper, cmd Command) (Exec, error)
	// AttachIO attach the I/O streams from the running command of the container to the Wrapper streams.
	AttachIO(ctx context.Context, w Wrapper) (IOStreamer, error)
	// Inspect the container.
	Inspect(ctx context.Context, w Wrapper) (types.ContainerJSON, error)
}

Container represents a docker container.

func FindContainerByName added in v1.0.0

func FindContainerByName(ctx context.Context, w Wrapper, name string) (Container, error)

FindContainerByName tries to find an existing container with the same name in the docker daemon.

func NewContainer

func NewContainer(cfg ContainerConfig) (Container, error)

type ContainerConfig

type ContainerConfig struct {
	Image       string            // Image Required
	Labels      map[string]string // Labels container's labels name:value
	Directories map[string]string // Directories to mount to container src:target
	WorkingDir  string            // WorkingDir the work directory of the container. Required
	Name        string            // Name is the container name, defaults to randomly generated
	Command     Command           // Command the Command to start the container with
	AutoRemove  bool              // AutoRemove automatically remove the container when it exits
}

ContainerConfig contains the configuration data about a container.

func (*ContainerConfig) String

func (cc *ContainerConfig) String() string

String returns the command as it would be run from cli.

type ContainerStatus

type ContainerStatus string
const (
	ContainerStatusCreated    ContainerStatus = "created"
	ContainerStatusRunning    ContainerStatus = "running"
	ContainerStatusPaused     ContainerStatus = "paused"
	ContainerStatusRestarting ContainerStatus = "restarting"
	ContainerStatusRemoving   ContainerStatus = "removing"
	ContainerStatusExited     ContainerStatus = "exited"
	ContainerStatusDead       ContainerStatus = "dead"
)

type Exec

type Exec interface {
	// ID the Exec id.
	ID() string
	// Start the Exec.
	Start(ctx context.Context, w Wrapper) error
	// AttachIO attach the I/O streams from the running to the Wrapper streams.
	AttachIO(ctx context.Context, w Wrapper) (IOStreamer, error)
	// Wait blocks until the Exec finishes, errors, or context is canceled.
	Wait(ctx context.Context, w Wrapper) error
}

type IOStreamer added in v1.0.0

type IOStreamer interface {
	Start()
	Wait(ctx context.Context) error
}

func NewIOStreamer added in v1.0.0

func NewIOStreamer(r types.HijackedResponse, w Wrapper) IOStreamer

type Image added in v1.0.0

type Image interface {
	Pull(ctx context.Context, w Wrapper) error
	Inspect(ctx context.Context, w Wrapper) (types.ImageInspect, error)
}

func NewImage added in v1.0.0

func NewImage(img string) Image

type Wrapper added in v1.0.0

type Wrapper interface {
	Cli() client.APIClient
	Logger() *zap.Logger
	Out() io.Writer
	Err() io.Writer
	In() io.Reader

	ContainerStart(ctx context.Context, cfg ContainerConfig) (Container, error)
	ContainerCreate(ctx context.Context, cfg ContainerConfig) (Container, error)
}

func NewWrapper added in v1.0.0

func NewWrapper(ops ...WrapperOption) (Wrapper, error)

type WrapperOption added in v1.0.0

type WrapperOption func(w *wrapper) error

func WithDockerClient added in v1.0.0

func WithDockerClient(cli client.APIClient) WrapperOption

WithDockerClient sets the docker cli.

func WithErrorStream added in v1.0.0

func WithErrorStream(err io.Writer) WrapperOption

WithErrorStream sets a cli error stream.

func WithInputStream added in v1.0.0

func WithInputStream(in io.Reader) WrapperOption

WithInputStream sets a cli input stream.

func WithLogger added in v1.0.0

func WithLogger(logger *zap.Logger) WrapperOption

WithLogger sets the logger.

func WithOutputStream added in v1.0.0

func WithOutputStream(out io.Writer) WrapperOption

WithOutputStream sets a cli output stream.

func WithStandardStreams added in v1.0.0

func WithStandardStreams() WrapperOption

WithStandardStreams sets a cli in, out and err streams with the standard streams.

Directories

Path Synopsis
Code generated by MockGen.
Code generated by MockGen.
client
Code generated by MockGen.
Code generated by MockGen.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL