container

package
v0.0.0-...-6be7acf Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// EnvFileMountTarget is the in-container path where the env tmpfs is
	// bind-mounted read-only for env-file forwarding.
	EnvFileMountTarget = "/var/run/evergreen-env"

	// OwnerLabel marks a container as agent-created for task isolation. The
	// orphan reaper matches this label rather than the container name so it
	// cannot remove containers owned by another agent or by a human.
	OwnerLabel = "evergreen.owner"

	// OwnerLabelValue is the value OwnerLabel carries.
	OwnerLabelValue = "evergreen-agent-task-isolation"

	// ContainerNamePrefix is the name prefix for agent-created isolation
	// containers. The reaper matches it as an anchored prefix to identify
	// containers created before ownership labels existed.
	ContainerNamePrefix = "evergreen-task-"
)

Variables

This section is empty.

Functions

func SetEnvFileBaseDir

func SetEnvFileBaseDir(dir string) error

SetEnvFileBaseDir overrides the host-side base directory for env tmpfs dirs. Intended for local dev environments where /var/run is not accessible inside the Docker daemon's VM (e.g. macOS with colima).

Types

type Config

type Config struct {
	Image         string
	WorkDir       string // Host path to task working directory.
	TaskID        string
	TaskExecution int
	MemoryMB      int64 // 0 means no limit.
	CPUs          int64 // 0 means no limit. In units of whole CPUs.

	// ExtraMounts are additional host→container bind mounts layered on top
	// of the workdir mount. Sources and targets must be absolute paths.
	ExtraMounts []Mount

	// Logger receives operational messages (image pull progress, container
	// lifecycle events). If nil, messages fall back to the global grip
	// sender, which is not visible in the Evergreen task UI.
	Logger grip.Journaler
}

Config holds the parameters for creating a task isolation container.

func (Config) Validate

func (c Config) Validate() error

type Mount

type Mount struct {
	Source   string // Absolute host path.
	Target   string // Absolute container path.
	ReadOnly bool
}

Mount is a host→container bind mount layered on top of the workdir mount.

type TaskContainer

type TaskContainer struct {
	ID             string // Docker container ID (short hash).
	Name           string // Human-readable container name.
	EnvFileHostDir string // host-side tmpfs dir for env-file forwarding; empty if not provisioned.
	// contains filtered or unexported fields
}

TaskContainer represents a running isolation container for a single task.

func CreateAndStart

func CreateAndStart(ctx context.Context, cfg Config) (*TaskContainer, error)

CreateAndStart creates a Docker container for task isolation and starts it. The container runs `sleep infinity` while the agent docker execs commands into it. The host task working directory is bind-mounted at the same path inside the container. A per-task tmpfs is bind-mounted read-only into the container at EnvFileMountTarget for env-file forwarding. The caller must call Destroy when the task is complete.

The container image must include the exec_user account (e.g. uid=1000 ubuntu) in its /etc/passwd, since task commands run via `docker exec --user=<exec_user>`. Minimal base images like ubuntu:22.04 only contain root and will produce "unable to find user" errors at exec time.

func (*TaskContainer) Destroy

func (tc *TaskContainer) Destroy(ctx context.Context) error

Destroy gracefully stops the container, force-removes it, and cleans up the env tmpfs. Cleanup uses bounded contexts detached from the caller so that caller-side cancellation does not bypass container removal or tmpfs cleanup, both of which must complete to avoid leaking resources on the host.

func (*TaskContainer) GetEnvFileHostDir

func (tc *TaskContainer) GetEnvFileHostDir() string

GetEnvFileHostDir returns the host-side tmpfs directory path.

func (*TaskContainer) GetID

func (tc *TaskContainer) GetID() string

GetID returns the Docker container ID.

func (*TaskContainer) GetName

func (tc *TaskContainer) GetName() string

GetName returns the human-readable container name.

Jump to

Keyboard shortcuts

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