Documentation ¶
Overview ¶
Package docker contains utils and helpers for commonly used Docker idioms.
Index ¶
- func BuildImage(ctx context.Context, ow *rpc.OutputWriter, client *client.Client, ...) (string, error)
- func CheckBridgeNetwork(ctx context.Context, ow *rpc.OutputWriter, cli *client.Client, name string) ([]types.NetworkResource, error)
- func CheckContainer(ctx context.Context, ow *rpc.OutputWriter, cli *client.Client, name string) (container *types.ContainerJSON, err error)
- func DeleteContainers(cli *client.Client, ow *rpc.OutputWriter, ids []string) (err error)
- func EnsureBridgeNetwork(ctx context.Context, ow *rpc.OutputWriter, cli *client.Client, name string, ...) (id string, err error)
- func EnsureContainerStarted(ctx context.Context, ow *rpc.OutputWriter, cli *client.Client, ...) (container *types.ContainerJSON, created bool, err error)
- func EnsureImage(ctx context.Context, ow *rpc.OutputWriter, client *client.Client, ...) (created bool, err error)
- func EnsureVolume(ctx context.Context, log *zap.SugaredLogger, cli *client.Client, ...) (volume *types.Volume, created bool, err error)
- func FindImage(ctx context.Context, ow *rpc.OutputWriter, client *client.Client, name string) (*types.ImageSummary, bool, error)
- func GetImageID(ctx context.Context, cli *client.Client, defaultTag string) (string, error)
- func NewBridgeNetwork(ctx context.Context, cli *client.Client, name string, internal bool, ...) (id string, err error)
- func PipeOutput(r io.ReadCloser, w io.Writer) (output string, err error)
- type BuildImageOpts
- type ContainerRef
- type EnsureContainerOpts
- type EnsureVolumeOpts
- type ImageStrategy
- type Manager
- type WorkerFn
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildImage ¶
func BuildImage(ctx context.Context, ow *rpc.OutputWriter, client *client.Client, opts *BuildImageOpts) (string, error)
BuildImage builds a docker image from provided BuildImageOpts or a set of default options. If BuildImageOpts.BuildOpts is filled, these options will be passed to the docker client un-edited. In this case, BuildImageOpts.Name is unused when the image is created. When BuildImageOpts.BuildOpts has nil value, a default set of options will be constructed using the Name, and the constructed options are sent to the docker client. The build output is directed to stdout via PipeOutput, and also returned from this function.
func CheckBridgeNetwork ¶
func CheckBridgeNetwork(ctx context.Context, ow *rpc.OutputWriter, cli *client.Client, name string) ([]types.NetworkResource, error)
func CheckContainer ¶
func CheckContainer(ctx context.Context, ow *rpc.OutputWriter, cli *client.Client, name string) (container *types.ContainerJSON, err error)
func DeleteContainers ¶ added in v0.5.3
DeleteContainers deletes a set of containers in parallel, using a ratelimit of 16 concurrent delete requests. If a deletion fails, it does not short-circuit. Instead, it accumulates errors and returns an multierror.
func EnsureBridgeNetwork ¶
func EnsureContainerStarted ¶
func EnsureContainerStarted(ctx context.Context, ow *rpc.OutputWriter, cli *client.Client, opts *EnsureContainerOpts) (container *types.ContainerJSON, created bool, err error)
EnsureContainerStarted ensures there's a container started of the specified kind, resorting to building it if necessary and so indicated.
func EnsureImage ¶
func EnsureImage(ctx context.Context, ow *rpc.OutputWriter, client *client.Client, opts *BuildImageOpts) (created bool, err error)
EnsureImage builds an image only of one does not yet exist. This is a thin wrapper around BuildImage, and the same comments regarding the passed BuildImageOpts applies here. Returns a bool depending on whether the image had to be created and any errors that were encountered.
func EnsureVolume ¶
func EnsureVolume(ctx context.Context, log *zap.SugaredLogger, cli *client.Client, opts *EnsureVolumeOpts) (volume *types.Volume, created bool, err error)
EnsureVolume ensures the volume is created. If another volume exists with the same name, nothing is created, regardless of any other options passed.
func FindImage ¶
func FindImage(ctx context.Context, ow *rpc.OutputWriter, client *client.Client, name string) (*types.ImageSummary, bool, error)
FindImage looks for an image with name `name` in our local daemon.
If found, it returns the image summary and true. If absent, it returns a nil image summary, and false. If an internal error occurs, it returns a nil image summary, false, and a non-nil error.
func GetImageID ¶ added in v0.5.1
func NewBridgeNetwork ¶
func PipeOutput ¶
PipeOutput pipes a reader that spits out jsonmessage structs into a writer, usually stdout. It returns normally when the reader is exhausted, or in error if one occurs. In both cases, it will return the accumulated string representation of the output.
Types ¶
type BuildImageOpts ¶
type BuildImageOpts struct { Name string // required for EnsureImage BuildCtx string // required BuildOpts *types.ImageBuildOptions // optional }
type ContainerRef ¶
Container is a convenient handle for a docker container.
func (*ContainerRef) Inspect ¶
func (c *ContainerRef) Inspect(ctx context.Context) (types.ContainerJSON, error)
Inspect inspects this docker container.
type EnsureContainerOpts ¶
type EnsureContainerOpts struct { ContainerName string ContainerConfig *container.Config HostConfig *container.HostConfig NetworkingConfig *network.NetworkingConfig ImageStrategy ImageStrategy BuildImageOpts *BuildImageOpts }
type EnsureVolumeOpts ¶
type EnsureVolumeOpts struct { Name string DriverOpts map[string]string Labels map[string]string Driver string }
EnsureVolumeOpts is used to construct the volume request. https://github.com/moby/moby/blob/master/api/types/volume/volume_create.go
type ImageStrategy ¶
type ImageStrategy int
const ( ImageStrategyNone ImageStrategy = iota ImageStrategyPull ImageStrategyBuild )
type Manager ¶
Manager is a convenient wrapper around the docker client.
func NewManager ¶
NewManager connects to the local docker instance and provides a convenient handle for managing containers.
func (*Manager) NewContainerRef ¶
func (m *Manager) NewContainerRef(id string) *ContainerRef
NewContainerRef constructs a reference to a given container.