@@ -336,18 +336,16 @@ func (a *agent) init() {
336336 // will not report anywhere.
337337 a .scriptRunner .RegisterMetrics (a .prometheusRegistry )
338338
339- if a .devcontainers {
340- containerAPIOpts := []agentcontainers.Option {
341- agentcontainers .WithExecer (a .execer ),
342- agentcontainers .WithCommandEnv (a .sshServer .CommandEnv ),
343- agentcontainers .WithScriptLogger (func (logSourceID uuid.UUID ) agentcontainers.ScriptLogger {
344- return a .logSender .GetScriptLogger (logSourceID )
345- }),
346- }
347- containerAPIOpts = append (containerAPIOpts , a .containerAPIOptions ... )
348-
349- a .containerAPI = agentcontainers .NewAPI (a .logger .Named ("containers" ), containerAPIOpts ... )
339+ containerAPIOpts := []agentcontainers.Option {
340+ agentcontainers .WithExecer (a .execer ),
341+ agentcontainers .WithCommandEnv (a .sshServer .CommandEnv ),
342+ agentcontainers .WithScriptLogger (func (logSourceID uuid.UUID ) agentcontainers.ScriptLogger {
343+ return a .logSender .GetScriptLogger (logSourceID )
344+ }),
350345 }
346+ containerAPIOpts = append (containerAPIOpts , a .containerAPIOptions ... )
347+
348+ a .containerAPI = agentcontainers .NewAPI (a .logger .Named ("containers" ), containerAPIOpts ... )
351349
352350 a .reconnectingPTYServer = reconnectingpty .NewServer (
353351 a .logger .Named ("reconnecting-pty" ),
@@ -1162,7 +1160,7 @@ func (a *agent) handleManifest(manifestOK *checkpoint) func(ctx context.Context,
11621160 scripts = manifest .Scripts
11631161 devcontainerScripts map [uuid.UUID ]codersdk.WorkspaceAgentScript
11641162 )
1165- if a .containerAPI != nil {
1163+ if a .devcontainers {
11661164 // Init the container API with the manifest and client so that
11671165 // we can start accepting requests. The final start of the API
11681166 // happens after the startup scripts have been executed to
@@ -1197,7 +1195,7 @@ func (a *agent) handleManifest(manifestOK *checkpoint) func(ctx context.Context,
11971195 // autostarted devcontainer will be included in this time.
11981196 err := a .scriptRunner .Execute (a .gracefulCtx , agentscripts .ExecuteStartScripts )
11991197
1200- if a .containerAPI != nil {
1198+ if a .devcontainers {
12011199 // Start the container API after the startup scripts have
12021200 // been executed to ensure that the required tools can be
12031201 // installed.
@@ -1928,10 +1926,8 @@ func (a *agent) Close() error {
19281926 a .logger .Error (a .hardCtx , "script runner close" , slog .Error (err ))
19291927 }
19301928
1931- if a .containerAPI != nil {
1932- if err := a .containerAPI .Close (); err != nil {
1933- a .logger .Error (a .hardCtx , "container API close" , slog .Error (err ))
1934- }
1929+ if err := a .containerAPI .Close (); err != nil {
1930+ a .logger .Error (a .hardCtx , "container API close" , slog .Error (err ))
19351931 }
19361932
19371933 // Wait for the graceful shutdown to complete, but don't wait forever so
0 commit comments