Documentation
¶
Index ¶
- Constants
- type Client
- func (a *Client) Close() error
- func (a *Client) ContainerRunning(ctx context.Context, labelOptions LabelOptions) (bool, error)
- func (a *Client) ContainersWithLabels(extraLabels map[string]string) LabelOptions
- func (a *Client) RemoveContainers(ctx context.Context, labelOptions LabelOptions) error
- func (a *Client) RemoveUnusedNetworks(ctx context.Context) error
- func (a *Client) RunContainer(ctx context.Context, params RunContainerParams) (<-chan domain.Container, <-chan error)
- type CopyFileConfig
- type DockerClient
- type LabelOptions
- type LogConfig
- type NetworkCountConfig
- type NewParams
- type RunContainerParams
- type ShouldRestartFunc
Constants ¶
const ( LabelPrefix = "io.netflux.octoplex." LabelApp = LabelPrefix + "app" LabelAppID = LabelPrefix + "app-id" LabelComponent = LabelPrefix + "component" LabelURL = LabelPrefix + "url" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client provides a thin wrapper around the Docker API client, and provides additional functionality such as exposing container stats.
func (*Client) ContainerRunning ¶
ContainerRunning checks if a container with the given labels is running.
func (*Client) ContainersWithLabels ¶
func (a *Client) ContainersWithLabels(extraLabels map[string]string) LabelOptions
ContainersWithLabels returns a LabelOptions function that returns the labels for this app instance.
func (*Client) RemoveContainers ¶
func (a *Client) RemoveContainers(ctx context.Context, labelOptions LabelOptions) error
RemoveContainers removes all containers with the given labels.
func (*Client) RemoveUnusedNetworks ¶
RemoveUnusedNetworks removes all networks that are not used by any container.
func (*Client) RunContainer ¶
func (a *Client) RunContainer(ctx context.Context, params RunContainerParams) (<-chan domain.Container, <-chan error)
RunContainer runs a container with the given parameters.
The returned state channel will receive the state of the container and will never be closed. The error channel will receive an error if the container fails to start, and will be closed when the container exits, possibly after receiving an error.
Panics if ShouldRestart is non-nil and the host config defines a restart policy of its own.
type CopyFileConfig ¶
CopyFileConfig holds configuration for a single file which should be copied into a container.
type DockerClient ¶
type DockerClient interface { io.Closer ContainerCreate(context.Context, *container.Config, *container.HostConfig, *network.NetworkingConfig, *ocispec.Platform, string) (container.CreateResponse, error) ContainerList(context.Context, container.ListOptions) ([]container.Summary, error) ContainerLogs(context.Context, string, container.LogsOptions) (io.ReadCloser, error) ContainerRemove(context.Context, string, container.RemoveOptions) error ContainerStart(context.Context, string, container.StartOptions) error ContainerStats(context.Context, string, bool) (container.StatsResponseReader, error) ContainerStop(context.Context, string, container.StopOptions) error CopyToContainer(context.Context, string, string, io.Reader, container.CopyToContainerOptions) error ContainerWait(context.Context, string, container.WaitCondition) (<-chan container.WaitResponse, <-chan error) Events(context.Context, events.ListOptions) (<-chan events.Message, <-chan error) ImagePull(context.Context, string, image.PullOptions) (io.ReadCloser, error) NetworkConnect(context.Context, string, string, *network.EndpointSettings) error NetworkCreate(context.Context, string, network.CreateOptions) (network.CreateResponse, error) NetworkDisconnect(context.Context, string, string, bool) error NetworkList(context.Context, network.ListOptions) ([]network.Summary, error) NetworkRemove(context.Context, string) error }
DockerClient isolates a docker *client.Client.
type LabelOptions ¶
LabelOptions is a function that returns a map of labels.
func AllContainers ¶
func AllContainers() LabelOptions
AllContainers returns a LabelOptions function that returns the labels for any app instance.
type LogConfig ¶ added in v0.0.6
type LogConfig struct {
Stdout, Stderr bool
}
LogConfig holds configuration for container logs.
type NetworkCountConfig ¶
type NetworkCountConfig struct { Rx string // the network name to count the Rx bytes Tx string // the network name to count the Tx bytes }
NetworkCountConfig holds configuration for observing network traffic.
type NewParams ¶ added in v0.0.11
type NewParams struct { APIClient DockerClient InDocker bool Logger *slog.Logger }
NewParams are the parameters for creating a new Client.
type RunContainerParams ¶
type RunContainerParams struct { Name string ChanSize int ContainerConfig *container.Config HostConfig *container.HostConfig NetworkingConfig *network.NetworkingConfig NetworkCountConfig NetworkCountConfig CopyFiles []CopyFileConfig Logs LogConfig ShouldRestart ShouldRestartFunc RestartInterval time.Duration // defaults to 10 seconds }
RunContainerParams are the parameters for running a container.
type ShouldRestartFunc ¶ added in v0.0.5
type ShouldRestartFunc func( exitCode int64, restartCount int, containerLogs [][]byte, runningTime time.Duration, ) (bool, error)
ShouldRestartFunc is a callback function that is called when a container exits. It should return true if the container is to be restarted. If not restarting, err may be non-nil.