runenv

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FreePort

func FreePort() (uint16, error)

FreePort finds a random, unused TCP port on the host by asking the OS to bind to port 0 and reading back the assigned port. The listener is closed before returning, so the port is free for the caller to use.

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

func (c *Container) ExecBash(ctx context.Context, script string) (stdout, stderr string, err error)

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.

func (*Container) ID

func (c *Container) ID() string

ID returns the Docker ID for the container.

func (*Container) Stop

func (c *Container) Stop(ctx context.Context, timeout time.Duration) error

Stop stops and removes the container identified by containerID. It first sends a SIGTERM, waiting up to timeout for the container to exit, then falls back to SIGKILL if it is still running. The container is removed afterwards regardless of whether it exited on its own.

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 (d *DockerClient) AbyssContainers(ctx context.Context) ([]container.Summary, error)

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.

Jump to

Keyboard shortcuts

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