Documentation ¶
Overview ¶
Package dockerutil provides some convience wrappers around the go-dockerclient package.
Index ¶
- Constants
- Variables
- func Lock(name string) *flock
- type Client
- func (client *Client) CreateContainer(opts DockerCreateContainerOptions) (*Container, error)
- func (client *Client) InspectContainer(id string) (*Container, error)
- func (client *Client) PullPublicIfRequired(imageName string) error
- func (client *Client) StartNewContainer(containerOpts DockerCreateContainerOptions) (c *Container, err error)
- type Container
- func StartContainer(name string, env []string, imageOverride string) (*Container, error)
- func StartContainerWithConfig(config *ContainerConfig, env []string, imageOverride string) (*Container, error)
- func StartDynamoContainer() (*Container, error)
- func StartKinesisContainer() (*Container, error)
- func StartMysqlContainer(rootPassword, databaseName string) (*Container, error)
- func StartPostgresContainer(rootPassword string) (*Container, error)
- func StartRedisContainer() (*Container, error)
- func StartS3Container(accessKey, secretKey string) (*Container, error)
- func StartSNSContainer() (*Container, error)
- func StartSQSContainer() (*Container, error)
- type ContainerConfig
- type ContainerConfigs
- type DockerAuthConfiguration
- type DockerBuildImageOptions
- type DockerClient
- type DockerConfig
- type DockerContainer
- type DockerCreateContainerOptions
- type DockerHostConfig
- type DockerHostPortBinding
- type DockerPort
- type DockerPullImageOptions
- type DockerRemoveContainerOptions
- type DynamoSuite
- type KinesisSuite
- func (s *KinesisSuite) CreateStream(name string) string
- func (s *KinesisSuite) DeleteStream(name string)
- func (s *KinesisSuite) GetIterator(stream, shardID string) string
- func (s *KinesisSuite) GetRecords(stream, shardID string) [][]byte
- func (s *KinesisSuite) PutRecords(stream string, recs [][]byte)
- func (s *KinesisSuite) SetupSuite()
- type PostgresSuite
- type RedisSuite
- type S3Object
- type S3Suite
- func (s *S3Suite) CreateBucket(name string)
- func (s *S3Suite) DeleteAllObjects(bucket string)
- func (s *S3Suite) DeleteBucket(name string)
- func (s *S3Suite) DeleteObject(bucket, path string)
- func (s *S3Suite) DeleteObjects(bucket string, paths []string)
- func (s *S3Suite) GetObject(bucket, path string) []byte
- func (s *S3Suite) GetObjectWithResponse(bucket, path string) (resp *s3.GetObjectOutput, respData []byte)
- func (s *S3Suite) GetObjects(bucket string, paths []string) map[string][]byte
- func (s *S3Suite) ListObjects(bucket, prefix string) []S3Object
- func (s *S3Suite) PutObject(bucket, path, contentType string, data []byte)
- func (s *S3Suite) PutObjects(bucket, contentType string, objs map[string][]byte)
- func (s *S3Suite) SetupSuite()
- type SNSSuite
- type SQSSuite
- type Suite
Constants ¶
const ( S3DefaultAccessKey = "access_key" S3DefaultSecretKey = "secret_key" )
const (
PostgresDefaultPassword = "password"
)
Variables ¶
var ( Logger io.Writer DefaultEndpoint = "unix:///var/run/docker.sock" DefaultClient, _ = NewClient(DefaultEndpoint) )
var ( DefaultTerminateAction = "PURGE" DefaultContainerTimeout uint = 10 )
var Containers = ContainerConfigs{ "postgres": &ContainerConfig{ Image: "postgres:11.2", Port: "5432/tcp", }, "dynamo": &ContainerConfig{ Image: "peopleperhour/dynamodb", Port: "8000/tcp", }, "s3": &ContainerConfig{ Image: "minio/minio:RELEASE.2019-03-13T21-59-47Z", Port: "9000/tcp", Env: []string{ "MINIO_BROWSER=off", "MINIO_UPDATE=off", }, Args: []string{ "server", "/home/minio", }, }, "sns": &ContainerConfig{ Image: "pafortin/goaws:1.1.2", Port: "4100/tcp", }, "sqs": &ContainerConfig{ Image: "fingershock/elasticmq:0.14.6", Port: "9324/tcp", }, "kinesis": &ContainerConfig{ Image: "instructure/kinesalite", Port: "4567/tcp", Args: []string{ "--deleteStreamMs", "0", }, }, "mysql": &ContainerConfig{ Image: "mysql:5.6.34", Port: "3306/tcp", Init: func(client *Client, config *ContainerConfig) error { img, _ := client.InspectImage(mysqlUtf8Image) if img == nil { if err := buildMysqlImage(config); err != nil { return err } } return nil }, }, "redis": &ContainerConfig{ Image: "redis:5.0", Port: "6379/tcp", }, }
Containers is a map defining a set of named container configurations available for use.
Functions ¶
Types ¶
type Client ¶
type Client struct {
*DockerClient
}
Client wraps the go-dockerclient Client type to add some convenience methods.
It embeds that type so all properties and methods are supported.
func NewClient ¶
NewClient creates a new Client object, wrapping the native go-dockerclient Client. See also NewClientFromEnv.
func NewClientFromEnv ¶
NewClientFromEnv initializes a new Docker client object from environment variables. This is the best way to initialize a client on OS X, where communication with the Docker API is via a self-signed HTTPS endpoint, not a UNIX socket.
func (*Client) CreateContainer ¶
func (client *Client) CreateContainer(opts DockerCreateContainerOptions) (*Container, error)
CreateContainer is a convenience wrapper around Client.CreateContainer() that returns a wrapped Container type.
func (*Client) InspectContainer ¶
InspectContainer is a convience wrapp around Client.InspectContainer() that returns a wrapped Container type.
func (*Client) PullPublicIfRequired ¶
PullPublicIfRequired checks to see if the local docker installation has an image available and if not attempts to fetch it from the public docker registry.
It sends any logging information to the Logger defined in this package (if any).
func (*Client) StartNewContainer ¶
func (client *Client) StartNewContainer(containerOpts DockerCreateContainerOptions) (c *Container, err error)
StartNewContainer creates a new container, starts it and retrieves detailed information about it.
type Container ¶
type Container struct { *DockerContainer // contains filtered or unexported fields }
Container wraps the go-dockerclient Container type to add some convenience methods.
It embeds that type so all properties and methods are supported.
func StartContainer ¶
StartContainer starts a named container configuration, with an optional set of environment variables, and an optional override for the image name.
func StartContainerWithConfig ¶
func StartContainerWithConfig(config *ContainerConfig, env []string, imageOverride string) (*Container, error)
func StartDynamoContainer ¶
func StartKinesisContainer ¶
func StartMysqlContainer ¶
func StartPostgresContainer ¶
func StartRedisContainer ¶
func StartS3Container ¶
func StartSNSContainer ¶
func StartSQSContainer ¶
func (*Container) Addr ¶
Addr returns a complete network address with IP address and exposed port for connecting to the primary service exposed by a container.
func (*Container) IPAddress ¶
IPAddress returns the IP address associated with the container, if any. If we're running under OS X, the returned address will be that of the docker host, as the container's address is not directly accessible.
func (*Container) Port ¶
Port returns the primary exposed port of the container. If we're running under OS X, this will be the mapped port on the Docker host's network address. If the container is running under Linux, this will be the exposed port on the container's network address.
func (*Container) WaitForContainer ¶
WaitForContainer waits until the container's primary exposed port is listening and available. See WaitForListeningPort().
func (*Container) WaitForListeningPort ¶
WaitForListeningPort waits for the container to be available by attempting to connect to the specified address and port. An error will be returned if the connection is not accepted before the timeout of 30 seconds.
type ContainerConfig ¶
type ContainerConfig struct { // Image is the name of the Docker image to be started. It will be // pulled from docker hub if necessary, or built, if Dockerfile or // Init are specified. Image string // Dockerfile is a custom Dockerfile to build a custom container // image from. At this time a custom Dockerfile cannot add // additional files to the image, but it can run configuration // commands during build. Only one of Dockerfile or Init should be // specified. Dockerfile string // Init specifies a handler function for optionally initializing // the docker image. This can be used to build a custom image, for // example, with more control than using the Dockerfile // parameter. Only one of Dockerfile or Init should be specified. Init func(*Client, *ContainerConfig) error // Port is a Docker port spec for the primary listening port and // protocol to be exposed, e.g. "8000/tcp". Port string // Env specifies a set of environment variables to pass to the // container, if supplied. Env []string // Args specifies a set of command line args to be passed to the // container invocation, if supplied. Args []string // Request to bind the docker Port to a given HostIP,HostPort // This option should only be hard-wired for local tests as // other environments, such as the build server, can't guarantee // that a particular port will be free HostPortBinding DockerHostPortBinding }
ContainerConfig defines the parameters for launching a Docker container.
func (*ContainerConfig) Build ¶
func (cfg *ContainerConfig) Build() error
type ContainerConfigs ¶
type ContainerConfigs map[string]*ContainerConfig
type DockerAuthConfiguration ¶
type DockerAuthConfiguration = docker.AuthConfiguration
type DockerBuildImageOptions ¶
type DockerBuildImageOptions = docker.BuildImageOptions
type DockerClient ¶
func DockerNewClient ¶
func DockerNewClient(endpoint string) (*DockerClient, error)
func DockerNewClientFromEnv ¶
func DockerNewClientFromEnv() (*DockerClient, error)
type DockerConfig ¶
type DockerContainer ¶
type DockerCreateContainerOptions ¶
type DockerCreateContainerOptions = docker.CreateContainerOptions
type DockerHostConfig ¶
type DockerHostConfig = docker.HostConfig
type DockerHostPortBinding ¶
type DockerHostPortBinding = docker.PortBinding
type DockerPort ¶
type DockerPullImageOptions ¶
type DockerPullImageOptions = docker.PullImageOptions
type DockerRemoveContainerOptions ¶
type DockerRemoveContainerOptions = docker.RemoveContainerOptions
type DynamoSuite ¶
type DynamoSuite struct { Suite // Dynamo is the AWS SDK client, which will be assigned when // SetupSuite() completes successfully. Dynamo *dynamodb.DynamoDB Config *aws.Config }
DynamoSuite is a base test suite type which launches a local Amazon DynamoDB-compatible docker container and configures the Amazon AWS SDK's dynamo client to point to it.
Unlike many other local implementations of an AWS backend, the local Dynamo implementation is provided by Amazon. See https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBLocal.html
This will also be home to some helper functions at some point.
func (*DynamoSuite) DeleteAllTables ¶
func (s *DynamoSuite) DeleteAllTables()
DeleteAllTables will, exactly as the name implies, delete *EVERY* table in DynamoDB. Needless to say, you should never, ever, EVER run this against an actual connection to live AWS.
func (*DynamoSuite) ListTableNames ¶
func (s *DynamoSuite) ListTableNames() []string
func (*DynamoSuite) SetupSuite ¶
func (s *DynamoSuite) SetupSuite()
type KinesisSuite ¶
func (*KinesisSuite) CreateStream ¶
func (s *KinesisSuite) CreateStream(name string) string
func (*KinesisSuite) DeleteStream ¶
func (s *KinesisSuite) DeleteStream(name string)
func (*KinesisSuite) GetIterator ¶
func (s *KinesisSuite) GetIterator(stream, shardID string) string
func (*KinesisSuite) GetRecords ¶
func (s *KinesisSuite) GetRecords(stream, shardID string) [][]byte
func (*KinesisSuite) PutRecords ¶
func (s *KinesisSuite) PutRecords(stream string, recs [][]byte)
func (*KinesisSuite) SetupSuite ¶
func (s *KinesisSuite) SetupSuite()
type PostgresSuite ¶
func (*PostgresSuite) SetupSuite ¶
func (s *PostgresSuite) SetupSuite()
type RedisSuite ¶
RedisSuite is a base test suite type which launches a local docker container with Redis.
func (*RedisSuite) SetupSuite ¶
func (s *RedisSuite) SetupSuite()
type S3Suite ¶
type S3Suite struct { Suite // S3 is the AWS SDK client, which will be assigned when // SetupSuite() completes successfully. S3 *s3.S3 AccessKey string SecretKey string Config *aws.Config }
S3Suite is a base test suite type which launches a local Amazon S3-compatible docker container and configures the Amazon AWS SDK's S3 client to point to it.
It also provides a number of wrapper functions for S3 SDK calls that simplify manipulating and inspecting S3 for test case setup and teardown. Rather than returning errors, these functions will cause test errors or failures, to keep the test code minimal.
func (*S3Suite) CreateBucket ¶
func (*S3Suite) DeleteAllObjects ¶
func (*S3Suite) DeleteBucket ¶
func (*S3Suite) DeleteObject ¶
func (*S3Suite) DeleteObjects ¶
func (*S3Suite) GetObjectWithResponse ¶
func (s *S3Suite) GetObjectWithResponse(bucket, path string) (resp *s3.GetObjectOutput, respData []byte)
func (*S3Suite) GetObjects ¶
func (*S3Suite) ListObjects ¶
func (*S3Suite) PutObjects ¶
func (*S3Suite) SetupSuite ¶
func (s *S3Suite) SetupSuite()
type SNSSuite ¶
type SNSSuite struct { Suite SNS *sns.SNS Config *aws.Config Endpoint string MetricsReg *metrics.Registry }
func (*SNSSuite) CreateTopic ¶
func (*SNSSuite) DeleteTopic ¶
func (*SNSSuite) SetupSuite ¶
func (s *SNSSuite) SetupSuite()
type SQSSuite ¶
type SQSSuite struct { Suite SQS *sqs.SQS Config *aws.Config Endpoint string MetricsReg *metrics.Registry EnableLogging bool }
func (*SQSSuite) CreateQueue ¶
func (*SQSSuite) DeleteQueue ¶
func (*SQSSuite) SetupSuite ¶
func (s *SQSSuite) SetupSuite()
type Suite ¶
type Suite struct { suite.Suite // Container is a pointer to the Container structure, which will // be assigned after SetupSuite() successfully starts the // container. Container *Container // Start is a function which launches a container, returning the // container and an optional error. Each concrete docker test // suite must set the Start member before propagating the // SetupSuite() call, and should call one of the container // starting functions provided by dockerutil. // // See S3Suite for a concrete example. Start func() (*Container, error) }
Suite provides a base type to use for constructing test suites that depend on docker container. Concrete test suite types must set the Start function.
func (*Suite) SetupSuite ¶
func (s *Suite) SetupSuite()
func (*Suite) TearDownSuite ¶
func (s *Suite) TearDownSuite()