docker

package
v0.31.0 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2022 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package docker contains Docker-related helpers for component tests.

Index

Constants

View Source
const DefaultSessionFile = ".bakesession"

DefaultSessionFile is the file name used for storing sessions.

Variables

View Source
var RetryMaxTimeout = 5 * time.Minute

RetryMaxTimeout is the timeout for the default retry func.

Functions

func CleanupResources added in v0.9.4

func CleanupResources() error

CleanupResources finds all session files and prunes Docker resources associated with them.

func CleanupSessionResources added in v0.22.0

func CleanupSessionResources(session *Session) error

CleanupSessionResources cleans up Docker resources for a Session.

func CleanupSessionResourcesFromFile added in v0.22.0

func CleanupSessionResourcesFromFile(fname string) error

CleanupSessionResourcesFromFile cleans up docker resources for a Session from a session file.

func GetEnv added in v0.9.4

func GetEnv() (sessionID, networkID string, err error)

GetEnv retrieves bake related env vars, with defaults.

func GetFreePort added in v0.9.4

func GetFreePort() (string, error)

GetFreePort tries to find a free port on the current machine.

func InDocker added in v0.19.2

func InDocker() bool

InDocker indicates whether the current process is running inside a Docker container.

func Retry added in v0.9.4

func Retry(op func() error) error

Retry is an exponential backoff retry helper. All built-in components use this func to detect whether a container is alive and ready. User supplied components may use this helper func or provide their own.

Types

type BuildOptions added in v0.9.4

type BuildOptions struct {
	Dockerfile string
	ContextDir string
	BuildArgs  []docker.BuildArg
}

BuildOptions contains simple docker build options.

type Component

type Component interface {
	Start(*Session) error
}

Component is a logical service, it groups together several containers.

type RunOptions added in v0.28.5

type RunOptions struct {
	Cmd         []string
	InitExecCmd string
}

RunOptions contains docker container run options.

type Session added in v0.9.4

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

Session is the docker session, used to manage the lifecycle of components.

func LoadSession added in v0.9.4

func LoadSession() (*Session, error)

LoadSession attempts to load a Session from the default file location.

func LoadSessionFromFile added in v0.9.4

func LoadSessionFromFile(inDocker bool, fpath string) (*Session, error)

LoadSessionFromFile attempts to load a session from a file.

func NewSession added in v0.9.4

func NewSession(id, networkID string) (*Session, error)

NewSession prepares a new Docker session.

func (*Session) AutoServiceAddress added in v0.9.4

func (s *Session) AutoServiceAddress(serviceName string) (string, error)

AutoServiceAddress retrieves an endpoint for a service name, appropriate for the running code.

func (*Session) DockerToDockerServiceAddress added in v0.9.4

func (s *Session) DockerToDockerServiceAddress(serviceName string) (string, error)

DockerToDockerServiceAddress retrieves an internal endpoint for a service name.

func (*Session) HostToDockerServiceAddress added in v0.9.4

func (s *Session) HostToDockerServiceAddress(serviceName string) (string, error)

HostToDockerServiceAddress retrieves a host mapped endpoint for a service name.

func (*Session) ID added in v0.9.4

func (s *Session) ID() string

ID returns the Session ID.

func (*Session) InDocker added in v0.19.2

func (s *Session) InDocker() bool

InDocker indicates whether this session was started from inside a Docker container.

func (*Session) NetworkID added in v0.23.0

func (s *Session) NetworkID() string

NetworkID returns the Docker NetworkID ID.

func (*Session) Persist added in v0.9.4

func (s *Session) Persist() error

Persist stores the session data in the default store.

func (*Session) PersistToFile added in v0.9.4

func (s *Session) PersistToFile(fpath string) error

PersistToFile serializes a session and writes it to a file.

func (*Session) RegisterHostMappedDockerService added in v0.17.1

func (s *Session) RegisterHostMappedDockerService(serviceName, endpoint string) error

RegisterHostMappedDockerService registers a host mapped endpoint against the service name.

func (*Session) RegisterInternalDockerService added in v0.17.1

func (s *Session) RegisterInternalDockerService(serviceName, endpoint string) error

RegisterInternalDockerService registers an internal endpoint against the service name.

func (*Session) ServiceNames added in v0.22.0

func (s *Session) ServiceNames() []string

ServiceNames list of registered service names

func (*Session) StartComponents added in v0.9.4

func (s *Session) StartComponents(cs ...Component) error

StartComponents starts the provided components.

type SimpleComponent added in v0.9.4

type SimpleComponent struct {
	Name       string
	Containers []SimpleContainerConfig
}

SimpleComponent groups together several containers.

func (*SimpleComponent) Start added in v0.9.4

func (c *SimpleComponent) Start(session *Session) error

Start all containers sequentially.

type SimpleContainerConfig added in v0.9.4

type SimpleContainerConfig struct {
	Name               string
	Repository         string
	Tag                string
	Env                []string
	BuildOpts          *BuildOptions
	ServicePorts       map[string]string
	StaticServicePorts map[string]string
	ReadyFunc          func(*Session) error
	RunOpts            *RunOptions
}

SimpleContainerConfig defines a Docker container with associated service ports.

type SimpleContainerOptionFunc added in v0.9.4

type SimpleContainerOptionFunc func(*SimpleContainerConfig)

SimpleContainerOptionFunc allows for customization of SimpleContainerConfigs.

func WithTag added in v0.9.4

func WithTag(tag string) SimpleContainerOptionFunc

WithTag sets a Docker tag in a SimpleContainerConfig.

Directories

Path Synopsis
Package component contains components for component tests.
Package component contains components for component tests.
consul
Package consul exposes a Consul service and client.
Package consul exposes a Consul service and client.
jaeger
Package jaeger exposes a Jaeger service.
Package jaeger exposes a Jaeger service.
kafka
Package kafka exposes Kafka and Zookeeper containers.
Package kafka exposes Kafka and Zookeeper containers.
localstack
Package localstack exposes a Localstack service.
Package localstack exposes a Localstack service.
mockserver
Package mockserver exposes a Mockserver services.
Package mockserver exposes a Mockserver services.
mongodb
Package mongodb exposes a Mongo DB service.
Package mongodb exposes a Mongo DB service.
redis
Package redis exposes a Redis service.
Package redis exposes a Redis service.
testservice
Package testservice exposes a simple test service.
Package testservice exposes a simple test service.
Package env contains helpers to export a service's env vars with some substitution in order to replace docker-to-docker to host-to-docker addresses.
Package env contains helpers to export a service's env vars with some substitution in order to replace docker-to-docker to host-to-docker addresses.

Jump to

Keyboard shortcuts

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