docker

package
v2.0.0-...-e8682ef Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2024 License: MPL-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const DockerAPIVersion = "1.40"

Variables

This section is empty.

Functions

func BuildImage

func BuildImage(ctx context.Context, api *client.Client, containerfile string, containerContext BuildContext, opts ...BuildOpt) ([]byte, error)

func NewDockerAPI

func NewDockerAPI() (*client.Client, error)

func RunCmdInBackground

func RunCmdInBackground(api *client.Client, ctx context.Context, container string, cmd []string, opts ...RunCmdOpt) (string, error)

func RunCmdWithOutput

func RunCmdWithOutput(api *client.Client, ctx context.Context, container string, cmd []string, opts ...RunCmdOpt) ([]byte, []byte, int, error)

Types

type BuildArgs

type BuildArgs map[string]*string

func (BuildArgs) Apply

func (u BuildArgs) Apply(cfg *types.ImageBuildOptions) error

type BuildContext

type BuildContext map[string]PathContents

func BuildContextFromTarball

func BuildContextFromTarball(reader io.Reader) (BuildContext, error)

func NewBuildContext

func NewBuildContext() BuildContext

func (*BuildContext) ToTarball

func (bCtx *BuildContext) ToTarball() (io.Reader, error)

type BuildForceRemove

type BuildForceRemove bool

func (BuildForceRemove) Apply

type BuildOpt

type BuildOpt interface {
	Apply(cfg *types.ImageBuildOptions) error
}

type BuildPullParent

type BuildPullParent bool

func (BuildPullParent) Apply

type BuildRemove

type BuildRemove bool

func (BuildRemove) Apply

func (u BuildRemove) Apply(cfg *types.ImageBuildOptions) error

type BuildTags

type BuildTags []string

func (BuildTags) Apply

func (u BuildTags) Apply(cfg *types.ImageBuildOptions) error

type FileContents

type FileContents struct {
	Data []byte
	Mode int64
	UID  int
	GID  int
}

func (FileContents) Get

func (b FileContents) Get() ([]byte, error)

func (*FileContents) SetMode

func (b *FileContents) SetMode(mode int64)

func (*FileContents) SetOwners

func (b *FileContents) SetOwners(uid int, gid int)

func (FileContents) UpdateHeader

func (b FileContents) UpdateHeader(header *tar.Header) error

type LogConsumerWriter

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

func (LogConsumerWriter) Write

func (l LogConsumerWriter) Write(p []byte) (n int, err error)

type PathContents

type PathContents interface {
	UpdateHeader(header *tar.Header) error
	Get() ([]byte, error)
	SetMode(mode int64)
	SetOwners(uid int, gid int)
}

Mapping of path->contents

func PathContentsFromBytes

func PathContentsFromBytes(data []byte) PathContents

func PathContentsFromString

func PathContentsFromString(data string) PathContents

type RunCmdOpt

type RunCmdOpt interface {
	Apply(cfg *types.ExecConfig) error
}

type RunCmdUser

type RunCmdUser string

func (RunCmdUser) Apply

func (u RunCmdUser) Apply(cfg *types.ExecConfig) error

type RunOptions

type RunOptions struct {
	ImageRepo              string
	ImageTag               string
	ContainerName          string
	Cmd                    []string
	Entrypoint             []string
	Env                    []string
	NetworkName            string
	NetworkID              string
	CopyFromTo             map[string]string
	Ports                  []string
	DoNotAutoRemove        bool
	AuthUsername           string
	AuthPassword           string
	OmitLogTimestamps      bool
	LogConsumer            func(string)
	Capabilities           []string
	PreDelete              bool
	PostStart              func(string, string) error
	LogStderr              io.Writer
	LogStdout              io.Writer
	VolumeNameToMountPoint map[string]string
}

type Runner

type Runner struct {
	DockerAPI  *client.Client
	RunOptions RunOptions
}

func NewServiceRunner

func NewServiceRunner(opts RunOptions) (*Runner, error)

func (*Runner) BuildImage

func (d *Runner) BuildImage(ctx context.Context, containerfile string, containerContext BuildContext, opts ...BuildOpt) ([]byte, error)

func (*Runner) CopyFrom

func (d *Runner) CopyFrom(container string, source string) (BuildContext, *types.ContainerPathStat, error)

func (*Runner) CopyTo

func (d *Runner) CopyTo(container string, destination string, contents BuildContext) error

func (*Runner) GetNetworkAndAddresses

func (d *Runner) GetNetworkAndAddresses(container string) (map[string]string, error)

func (*Runner) RefreshFiles

func (d *Runner) RefreshFiles(ctx context.Context, containerID string) error

func (*Runner) Restart

func (d *Runner) Restart(ctx context.Context, containerID string) error

func (*Runner) RunCmdInBackground

func (d *Runner) RunCmdInBackground(ctx context.Context, container string, cmd []string, opts ...RunCmdOpt) (string, error)

func (*Runner) RunCmdWithOutput

func (d *Runner) RunCmdWithOutput(ctx context.Context, container string, cmd []string, opts ...RunCmdOpt) ([]byte, []byte, int, error)

func (*Runner) Start

func (d *Runner) Start(ctx context.Context, addSuffix, forceLocalAddr bool) (*StartResult, error)

func (*Runner) StartNewService

func (d *Runner) StartNewService(ctx context.Context, addSuffix, forceLocalAddr bool, connect ServiceAdapter) (*Service, string, error)

StartNewService will start the runner's configured docker container but with the ability to control adding a name suffix or forcing a local address to be returned. 'addSuffix' will add a random UUID to the end of the container name. 'forceLocalAddr' will force the container address returned to be in the form of '127.0.0.1:1234' where 1234 is the mapped container port.

func (*Runner) StartService

func (d *Runner) StartService(ctx context.Context, connect ServiceAdapter) (*Service, error)

StartService will start the runner's configured docker container with a random UUID suffix appended to the name to make it unique and will return either a hostname or local address depending on if a Docker network was given.

Most tests can default to using this.

func (*Runner) Stop

func (d *Runner) Stop(ctx context.Context, containerID string) error

type Service

type Service struct {
	Config      ServiceConfig
	Cleanup     func()
	Container   *types.ContainerJSON
	StartResult *StartResult
}

type ServiceAdapter

type ServiceAdapter func(ctx context.Context, host string, port int) (ServiceConfig, error)

ServiceAdapter verifies connectivity to the service, then returns either the connection string (typically a URL) and nil, or empty string and an error.

type ServiceConfig

type ServiceConfig interface {
	Address() string
	URL() *url.URL
}

type ServiceHostPort

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

func NewServiceHostPort

func NewServiceHostPort(host string, port int) *ServiceHostPort

func NewServiceHostPortParse

func NewServiceHostPortParse(s string) (*ServiceHostPort, error)

func (ServiceHostPort) Address

func (s ServiceHostPort) Address() string

func (ServiceHostPort) URL

func (s ServiceHostPort) URL() *url.URL

type ServiceURL

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

func NewServiceURL

func NewServiceURL(u url.URL) *ServiceURL

func NewServiceURLParse

func NewServiceURLParse(s string) (*ServiceURL, error)

func (ServiceURL) Address

func (s ServiceURL) Address() string

func (ServiceURL) URL

func (s ServiceURL) URL() *url.URL

type StartResult

type StartResult struct {
	Container *types.ContainerJSON
	Addrs     []string
	RealIP    string
}

Jump to

Keyboard shortcuts

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