Skip to content

Commit 0860ba7

Browse files
committed
refactor(agent): read boundary log socket path from manifest
Read CODER_BOUNDARY_LOG_SOCKET from manifest.EnvironmentVariables instead of os.Getenv. This allows the socket path to be configured via coder_env in the workspace template. The proxy is now started in handleManifest after the manifest is fetched, rather than in init() before the manifest is available.
1 parent 295d760 commit 0860ba7

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

agent/agent.go

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,6 @@ func (a *agent) init() {
372372
)
373373

374374
a.initSocketServer()
375-
a.startBoundaryLogProxyServer()
376375

377376
go a.runLoop()
378377
}
@@ -397,16 +396,10 @@ func (a *agent) initSocketServer() {
397396
a.logger.Debug(a.hardCtx, "socket server started", slog.F("path", a.socketPath))
398397
}
399398

400-
// startBoundaryLogProxyServer starts the boundary log proxy socket server if
401-
// CODER_BOUNDARY_LOG_SOCKET is set. The socket path is configured via the
402-
// workspace template so both the agent and boundary can use the same path.
403-
func (a *agent) startBoundaryLogProxyServer() {
404-
socketPath := os.Getenv("CODER_BOUNDARY_LOG_SOCKET")
405-
if socketPath == "" {
406-
// Boundary log forwarding not configured.
407-
return
408-
}
409-
399+
// startBoundaryLogProxyServer starts the boundary log proxy socket server.
400+
// The socket path is configured via CODER_BOUNDARY_LOG_SOCKET in the workspace
401+
// template so both the agent and boundary can use the same path.
402+
func (a *agent) startBoundaryLogProxyServer(socketPath string) {
410403
proxy := boundarylogproxy.NewServer(a.logger, socketPath)
411404
if err := proxy.Start(a.hardCtx); err != nil {
412405
a.logger.Warn(a.hardCtx, "failed to start boundary log proxy", slog.Error(err))
@@ -1219,6 +1212,11 @@ func (a *agent) handleManifest(manifestOK *checkpoint) func(ctx context.Context,
12191212

12201213
// The startup script should only execute on the first run!
12211214
if oldManifest == nil {
1215+
// Start boundary log proxy if configured via CODER_BOUNDARY_LOG_SOCKET.
1216+
if socketPath := manifest.EnvironmentVariables["CODER_BOUNDARY_LOG_SOCKET"]; socketPath != "" {
1217+
a.startBoundaryLogProxyServer(socketPath)
1218+
}
1219+
12221220
a.setLifecycle(codersdk.WorkspaceAgentLifecycleStarting)
12231221

12241222
// Perform overrides early so that Git auth can work even if users

0 commit comments

Comments
 (0)