@@ -336,18 +336,16 @@ func (a *agent) init() {
336
336
// will not report anywhere.
337
337
a .scriptRunner .RegisterMetrics (a .prometheusRegistry )
338
338
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
+ }),
350
345
}
346
+ containerAPIOpts = append (containerAPIOpts , a .containerAPIOptions ... )
347
+
348
+ a .containerAPI = agentcontainers .NewAPI (a .logger .Named ("containers" ), containerAPIOpts ... )
351
349
352
350
a .reconnectingPTYServer = reconnectingpty .NewServer (
353
351
a .logger .Named ("reconnecting-pty" ),
@@ -1162,7 +1160,7 @@ func (a *agent) handleManifest(manifestOK *checkpoint) func(ctx context.Context,
1162
1160
scripts = manifest .Scripts
1163
1161
devcontainerScripts map [uuid.UUID ]codersdk.WorkspaceAgentScript
1164
1162
)
1165
- if a .containerAPI != nil {
1163
+ if a .devcontainers {
1166
1164
// Init the container API with the manifest and client so that
1167
1165
// we can start accepting requests. The final start of the API
1168
1166
// happens after the startup scripts have been executed to
@@ -1197,7 +1195,7 @@ func (a *agent) handleManifest(manifestOK *checkpoint) func(ctx context.Context,
1197
1195
// autostarted devcontainer will be included in this time.
1198
1196
err := a .scriptRunner .Execute (a .gracefulCtx , agentscripts .ExecuteStartScripts )
1199
1197
1200
- if a .containerAPI != nil {
1198
+ if a .devcontainers {
1201
1199
// Start the container API after the startup scripts have
1202
1200
// been executed to ensure that the required tools can be
1203
1201
// installed.
@@ -1928,10 +1926,8 @@ func (a *agent) Close() error {
1928
1926
a .logger .Error (a .hardCtx , "script runner close" , slog .Error (err ))
1929
1927
}
1930
1928
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 ))
1935
1931
}
1936
1932
1937
1933
// Wait for the graceful shutdown to complete, but don't wait forever so
0 commit comments