agentcontainers
packageThis package is not in the latest version of its module.
Details
Validgo.mod file
The Go module system was introduced in Go 1.11 and is the official dependency management solution for Go.
Redistributable license
Redistributable licenses place minimal restrictions on how software can be used, modified, and redistributed.
Tagged version
Modules with tagged versions give importers more predictable builds.
Stable version
When a project reaches major version v1 it is considered stable.
- Learn more about best practices
Repository
Links
Documentation¶
Index¶
- Constants
- func ExpandAllDevcontainerPaths(logger slog.Logger, expandPath func(string) (string, error), ...) []codersdk.WorkspaceAgentDevcontainer
- func ExtractDevcontainerScripts(devcontainers []codersdk.WorkspaceAgentDevcontainer, ...) (filteredScripts []codersdk.WorkspaceAgentScript, ...)
- type API
- func (api *API) Close() error
- func (api *API) CreateDevcontainer(workspaceFolder, configPath string, opts ...DevcontainerCLIUpOptions) error
- func (api *API) Init(opts ...Option)
- func (api *API) RefreshContainers(ctx context.Context) (err error)
- func (api *API) Routes() http.Handler
- func (api *API) Start()
- func (api *API) UpdateSubAgentClient(client SubAgentClient)
- type CoderCustomization
- type CommandEnv
- type ContainerCLI
- type DevcontainerCLI
- type DevcontainerCLIExecOptions
- type DevcontainerCLIReadConfigOptions
- type DevcontainerCLIUpOptions
- type DevcontainerConfig
- type DevcontainerConfiguration
- type DevcontainerCustomizations
- type DevcontainerFeatures
- type DevcontainerMergedConfiguration
- type DevcontainerMergedCustomizations
- type DevcontainerWorkspace
- type DockerEnvInfoer
- type Option
- func WithClock(clock quartz.Clock) Option
- func WithCommandEnv(ce CommandEnv) Option
- func WithContainerCLI(ccli ContainerCLI) Option
- func WithContainerLabelIncludeFilter(label, value string) Option
- func WithDevcontainerCLI(dccli DevcontainerCLI) Option
- func WithDevcontainers(devcontainers []codersdk.WorkspaceAgentDevcontainer, ...) Option
- func WithExecer(execer agentexec.Execer) Option
- func WithManifestInfo(owner, workspace, parentAgent string) Option
- func WithScriptLogger(scriptLogger func(logSourceID uuid.UUID) ScriptLogger) Option
- func WithSubAgentClient(client SubAgentClient) Option
- func WithSubAgentEnv(env ...string) Option
- func WithSubAgentURL(url string) Option
- func WithWatcher(w watcher.Watcher) Option
- type ScriptLogger
- type SubAgent
- type SubAgentApp
- type SubAgentClient
- type SubAgentHealthCheck
Constants¶
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"// DevcontainerIsTestRunLabel is set if the devcontainer is part of a test// and should be excluded.DevcontainerIsTestRunLabel = "devcontainer.is_test_run"// The default workspace folder inside the devcontainer.DevcontainerDefaultContainerWorkspaceFolder = "/workspaces")
Variables¶
This section is empty.
Functions¶
funcExpandAllDevcontainerPaths¶added inv2.23.0
func ExpandAllDevcontainerPaths(loggerslog.Logger, expandPath func(string) (string,error), devcontainers []codersdk.WorkspaceAgentDevcontainer) []codersdk.WorkspaceAgentDevcontainer
ExpandAllDevcontainerPaths expands all devcontainer paths in the givendevcontainers. This is required by the devcontainer CLI, which requiresabsolute paths for the workspace folder and config path.
funcExtractDevcontainerScripts¶added inv2.24.0
func ExtractDevcontainerScripts(devcontainers []codersdk.WorkspaceAgentDevcontainer,scripts []codersdk.WorkspaceAgentScript,) (filteredScripts []codersdk.WorkspaceAgentScript, devcontainerScripts map[uuid.UUID]codersdk.WorkspaceAgentScript)
Types¶
typeAPI¶added inv2.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 (*API)CreateDevcontainer¶added inv2.24.0
func (api *API) CreateDevcontainer(workspaceFolder, configPathstring, opts ...DevcontainerCLIUpOptions)error
createDevcontainer should run in its own goroutine and is responsible forrecreating a devcontainer based on the provided devcontainer configuration.It updates the devcontainer status and logs the process. The configPath ispassed as a parameter for the odd chance that the container being recreatedhas a different config file than the one stored in the devcontainer state.The devcontainer state must be set to starting and the asyncWg must beincremented before calling this function.
func (*API)Init¶added inv2.24.0
Init applies a final set of options to the API and thencloses initDone. This method can only be called once.
func (*API)RefreshContainers¶added inv2.24.0
RefreshContainers triggers an immediate update of the container listand waits for it to complete.
func (*API)Start¶added inv2.24.0
func (api *API) Start()
Start starts the API by initializing the watcher and updater loops.This method calls Init, if it is desired to apply options afterthe API has been created, it should be done by calling Init beforeStart. This method must only be called once.
func (*API)UpdateSubAgentClient¶added inv2.24.0
func (api *API) UpdateSubAgentClient(clientSubAgentClient)
UpdateSubAgentClient updates the `SubAgentClient` for the API.
typeCoderCustomization¶added inv2.24.0
type CoderCustomization struct {DisplayApps map[codersdk.DisplayApp]bool `json:"displayApps,omitempty"`Apps []SubAgentApp `json:"apps,omitempty"`Namestring `json:"name,omitempty"`Ignorebool `json:"ignore,omitempty"`}
typeCommandEnv¶added inv2.24.0
type CommandEnv func(eiusershell.EnvInfoer, addEnv []string) (shell, dirstring, env []string, errerror)
CommandEnv is a function that returns the shell, working directory,and environment variables to use when executing a command. It takesan EnvInfoer and a pre-existing environment slice as arguments.This signature matches agentssh.Server.CommandEnv.
typeContainerCLI¶added inv2.24.0
type ContainerCLI interface {// List returns a list of containers visible to the workspace agent.// This should include running and stopped containers.List(ctxcontext.Context) (codersdk.WorkspaceAgentListContainersResponse,error)// DetectArchitecture detects the architecture of a container.DetectArchitecture(ctxcontext.Context, containerNamestring) (string,error)// Copy copies a file from the host to a container.Copy(ctxcontext.Context, containerName, src, dststring)error// ExecAs executes a command in a container as a specific user.ExecAs(ctxcontext.Context, containerName, userstring, args ...string) ([]byte,error)}
ContainerCLI is an interface for interacting with containers in a workspace.
funcNewDockerCLI¶added inv2.24.0
func NewDockerCLI(execeragentexec.Execer)ContainerCLI
typeDevcontainerCLI¶added inv2.22.0
type DevcontainerCLI interface {Up(ctxcontext.Context, workspaceFolder, configPathstring, opts ...DevcontainerCLIUpOptions) (idstring, errerror)Exec(ctxcontext.Context, workspaceFolder, configPathstring, cmdstring, cmdArgs []string, opts ...DevcontainerCLIExecOptions)errorReadConfig(ctxcontext.Context, workspaceFolder, configPathstring, env []string, opts ...DevcontainerCLIReadConfigOptions) (DevcontainerConfig,error)}
DevcontainerCLI is an interface for the devcontainer CLI.
funcNewDevcontainerCLI¶added inv2.22.0
func NewDevcontainerCLI(loggerslog.Logger, execeragentexec.Execer)DevcontainerCLI
typeDevcontainerCLIExecOptions¶added inv2.24.0
type DevcontainerCLIExecOptions func(*devcontainerCLIExecConfig)
DevcontainerCLIExecOptions are options for the devcontainer CLI Execcommand.
funcWithExecContainerID¶added inv2.24.0
func WithExecContainerID(idstring)DevcontainerCLIExecOptions
WithExecContainerID sets the container ID to target a specificcontainer.
funcWithExecOutput¶added inv2.24.0
func WithExecOutput(stdout, stderrio.Writer)DevcontainerCLIExecOptions
WithExecOutput sets additional stdout and stderr writers for logsduring Exec operations.
funcWithRemoteEnv¶added inv2.24.0
func WithRemoteEnv(env ...string)DevcontainerCLIExecOptions
WithRemoteEnv sets environment variables for the Exec command.
typeDevcontainerCLIReadConfigOptions¶added inv2.24.0
type DevcontainerCLIReadConfigOptions func(*devcontainerCLIReadConfigConfig)
DevcontainerCLIExecOptions are options for the devcontainer CLI ReadConfigcommand.
funcWithReadConfigOutput¶added inv2.24.0
func WithReadConfigOutput(stdout, stderrio.Writer)DevcontainerCLIReadConfigOptions
WithReadConfigOutput sets additional stdout and stderr writers for logsduring ReadConfig operations.
typeDevcontainerCLIUpOptions¶added inv2.22.0
type DevcontainerCLIUpOptions func(*devcontainerCLIUpConfig)
DevcontainerCLIUpOptions are options for the devcontainer CLI Upcommand.
funcWithRemoveExistingContainer¶added inv2.22.0
func WithRemoveExistingContainer()DevcontainerCLIUpOptions
WithRemoveExistingContainer is an option to remove the existingcontainer.
funcWithUpOutput¶added inv2.24.0
func WithUpOutput(stdout, stderrio.Writer)DevcontainerCLIUpOptions
WithUpOutput sets additional stdout and stderr writers for logsduring Up operations.
typeDevcontainerConfig¶added inv2.24.0
type DevcontainerConfig struct {MergedConfigurationDevcontainerMergedConfiguration `json:"mergedConfiguration"`ConfigurationDevcontainerConfiguration `json:"configuration"`WorkspaceDevcontainerWorkspace `json:"workspace"`}
DevcontainerConfig is a wrapper around the output from `read-configuration`.Unfortunately we cannot make use of `dcspec` as the output doesn't appear tomatch.
typeDevcontainerConfiguration¶added inv2.24.0
type DevcontainerConfiguration struct {CustomizationsDevcontainerCustomizations `json:"customizations,omitempty"`}
typeDevcontainerCustomizations¶added inv2.24.0
type DevcontainerCustomizations struct {CoderCoderCustomization `json:"coder,omitempty"`}
typeDevcontainerFeatures¶added inv2.24.0
func (DevcontainerFeatures)OptionsAsEnvs¶added inv2.24.0
func (fDevcontainerFeatures) OptionsAsEnvs() []string
OptionsAsEnvs converts the DevcontainerFeatures into a list ofenvironment variables that can be used to set feature options.The format is FEATURE_<FEATURE_NAME>_OPTION_<OPTION_NAME>=<value>.For example, if the feature is:
"ghcr.io/coder/devcontainer-features/code-server:1": { "port": 9090, }
It will produce:
FEATURE_CODE_SERVER_OPTION_PORT=9090
Note that the feature name is derived from the last part of the key,so "ghcr.io/coder/devcontainer-features/code-server:1" becomes"CODE_SERVER". The version part (e.g. ":1") is removed, and dashes inthe feature and option names are replaced with underscores.
typeDevcontainerMergedConfiguration¶added inv2.24.0
type DevcontainerMergedConfiguration struct {CustomizationsDevcontainerMergedCustomizations `json:"customizations,omitempty"`FeaturesDevcontainerFeatures `json:"features,omitempty"`}
typeDevcontainerMergedCustomizations¶added inv2.24.0
type DevcontainerMergedCustomizations struct {Coder []CoderCustomization `json:"coder,omitempty"`}
typeDevcontainerWorkspace¶added inv2.24.0
type DevcontainerWorkspace struct {WorkspaceFolderstring `json:"workspaceFolder"`}
typeDockerEnvInfoer¶
type DockerEnvInfoer struct {usershell.SystemEnvInfo// contains filtered or unexported fields}
DockerEnvInfoer is an implementation of agentssh.EnvInfoer that returnsinformation about a container.
funcEnvInfo¶
func EnvInfo(ctxcontext.Context, execeragentexec.Execer, container, containerUserstring) (*DockerEnvInfoer,error)
EnvInfo returns information about the environment of a container.
func (*DockerEnvInfoer)ModifyCommand¶
func (dei *DockerEnvInfoer) ModifyCommand(cmdstring, args ...string) (string, []string)
typeOption¶
type Option func(*API)
Option is a functional option for API.
funcWithClock¶added inv2.22.0
WithClock sets the quartz.Clock implementation to use.This is primarily used for testing to control time.
funcWithCommandEnv¶added inv2.24.0
func WithCommandEnv(ceCommandEnv)Option
WithCommandEnv sets the CommandEnv implementation to use.
funcWithContainerCLI¶added inv2.24.0
func WithContainerCLI(ccliContainerCLI)Option
WithContainerCLI sets the agentcontainers.ContainerCLI implementationto use. The default implementation uses the Docker CLI.
funcWithContainerLabelIncludeFilter¶added inv2.24.0
WithContainerLabelIncludeFilter sets a label filter for containers.This option can be given multiple times to filter by multiple labels.The behavior is such that only containers matching one or more of theprovided labels will be included.
funcWithDevcontainerCLI¶added inv2.22.0
func WithDevcontainerCLI(dccliDevcontainerCLI)Option
WithDevcontainerCLI sets the DevcontainerCLI implementation to use.This can be used in tests to modify @devcontainer/cli behavior.
funcWithDevcontainers¶added inv2.22.0
func WithDevcontainers(devcontainers []codersdk.WorkspaceAgentDevcontainer, scripts []codersdk.WorkspaceAgentScript)Option
WithDevcontainers sets the known devcontainers for the API. Thisallows the API to be aware of devcontainers defined in the workspaceagent manifest.
funcWithExecer¶added inv2.22.0
WithExecer sets the agentexec.Execer implementation to use.
funcWithManifestInfo¶added inv2.24.0
WithManifestInfo sets the owner name, and workspace namefor the sub-agent.
funcWithScriptLogger¶added inv2.23.0
func WithScriptLogger(scriptLogger func(logSourceIDuuid.UUID)ScriptLogger)Option
WithScriptLogger sets the script logger provider for devcontainer operations.
funcWithSubAgentClient¶added inv2.24.0
func WithSubAgentClient(clientSubAgentClient)Option
WithSubAgentClient sets the SubAgentClient implementation to use.This is used to list, create, and delete devcontainer agents.
funcWithSubAgentEnv¶added inv2.24.0
WithSubAgentEnv sets the environment variables for the sub-agent.
funcWithSubAgentURL¶added inv2.24.0
WithSubAgentURL sets the agent URL for the sub-agent forcommunicating with the control plane.
funcWithWatcher¶added inv2.22.0
WithWatcher sets the file watcher implementation to use. By default anoop watcher is used. This can be used in tests to modify the watcherbehavior or to use an actual file watcher (e.g. fsnotify).
typeScriptLogger¶added inv2.23.0
type ScriptLogger interface {Send(ctxcontext.Context, log ...agentsdk.Log)errorFlush(ctxcontext.Context)error}
ScriptLogger is an interface for sending devcontainer logs to thecontrolplane.
typeSubAgent¶added inv2.24.0
type SubAgent struct {IDuuid.UUIDNamestringAuthTokenuuid.UUIDDirectorystringArchitecturestringOperatingSystemstringApps []SubAgentAppDisplayApps []codersdk.DisplayApp}
SubAgent represents an agent running in a dev container.
func (SubAgent)CloneConfig¶added inv2.24.0
func (sSubAgent) CloneConfig(dccodersdk.WorkspaceAgentDevcontainer)SubAgent
CloneConfig makes a copy of SubAgent without ID and AuthToken. Thename is inherited from the devcontainer.
func (SubAgent)EqualConfig¶added inv2.24.0
typeSubAgentApp¶added inv2.24.0
type SubAgentApp struct {Slugstring `json:"slug"`Commandstring `json:"command"`DisplayNamestring `json:"displayName"`Externalbool `json:"external"`Groupstring `json:"group"`HealthCheckSubAgentHealthCheck `json:"healthCheck"`Hiddenbool `json:"hidden"`Iconstring `json:"icon"`OpenIncodersdk.WorkspaceAppOpenIn `json:"openIn"`Orderint32 `json:"order"`Sharecodersdk.WorkspaceAppSharingLevel `json:"share"`Subdomainbool `json:"subdomain"`URLstring `json:"url"`}
func (SubAgentApp)ToProtoApp¶added inv2.24.0
func (appSubAgentApp) ToProtoApp() (*agentproto.CreateSubAgentRequest_App,error)
typeSubAgentClient¶added inv2.24.0
type SubAgentClient interface {// List returns a list of all agents.List(ctxcontext.Context) ([]SubAgent,error)// Create adds a new agent.Create(ctxcontext.Context, agentSubAgent) (SubAgent,error)// Delete removes an agent by its ID.Delete(ctxcontext.Context, iduuid.UUID)error}
SubAgentClient is an interface for managing sub agents and allowschanging the implementation without having to deal with theagentproto package directly.
funcNewSubAgentClientFromAPI¶added inv2.24.0
func NewSubAgentClientFromAPI(loggerslog.Logger, agentAPIagentproto.DRPCAgentClient26)SubAgentClient
typeSubAgentHealthCheck¶added inv2.24.0
Source Files¶
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. |