docker

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2023 License: Apache-2.0, MIT Imports: 20 Imported by: 0

Documentation

Overview

Package docker contains utils and helpers for commonly used Docker idioms.

Index

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

func DeleteContainers(cli *client.Client, ow *rpc.OutputWriter, ids []string) (err error)

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 EnsureBridgeNetwork(ctx context.Context, ow *rpc.OutputWriter, cli *client.Client, name string, internal bool, config ...network.IPAMConfig) (id string, err error)

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 GetImageID(ctx context.Context, cli *client.Client, defaultTag string) (string, error)

func NewBridgeNetwork

func NewBridgeNetwork(ctx context.Context, cli *client.Client, name string, internal bool, labels map[string]string, config ...network.IPAMConfig) (id string, err error)

func PipeOutput

func PipeOutput(r io.ReadCloser, w io.Writer) (output string, err error)

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

type ContainerRef struct {
	logging.Logging

	ID      string
	Manager *Manager
}

Container is a convenient handle for a docker container.

func (*ContainerRef) Exec

func (c *ContainerRef) Exec(ctx context.Context, cmd ...string) error

func (*ContainerRef) Inspect

func (c *ContainerRef) Inspect(ctx context.Context) (types.ContainerJSON, error)

Inspect inspects this docker container.

func (*ContainerRef) IsOnline

func (c *ContainerRef) IsOnline(ctx context.Context) (bool, error)

IsOnline returns whether or not the container is online.

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

type Manager struct {
	logging.Logging

	*client.Client
}

Manager is a convenient wrapper around the docker client.

func NewManager

func NewManager() (*Manager, error)

NewManager connects to the local docker instance and provides a convenient handle for managing containers.

func (*Manager) Close

func (m *Manager) Close() error

Close closes the docker client.

func (*Manager) NewContainerRef

func (m *Manager) NewContainerRef(id string) *ContainerRef

NewContainerRef constructs a reference to a given container.

func (*Manager) Watch

func (m *Manager) Watch(ctx context.Context, worker WorkerFn, labels ...string) error

Watch monitors container status, and runs the provider worker for each container that starts.

If you pass labels, only containers labeled with at least one of the given labels will be managed.

type WorkerFn

type WorkerFn func(context.Context, *ContainerRef) error

Jump to

Keyboard shortcuts

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