docker

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2020 License: Apache-2.0, MIT Imports: 18 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 added in v0.3.0

func BuildImage(ctx context.Context, ow *rpc.OutputWriter, client *client.Client, opts *BuildImageOpts) 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.

func CheckBridgeNetwork added in v0.2.0

func CheckBridgeNetwork(ctx context.Context, ow *rpc.OutputWriter, cli *client.Client, name string) ([]types.NetworkResource, error)

func CheckContainer added in v0.2.0

func CheckContainer(ctx context.Context, ow *rpc.OutputWriter, cli *client.Client, name string) (container *types.ContainerJSON, err error)

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 added in v0.4.0

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 added in v0.3.0

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 added in v0.2.0

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 added in v0.4.0

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 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) 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.

Types

type BuildImageOpts added in v0.3.0

type BuildImageOpts struct {
	Name      string                   // reuired for EnsureImage
	BuildCtx  string                   // required
	BuildOpts *types.ImageBuildOptions // optional
}

type ContainerRef added in v0.3.0

type ContainerRef struct {
	logging.Logging

	ID      string
	Manager *Manager
}

Container is a convenient handle for a docker container.

func (*ContainerRef) Exec added in v0.3.0

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

func (*ContainerRef) Inspect added in v0.3.0

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

Inspect inspects this docker container.

func (*ContainerRef) IsOnline added in v0.3.0

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 added in v0.2.0

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 added in v0.4.0

type ImageStrategy int
const (
	ImageStrategyNone ImageStrategy = iota
	ImageStrategyPull
	ImageStrategyBuild
)

type Manager added in v0.3.0

type Manager struct {
	logging.Logging

	*client.Client
}

Manager is a convenient wrapper around the docker client.

func NewManager added in v0.3.0

func NewManager() (*Manager, error)

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

func (*Manager) Close added in v0.3.0

func (m *Manager) Close() error

Close closes the docker client.

func (*Manager) NewContainerRef added in v0.3.0

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

NewContainerRef constructs a reference to a given container.

func (*Manager) Watch added in v0.3.0

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 added in v0.3.0

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