Documentation ¶
Index ¶
- Constants
- Variables
- type Client
- func (c *Client) CreateContainer(ctx context.Context, config *container.Config, ...) (string, error)
- func (c *Client) Exec(ctx context.Context, containerID string, cmd []string) (int, string, string, error)
- func (c *Client) FindContainer(ctx context.Context, label string, value string) (string, error)
- func (c *Client) FollowLogs(ctx context.Context, id string) (stdout, stderr io.Reader, err error)
- func (c *Client) GetImage(ctx context.Context, imageName string) (image.Summary, error)
- func (c *Client) GetOutputStream(ctx context.Context, containerID string, since string, follow bool) (io.ReadCloser, error)
- func (c *Client) HasImage(ctx context.Context, imageName string) bool
- func (c *Client) InspectContainer(ctx context.Context, id string) (types.ContainerJSON, error)
- func (c *Client) IsInstalled(ctx context.Context) bool
- func (c *Client) PauseContainer(ctx context.Context, containerID string) error
- func (c *Client) PullImage(ctx context.Context, imageName string) (string, error)
- func (c *Client) RemoveContainer(ctx context.Context, containerID string) error
- func (c *Client) RemoveObjectsWithLabel(ctx context.Context, label string, value string) error
- func (c *Client) ResumeContainer(ctx context.Context, containerID string) error
- func (c *Client) StartContainer(ctx context.Context, containerID string) error
- func (c *Client) StopContainer(ctx context.Context, containerID string, options container.StopOptions) error
- func (c *Client) WaitContainer(ctx context.Context, containerID string) (<-chan container.WaitResponse, <-chan error)
- type ClientInterface
- type EngineBuilder
- func (b *EngineBuilder) Build() *types.SpecConfig
- func (b *EngineBuilder) WithCmd(c ...string) *EngineBuilder
- func (b *EngineBuilder) WithEntrypoint(e ...string) *EngineBuilder
- func (b *EngineBuilder) WithEnvironment(e ...string) *EngineBuilder
- func (b *EngineBuilder) WithWorkingDirectory(w string) *EngineBuilder
- type EngineSpec
- type Executor
- func (e *Executor) Cancel(ctx context.Context, executionID string) error
- func (e *Executor) Cleanup(ctx context.Context) error
- func (e *Executor) Exec(ctx context.Context, executionID string, command []string) (int, string, string, error)
- func (e *Executor) FindRunningContainer(ctx context.Context, jobID string, executionID string) (string, error)
- func (e *Executor) GetID() string
- func (e *Executor) GetLogStream(ctx context.Context, request types.LogStreamRequest) (io.ReadCloser, error)
- func (e *Executor) GetStatus(ctx context.Context, executionID string) (types.ExecutionStatus, error)
- func (e *Executor) List() []types.ExecutionListItem
- func (e *Executor) Pause(ctx context.Context, executionID string) error
- func (e *Executor) Remove(executionID string, timeout time.Duration) error
- func (e *Executor) Resume(ctx context.Context, executionID string) error
- func (e *Executor) Run(ctx context.Context, request *types.ExecutionRequest) (*types.ExecutionResult, error)
- func (e *Executor) Start(ctx context.Context, request *types.ExecutionRequest) error
- func (e *Executor) Wait(ctx context.Context, executionID string) (<-chan *types.ExecutionResult, <-chan error)
- func (e *Executor) WaitForStatus(ctx context.Context, executionID string, status types.ExecutionStatus, ...) error
Constants ¶
const ( EngineKeyImage = "image" EngineKeyEntrypoint = "entrypoint" EngineKeyCmd = "cmd" EngineKeyEnvironment = "environment" EngineKeyWorkingDirectory = "working_directory" )
Variables ¶
var DestroyTimeout = time.Second * 10
var ErrNotInstalled = errors.New("docker is not installed")
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client wraps the Docker client to provide high-level operations on Docker containers and networks.
func NewDockerClient ¶
NewDockerClient initializes a new Docker client with environment variables and API version negotiation.
func (*Client) CreateContainer ¶
func (c *Client) CreateContainer( ctx context.Context, config *container.Config, hostConfig *container.HostConfig, networkingConfig *network.NetworkingConfig, platform *v1.Platform, name string, pullImage bool, ) (string, error)
CreateContainer creates a new Docker container with the specified configuration.
func (*Client) Exec ¶
func (c *Client) Exec(ctx context.Context, containerID string, cmd []string) (int, string, string, error)
Exec executes a command inside a running container. Returns (exit code, stdout, stderr, and an error if the operation fails)
func (*Client) FindContainer ¶
FindContainer searches for a container by label and value, returning its ID if found.
func (*Client) FollowLogs ¶
FollowLogs tails the logs of a specified container, returning separate readers for stdout and stderr.
func (*Client) GetOutputStream ¶
func (c *Client) GetOutputStream( ctx context.Context, containerID string, since string, follow bool, ) (io.ReadCloser, error)
GetOutputStream streams the logs for a specified container. The 'since' parameter specifies the timestamp from which to start streaming logs. The 'follow' parameter indicates whether to continue streaming logs as they are produced. Returns an io.ReadCloser to read the output stream and an error if the operation fails.
func (*Client) InspectContainer ¶
InspectContainer returns detailed information about a Docker container.
func (*Client) IsInstalled ¶
IsInstalled checks if Docker is installed and reachable by pinging the Docker daemon.
func (*Client) PauseContainer ¶
PauseContainer pauses the main process of the given container without terminating it.
func (*Client) RemoveContainer ¶
RemoveContainer removes a Docker container, optionally forcing removal and removing associated volumes.
func (*Client) RemoveObjectsWithLabel ¶
RemoveObjectsWithLabel removes all Docker containers and networks with a specific label.
func (*Client) ResumeContainer ¶
ResumeContainer resumes the process execution within the container
func (*Client) StartContainer ¶
StartContainer starts a specified Docker container.
func (*Client) StopContainer ¶
func (c *Client) StopContainer( ctx context.Context, containerID string, options container.StopOptions, ) error
StopContainer stops a running Docker container with a specified timeout.
func (*Client) WaitContainer ¶
func (c *Client) WaitContainer( ctx context.Context, containerID string, ) (<-chan container.WaitResponse, <-chan error)
WaitContainer waits for a container to stop, returning channels for the result and errors.
type ClientInterface ¶
type ClientInterface interface { IsInstalled(ctx context.Context) bool CreateContainer( ctx context.Context, config *container.Config, hostConfig *container.HostConfig, networkingConfig *network.NetworkingConfig, platform *v1.Platform, name string, pullImage bool, ) (string, error) InspectContainer(ctx context.Context, id string) (types.ContainerJSON, error) FollowLogs(ctx context.Context, id string) (stdout, stderr io.Reader, err error) StartContainer(ctx context.Context, containerID string) error WaitContainer( ctx context.Context, containerID string, ) (<-chan container.WaitResponse, <-chan error) PauseContainer(ctx context.Context, containerID string) error ResumeContainer(ctx context.Context, containerID string) error StopContainer( ctx context.Context, containerID string, options container.StopOptions, ) error RemoveContainer(ctx context.Context, containerID string) error RemoveObjectsWithLabel(ctx context.Context, label string, value string) error FindContainer(ctx context.Context, label string, value string) (string, error) GetImage(ctx context.Context, imageName string) (image.Summary, error) PullImage(ctx context.Context, imageName string) (string, error) GetOutputStream( ctx context.Context, containerID string, since string, follow bool, ) (io.ReadCloser, error) Exec(ctx context.Context, containerID string, cmd []string) (int, string, string, error) }
type EngineBuilder ¶
type EngineBuilder struct {
// contains filtered or unexported fields
}
EngineBuilder is a struct that is used for constructing an EngineSpec object specifically for Docker engines using the Builder pattern. It embeds an EngineBuilder object for handling the common builder methods.
func NewDockerEngineBuilder ¶
func NewDockerEngineBuilder(image string) *EngineBuilder
NewDockerEngineBuilder function initializes a new DockerEngineBuilder instance. It sets the engine type to model.EngineDocker.String() and image as per the input argument.
func (*EngineBuilder) Build ¶
func (b *EngineBuilder) Build() *types.SpecConfig
Build method constructs the final SpecConfig object by calling the embedded EngineBuilder's Build method.
func (*EngineBuilder) WithCmd ¶
func (b *EngineBuilder) WithCmd(c ...string) *EngineBuilder
WithCmd is a builder method that sets the Docker engine's Command. It returns the DockerEngineBuilder for further chaining of builder methods.
func (*EngineBuilder) WithEntrypoint ¶
func (b *EngineBuilder) WithEntrypoint(e ...string) *EngineBuilder
WithEntrypoint is a builder method that sets the Docker engine entrypoint. It returns the DockerEngineBuilder for further chaining of builder methods.
func (*EngineBuilder) WithEnvironment ¶
func (b *EngineBuilder) WithEnvironment(e ...string) *EngineBuilder
WithEnvironment is a builder method that sets the Docker engine's environment variables. It returns the DockerEngineBuilder for further chaining of builder methods.
func (*EngineBuilder) WithWorkingDirectory ¶
func (b *EngineBuilder) WithWorkingDirectory(w string) *EngineBuilder
WithWorkingDirectory is a builder method that sets the Docker engine's working directory. It returns the DockerEngineBuilder for further chaining of builder methods.
type EngineSpec ¶
type EngineSpec struct { // Image this should be pullable by docker Image string `json:"image,omitempty"` // Entrypoint optionally override the default entrypoint Entrypoint []string `json:"entrypoint,omitempty"` // Cmd specifies the command to run in the container Cmd []string `json:"cmd,omitempty"` // EnvironmentVariables is a slice of env to run the container with Environment []string `json:"environment,omitempty"` // WorkingDirectory inside the container WorkingDirectory string `json:"working_directory,omitempty"` // Privileged indicates whether the container should run with --privileged mode Privileged bool `json:"privileged,omitempty"` }
EngineSpec contains necessary parameters to execute a docker job.
func DecodeSpec ¶
func DecodeSpec(spec *types.SpecConfig) (EngineSpec, error)
DecodeSpec decodes a spec config into a docker engine spec It converts the params into a docker EngineSpec struct and validates it
func (EngineSpec) Validate ¶
func (c EngineSpec) Validate() error
Validate checks if the engine spec is valid
type Executor ¶
type Executor struct { ID string // contains filtered or unexported fields }
Executor manages the lifecycle of Docker containers for execution requests.
func NewExecutor ¶
NewExecutor initializes a new Executor instance with a Docker client.
func (*Executor) Cancel ¶
Cancel tries to cancel a specific execution by its executionID. It returns an error if the execution is not found.
func (*Executor) Cleanup ¶
Cleanup removes all Docker resources associated with the executor. This includes removing containers including networks and volumes with the executor's label. It also removes all temporary directories created for init scripts.
func (*Executor) Exec ¶
func (e *Executor) Exec(ctx context.Context, executionID string, command []string) (int, string, string, error)
Exec executes a command in the container with the given containerID. Returns the exit code, stdout, stderr and an error if the execution fails.
func (*Executor) FindRunningContainer ¶
func (e *Executor) FindRunningContainer( ctx context.Context, jobID string, executionID string, ) (string, error)
FindRunningContainer finds the container that is running the execution with the given ID. It returns the container ID if found, or an error if the container is not found.
func (*Executor) GetLogStream ¶
func (e *Executor) GetLogStream( ctx context.Context, request types.LogStreamRequest, ) (io.ReadCloser, error)
GetLogStream provides a stream of output logs for a specific execution. Parameters 'withHistory' and 'follow' control whether to include past logs and whether to keep the stream open for new logs, respectively. It returns an error if the execution is not found.
func (*Executor) GetStatus ¶
func (e *Executor) GetStatus(ctx context.Context, executionID string) (types.ExecutionStatus, error)
GetStatus returns the status of the execution identified by its executionID. It returns the status of the execution and an error if the execution is not found or status is unknown.
func (*Executor) List ¶
func (e *Executor) List() []types.ExecutionListItem
List returns a slice of ExecutionListItem containing information about current executions. This implementation currently returns an empty list and should be updated in the future.
func (*Executor) Remove ¶
Remove removes a container identified by its executionID. It returns an error if the execution is not found.
func (*Executor) Run ¶
func (e *Executor) Run( ctx context.Context, request *types.ExecutionRequest, ) (*types.ExecutionResult, error)
Run initiates and waits for the completion of an execution in one call. This method serves as a higher-level convenience function that internally calls Start and Wait methods. It returns the result of the execution or an error if either starting or waiting fails, or if the context is canceled.
func (*Executor) Wait ¶
func (e *Executor) Wait( ctx context.Context, executionID string, ) (<-chan *types.ExecutionResult, <-chan error)
Wait initiates a wait for the completion of a specific execution using its executionID. The function returns two channels: one for the result and another for any potential error. If the executionID is not found, an error is immediately sent to the error channel. Otherwise, an internal goroutine (doWait) is spawned to handle the asynchronous waiting. Callers should use the two returned channels to wait for the result of the execution or an error. This can be due to issues either beginning the wait or in getting the response. This approach allows the caller to synchronize Wait with calls to Start, waiting for the execution to complete.
func (*Executor) WaitForStatus ¶
func (e *Executor) WaitForStatus( ctx context.Context, executionID string, status types.ExecutionStatus, timeout *time.Duration, ) error
WaitForStatus waits for the execution to reach a specific status. It returns an error if the execution is not found or the status is unknown.