Documentation ¶
Overview ¶
package dccli provides a Go wrapper around Docker Compose, useful for integration testing. Check out the test cases for example usage
Index ¶
- func InferDockerHost() (string, error)
- func MustInferDockerHost() string
- type Compose
- type Config
- type ContainerConfig
- type ContainerInfo
- type ContainerState
- type ExponentialBackoffRetryPolicy
- type HealthCheck
- type Network
- type NetworkSettings
- type Option
- type PortBinding
- type RestartPolicy
- type RetryPolicy
- type Service
- type SimpleRetryPolicy
- type Volume
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func InferDockerHost ¶
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 Start ¶
Start starts a Docker Compose configuration. TODO(mclemens) accept an io.Reader or a set of options
func (*Compose) Cleanup ¶
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 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 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 ¶
If OptionForcePull is true, it attempts do pull newer versions of the images.
func OptionKeepAround ¶ added in v0.2.2
If OptionKeepAround is true, it will not remove the containers after cleanup
func OptionRMFirst ¶
If OptionRMFirst is true, it attempts to kill and delete containers before starting new ones.
func OptionStartRetries ¶ added in v0.2.2
OptionStartRetries sets the number of times to retry the starting docker-compose
func OptionWithCompose ¶
OptionWithCompose sets the compose file to use during start
func OptionWithLogger ¶
OptionWithLogger sets the logger to use
func OptionWithProjectName ¶
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 RetryPolicy ¶ added in v0.3.0
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"` }