dccli

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2019 License: MIT Imports: 16 Imported by: 0

README

dccli

Wrapper around the docker-compose cli, useful for integration testing

Documentation

Overview

package dccli provides a Go wrapper around Docker Compose, useful for integration testing. Check out the test cases for example usage

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InferDockerHost

func InferDockerHost() (string, error)

InferDockerHost returns the current docker host based on the contents of the DOCKER_HOST environment variable. If DOCKER_HOST is not set, it returns "localhost".

func MustInferDockerHost

func MustInferDockerHost() string

MustInferDockerHost is like InferDockerHost, but panics on error.

Types

type Compose

type Compose struct {
	// contains filtered or unexported fields
}

Compose is the main type exported by the package, used to interact with a running Docker Compose configuration.

func MustStart

func MustStart(opts ...Option) *Compose

MustStart is like Start, but panics on error.

func Start

func Start(opts ...Option) (*Compose, error)

Start starts a Docker Compose configuration. TODO(mclemens) accept an io.Reader or a set of options

func (*Compose) Cleanup

func (c *Compose) Cleanup() error

Cleanup will try and kill then remove any running containers for the current configuration.

func (*Compose) Connect added in v0.3.0

func (c *Compose) Connect(policy RetryPolicy, connectFunc func() error) error

Connect

func (*Compose) GetContainer added in v0.4.0

func (c *Compose) GetContainer(key string) (*ContainerInfo, error)

func (*Compose) MustCleanup

func (c *Compose) MustCleanup()

MustCleanup is like Cleanup, but panics on error.

type Config

type Config struct {
	Version   string                 `yaml:"version,omitempty"`
	Networks  map[string]*Network    `yaml:"networks,omitempty"`
	Volumes   map[string]interface{} `yaml:"volumes,omitempty"`
	Services  map[string]Service     `yaml:"services,omitempty"`
	Extension map[string]interface{} `yaml:",inline,omitempty"`
}

type ContainerConfig

type ContainerConfig struct {
	Hostname     string              `json:"Hostname,omitempty"`
	ExposedPorts map[string]struct{} `json:"ExposedPorts,omitempty"`
	Env          []string            `json:"Env,omitempty"`
	Cmd          []string            `json:"Cmd"`
	Image        string              `json:"Image,omitempty"`
	Labels       map[string]string   `json:"Labels,omitempty"`
}

ContainerConfig models the config section of the `docker inspect` command output.

type ContainerInfo

type ContainerInfo struct {
	ID              string           `json:"Id"`
	Name            string           `json:"Name,omitempty"`
	Created         time.Time        `json:"Created,omitempty"`
	Config          *ContainerConfig `json:"Config,omitempty"`
	State           ContainerState   `json:"State,omitempty"`
	Image           string           `json:"Image,omitempty"`
	NetworkSettings *NetworkSettings `json:"NetworkSettings,omitempty"`
}

ContainerInfo models the `docker inspect` command output.

func Inspect

func Inspect(id string) (*ContainerInfo, error)

Inspect inspects a container using the `docker inspect` command and returns a parsed version of its output.

func MustInspect

func MustInspect(id string) *ContainerInfo

MustInspect is like Inspect, but panics on error.

func (*ContainerInfo) GetFirstPublicPort

func (c *ContainerInfo) GetFirstPublicPort(exposedPort uint32, proto string) (uint32, error)

GetFirstPublicPort returns the first public public port mapped to the given exposedPort, for the given proto ("tcp", "udp", etc.), if found.

func (*ContainerInfo) MustGetFirstPublicPort

func (c *ContainerInfo) MustGetFirstPublicPort(exposedPort uint32, proto string) uint32

MustGetFirstPublicPort is like GetFirstPublicPort, but panics on error.

type ContainerState

type ContainerState struct {
	Running    bool      `json:"Running,omitempty"`
	Paused     bool      `json:"Paused,omitempty"`
	Restarting bool      `json:"Restarting,omitempty"`
	OOMKilled  bool      `json:"OOMKilled,omitempty"`
	Pid        int       `json:"Pid,omitempty"`
	ExitCode   int       `json:"ExitCode,omitempty"`
	Error      string    `json:"Error,omitempty"`
	StartedAt  time.Time `json:"StartedAt,omitempty"`
	FinishedAt time.Time `json:"FinishedAt,omitempty"`
}

ContainerState models the state section of the `docker inspect` command.

type ExponentialBackoffRetryPolicy added in v0.3.0

type ExponentialBackoffRetryPolicy struct {
	NumRetries int
	Min, Max   time.Duration
	// contains filtered or unexported fields
}

func (*ExponentialBackoffRetryPolicy) AttemptAgain added in v0.3.0

func (e *ExponentialBackoffRetryPolicy) AttemptAgain(err error) (bool, time.Duration)

type HealthCheck

type HealthCheck struct {
	Test        []string `yaml:"test,omitempty"`
	Interval    string   `yaml:"interval,omitempty"`
	Timeout     string   `yaml:"timeout,omitempty"`
	StartPeriod string   `yaml:"start_period,omitempty"`
	Retries     string   `yaml:"retries,omitempty"`
}

type Network

type Network struct {
	Driver   string
	External string
	//DriverOpts map[string]string "driver_opts"
	Extension map[string]interface{} `yaml:",inline,omitempty"`
}

type NetworkSettings

type NetworkSettings struct {
	Ports map[string][]PortBinding `json:"Ports,omitempty"`
}

NetworkSettings models the network settings section of the `docker inspect` command.

type Option

type Option func(*internalCFG)

Option is the type used for defining optional configuration

func OptionForcePull

func OptionForcePull(b bool) Option

If OptionForcePull is true, it attempts do pull newer versions of the images.

func OptionKeepAround added in v0.2.2

func OptionKeepAround(b bool) Option

If OptionKeepAround is true, it will not remove the containers after cleanup

func OptionRMFirst

func OptionRMFirst(b bool) Option

If OptionRMFirst is true, it attempts to kill and delete containers before starting new ones.

func OptionStartRetries added in v0.2.2

func OptionStartRetries(count int) Option

OptionStartRetries sets the number of times to retry the starting docker-compose

func OptionWithCompose

func OptionWithCompose(o Config) Option

OptionWithCompose sets the compose file to use during start

func OptionWithLogger

func OptionWithLogger(l *log.Logger) Option

OptionWithLogger sets the logger to use

func OptionWithProjectName

func OptionWithProjectName(p string) Option

OptionWithProjectName sets the project name to use

type PortBinding

type PortBinding struct {
	HostIP   string `json:"HostIP,omitempty"`
	HostPort string `json:"HostPort,omitempty"`
}

PortBinding models a port binding in the network settings section of the `docker inspect command.

type RestartPolicy added in v0.3.2

type RestartPolicy struct {
	Condition   string `yaml:"condition,omitempty"`
	Delay       string `yaml:"delay,omitempty"`
	MaxAttempts int    `yaml:"max_attempts,omitempty"`
	Window      string `yaml:"window,omitempty"`
}

type RetryPolicy added in v0.3.0

type RetryPolicy interface {
	AttemptAgain(error) (bool, time.Duration)
}

type Service

type Service struct {
	//ContainerName string   `yaml:"container_name,omitempty"`
	Image      string   `yaml:"image,omitempty"`
	Entrypoint string   `yaml:"entrypoint,omitempty"`
	Networks   []string `yaml:"networks,omitempty"`
	//Expose        []string    `yaml:"expose,omitempty"`
	Hostname    string                 `yaml:"hostname,omitempty"`
	Ports       []string               `yaml:"ports,omitempty"`
	Volumes     []*Volume              `yaml:"volumes,omitempty"`
	Command     []string               `yaml:"command,omitempty"`
	HealthCheck HealthCheck            `yaml:"healthcheck,omitempty"`
	DependsOn   []string               `yaml:"depends_on,omitempty"`
	Environment []string               `yaml:"environment,omitempty"`
	Deploy      map[string]interface{} `yaml:"deploy,omitempty"`
	Extension   map[string]interface{} `yaml:",inline,omitempty"`
}

type SimpleRetryPolicy added in v0.3.0

type SimpleRetryPolicy struct {
	NumRetries int //Number of times to retry a query
	Wait       time.Duration
	// contains filtered or unexported fields
}

func NewSimpleRetryPolicy added in v0.3.0

func NewSimpleRetryPolicy(retries int, wait time.Duration) *SimpleRetryPolicy

func (*SimpleRetryPolicy) AttemptAgain added in v0.3.0

func (s *SimpleRetryPolicy) AttemptAgain(err error) (bool, time.Duration)

type Volume added in v0.3.0

type Volume struct {
	Source     string                 `yaml:"source,omitempty"`
	Target     string                 `yaml:"target,omitempty"`
	Driver     string                 `yaml:"driver,omitempty"`
	External   string                 `yaml:"external,omitempty"`
	Type       string                 `yaml:"type,omitempty"`
	DriverOpts map[string]string      `yaml:"services,omitempty"`
	Volume     map[string]interface{} `yaml:"volume,omitempty"`
}

func (*Volume) UnmarshalYAML added in v0.3.0

func (v *Volume) UnmarshalYAML(unmarshal func(interface{}) error) error

Jump to

Keyboard shortcuts

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