Documentation
¶
Index ¶
- func FreePort() (uint16, error)
- type Container
- func (d *Container) CopyFileFromHost(ctx context.Context, content []byte, containerPath string, mode os.FileMode) error
- func (d *Container) CopyFromHost(ctx context.Context, containerID, hostPath, containerDir string) error
- func (c *Container) ExecBash(ctx context.Context, script string) (stdout, stderr string, err error)
- func (c *Container) ID() string
- func (c *Container) Stop(ctx context.Context, timeout time.Duration) error
- type ContainerEndpoint
- type DockerClient
- func (d *DockerClient) AbyssContainers(ctx context.Context) ([]container.Summary, error)
- func (d *DockerClient) ApplyHostMounts(cfg *agentconfig.DockerConfig, hostConfig *container.HostConfig) *container.HostConfig
- func (d *DockerClient) Close() error
- func (d *DockerClient) PullImage(ctx context.Context, imageRef string) error
- func (d *DockerClient) StartContainer(ctx context.Context, imageRef string, config *container.Config, ...) (*Container, ContainerEndpoint, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Container ¶
type Container struct {
// contains filtered or unexported fields
}
func NewContainer ¶
func NewContainer(docker *DockerClient, containerID string) *Container
NewContainer initializes a new container.
func (*Container) CopyFileFromHost ¶
func (d *Container) CopyFileFromHost(ctx context.Context, content []byte, containerPath string, mode os.FileMode) error
CopyFileFromHost copies a single file's content into the container identified by containerID. Parent directories of containerPath are created as needed.
func (*Container) CopyFromHost ¶
func (d *Container) CopyFromHost(ctx context.Context, containerID, hostPath, containerDir string) error
CopyToContainer copies the file or directory at hostPath into the container identified by containerID, placing it under containerDir. Any parent directories of containerDir that do not already exist inside the container are created. The basename of hostPath is preserved, so a host path of "/tmp/foo.txt" copied into "/opt/app" lands at "/opt/app/foo.txt".
func (*Container) ExecBash ¶
ExecBash runs script inside the container identified by containerID using "bash -c". It returns the script's stdout and stderr. If the script exits with a non-zero status, the returned error reports the exit code and the output is still returned so callers can inspect it.
type ContainerEndpoint ¶
type ContainerEndpoint struct {
// ContainerID is the ID of the started container.
ContainerID string
// IP is the address the host should connect to.
IP string
// Port is the host port bound to the container's exposed port.
Port uint16
}
ContainerEndpoint describes how the host can reach a started container.
func (ContainerEndpoint) String ¶
func (e ContainerEndpoint) String() string
String returns the endpoint as an "ip:port" address.
type DockerClient ¶
type DockerClient struct {
// contains filtered or unexported fields
}
DockerClient wraps the Docker SDK client and provides helpers for managing containers in a run environment.
func NewDockerClient ¶
func NewDockerClient() (*DockerClient, error)
NewDockerClient creates a DockerClient configured from the environment (DOCKER_HOST, DOCKER_API_VERSION, DOCKER_CERT_PATH, DOCKER_TLS_VERIFY).
func (*DockerClient) AbyssContainers ¶
func (*DockerClient) ApplyHostMounts ¶
func (d *DockerClient) ApplyHostMounts(cfg *agentconfig.DockerConfig, hostConfig *container.HostConfig) *container.HostConfig
ApplyHostMounts populates hostConfig.Binds from the HostMounts declared in cfg. Each entry maps a host path to a container path using Docker's "hostPath:containerPath" bind format. If hostConfig is nil a new HostConfig is allocated. Mounts are appended to any existing binds so callers can layer additional mounts. Paths are normalized to absolute form; a mount whose host path does not exist on the host is skipped with a warning, since Docker would create it as an empty directory owned by root, which is rarely intended.
func (*DockerClient) Close ¶
func (d *DockerClient) Close() error
Close releases resources held by the underlying Docker client.
func (*DockerClient) PullImage ¶
func (d *DockerClient) PullImage(ctx context.Context, imageRef string) error
pullImage ensures imageRef is present on the Docker host.
func (*DockerClient) StartContainer ¶
func (d *DockerClient) StartContainer( ctx context.Context, imageRef string, config *container.Config, hostConfig *container.HostConfig, name string, containerPort uint16, hostPort uint16, ) (*Container, ContainerEndpoint, error)
StartContainer pulls imageRef (if necessary) and starts a container from it. The container's containerPort is published to the host so the host can reach it. hostPort selects the host port to bind; pass 0 to let Docker assign a free port. config and hostConfig may be nil to use Docker's defaults for the image.