Movatterモバイル変換


[0]ホーム

URL:


agentcontainers

package
v2.24.2Latest Latest
Warning

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

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

Details

Repository

github.com/coder/coder

Links

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"// 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

funcExpandAllDevcontainerPathsadded 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.

funcExtractDevcontainerScriptsadded inv2.24.0

func ExtractDevcontainerScripts(devcontainers []codersdk.WorkspaceAgentDevcontainer,scripts []codersdk.WorkspaceAgentScript,) (filteredScripts []codersdk.WorkspaceAgentScript, devcontainerScripts map[uuid.UUID]codersdk.WorkspaceAgentScript)

Types

typeAPIadded 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.

funcNewAPIadded inv2.22.0

func NewAPI(loggerslog.Logger, options ...Option) *API

NewAPI returns a new API with the given options applied.

func (*API)Closeadded inv2.22.0

func (api *API) Close()error

func (*API)CreateDevcontaineradded 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)Initadded inv2.24.0

func (api *API) Init(opts ...Option)

Init applies a final set of options to the API and thencloses initDone. This method can only be called once.

func (*API)RefreshContainersadded inv2.24.0

func (api *API) RefreshContainers(ctxcontext.Context) (errerror)

RefreshContainers triggers an immediate update of the container listand waits for it to complete.

func (*API)Routesadded inv2.22.0

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

Routes returns the HTTP handler for container-related routes.

func (*API)Startadded 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)UpdateSubAgentClientadded inv2.24.0

func (api *API) UpdateSubAgentClient(clientSubAgentClient)

UpdateSubAgentClient updates the `SubAgentClient` for the API.

typeCoderCustomizationadded 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"`}

typeCommandEnvadded 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.

typeContainerCLIadded 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.

funcNewDockerCLIadded inv2.24.0

func NewDockerCLI(execeragentexec.Execer)ContainerCLI

typeDevcontainerCLIadded 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.

funcNewDevcontainerCLIadded inv2.22.0

func NewDevcontainerCLI(loggerslog.Logger, execeragentexec.Execer)DevcontainerCLI

typeDevcontainerCLIExecOptionsadded inv2.24.0

type DevcontainerCLIExecOptions func(*devcontainerCLIExecConfig)

DevcontainerCLIExecOptions are options for the devcontainer CLI Execcommand.

funcWithExecContainerIDadded inv2.24.0

func WithExecContainerID(idstring)DevcontainerCLIExecOptions

WithExecContainerID sets the container ID to target a specificcontainer.

funcWithExecOutputadded inv2.24.0

func WithExecOutput(stdout, stderrio.Writer)DevcontainerCLIExecOptions

WithExecOutput sets additional stdout and stderr writers for logsduring Exec operations.

funcWithRemoteEnvadded inv2.24.0

func WithRemoteEnv(env ...string)DevcontainerCLIExecOptions

WithRemoteEnv sets environment variables for the Exec command.

typeDevcontainerCLIReadConfigOptionsadded inv2.24.0

type DevcontainerCLIReadConfigOptions func(*devcontainerCLIReadConfigConfig)

DevcontainerCLIExecOptions are options for the devcontainer CLI ReadConfigcommand.

funcWithReadConfigOutputadded inv2.24.0

func WithReadConfigOutput(stdout, stderrio.Writer)DevcontainerCLIReadConfigOptions

WithReadConfigOutput sets additional stdout and stderr writers for logsduring ReadConfig operations.

typeDevcontainerCLIUpOptionsadded inv2.22.0

type DevcontainerCLIUpOptions func(*devcontainerCLIUpConfig)

DevcontainerCLIUpOptions are options for the devcontainer CLI Upcommand.

funcWithRemoveExistingContaineradded inv2.22.0

func WithRemoveExistingContainer()DevcontainerCLIUpOptions

WithRemoveExistingContainer is an option to remove the existingcontainer.

funcWithUpOutputadded inv2.24.0

func WithUpOutput(stdout, stderrio.Writer)DevcontainerCLIUpOptions

WithUpOutput sets additional stdout and stderr writers for logsduring Up operations.

typeDevcontainerConfigadded 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.

typeDevcontainerConfigurationadded inv2.24.0

type DevcontainerConfiguration struct {CustomizationsDevcontainerCustomizations `json:"customizations,omitempty"`}

typeDevcontainerCustomizationsadded inv2.24.0

type DevcontainerCustomizations struct {CoderCoderCustomization `json:"coder,omitempty"`}

typeDevcontainerFeaturesadded inv2.24.0

type DevcontainerFeatures map[string]any

func (DevcontainerFeatures)OptionsAsEnvsadded 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.

typeDevcontainerMergedConfigurationadded inv2.24.0

type DevcontainerMergedConfiguration struct {CustomizationsDevcontainerMergedCustomizations `json:"customizations,omitempty"`FeaturesDevcontainerFeatures             `json:"features,omitempty"`}

typeDevcontainerMergedCustomizationsadded inv2.24.0

type DevcontainerMergedCustomizations struct {Coder []CoderCustomization `json:"coder,omitempty"`}

typeDevcontainerWorkspaceadded 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)

func (*DockerEnvInfoer)Shelladded inv2.21.0

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

func (*DockerEnvInfoer)Useradded inv2.21.0

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

typeOption

type Option func(*API)

Option is a functional option for API.

funcWithClockadded inv2.22.0

func WithClock(clockquartz.Clock)Option

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

funcWithCommandEnvadded inv2.24.0

func WithCommandEnv(ceCommandEnv)Option

WithCommandEnv sets the CommandEnv implementation to use.

funcWithContainerCLIadded inv2.24.0

func WithContainerCLI(ccliContainerCLI)Option

WithContainerCLI sets the agentcontainers.ContainerCLI implementationto use. The default implementation uses the Docker CLI.

funcWithContainerLabelIncludeFilteradded inv2.24.0

func WithContainerLabelIncludeFilter(label, valuestring)Option

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.

funcWithDevcontainerCLIadded 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.

funcWithDevcontainersadded 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.

funcWithExeceradded inv2.22.0

func WithExecer(execeragentexec.Execer)Option

WithExecer sets the agentexec.Execer implementation to use.

funcWithManifestInfoadded inv2.24.0

func WithManifestInfo(owner, workspace, parentAgentstring)Option

WithManifestInfo sets the owner name, and workspace namefor the sub-agent.

funcWithScriptLoggeradded inv2.23.0

func WithScriptLogger(scriptLogger func(logSourceIDuuid.UUID)ScriptLogger)Option

WithScriptLogger sets the script logger provider for devcontainer operations.

funcWithSubAgentClientadded inv2.24.0

func WithSubAgentClient(clientSubAgentClient)Option

WithSubAgentClient sets the SubAgentClient implementation to use.This is used to list, create, and delete devcontainer agents.

funcWithSubAgentEnvadded inv2.24.0

func WithSubAgentEnv(env ...string)Option

WithSubAgentEnv sets the environment variables for the sub-agent.

funcWithSubAgentURLadded inv2.24.0

func WithSubAgentURL(urlstring)Option

WithSubAgentURL sets the agent URL for the sub-agent forcommunicating with the control plane.

funcWithWatcheradded inv2.22.0

func WithWatcher(wwatcher.Watcher)Option

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).

typeScriptLoggeradded 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.

typeSubAgentadded inv2.24.0

type SubAgent struct {IDuuid.UUIDNamestringAuthTokenuuid.UUIDDirectorystringArchitecturestringOperatingSystemstringApps            []SubAgentAppDisplayApps     []codersdk.DisplayApp}

SubAgent represents an agent running in a dev container.

func (SubAgent)CloneConfigadded inv2.24.0

CloneConfig makes a copy of SubAgent without ID and AuthToken. Thename is inherited from the devcontainer.

func (SubAgent)EqualConfigadded inv2.24.0

func (sSubAgent) EqualConfig(otherSubAgent)bool

typeSubAgentAppadded 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)ToProtoAppadded inv2.24.0

typeSubAgentClientadded 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.

funcNewSubAgentClientFromAPIadded inv2.24.0

func NewSubAgentClientFromAPI(loggerslog.Logger, agentAPIagentproto.DRPCAgentClient26)SubAgentClient

typeSubAgentHealthCheckadded inv2.24.0

type SubAgentHealthCheck struct {Intervalint32  `json:"interval"`Thresholdint32  `json:"threshold"`URLstring `json:"url"`}

Source Files

View all Source files

Directories

PathSynopsis
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 orF : Jump to
y orY : Canonical URL
go.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic.Learn more.

[8]ページ先頭

©2009-2025 Movatter.jp