docker

package
v0.33.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2024 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

func CleanupResources() error

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

func CleanupSessionResources

func CleanupSessionResources(session *Session) error

CleanupSessionResources cleans up Docker resources for a Session.

func CleanupSessionResourcesFromFile

func CleanupSessionResourcesFromFile(fname string) error

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

func GetEnv

func GetEnv() (string, string, error)

GetEnv retrieves bake related env vars, with defaults.

func GetFreePort

func GetFreePort() (string, error)

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

func InDocker

func InDocker() bool

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

func Retry

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

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

type RunOptions struct {
	Cmd         []string
	InitExecCmd string
}

RunOptions contains docker container run options.

type Session

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

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

func LoadSession

func LoadSession() (*Session, error)

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

func LoadSessionFromFile

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

LoadSessionFromFile attempts to load a session from a file.

func NewSession

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

NewSession prepares a new Docker session.

func (*Session) AutoServiceAddress

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

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

func (*Session) DockerToDockerServiceAddress

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

DockerToDockerServiceAddress retrieves an internal endpoint for a service name.

func (*Session) HostToDockerServiceAddress

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

HostToDockerServiceAddress retrieves a host mapped endpoint for a service name.

func (*Session) ID

func (s *Session) ID() string

ID returns the Session ID.

func (*Session) InDocker

func (s *Session) InDocker() bool

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

func (*Session) NetworkID

func (s *Session) NetworkID() string

NetworkID returns the Docker NetworkID ID.

func (*Session) Persist

func (s *Session) Persist() error

Persist stores the session data in the default store.

func (*Session) PersistToFile

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

PersistToFile serializes a session and writes it to a file.

func (*Session) RegisterHostMappedDockerService

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

RegisterHostMappedDockerService registers a host mapped endpoint against the service name.

func (*Session) RegisterInternalDockerService

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

RegisterInternalDockerService registers an internal endpoint against the service name.

func (*Session) ServiceNames

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

ServiceNames list of registered service names.

func (*Session) StartComponents

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

StartComponents starts the provided components.

type SimpleComponent

type SimpleComponent struct {
	Name       string
	Containers []SimpleContainerConfig
}

SimpleComponent groups together several containers.

func (*SimpleComponent) Start

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

Start all containers sequentially.

type SimpleContainerConfig

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

type SimpleContainerOptionFunc func(*SimpleContainerConfig)

SimpleContainerOptionFunc allows for customization of SimpleContainerConfigs.

func WithTag

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.
testservice/cmd/testservice
Package main of the test service.
Package main of the 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