compose

package module
v0.30.0 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2024 License: MIT Imports: 27 Imported by: 13

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrNoStackConfigured = errors.New("no stack files configured")

Functions

func NewDockerCompose

func NewDockerCompose(filePaths ...string) (*dockerCompose, error)

func NewDockerComposeWith

func NewDockerComposeWith(opts ...ComposeStackOption) (*dockerCompose, error)

Types

type ComposeLoggerOption

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

func WithLogger

func WithLogger(logger testcontainers.Logging) ComposeLoggerOption

WithLogger is a generic option that implements LocalDockerComposeOption It replaces the global Logging implementation with a user defined one e.g. to aggregate logs from testcontainers with the logs of specific test case

func (ComposeLoggerOption) ApplyToLocalCompose deprecated

func (o ComposeLoggerOption) ApplyToLocalCompose(opts *LocalDockerComposeOptions)

Deprecated: it will be removed in the next major release

type ComposeStack

type ComposeStack interface {
	Up(ctx context.Context, opts ...StackUpOption) error
	Down(ctx context.Context, opts ...StackDownOption) error
	Services() []string
	WaitForService(s string, strategy wait.Strategy) ComposeStack
	WithEnv(m map[string]string) ComposeStack
	WithOsEnv() ComposeStack
	ServiceContainer(ctx context.Context, svcName string) (*testcontainers.DockerContainer, error)
}

ComposeStack defines operations that can be applied to a parsed compose stack

type ComposeStackFiles

type ComposeStackFiles []string

type ComposeStackOption

type ComposeStackOption interface {
	// contains filtered or unexported methods
}

func WithStackFiles

func WithStackFiles(filePaths ...string) ComposeStackOption

type ComposeVersion

type ComposeVersion interface {
	Format(parts ...string) string
}

type DockerCompose deprecated

type DockerCompose interface {
	Down() ExecError
	Invoke() ExecError
	WaitForService(string, wait.Strategy) DockerCompose
	WithCommand([]string) DockerCompose
	WithEnv(map[string]string) DockerCompose
	WithExposedService(string, int, wait.Strategy) DockerCompose
}

Deprecated: DockerCompose is the old shell escape based API use ComposeStack instead DockerCompose defines the contract for running Docker Compose

type ExecError

type ExecError struct {
	Command      []string
	StdoutOutput []byte
	StderrOutput []byte
	Error        error
	Stdout       error
	Stderr       error
}

ExecError is super struct that holds any information about an execution error, so the client code can handle the result

type IgnoreOrphans

type IgnoreOrphans bool

IgnoreOrphans - Ignore legacy containers for services that are not defined in the project

type LocalDockerCompose deprecated

type LocalDockerCompose struct {
	ComposeVersion
	*LocalDockerComposeOptions
	Executable string

	ComposeFilePaths []string

	Identifier string
	Cmd        []string
	Env        map[string]string
	Services   map[string]interface{}

	WaitStrategyMap map[waitService]wait.Strategy
	// contains filtered or unexported fields
}

Deprecated: use ComposeStack instead LocalDockerCompose represents a Docker Compose execution using local binary docker compose or docker.exe compose, depending on the underlying platform

Example
_ = LocalDockerCompose{
	Executable: "docker compose",
	ComposeFilePaths: []string{
		"/path/to/docker-compose.yml",
		"/path/to/docker-compose-1.yml",
		"/path/to/docker-compose-2.yml",
		"/path/to/docker-compose-3.yml",
	},
	Identifier: "my_project",
	Cmd: []string{
		"up", "-d",
	},
	Env: map[string]string{
		"FOO": "foo",
		"BAR": "bar",
	},
}
Output:

func NewLocalDockerCompose deprecated

func NewLocalDockerCompose(filePaths []string, identifier string, opts ...LocalDockerComposeOption) *LocalDockerCompose

Deprecated: NewLocalDockerCompose returns a DockerCompose compatible instance which is superseded by ComposeStack use NewDockerCompose instead to get a ComposeStack compatible instance

NewLocalDockerCompose returns an instance of the local Docker Compose, using an array of Docker Compose file paths and an identifier for the Compose execution.

It will iterate through the array adding '-f compose-file-path' flags to the local Docker Compose execution. The identifier represents the name of the execution, which will define the name of the underlying Docker network and the name of the running Compose services.

Example
path := "/path/to/docker-compose.yml"

_ = NewLocalDockerCompose([]string{path}, "my_project")
Output:

func (*LocalDockerCompose) Down deprecated

func (dc *LocalDockerCompose) Down() ExecError

Deprecated: it will be removed in the next major release Down executes docker compose down

Example
path := "/path/to/docker-compose.yml"

compose := NewLocalDockerCompose([]string{path}, "my_project")

execError := compose.WithCommand([]string{"up", "-d"}).Invoke()
if execError.Error != nil {
	_ = fmt.Errorf("Failed when running: %v", execError.Command)
}

execError = compose.Down()
if execError.Error != nil {
	_ = fmt.Errorf("Failed when running: %v", execError.Command)
}
Output:

func (*LocalDockerCompose) Invoke deprecated

func (dc *LocalDockerCompose) Invoke() ExecError

Deprecated: it will be removed in the next major release Invoke invokes the docker compose

Example
path := "/path/to/docker-compose.yml"

compose := NewLocalDockerCompose([]string{path}, "my_project")

execError := compose.
	WithCommand([]string{"up", "-d"}).
	WithEnv(map[string]string{
		"bar": "BAR",
	}).
	Invoke()
if execError.Error != nil {
	_ = fmt.Errorf("Failed when running: %v", execError.Command)
}
Output:

func (*LocalDockerCompose) WaitForService deprecated

func (dc *LocalDockerCompose) WaitForService(service string, strategy wait.Strategy) DockerCompose

Deprecated: it will be removed in the next major release WaitForService sets the strategy for the service that is to be waited on

func (*LocalDockerCompose) WithCommand deprecated

func (dc *LocalDockerCompose) WithCommand(cmd []string) DockerCompose

Deprecated: it will be removed in the next major release WithCommand assigns the command

Example
path := "/path/to/docker-compose.yml"

compose := NewLocalDockerCompose([]string{path}, "my_project")

compose.WithCommand([]string{"up", "-d"})
Output:

func (*LocalDockerCompose) WithEnv deprecated

func (dc *LocalDockerCompose) WithEnv(env map[string]string) DockerCompose

Deprecated: it will be removed in the next major release WithEnv assigns the environment

Example
path := "/path/to/docker-compose.yml"

compose := NewLocalDockerCompose([]string{path}, "my_project")

compose.WithEnv(map[string]string{
	"FOO": "foo",
	"BAR": "bar",
})
Output:

func (*LocalDockerCompose) WithExposedService deprecated

func (dc *LocalDockerCompose) WithExposedService(service string, port int, strategy wait.Strategy) DockerCompose

Deprecated: it will be removed in the next major release WithExposedService sets the strategy for the service that is to be waited on. If multiple strategies are given for a single service running on different ports, both strategies will be applied on the same container

type LocalDockerComposeOption deprecated

type LocalDockerComposeOption interface {
	ApplyToLocalCompose(opts *LocalDockerComposeOptions)
}

Deprecated: it will be removed in the next major release LocalDockerComposeOption defines a common interface to modify LocalDockerComposeOptions These options can be passed to NewLocalDockerCompose in a variadic way to customize the returned LocalDockerCompose instance

type LocalDockerComposeOptions deprecated

type LocalDockerComposeOptions struct {
	Logger testcontainers.Logging
}

Deprecated: it will be removed in the next major release LocalDockerComposeOptions defines options applicable to LocalDockerCompose

type LocalDockerComposeOptionsFunc deprecated

type LocalDockerComposeOptionsFunc func(opts *LocalDockerComposeOptions)

Deprecated: it will be removed in the next major release LocalDockerComposeOptionsFunc is a shorthand to implement the LocalDockerComposeOption interface

func (LocalDockerComposeOptionsFunc) ApplyToLocalCompose deprecated

func (f LocalDockerComposeOptionsFunc) ApplyToLocalCompose(opts *LocalDockerComposeOptions)

Deprecated: it will be removed in the next major release

type RemoveImages

type RemoveImages uint8

RemoveImages used by services

const (
	// RemoveImagesAll - remove all images used by the stack
	RemoveImagesAll RemoveImages = iota
	// RemoveImagesLocal - remove only images that don't have a tag
	RemoveImagesLocal
)

type RemoveOrphans

type RemoveOrphans bool

RemoveOrphans will clean up containers that are not declared on the compose model but own the same labels

type RemoveVolumes added in v0.19.0

type RemoveVolumes bool

type StackDownOption

type StackDownOption interface {
	// contains filtered or unexported methods
}

type StackIdentifier

type StackIdentifier string

func (StackIdentifier) String

func (f StackIdentifier) String() string

type StackUpOption

type StackUpOption interface {
	// contains filtered or unexported methods
}

func RunServices

func RunServices(serviceNames ...string) StackUpOption

RunServices is comparable to 'docker compose run' as it only creates a subset of containers instead of all services defined by the project

type Wait

type Wait bool

Wait won't return until containers reached the running|healthy state

Jump to

Keyboard shortcuts

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