Skip to content

Commit 99d124e

Browse files
authored
feat(agent): enable devcontainers by default (#18533)
1 parent fcf9371 commit 99d124e

File tree

11 files changed

+59
-59
lines changed

11 files changed

+59
-59
lines changed

agent/agent.go

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,8 @@ type Options struct {
8989
ServiceBannerRefreshInterval time.Duration
9090
BlockFileTransfer bool
9191
Execer agentexec.Execer
92-
93-
ExperimentalDevcontainersEnabled bool
94-
ContainerAPIOptions []agentcontainers.Option // Enable ExperimentalDevcontainersEnabled for these to be effective.
92+
Devcontainers bool
93+
DevcontainerAPIOptions []agentcontainers.Option // Enable Devcontainers for these to be effective.
9594
}
9695

9796
type Client interface {
@@ -190,8 +189,8 @@ func New(options Options) Agent {
190189
metrics: newAgentMetrics(prometheusRegistry),
191190
execer: options.Execer,
192191

193-
experimentalDevcontainersEnabled: options.ExperimentalDevcontainersEnabled,
194-
containerAPIOptions: options.ContainerAPIOptions,
192+
devcontainers: options.Devcontainers,
193+
containerAPIOptions: options.DevcontainerAPIOptions,
195194
}
196195
// Initially, we have a closed channel, reflecting the fact that we are not initially connected.
197196
// Each time we connect we replace the channel (while holding the closeMutex) with a new one
@@ -272,9 +271,9 @@ type agent struct {
272271
metrics *agentMetrics
273272
execer agentexec.Execer
274273

275-
experimentalDevcontainersEnabled bool
276-
containerAPIOptions []agentcontainers.Option
277-
containerAPI atomic.Pointer[agentcontainers.API] // Set by apiHandler.
274+
devcontainers bool
275+
containerAPIOptions []agentcontainers.Option
276+
containerAPI atomic.Pointer[agentcontainers.API] // Set by apiHandler.
278277
}
279278

280279
func (a *agent) TailnetConn() *tailnet.Conn {
@@ -311,7 +310,7 @@ func (a *agent) init() {
311310
return a.reportConnection(id, connectionType, ip)
312311
},
313312

314-
ExperimentalDevContainersEnabled: a.experimentalDevcontainersEnabled,
313+
ExperimentalContainers: a.devcontainers,
315314
})
316315
if err != nil {
317316
panic(err)
@@ -340,7 +339,7 @@ func (a *agent) init() {
340339
a.metrics.connectionsTotal, a.metrics.reconnectingPTYErrors,
341340
a.reconnectingPTYTimeout,
342341
func(s *reconnectingpty.Server) {
343-
s.ExperimentalDevcontainersEnabled = a.experimentalDevcontainersEnabled
342+
s.ExperimentalContainers = a.devcontainers
344343
},
345344
)
346345
go a.runLoop()
@@ -1087,9 +1086,9 @@ func (a *agent) handleManifest(manifestOK *checkpoint) func(ctx context.Context,
10871086
slog.F("parent_id", manifest.ParentID),
10881087
slog.F("agent_id", manifest.AgentID),
10891088
)
1090-
if a.experimentalDevcontainersEnabled {
1089+
if a.devcontainers {
10911090
a.logger.Info(ctx, "devcontainers are not supported on sub agents, disabling feature")
1092-
a.experimentalDevcontainersEnabled = false
1091+
a.devcontainers = false
10931092
}
10941093
}
10951094
a.client.RewriteDERPMap(manifest.DERPMap)
@@ -1145,7 +1144,7 @@ func (a *agent) handleManifest(manifestOK *checkpoint) func(ctx context.Context,
11451144
scripts = manifest.Scripts
11461145
scriptRunnerOpts []agentscripts.InitOption
11471146
)
1148-
if a.experimentalDevcontainersEnabled {
1147+
if a.devcontainers {
11491148
var dcScripts []codersdk.WorkspaceAgentScript
11501149
scripts, dcScripts = agentcontainers.ExtractAndInitializeDevcontainerScripts(manifest.Devcontainers, scripts)
11511150
// See ExtractAndInitializeDevcontainerScripts for motivation

agent/agent_test.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1954,8 +1954,8 @@ func TestAgent_ReconnectingPTYContainer(t *testing.T) {
19541954

19551955
// nolint: dogsled
19561956
conn, _, _, _, _ := setupAgent(t, agentsdk.Manifest{}, 0, func(_ *agenttest.Client, o *agent.Options) {
1957-
o.ExperimentalDevcontainersEnabled = true
1958-
o.ContainerAPIOptions = append(o.ContainerAPIOptions,
1957+
o.Devcontainers = true
1958+
o.DevcontainerAPIOptions = append(o.DevcontainerAPIOptions,
19591959
agentcontainers.WithContainerLabelIncludeFilter("this.label.does.not.exist.ignore.devcontainers", "true"),
19601960
)
19611961
})
@@ -2161,9 +2161,9 @@ func TestAgent_DevcontainerAutostart(t *testing.T) {
21612161

21622162
//nolint:dogsled
21632163
_, agentClient, _, _, _ := setupAgent(t, manifest, 0, func(_ *agenttest.Client, o *agent.Options) {
2164-
o.ExperimentalDevcontainersEnabled = true
2165-
o.ContainerAPIOptions = append(
2166-
o.ContainerAPIOptions,
2164+
o.Devcontainers = true
2165+
o.DevcontainerAPIOptions = append(
2166+
o.DevcontainerAPIOptions,
21672167
// Only match this specific dev container.
21682168
agentcontainers.WithClock(mClock),
21692169
agentcontainers.WithContainerLabelIncludeFilter("devcontainer.local_folder", tempWorkspaceFolder),
@@ -2312,8 +2312,8 @@ func TestAgent_DevcontainerRecreate(t *testing.T) {
23122312

23132313
//nolint:dogsled
23142314
conn, client, _, _, _ := setupAgent(t, manifest, 0, func(_ *agenttest.Client, o *agent.Options) {
2315-
o.ExperimentalDevcontainersEnabled = true
2316-
o.ContainerAPIOptions = append(o.ContainerAPIOptions,
2315+
o.Devcontainers = true
2316+
o.DevcontainerAPIOptions = append(o.DevcontainerAPIOptions,
23172317
agentcontainers.WithContainerLabelIncludeFilter("devcontainer.local_folder", workspaceFolder),
23182318
)
23192319
})
@@ -2438,8 +2438,7 @@ func TestAgent_DevcontainersDisabledForSubAgent(t *testing.T) {
24382438

24392439
// Setup the agent with devcontainers enabled initially.
24402440
//nolint:dogsled
2441-
conn, _, _, _, _ := setupAgent(t, manifest, 0, func(_ *agenttest.Client, o *agent.Options) {
2442-
o.ExperimentalDevcontainersEnabled = true
2441+
conn, _, _, _, _ := setupAgent(t, manifest, 0, func(*agenttest.Client, *agent.Options) {
24432442
})
24442443

24452444
// Query the containers API endpoint. This should fail because

agent/agentssh/agentssh.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,10 @@ type Config struct {
113113
BlockFileTransfer bool
114114
// ReportConnection.
115115
ReportConnection reportConnectionFunc
116-
// Experimental: allow connecting to running containers if
117-
// CODER_AGENT_DEVCONTAINERS_ENABLE=true.
118-
ExperimentalDevContainersEnabled bool
116+
// Experimental: allow connecting to running containers via Docker exec.
117+
// Note that this is different from the devcontainers feature, which uses
118+
// subagents.
119+
ExperimentalContainers bool
119120
}
120121

121122
type Server struct {
@@ -435,7 +436,7 @@ func (s *Server) sessionHandler(session ssh.Session) {
435436
switch ss := session.Subsystem(); ss {
436437
case "":
437438
case "sftp":
438-
if s.config.ExperimentalDevContainersEnabled && container != "" {
439+
if s.config.ExperimentalContainers && container != "" {
439440
closeCause("sftp not yet supported with containers")
440441
_ = session.Exit(1)
441442
return
@@ -549,7 +550,7 @@ func (s *Server) sessionStart(logger slog.Logger, session ssh.Session, env []str
549550

550551
var ei usershell.EnvInfoer
551552
var err error
552-
if s.config.ExperimentalDevContainersEnabled && container != "" {
553+
if s.config.ExperimentalContainers && container != "" {
553554
ei, err = agentcontainers.EnvInfo(ctx, s.Execer, container, containerUser)
554555
if err != nil {
555556
s.metrics.sessionErrors.WithLabelValues(magicTypeLabel, ptyLabel, "container_env_info").Add(1)

agent/api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func (a *agent) apiHandler(aAPI proto.DRPCAgentClient26) (http.Handler, func() e
4040
cacheDuration: cacheDuration,
4141
}
4242

43-
if a.experimentalDevcontainersEnabled {
43+
if a.devcontainers {
4444
containerAPIOpts := []agentcontainers.Option{
4545
agentcontainers.WithExecer(a.execer),
4646
agentcontainers.WithCommandEnv(a.sshServer.CommandEnv),

agent/reconnectingpty/server.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ type Server struct {
3131
connCount atomic.Int64
3232
reconnectingPTYs sync.Map
3333
timeout time.Duration
34-
35-
ExperimentalDevcontainersEnabled bool
34+
// Experimental: allow connecting to running containers via Docker exec.
35+
// Note that this is different from the devcontainers feature, which uses
36+
// subagents.
37+
ExperimentalContainers bool
3638
}
3739

3840
// NewServer returns a new ReconnectingPTY server
@@ -187,7 +189,7 @@ func (s *Server) handleConn(ctx context.Context, logger slog.Logger, conn net.Co
187189
}()
188190

189191
var ei usershell.EnvInfoer
190-
if s.ExperimentalDevcontainersEnabled && msg.Container != "" {
192+
if s.ExperimentalContainers && msg.Container != "" {
191193
dei, err := agentcontainers.EnvInfo(ctx, s.commandCreator.Execer, msg.Container, msg.ContainerUser)
192194
if err != nil {
193195
return xerrors.Errorf("get container env info: %w", err)

cli/agent.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ func (r *RootCmd) workspaceAgent() *serpent.Command {
5555
blockFileTransfer bool
5656
agentHeaderCommand string
5757
agentHeader []string
58-
59-
experimentalDevcontainersEnabled bool
58+
devcontainers bool
6059
)
6160
cmd := &serpent.Command{
6261
Use: "agent",
@@ -321,7 +320,7 @@ func (r *RootCmd) workspaceAgent() *serpent.Command {
321320
return xerrors.Errorf("create agent execer: %w", err)
322321
}
323322

324-
if experimentalDevcontainersEnabled {
323+
if devcontainers {
325324
logger.Info(ctx, "agent devcontainer detection enabled")
326325
} else {
327326
logger.Info(ctx, "agent devcontainer detection not enabled")
@@ -359,11 +358,11 @@ func (r *RootCmd) workspaceAgent() *serpent.Command {
359358
SSHMaxTimeout: sshMaxTimeout,
360359
Subsystems: subsystems,
361360

362-
PrometheusRegistry: prometheusRegistry,
363-
BlockFileTransfer: blockFileTransfer,
364-
Execer: execer,
365-
ExperimentalDevcontainersEnabled: experimentalDevcontainersEnabled,
366-
ContainerAPIOptions: []agentcontainers.Option{
361+
PrometheusRegistry: prometheusRegistry,
362+
BlockFileTransfer: blockFileTransfer,
363+
Execer: execer,
364+
Devcontainers: devcontainers,
365+
DevcontainerAPIOptions: []agentcontainers.Option{
367366
agentcontainers.WithSubAgentURL(r.agentURL.String()),
368367
},
369368
})
@@ -506,10 +505,10 @@ func (r *RootCmd) workspaceAgent() *serpent.Command {
506505
},
507506
{
508507
Flag: "devcontainers-enable",
509-
Default: "false",
508+
Default: "true",
510509
Env: "CODER_AGENT_DEVCONTAINERS_ENABLE",
511510
Description: "Allow the agent to automatically detect running devcontainers.",
512-
Value: serpent.BoolOf(&experimentalDevcontainersEnabled),
511+
Value: serpent.BoolOf(&devcontainers),
513512
},
514513
}
515514

cli/exp_rpty_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ func TestExpRpty(t *testing.T) {
116116
})
117117

118118
_ = agenttest.New(t, client.URL, agentToken, func(o *agent.Options) {
119-
o.ExperimentalDevcontainersEnabled = true
120-
o.ContainerAPIOptions = append(o.ContainerAPIOptions,
119+
o.Devcontainers = true
120+
o.DevcontainerAPIOptions = append(o.DevcontainerAPIOptions,
121121
agentcontainers.WithContainerLabelIncludeFilter(wantLabel, "true"),
122122
)
123123
})

cli/open_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,8 @@ func TestOpenVSCodeDevContainer(t *testing.T) {
334334
})
335335

336336
_ = agenttest.New(t, client.URL, agentToken, func(o *agent.Options) {
337-
o.ExperimentalDevcontainersEnabled = true
338-
o.ContainerAPIOptions = append(o.ContainerAPIOptions,
337+
o.Devcontainers = true
338+
o.DevcontainerAPIOptions = append(o.DevcontainerAPIOptions,
339339
agentcontainers.WithContainerCLI(mccli),
340340
agentcontainers.WithContainerLabelIncludeFilter("this.label.does.not.exist.ignore.devcontainers", "true"),
341341
)
@@ -509,8 +509,8 @@ func TestOpenVSCodeDevContainer_NoAgentDirectory(t *testing.T) {
509509
})
510510

511511
_ = agenttest.New(t, client.URL, agentToken, func(o *agent.Options) {
512-
o.ExperimentalDevcontainersEnabled = true
513-
o.ContainerAPIOptions = append(o.ContainerAPIOptions,
512+
o.Devcontainers = true
513+
o.DevcontainerAPIOptions = append(o.DevcontainerAPIOptions,
514514
agentcontainers.WithContainerCLI(mccli),
515515
agentcontainers.WithContainerLabelIncludeFilter("this.label.does.not.exist.ignore.devcontainers", "true"),
516516
)

cli/ssh_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2029,8 +2029,8 @@ func TestSSH_Container(t *testing.T) {
20292029
})
20302030

20312031
_ = agenttest.New(t, client.URL, agentToken, func(o *agent.Options) {
2032-
o.ExperimentalDevcontainersEnabled = true
2033-
o.ContainerAPIOptions = append(o.ContainerAPIOptions,
2032+
o.Devcontainers = true
2033+
o.DevcontainerAPIOptions = append(o.DevcontainerAPIOptions,
20342034
agentcontainers.WithContainerLabelIncludeFilter("this.label.does.not.exist.ignore.devcontainers", "true"),
20352035
)
20362036
})
@@ -2069,8 +2069,8 @@ func TestSSH_Container(t *testing.T) {
20692069
Warnings: nil,
20702070
}, nil).AnyTimes()
20712071
_ = agenttest.New(t, client.URL, agentToken, func(o *agent.Options) {
2072-
o.ExperimentalDevcontainersEnabled = true
2073-
o.ContainerAPIOptions = append(o.ContainerAPIOptions,
2072+
o.Devcontainers = true
2073+
o.DevcontainerAPIOptions = append(o.DevcontainerAPIOptions,
20742074
agentcontainers.WithContainerCLI(mLister),
20752075
agentcontainers.WithContainerLabelIncludeFilter("this.label.does.not.exist.ignore.devcontainers", "true"),
20762076
)

cli/testdata/coder_agent_--help.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ OPTIONS:
3333
--debug-address string, $CODER_AGENT_DEBUG_ADDRESS (default: 127.0.0.1:2113)
3434
The bind address to serve a debug HTTP server.
3535

36-
--devcontainers-enable bool, $CODER_AGENT_DEVCONTAINERS_ENABLE (default: false)
36+
--devcontainers-enable bool, $CODER_AGENT_DEVCONTAINERS_ENABLE (default: true)
3737
Allow the agent to automatically detect running devcontainers.
3838

3939
--log-dir string, $CODER_AGENT_LOG_DIR (default: /tmp)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy