Documentation
¶
Index ¶
- Constants
- func ExitCode(inspect *types.ContainerJSON, err error) (int, error)
- func HostUser() string
- func ResolveRunID(generate bool) string
- type Client
- func (c *Client) Close() error
- func (c *Client) CopyFileToContainer(ctx context.Context, containerID, dir, name string, data []byte) error
- func (c *Client) CopyToContainer(ctx context.Context, containerID, targetPath string, content io.Reader) error
- func (c *Client) CreateContainer(ctx context.Context, config *ContainerConfig) (string, error)
- func (c *Client) EnsureImage(ctx context.Context, imageName string) error
- func (c *Client) ExecInContainer(ctx context.Context, containerID string, config *ExecConfig) (string, error)
- func (c *Client) FollowContainerLogs(ctx context.Context, containerID string, tail int, w io.Writer) error
- func (c *Client) GetContainerLogs(ctx context.Context, containerID string, tail int) (string, error)
- func (c *Client) ImageExists(ctx context.Context, imageName string) (bool, error)
- func (c *Client) InspectContainer(ctx context.Context, containerID string) (*types.ContainerJSON, error)
- func (c *Client) IsContainerRunning(ctx context.Context, containerID string) (bool, error)
- func (c *Client) ListContainersByLabels(ctx context.Context, labels map[string]string) ([]types.Container, error)
- func (c *Client) Ping(ctx context.Context) error
- func (c *Client) PullImage(ctx context.Context, imageName string) error
- func (c *Client) RemoveContainer(ctx context.Context, containerID string, force bool) error
- func (c *Client) RemoveContainerByName(ctx context.Context, name string, labels map[string]string) (bool, error)
- func (c *Client) RunContainer(ctx context.Context, config *ContainerConfig) (string, error)
- func (c *Client) RunID() string
- func (c *Client) SetAllRuns(all bool)
- func (c *Client) SetRunID(id string)
- func (c *Client) StartContainer(ctx context.Context, containerID string) error
- func (c *Client) StopContainer(ctx context.Context, containerID string, timeout *int) error
- func (c *Client) WaitForContainer(ctx context.Context, containerID string, condition container.WaitCondition) error
- func (c *Client) WaitForHealthy(ctx context.Context, containerID string, interval time.Duration, retries int) error
- type ContainerConfig
- type ExecConfig
- type Mount
Constants ¶
const ( // RunIDEnv lets CI pin the run ID (e.g. to Jenkins' BUILD_TAG) so separate // gtool invocations of one build share it and other builds stay isolated. RunIDEnv = "GTOOL_RUN_ID" // RunLabel is the container label that scopes resources to one run. RunLabel = "gtool-run" )
Variables ¶
This section is empty.
Functions ¶
func ExitCode ¶ added in v1.0.0
func ExitCode(inspect *types.ContainerJSON, err error) (int, error)
ExitCode extracts the exit code of a finished container from the result of InspectContainer. A failed inspect or a missing state is an error: assuming 0 would report a run nobody observed as passed.
func ResolveRunID ¶ added in v1.0.0
ResolveRunID returns the run ID from GTOOL_RUN_ID. When unset it returns a random ID if generate is true (single-invocation pipelines) or "" otherwise, which keeps the legacy, unscoped behaviour.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func NewRunClient ¶ added in v1.0.0
NewRunClient returns a client scoped to one pipeline run (GTOOL_RUN_ID or a generated ID). Every single-invocation pipeline (test, stress) must use it so concurrent runs never see or tear down each other's containers.
func (*Client) CopyFileToContainer ¶ added in v1.0.0
func (c *Client) CopyFileToContainer(ctx context.Context, containerID, dir, name string, data []byte) error
CopyFileToContainer writes data as dir/name inside the container; dir must exist.
func (*Client) CopyToContainer ¶
func (*Client) CreateContainer ¶
func (*Client) EnsureImage ¶
EnsureImage makes an image available, preferring a local copy: if the image already exists locally it skips the pull, otherwise it pulls from the registry.
func (*Client) ExecInContainer ¶
func (*Client) FollowContainerLogs ¶ added in v1.0.0
func (c *Client) FollowContainerLogs(ctx context.Context, containerID string, tail int, w io.Writer) error
FollowContainerLogs streams the container's logs (starting with the last tail lines) to w until the container stops or ctx is cancelled; a cancellation (Ctrl-C) is a normal end, not an error.
func (*Client) GetContainerLogs ¶
func (*Client) ImageExists ¶
ImageExists reports whether an image is already present in the local Docker image store, so callers can avoid a registry pull for local-only images (e.g. freshly built ones).
func (*Client) InspectContainer ¶
func (*Client) IsContainerRunning ¶
IsContainerRunning reports whether the container runs. A container that has already exited is an ErrContainerExited error, so readiness loops fail fast instead of polling a dead container until their budget runs out.
func (*Client) ListContainersByLabels ¶
func (*Client) RemoveContainer ¶
func (*Client) RemoveContainerByName ¶
func (c *Client) RemoveContainerByName(ctx context.Context, name string, labels map[string]string) (bool, error)
RemoveContainerByName force-removes the container with exactly this name, in any state, when it carries every label in labels; it is a no-op when none exists. A same-named container without those labels was not created by gtool: it is left alone and ErrContainerForeign is returned.
func (*Client) RunContainer ¶ added in v1.0.0
RunContainer creates and starts a container. When the start fails (e.g. the host port is already allocated) the created container is removed, so a failed launch never leaves an orphan behind.