package docker
import "github.com/hashicorp/vault/sdk/helper/docker"
Index ¶
- Constants
- func BuildImage(ctx context.Context, api *client.Client, containerfile string, containerContext BuildContext, opts ...BuildOpt) ([]byte, error)
- func NewDockerAPI() (*client.Client, error)
- func RunCmdInBackground(api *client.Client, ctx context.Context, containerID string, cmd []string, opts ...RunCmdOpt) (string, error)
- func RunCmdWithOutput(api *client.Client, ctx context.Context, containerID string, cmd []string, opts ...RunCmdOpt) ([]byte, []byte, int, error)
- type BuildArgs
- type BuildContext
- func BuildContextFromTarball(reader io.Reader) (BuildContext, error)
- func NewBuildContext() BuildContext
- func (bCtx *BuildContext) ToTarball() (io.Reader, error)
- type BuildForceRemove
- type BuildOpt
- type BuildPullParent
- type BuildRemove
- type BuildTags
- type FileContents
- func (b FileContents) Get() ([]byte, error)
- func (b *FileContents) SetMode(mode int64)
- func (b *FileContents) SetOwners(uid int, gid int)
- func (b FileContents) UpdateHeader(header *tar.Header) error
- type LogConsumerWriter
- type PathContents
- func PathContentsFromBytes(data []byte) PathContents
- func PathContentsFromString(data string) PathContents
- type RunCmdOpt
- type RunCmdUser
- type RunOptions
- type Runner
- func NewServiceRunner(opts RunOptions) (*Runner, error)
- func (d *Runner) BuildImage(ctx context.Context, containerfile string, containerContext BuildContext, opts ...BuildOpt) ([]byte, error)
- func (d *Runner) CopyFrom(container string, source string) (BuildContext, *container.PathStat, error)
- func (d *Runner) CopyTo(containerID string, destination string, contents BuildContext) error
- func (d *Runner) GetNetworkAndAddresses(container string) (map[string]string, error)
- func (d *Runner) RefreshFiles(ctx context.Context, containerID string) error
- func (d *Runner) Restart(ctx context.Context, containerID string) error
- func (d *Runner) RestartContainerWithTimeout(ctx context.Context, containerID string, timeout int) error
- func (d *Runner) RunCmdInBackground(ctx context.Context, container string, cmd []string, opts ...RunCmdOpt) (string, error)
- func (d *Runner) RunCmdWithOutput(ctx context.Context, container string, cmd []string, opts ...RunCmdOpt) ([]byte, []byte, int, error)
- func (d *Runner) Start(ctx context.Context, addSuffix, forceLocalAddr bool) (*StartResult, error)
- func (d *Runner) StartNewService(ctx context.Context, addSuffix, forceLocalAddr bool, connect ServiceAdapter) (*Service, string, error)
- func (d *Runner) StartService(ctx context.Context, connect ServiceAdapter) (*Service, error)
- func (d *Runner) Stop(ctx context.Context, containerID string) error
- type Service
- type ServiceAdapter
- type ServiceConfig
- type ServiceHostPort
- func NewServiceHostPort(host string, port int) *ServiceHostPort
- func NewServiceHostPortParse(s string) (*ServiceHostPort, error)
- func (s ServiceHostPort) Address() string
- func (s ServiceHostPort) URL() *url.URL
- type ServiceURL
- func NewServiceURL(u url.URL) *ServiceURL
- func NewServiceURLParse(s string) (*ServiceURL, error)
- func (s ServiceURL) Address() string
- func (s ServiceURL) URL() *url.URL
- type StartResult
Constants ¶
const DockerAPIVersion = "1.40"
Functions ¶
func BuildImage ¶
func BuildImage(ctx context.Context, api *client.Client, containerfile string, containerContext BuildContext, opts ...BuildOpt) ([]byte, error)
func NewDockerAPI ¶
func RunCmdInBackground ¶
func RunCmdInBackground(api *client.Client, ctx context.Context, containerID string, cmd []string, opts ...RunCmdOpt) (string, error)
func RunCmdWithOutput ¶
func RunCmdWithOutput(api *client.Client, ctx context.Context, containerID string, cmd []string, opts ...RunCmdOpt) ([]byte, []byte, int, error)
Types ¶
type BuildArgs ¶
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 ¶
func (u BuildForceRemove) Apply(cfg *types.ImageBuildOptions) error
type BuildOpt ¶
type BuildOpt interface { Apply(cfg *types.ImageBuildOptions) error }
type BuildPullParent ¶
type BuildPullParent bool
func (BuildPullParent) Apply ¶
func (u BuildPullParent) Apply(cfg *types.ImageBuildOptions) error
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 ¶
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 *container.ExecOptions) error }
type RunCmdUser ¶
type RunCmdUser string
func (RunCmdUser) Apply ¶
func (u RunCmdUser) Apply(cfg *container.ExecOptions) 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, *container.PathStat, error)
func (*Runner) CopyTo ¶
func (d *Runner) CopyTo(containerID string, destination string, contents BuildContext) error
func (*Runner) GetNetworkAndAddresses ¶
func (*Runner) RefreshFiles ¶
func (*Runner) Restart ¶
func (*Runner) RestartContainerWithTimeout ¶
func (d *Runner) RestartContainerWithTimeout(ctx context.Context, containerID string, timeout int) 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 (*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 ¶
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 ¶
type Service ¶
type Service struct { Config ServiceConfig Cleanup func() Container *types.ContainerJSON StartResult *StartResult }
type ServiceAdapter ¶
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 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 }
Source Files ¶
- Version
- v0.18.0 (latest)
- Published
- Jun 5, 2025
- Platform
- linux/amd64
- Imports
- 27 packages
- Last checked
- 1 month ago –
Tools for package owners.