Documentation ¶
Overview ¶
Package compose is the main rocker-compose facade. It provides functions to execute various rocker-compose tasks based on the given manifest.
Rocker-compose is a docker composition tool with idempotency features for deploying applications that consist of multiple containers.
Index ¶
- Variables
- func GetBridgeIP(client *docker.Client) (ip string, err error)
- func NewContainerFormatter(container *Container, level log.Level) log.Formatter
- func PullDockerImage(client *docker.Client, image *imagename.ImageName, ...) (*docker.Image, error)
- func WalkActions(actions []Action, fn func(action Action))
- type Action
- func NewEnsureContainerExistAction(c *Container) Action
- func NewEnsureContainerStateAction(c *Container) Action
- func NewRemoveContainerAction(c *Container) Action
- func NewRunContainerAction(c *Container) Action
- func NewStepAction(async bool, actions ...Action) Action
- func NewWaitContainerAction(c *Container) Action
- type Client
- type Compose
- func (compose *Compose) CleanAction() error
- func (compose *Compose) PinAction(local, hub bool) (template.Vars, error)
- func (compose *Compose) PullAction() error
- func (compose *Compose) RecoverAction() error
- func (compose *Compose) RunAction() error
- func (compose *Compose) WritePlan(resp *ansible.Response) *ansible.Response
- type Config
- type Container
- type ContainerIo
- type ContainerState
- type Diff
- type DockerClient
- func (client *DockerClient) AttachToContainer(container *Container) error
- func (client *DockerClient) AttachToContainers(containers []*Container) error
- func (client *DockerClient) Clean(config *config.Config) error
- func (client *DockerClient) EnsureContainerExist(container *Container) error
- func (client *DockerClient) EnsureContainerState(container *Container) error
- func (client *DockerClient) FetchImages(containers []*Container, vars template.Vars) error
- func (client *DockerClient) GetContainers(global bool) ([]*Container, error)
- func (client *DockerClient) GetPulledImages() []*imagename.ImageName
- func (client *DockerClient) GetRemovedImages() []*imagename.ImageName
- func (client *DockerClient) Pin(local, hub bool, vars template.Vars, containers []*Container) error
- func (client *DockerClient) PullAll(containers []*Container, vars template.Vars) error
- func (client *DockerClient) RemoveContainer(container *Container) error
- func (client *DockerClient) RunContainer(container *Container) error
- func (client *DockerClient) StartContainer(container *Container) error
- func (client *DockerClient) WaitForContainer(container *Container) (err error)
- type ErrContainerBadState
- type Runner
Constants ¶
This section is empty.
Variables ¶
var NoAction = &noAction{}
NoAction is an empty action which does nothing
Functions ¶
func GetBridgeIP ¶
GetBridgeIP gets the ip address of docker network bridge it is useful when you want to loose couple containers and not have tightly link them container A may publish port 8125 to host network and container B may access this port through a bridge ip address; it's a hacky solution, any better way to obtain bridge ip without ssh access to host machine is welcome
Here we create a dummy container and look at .NetworkSettings.Gateway value ¶
TODO: maybe we don't need this anymore since docker 1.8 seem to specify all existing containers
in a /etc/hosts file of every contianer. Need to research it further.
https://github.com/docker/docker/issues/1143 https://github.com/docker/docker/issues/11247
func NewContainerFormatter ¶
NewContainerFormatter returns an object that is given to logrus to better format contaienr output
func PullDockerImage ¶
func PullDockerImage(client *docker.Client, image *imagename.ImageName, auth *docker.AuthConfigurations) (*docker.Image, error)
PullDockerImage pulls an image and streams to a logger respecting terminal features
func WalkActions ¶
WalkActions recursively though all action and applies given function to every action.
Types ¶
type Action ¶
Action interface describes action that can be done by rocker-compose docker client
func NewEnsureContainerExistAction ¶
NewEnsureContainerExistAction makes action that ensures that container exists
func NewEnsureContainerStateAction ¶
NewEnsureContainerStateAction makes action that ensures that container state is a desired one
func NewRemoveContainerAction ¶
NewRemoveContainerAction makes action that removes a container
func NewRunContainerAction ¶
NewRunContainerAction makes action that runs a container
func NewStepAction ¶
NewStepAction makes a "step" wrapper which holds the list of actions that may run in parallel. Multiple steps can only run one by one. Steps can be nested.
func NewWaitContainerAction ¶
NewWaitContainerAction makes action that waits for container
type Client ¶
type Client interface { GetContainers(global bool) ([]*Container, error) RemoveContainer(container *Container) error RunContainer(container *Container) error EnsureContainerExist(name *Container) error EnsureContainerState(name *Container) error PullAll(containers []*Container, vars template.Vars) error Clean(config *config.Config) error AttachToContainers(container []*Container) error AttachToContainer(container *Container) error FetchImages(containers []*Container, vars template.Vars) error WaitForContainer(container *Container) error GetPulledImages() []*imagename.ImageName GetRemovedImages() []*imagename.ImageName Pin(local, hub bool, vars template.Vars, containers []*Container) error }
Client interface describes a rocker-compose client that can do various operations needed for rocker-compose to make changes.
type Compose ¶
type Compose struct { Manifest *config.Config DryRun bool Attach bool Pull bool Remove bool Wait time.Duration // contains filtered or unexported fields }
Compose is the main object that executes actions and holds runtime information.
func (*Compose) CleanAction ¶
CleanAction implements 'rocker-compose clean'
func (*Compose) PullAction ¶
PullAction implements 'rocker-compose pull'
func (*Compose) RecoverAction ¶
RecoverAction implements 'rocker-compose recover'
TODO: It duplicates the code of RunAction a bit. Also, do we need this function at all?
Docker starts containers of "restart=always" automatically after daemon restart.
type Config ¶
type Config struct { Manifest *config.Config Docker *docker.Client Force bool DryRun bool Attach bool Pull bool Remove bool Recover bool Wait time.Duration Auth *docker.AuthConfigurations KeepImages int }
Config is a configuration object which is passed to compose.New() for creating the new Compose instance.
type Container ¶
type Container struct { ID string Image *imagename.ImageName ImageResolved *imagename.ImageName ImageID string Name *config.ContainerName Created time.Time State *ContainerState Config *config.Container Io *ContainerIo // contains filtered or unexported fields }
Container object represents a single container produced by a rocker-compose spec
func GetContainersFromConfig ¶
GetContainersFromConfig returns the list of Container objects from a spec Config object.
func NewContainerFromConfig ¶
func NewContainerFromConfig(name *config.ContainerName, containerConfig *config.Container) *Container
NewContainerFromConfig makes a single Container object from a spec Config object.
func NewContainerFromDocker ¶
NewContainerFromDocker converts a container object given by docker client to a local Container object
func (*Container) CreateContainerOptions ¶
CreateContainerOptions returns create configuration eatable by go-dockerclient
func (*Container) IsEqualTo ¶
IsEqualTo returns true if current and given containers are equal by all dimensions. It compares configuration, image id (image can be updated), state (running, craeted)
func (*Container) IsSameKind ¶
IsSameKind returns true if current and given containers have same name, without considering namespace
func (*Container) IsSameNamespace ¶
IsSameNamespace returns true if current and given containers are from same namespace
type ContainerIo ¶
type ContainerIo struct { Stdout io.Writer Stderr io.Writer // contains filtered or unexported fields }
ContainerIo initializes and maintains container I/O and also owns 'done' channel that can be used by other actors
func NewContainerIo ¶
func NewContainerIo(container *Container) *ContainerIo
NewContainerIo makes ContainerIo objects and initializes formatters for container's stdout and stderr streams
func (*ContainerIo) Done ¶
func (cio *ContainerIo) Done(err error)
Done marks I/O not alive and if it not becomes alive during next 1 second, then it sends to 'done' channel
func (*ContainerIo) Wait ¶
func (cio *ContainerIo) Wait() error
Wait waits for 'done' event for a container I/O
type ContainerState ¶
type ContainerState struct { Running bool Paused bool Restarting bool OOMKilled bool Pid int ExitCode int Error string StartedAt time.Time FinishedAt time.Time }
ContainerState represents the state of a container.
func (*ContainerState) IsEqualState ¶
func (a *ContainerState) IsEqualState(b *ContainerState) bool
IsEqualState returns true if current and given containers have the same state
type Diff ¶
Diff describes a comparison functionality of two container sets: expected and actual 'expected' is a list of containers from a spec (compose.yml) 'actual' is a list of existing containers in a docker daemon
The Diff function should return the action list that is needed to transition form the 'actual' state to the 'expected' one.
type DockerClient ¶
type DockerClient struct { Docker *docker.Client Attach bool Wait time.Duration Auth *docker.AuthConfigurations KeepImages int Recover bool // contains filtered or unexported fields }
DockerClient is an implementation of Client interface that do operations to a given docker client
func NewClient ¶
func NewClient(initialClient *DockerClient) (*DockerClient, error)
NewClient makes a new DockerClient object based on configuration params that is given with input DockerClient object.
func (*DockerClient) AttachToContainer ¶
func (client *DockerClient) AttachToContainer(container *Container) error
AttachToContainer attaches to a running container and redirects its streams to log
func (*DockerClient) AttachToContainers ¶
func (client *DockerClient) AttachToContainers(containers []*Container) error
AttachToContainers attaches to all containers that specified to be running
func (*DockerClient) Clean ¶
func (client *DockerClient) Clean(config *config.Config) error
Clean finds the obsolete image tags from container specs that exist in docker daemon, skipping topN images that we want to keep (keep_images, default 5) and deletes them.
func (*DockerClient) EnsureContainerExist ¶
func (client *DockerClient) EnsureContainerExist(container *Container) error
EnsureContainerExist implements ensuring that container exists in docker daemon
func (*DockerClient) EnsureContainerState ¶
func (client *DockerClient) EnsureContainerState(container *Container) error
EnsureContainerState checks that the state of existing docker daemon container equals expected state specified in the spec.
func (*DockerClient) FetchImages ¶
func (client *DockerClient) FetchImages(containers []*Container, vars template.Vars) error
FetchImages fetches the missing images for all containers in the manifest
func (*DockerClient) GetContainers ¶
func (client *DockerClient) GetContainers(global bool) ([]*Container, error)
GetContainers implements the retrieval of existing containers from the docker daemon. It fetches the list and then inspects every container in parallel (pmap). Timeouts after 30 seconds if some inspect operations hanged.
func (*DockerClient) GetPulledImages ¶
func (client *DockerClient) GetPulledImages() []*imagename.ImageName
GetPulledImages returns the list of images pulled by a recent run
func (*DockerClient) GetRemovedImages ¶
func (client *DockerClient) GetRemovedImages() []*imagename.ImageName
GetRemovedImages returns the list of images removed by a recent run
func (*DockerClient) PullAll ¶
func (client *DockerClient) PullAll(containers []*Container, vars template.Vars) error
PullAll grabs all image names from containers in spec and pulls all of them
func (*DockerClient) RemoveContainer ¶
func (client *DockerClient) RemoveContainer(container *Container) error
RemoveContainer implements removing a container
func (*DockerClient) RunContainer ¶
func (client *DockerClient) RunContainer(container *Container) error
RunContainer implements creating and optionally running a container depending on its state preference.
func (*DockerClient) StartContainer ¶
func (client *DockerClient) StartContainer(container *Container) error
StartContainer implements starting a container If contianer state is "ran" then it waits until container exit and checks exit code; otherwise it waits for configurable '--wait' seconds interval and ensures container not exited.
func (*DockerClient) WaitForContainer ¶
func (client *DockerClient) WaitForContainer(container *Container) (err error)
WaitForContainer waits for a container and checks exit code at the end If exitCode != 0 then fires an error
type ErrContainerBadState ¶
type ErrContainerBadState struct { Container *Container Running bool OOMKilled bool ExitCode int ErrorStr string StartedAt time.Time FinishedAt time.Time }
ErrContainerBadState is an error that describes state inconsistency that can be checked by EnsureContainerState function
func (ErrContainerBadState) Error ¶
func (e ErrContainerBadState) Error() string
Error returns string representation of the error
type Runner ¶
Runner interface describes a runnable facade which executes given list of actions
func NewDockerClientRunner ¶
NewDockerClientRunner makes a runner that uses a DockerClient for executing actions
func NewDryRunner ¶
func NewDryRunner() Runner
NewDryRunner makes a runner that does not actually execute actions, but prints them
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package ansible is providing data structures and functions for responses when rocker-compose is running in ansible mode (rocker-compose run --ansible)
|
Package ansible is providing data structures and functions for responses when rocker-compose is running in ansible mode (rocker-compose run --ansible) |
Package config holds functionality for processing compose.yml manifests, templating, converting manifests to docker api run spec and comparing them against each other.
|
Package config holds functionality for processing compose.yml manifests, templating, converting manifests to docker api run spec and comparing them against each other. |