- Notifications
You must be signed in to change notification settings - Fork35
Show Remote SSH Output panel on workspace start#627
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
+654 −431
Merged
Changes fromall commits
Commits
Show all changes
11 commits Select commitHold shift + click to select a range
5e0f0ce Show Remote SSH Output panel on workspace start
EhabY6e86cfe Wait for startup script when launching the workspace
EhabYd545ba5 Refactoring and cleanup of agent startup script waiting
EhabY9bf0cd7 More refactoring
EhabYe4bd57f Review comments
EhabY2bc26f9 Add agent state machine
EhabYb18dd33 Rely on the websocket to get all the logs instead of fetching the ini…
EhabYbc4ba72 Add workspace state and agent state machines
EhabYd8beda6 Review comments
EhabY5ea5ee3 Enhance the progress monitor messages, terminal title, and error mess…
EhabY5e61d40 Add changelog entry
EhabYFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
6 changes: 6 additions & 0 deletionsCHANGELOG.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
31 changes: 28 additions & 3 deletionssrc/api/coderApi.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
125 changes: 75 additions & 50 deletionssrc/api/workspace.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,17 @@ | ||
| import { type Api } from "coder/site/src/api/api"; | ||
| import { | ||
| type WorkspaceAgentLog, | ||
| type ProvisionerJobLog, | ||
| type Workspace, | ||
| type WorkspaceAgent, | ||
| } from "coder/site/src/api/typesGenerated"; | ||
| import { spawn } from "node:child_process"; | ||
| import * as vscode from "vscode"; | ||
| import { type FeatureSet } from "../featureSet"; | ||
| import { getGlobalFlags } from "../globalFlags"; | ||
| import { escapeCommandArg } from "../util"; | ||
| import { type OneWayWebSocket } from "../websocket/oneWayWebSocket"; | ||
| import { errToStr, createWorkspaceIdentifier } from "./api-helper"; | ||
| import { type CoderApi } from "./coderApi"; | ||
| @@ -36,35 +42,33 @@ export async function startWorkspaceIfStoppedOrFailed( | ||
| createWorkspaceIdentifier(workspace), | ||
| ]; | ||
| if (featureSet.buildReason) { | ||
| startArgs.push("--reason", "vscode_connection"); | ||
| } | ||
| // { shell: true } requires one shell-safe command string, otherwise we lose all escaping | ||
| const cmd = `${escapeCommandArg(binPath)} ${startArgs.join(" ")}`; | ||
| const startProcess = spawn(cmd, { shell: true }); | ||
| startProcess.stdout.on("data", (data: Buffer) => { | ||
| const lines =data | ||
| .toString() | ||
| .split(/\r*\n/) | ||
| .filter((line) => line !== ""); | ||
| for (const line of lines) { | ||
code-asher marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| writeEmitter.fire(line.toString() + "\r\n"); | ||
| } | ||
| }); | ||
| let capturedStderr = ""; | ||
| startProcess.stderr.on("data", (data: Buffer) => { | ||
| const lines =data | ||
| .toString() | ||
| .split(/\r*\n/) | ||
| .filter((line) => line !== ""); | ||
| for (const line of lines) { | ||
| writeEmitter.fire(line.toString() + "\r\n"); | ||
| capturedStderr += line.toString() + "\n"; | ||
| } | ||
| }); | ||
| startProcess.on("close", (code: number) => { | ||
| @@ -82,51 +86,72 @@ export async function startWorkspaceIfStoppedOrFailed( | ||
| } | ||
| /** | ||
| * Streams build logs to the emitter in real-time. | ||
| * Returns the websocket for lifecycle management. | ||
| */ | ||
| export async functionstreamBuildLogs( | ||
| client: CoderApi, | ||
| writeEmitter: vscode.EventEmitter<string>, | ||
| workspace: Workspace, | ||
| ): Promise<OneWayWebSocket<ProvisionerJobLog>> { | ||
| const socket = await client.watchBuildLogsByBuildId( | ||
| workspace.latest_build.id, | ||
| [], | ||
| ); | ||
| socket.addEventListener("message", (data) => { | ||
| if (data.parseError) { | ||
| writeEmitter.fire( | ||
| errToStr(data.parseError, "Failed to parse message") + "\r\n", | ||
| ); | ||
| } else { | ||
| writeEmitter.fire(data.parsedMessage.output + "\r\n"); | ||
| } | ||
| }); | ||
| socket.addEventListener("error", (error) => { | ||
| const baseUrlRaw = client.getAxiosInstance().defaults.baseURL; | ||
| writeEmitter.fire( | ||
| `Error watching workspace build logs on ${baseUrlRaw}: ${errToStr(error, "no further details")}\r\n`, | ||
| ); | ||
| }); | ||
| socket.addEventListener("close", () => { | ||
| writeEmitter.fire("Build complete\r\n"); | ||
| }); | ||
| return socket; | ||
| } | ||
| /** | ||
| * Streams agent logs to the emitter in real-time. | ||
| * Returns the websocket for lifecycle management. | ||
| */ | ||
| export async function streamAgentLogs( | ||
| client: CoderApi, | ||
| writeEmitter: vscode.EventEmitter<string>, | ||
| agent: WorkspaceAgent, | ||
| ): Promise<OneWayWebSocket<WorkspaceAgentLog[]>> { | ||
| const socket = await client.watchWorkspaceAgentLogs(agent.id, []); | ||
| socket.addEventListener("message", (data) => { | ||
| if (data.parseError) { | ||
| writeEmitter.fire( | ||
| errToStr(data.parseError, "Failed to parse message") + "\r\n", | ||
| ); | ||
| } else { | ||
| for (const log of data.parsedMessage) { | ||
| writeEmitter.fire(log.output + "\r\n"); | ||
| } | ||
| } | ||
| }); | ||
| socket.addEventListener("error", (error) => { | ||
| const baseUrlRaw = client.getAxiosInstance().defaults.baseURL; | ||
| writeEmitter.fire( | ||
| `Error watching agent logs on ${baseUrlRaw}: ${errToStr(error, "no further details")}\r\n`, | ||
| ); | ||
| }); | ||
| return socket; | ||
| } | ||
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.