mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat(agent/agentcontainers): auto detect dev containers (#18950)
Relates to https://github.com/coder/internal/issues/711 This PR implements a project discovery mechanism that searches for any dev container projects and makes them visible in the UI so that they can be started. To make the wording on the site more clear, "Rebuild" has been changed to "Start" when there is no container associated with a known dev container configuration. I've also made it so that site will show the dev container config path when there is no other name available. ### Design decisions Just want to ensure my explanation for a few design decisions are noted down: - We only search for dev container configurations inside git repositories - We only search for these git repositories if they're at the top level or a direct child of the agent directory. This limited approach is to reduce the amount of files we ultimately walk when trying to find these projects. It makes sense to limit it to only the agent directory, although I'm open to expanding how deep we search.
This commit is contained in:
+25
-16
@@ -40,22 +40,23 @@ import (
|
||||
|
||||
func (r *RootCmd) workspaceAgent() *serpent.Command {
|
||||
var (
|
||||
auth string
|
||||
logDir string
|
||||
scriptDataDir string
|
||||
pprofAddress string
|
||||
noReap bool
|
||||
sshMaxTimeout time.Duration
|
||||
tailnetListenPort int64
|
||||
prometheusAddress string
|
||||
debugAddress string
|
||||
slogHumanPath string
|
||||
slogJSONPath string
|
||||
slogStackdriverPath string
|
||||
blockFileTransfer bool
|
||||
agentHeaderCommand string
|
||||
agentHeader []string
|
||||
devcontainers bool
|
||||
auth string
|
||||
logDir string
|
||||
scriptDataDir string
|
||||
pprofAddress string
|
||||
noReap bool
|
||||
sshMaxTimeout time.Duration
|
||||
tailnetListenPort int64
|
||||
prometheusAddress string
|
||||
debugAddress string
|
||||
slogHumanPath string
|
||||
slogJSONPath string
|
||||
slogStackdriverPath string
|
||||
blockFileTransfer bool
|
||||
agentHeaderCommand string
|
||||
agentHeader []string
|
||||
devcontainers bool
|
||||
devcontainerProjectDiscovery bool
|
||||
)
|
||||
cmd := &serpent.Command{
|
||||
Use: "agent",
|
||||
@@ -364,6 +365,7 @@ func (r *RootCmd) workspaceAgent() *serpent.Command {
|
||||
Devcontainers: devcontainers,
|
||||
DevcontainerAPIOptions: []agentcontainers.Option{
|
||||
agentcontainers.WithSubAgentURL(r.agentURL.String()),
|
||||
agentcontainers.WithProjectDiscovery(devcontainerProjectDiscovery),
|
||||
},
|
||||
})
|
||||
|
||||
@@ -510,6 +512,13 @@ func (r *RootCmd) workspaceAgent() *serpent.Command {
|
||||
Description: "Allow the agent to automatically detect running devcontainers.",
|
||||
Value: serpent.BoolOf(&devcontainers),
|
||||
},
|
||||
{
|
||||
Flag: "devcontainers-project-discovery-enable",
|
||||
Default: "true",
|
||||
Env: "CODER_AGENT_DEVCONTAINERS_PROJECT_DISCOVERY_ENABLE",
|
||||
Description: "Allow the agent to search the filesystem for devcontainer projects.",
|
||||
Value: serpent.BoolOf(&devcontainerProjectDiscovery),
|
||||
},
|
||||
}
|
||||
|
||||
return cmd
|
||||
|
||||
@@ -118,6 +118,7 @@ func TestExpRpty(t *testing.T) {
|
||||
_ = agenttest.New(t, client.URL, agentToken, func(o *agent.Options) {
|
||||
o.Devcontainers = true
|
||||
o.DevcontainerAPIOptions = append(o.DevcontainerAPIOptions,
|
||||
agentcontainers.WithProjectDiscovery(false),
|
||||
agentcontainers.WithContainerLabelIncludeFilter(wantLabel, "true"),
|
||||
)
|
||||
})
|
||||
|
||||
@@ -406,6 +406,7 @@ func TestOpenVSCodeDevContainer(t *testing.T) {
|
||||
_ = agenttest.New(t, client.URL, agentToken, func(o *agent.Options) {
|
||||
o.Devcontainers = true
|
||||
o.DevcontainerAPIOptions = append(o.DevcontainerAPIOptions,
|
||||
agentcontainers.WithProjectDiscovery(false),
|
||||
agentcontainers.WithContainerCLI(fCCLI),
|
||||
agentcontainers.WithDevcontainerCLI(fDCCLI),
|
||||
agentcontainers.WithWatcher(watcher.NewNoop()),
|
||||
|
||||
@@ -2031,6 +2031,7 @@ func TestSSH_Container(t *testing.T) {
|
||||
_ = agenttest.New(t, client.URL, agentToken, func(o *agent.Options) {
|
||||
o.Devcontainers = true
|
||||
o.DevcontainerAPIOptions = append(o.DevcontainerAPIOptions,
|
||||
agentcontainers.WithProjectDiscovery(false),
|
||||
agentcontainers.WithContainerLabelIncludeFilter("this.label.does.not.exist.ignore.devcontainers", "true"),
|
||||
)
|
||||
})
|
||||
@@ -2072,6 +2073,7 @@ func TestSSH_Container(t *testing.T) {
|
||||
o.Devcontainers = true
|
||||
o.DevcontainerAPIOptions = append(o.DevcontainerAPIOptions,
|
||||
agentcontainers.WithContainerCLI(mLister),
|
||||
agentcontainers.WithProjectDiscovery(false),
|
||||
agentcontainers.WithContainerLabelIncludeFilter("this.label.does.not.exist.ignore.devcontainers", "true"),
|
||||
)
|
||||
})
|
||||
|
||||
+3
@@ -36,6 +36,9 @@ OPTIONS:
|
||||
--devcontainers-enable bool, $CODER_AGENT_DEVCONTAINERS_ENABLE (default: true)
|
||||
Allow the agent to automatically detect running devcontainers.
|
||||
|
||||
--devcontainers-project-discovery-enable bool, $CODER_AGENT_DEVCONTAINERS_PROJECT_DISCOVERY_ENABLE (default: true)
|
||||
Allow the agent to search the filesystem for devcontainer projects.
|
||||
|
||||
--log-dir string, $CODER_AGENT_LOG_DIR (default: /tmp)
|
||||
Specify the location for the agent log files.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user