container

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2018 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MapToEnv added in v0.2.0

func MapToEnv(data map[string]string) []string

MapToEnv transform a map of key value to a array of env string. env vars sorted by names to get an accurate order while testing, otherwise comparing a string slice with different orders will fail.

Types

type BuildResponse

type BuildResponse struct {
	Stream string `json:"stream"`
	Error  string `json:"error"`
}

BuildResponse is the object that is returned by the docker api in json

type Container added in v0.2.0

type Container interface {
	Build(path string) (tag string, err error)
	CreateNetwork(namespace []string) (id string, err error)
	DeleteNetwork(namespace []string, event EventType) error
	FindContainer(namespace []string) (types.ContainerJSON, error)
	FindNetwork(namespace []string) (types.NetworkResource, error)
	FindService(namespace []string) (swarm.Service, error)
	ListServices(labels ...string) ([]swarm.Service, error)
	ListTasks(namespace []string) ([]swarm.Task, error)
	Namespace(ss []string) string
	ServiceLogs(namespace []string) (io.ReadCloser, error)
	SharedNetworkID() (networkID string, err error)
	StartService(options ServiceOptions) (serviceID string, err error)
	Status(namespace []string) (StatusType, error)
	StopService(namespace []string) (err error)
	TasksError(namespace []string) ([]string, error)
}

Container describes the API of container package.

type DockerContainer added in v0.3.0

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

DockerContainer provides high level interactions with Docker API for MESG.

func New added in v0.2.0

func New(options ...Option) (*DockerContainer, error)

New creates a new Container with given options.

func (*DockerContainer) Build added in v0.3.0

func (c *DockerContainer) Build(path string) (tag string, err error)

Build builds a docker image.

func (*DockerContainer) CreateNetwork added in v0.3.0

func (c *DockerContainer) CreateNetwork(namespace []string) (id string, err error)

CreateNetwork creates a Docker Network with a namespace.

func (*DockerContainer) DeleteNetwork added in v0.3.0

func (c *DockerContainer) DeleteNetwork(namespace []string, event EventType) error

DeleteNetwork deletes a Docker Network associated with a namespace. event parameter can be "destroy" or "remove". If the network was used by a service, the event to use is "destroy". If the network has not been used, the event is "remove". Remove removes the reference from Docker to the network. Destroy removes the network from Docker active network.

func (*DockerContainer) FindContainer added in v0.3.0

func (c *DockerContainer) FindContainer(namespace []string) (types.ContainerJSON, error)

FindContainer returns a docker container.

func (*DockerContainer) FindNetwork added in v0.3.0

func (c *DockerContainer) FindNetwork(namespace []string) (types.NetworkResource, error)

FindNetwork finds a Docker Network by a namespace. If no network is found, an error is returned.

func (*DockerContainer) FindService added in v0.3.0

func (c *DockerContainer) FindService(namespace []string) (swarm.Service, error)

FindService returns the Docker Service or an error if not found.

func (*DockerContainer) ListServices added in v0.3.0

func (c *DockerContainer) ListServices(labels ...string) ([]swarm.Service, error)

ListServices returns existing docker services matching a specific label name.

func (*DockerContainer) ListTasks added in v0.3.0

func (c *DockerContainer) ListTasks(namespace []string) ([]swarm.Task, error)

ListTasks returns all the docker tasks.

func (*DockerContainer) Namespace added in v0.3.0

func (c *DockerContainer) Namespace(ss []string) string

Namespace creates a namespace from a list of string.

func (*DockerContainer) ServiceLogs added in v0.3.0

func (c *DockerContainer) ServiceLogs(namespace []string) (io.ReadCloser, error)

ServiceLogs returns the logs of a service.

func (*DockerContainer) SharedNetworkID added in v0.3.0

func (c *DockerContainer) SharedNetworkID() (networkID string, err error)

SharedNetworkID returns the ID of the shared network.

func (*DockerContainer) StartService added in v0.3.0

func (c *DockerContainer) StartService(options ServiceOptions) (serviceID string, err error)

StartService starts a docker service.

func (*DockerContainer) Status added in v0.3.0

func (c *DockerContainer) Status(namespace []string) (StatusType, error)

Status returns the status of the container based on the docker container and docker service. if any error occurs during the status check, status will be shown as UNKNOWN. otherwise the following rules will be applied to determine a status:

  • RUNNING: when the container is running in docker regardless of the status of the service.
  • STARTING: when the service is running but the container is not yet started.
  • STOPPED: when the container and the service is not running in docker.

func (*DockerContainer) StopService added in v0.3.0

func (c *DockerContainer) StopService(namespace []string) (err error)

StopService stops a docker service.

func (*DockerContainer) TasksError added in v0.3.0

func (c *DockerContainer) TasksError(namespace []string) ([]string, error)

TasksError returns the error of matching tasks.

type EventType added in v0.3.0

type EventType string

EventType is a type to define the kind of event related to the network

const (
	EventRemove  EventType = "remove"
	EventDestroy EventType = "destroy"
)

List of Network status to listen to confirm a network deletion

type Mount

type Mount struct {
	Source string
	Target string
	Bind   bool
}

Mount is a simplify version of mount.Mount.

type Network added in v0.4.0

type Network struct {
	// ID of the docker network.
	ID string

	// Alias is an optional attribute to name this service in the
	// network and be able to access to it using this name.
	Alias string
}

Network keeps the network info for service.

type Option added in v0.2.0

type Option func(*DockerContainer)

Option is a configuration func for Container.

func ClientOption added in v0.2.0

func ClientOption(client docker.CommonAPIClient) Option

ClientOption receives a client which will be used to interact with Docker API.

func TimeoutOption added in v0.2.0

func TimeoutOption(d time.Duration) Option

TimeoutOption receives d which will be set as a timeout value for Docker API calls.

type Port

type Port struct {
	Target    uint32
	Published uint32
}

Port is a simplify version of swarm.PortConfig.

type ServiceOptions

type ServiceOptions struct {
	Image     string
	Namespace []string
	Ports     []Port
	Mounts    []Mount
	Env       []string // TODO: should be transform to  map[string]string and use the func mapToEnv
	Args      []string
	Networks  []Network
	Labels    map[string]string
}

ServiceOptions is a simplify version of swarm.ServiceSpec.

type StatusType

type StatusType uint

StatusType of the service.

const (
	UNKNOWN StatusType = iota
	STOPPED
	STARTING
	RUNNING
)

Possible status for services.

Directories

Path Synopsis
Package dockertest provides functionalities for mocking and faking the Docker API.
Package dockertest provides functionalities for mocking and faking the Docker API.

Jump to

Keyboard shortcuts

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