Thanks to visit codestin.com
Credit goes to pkg.go.dev

agentcontainers

package
v2.22.0 Latest Latest
Warning

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

Go to latest
Published: May 15, 2025 License: AGPL-3.0 Imports: 32 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DevcontainerLocalFolderLabel is the label that contains the path to
	// the local workspace folder for a devcontainer.
	DevcontainerLocalFolderLabel = "devcontainer.local_folder"
	// DevcontainerConfigFileLabel is the label that contains the path to
	// the devcontainer.json configuration file.
	DevcontainerConfigFileLabel = "devcontainer.config_file"
)

Variables

This section is empty.

Functions

func ExtractAndInitializeDevcontainerScripts added in v2.21.0

func ExtractAndInitializeDevcontainerScripts(
	logger slog.Logger,
	expandPath func(string) (string, error),
	devcontainers []codersdk.WorkspaceAgentDevcontainer,
	scripts []codersdk.WorkspaceAgentScript,
) (filteredScripts []codersdk.WorkspaceAgentScript, devcontainerScripts []codersdk.WorkspaceAgentScript)

ExtractAndInitializeDevcontainerScripts extracts devcontainer scripts from the given scripts and devcontainers. The devcontainer scripts are removed from the returned scripts so that they can be run separately.

Dev Containers have an inherent dependency on start scripts, since they initialize the workspace (e.g. git clone, npm install, etc). This is important if e.g. a Coder module to install @devcontainer/cli is used.

Types

type API added in v2.22.0

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

API is responsible for container-related operations in the agent. It provides methods to list and manage containers.

func NewAPI added in v2.22.0

func NewAPI(logger slog.Logger, options ...Option) *API

NewAPI returns a new API with the given options applied.

func (*API) Close added in v2.22.0

func (api *API) Close() error

func (*API) Routes added in v2.22.0

func (api *API) Routes() http.Handler

Routes returns the HTTP handler for container-related routes.

func (*API) SignalReady added in v2.22.0

func (api *API) SignalReady()

SignalReady signals the API that we are ready to begin watching for file changes. This is used to prime the cache with the current list of containers and to start watching the devcontainer config files for changes. It should be called after the agent ready.

type DevcontainerCLI added in v2.22.0

type DevcontainerCLI interface {
	Up(ctx context.Context, workspaceFolder, configPath string, opts ...DevcontainerCLIUpOptions) (id string, err error)
}

DevcontainerCLI is an interface for the devcontainer CLI.

func NewDevcontainerCLI added in v2.22.0

func NewDevcontainerCLI(logger slog.Logger, execer agentexec.Execer) DevcontainerCLI

type DevcontainerCLIUpOptions added in v2.22.0

type DevcontainerCLIUpOptions func(*devcontainerCLIUpConfig)

DevcontainerCLIUpOptions are options for the devcontainer CLI up command.

func WithRemoveExistingContainer added in v2.22.0

func WithRemoveExistingContainer() DevcontainerCLIUpOptions

WithRemoveExistingContainer is an option to remove the existing container.

type DockerCLILister

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

DockerCLILister is a ContainerLister that lists containers using the docker CLI

func (*DockerCLILister) List

type DockerEnvInfoer

type DockerEnvInfoer struct {
	usershell.SystemEnvInfo
	// contains filtered or unexported fields
}

DockerEnvInfoer is an implementation of agentssh.EnvInfoer that returns information about a container.

func EnvInfo

func EnvInfo(ctx context.Context, execer agentexec.Execer, container, containerUser string) (*DockerEnvInfoer, error)

EnvInfo returns information about the environment of a container.

func (*DockerEnvInfoer) ModifyCommand

func (dei *DockerEnvInfoer) ModifyCommand(cmd string, args ...string) (string, []string)

func (*DockerEnvInfoer) Shell added in v2.21.0

func (dei *DockerEnvInfoer) Shell(string) (string, error)

func (*DockerEnvInfoer) User added in v2.21.0

func (dei *DockerEnvInfoer) User() (*user.User, error)

type Lister

type Lister interface {
	// List returns a list of containers visible to the workspace agent.
	// This should include running and stopped containers.
	List(ctx context.Context) (codersdk.WorkspaceAgentListContainersResponse, error)
}

Lister is an interface for listing containers visible to the workspace agent.

func NewDocker

func NewDocker(execer agentexec.Execer) Lister

type NoopLister

type NoopLister struct{}

NoopLister is a Lister interface that never returns any containers.

type Option

type Option func(*API)

Option is a functional option for API.

func WithClock added in v2.22.0

func WithClock(clock quartz.Clock) Option

WithClock sets the quartz.Clock implementation to use. This is primarily used for testing to control time.

func WithDevcontainerCLI added in v2.22.0

func WithDevcontainerCLI(dccli DevcontainerCLI) Option

WithDevcontainerCLI sets the DevcontainerCLI implementation to use. This can be used in tests to modify @devcontainer/cli behavior.

func WithDevcontainers added in v2.22.0

func WithDevcontainers(devcontainers []codersdk.WorkspaceAgentDevcontainer) Option

WithDevcontainers sets the known devcontainers for the API. This allows the API to be aware of devcontainers defined in the workspace agent manifest.

func WithExecer added in v2.22.0

func WithExecer(execer agentexec.Execer) Option

WithExecer sets the agentexec.Execer implementation to use.

func WithLister

func WithLister(cl Lister) Option

WithLister sets the agentcontainers.Lister implementation to use. The default implementation uses the Docker CLI to list containers.

func WithWatcher added in v2.22.0

func WithWatcher(w watcher.Watcher) Option

WithWatcher sets the file watcher implementation to use. By default a noop watcher is used. This can be used in tests to modify the watcher behavior or to use an actual file watcher (e.g. fsnotify).

Directories

Path Synopsis
Package acmock is a generated GoMock package.
Package acmock is a generated GoMock package.
Package dcspec contains an automatically generated Devcontainer specification.
Package dcspec contains an automatically generated Devcontainer specification.
Package watcher provides file system watching capabilities for the agent.
Package watcher provides file system watching capabilities for the agent.

Jump to

Keyboard shortcuts

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