container

package
v0.0.0-...-3511abf Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2023 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AgentIDEnvVar      = "DET_AGENT_ID"
	TaskIDEnvVar       = "DET_TASK_ID"
	AllocationIDEnvVar = "DET_ALLOCATION_ID"
	ContainerIDEnvVar  = "DET_CONTAINER_ID"
)

Environment variable names for various Determined container vars.

Variables

View Source
var ErrKilledBeforeRun = aproto.NewContainerFailure(
	aproto.ContainerAborted,
	errors.New("killed before run"),
)

ErrKilledBeforeRun indicates a container was aborted before we were able to run it.

View Source
var ErrMissing = aproto.NewContainerFailure(
	aproto.ContainerMissing,
	errors.New("container is gone on reattachment"),
)

ErrMissing indicates a container was missing when we tried to reattach it after a crash.

Functions

This section is empty.

Types

type Container

type Container struct {
	// contains filtered or unexported fields
}

Container is a layer for managing a single Docker container. It can be constructed by launching a new container or reattaching an existing one. Once constructed, it provides an interface to interact with a running container.

func Reattach

func Reattach(
	container cproto.Container,
	cl ContainerRuntime,
	pub events.Publisher[Event],
) *Container

Reattach an existing container and receive a handle to interact with it.

func Start

Start a container asynchronously and receive a handle to interact with it.

func (*Container) Detach

func (c *Container) Detach()

Detach the monitoring loops without affecting the Docker container.

func (*Container) Signal

func (c *Container) Signal(ctx context.Context, s syscall.Signal)

Signal asynchronously delivers the signal. Delivery failures are surfaced in logs.

func (*Container) Stop

func (c *Container) Stop()

Stop the Docker container by killing it and awaiting its exit.

func (*Container) Summary

func (c *Container) Summary() cproto.Container

Summary returns a snapshot of the container state.

func (*Container) Wait

Wait until the container exits. Always returns a ContainerExit unless canceled by Detach.

type ContainerRuntime

type ContainerRuntime interface {
	ReattachContainer(
		ctx context.Context,
		id cproto.ID,
	) (*docker.Container, *aproto.ExitCode, error)

	PullImage(ctx context.Context, req docker.PullImage, p events.Publisher[docker.Event]) error

	// TODO(DET-9075): Refactor Create and Run to not be separate calls.
	CreateContainer(
		ctx context.Context,
		id cproto.ID,
		req cproto.RunSpec,
		p events.Publisher[docker.Event],
	) (string, error)

	// TODO(DET-9075): Make a custom return type rather than just reusing the Docker type.
	RunContainer(
		ctx context.Context,
		waitCtx context.Context,
		id string,
		p events.Publisher[docker.Event],
	) (*docker.Container, error)

	SignalContainer(ctx context.Context, id string, sig syscall.Signal) error

	RemoveContainer(ctx context.Context, id string, force bool) error

	ListRunningContainers(ctx context.Context, fs filters.Args) (map[cproto.ID]types.Container, error)
}

ContainerRuntime is our interface for interacting with runtimes like Docker or Singularity.

type Event

type Event struct {
	StateChange *aproto.ContainerStateChanged
	Log         *aproto.ContainerLog
	StatsRecord *aproto.ContainerStatsRecord
}

Event is the union of all events emitted by a container. When used, only one should be set.

Jump to

Keyboard shortcuts

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