Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8a896dd

Browse files
authored
Start workspaces by shelling out to CLI (#518)
Replace the REST-API-based start flow with one that shells out to thecoder CLI.This is the JetBrains extension equivalent tocoder/vscode-coder#400.
1 parent83efd4d commit8a896dd

File tree

4 files changed

+38
-17
lines changed

4 files changed

+38
-17
lines changed

‎src/main/kotlin/com/coder/gateway/cli/CoderCLIManager.kt‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,21 @@ class CoderCLIManager(
451451
return matches
452452
}
453453

454+
/**
455+
* Start a workspace.
456+
*
457+
* Throws if the command execution fails.
458+
*/
459+
funstartWorkspace(workspaceOwner:String,workspaceName:String):String {
460+
return exec(
461+
"--global-config",
462+
coderConfigPath.toString(),
463+
"start",
464+
"--yes",
465+
workspaceOwner+"/"+workspaceName,
466+
)
467+
}
468+
454469
privatefunexec(varargargs:String):String {
455470
val stdout=
456471
ProcessExecutor()

‎src/main/kotlin/com/coder/gateway/sdk/CoderRestClient.kt‎

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -227,18 +227,6 @@ open class CoderRestClient(
227227
return templateResponse.body()!!
228228
}
229229

230-
/**
231-
* @throws [APIResponseException].
232-
*/
233-
funstartWorkspace(workspace:Workspace):WorkspaceBuild {
234-
val buildRequest=CreateWorkspaceBuildRequest(null,WorkspaceTransition.START)
235-
val buildResponse= retroRestClient.createWorkspaceBuild(workspace.id, buildRequest).execute()
236-
if (buildResponse.code()!=HttpURLConnection.HTTP_CREATED) {
237-
throwAPIResponseException("start workspace${workspace.name}", url, buildResponse)
238-
}
239-
return buildResponse.body()!!
240-
}
241-
242230
/**
243231
* @throws [APIResponseException].
244232
*/

‎src/main/kotlin/com/coder/gateway/views/CoderGatewayRecentWorkspaceConnectionsView.kt‎

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ package com.coder.gateway.views
55
importcom.coder.gateway.CoderGatewayBundle
66
importcom.coder.gateway.CoderGatewayConstants
77
importcom.coder.gateway.CoderRemoteConnectionHandle
8+
importcom.coder.gateway.cli.CoderCLIManager
9+
importcom.coder.gateway.cli.ensureCLI
810
importcom.coder.gateway.icons.CoderIcons
911
importcom.coder.gateway.models.WorkspaceAgentListModel
1012
importcom.coder.gateway.models.WorkspaceProjectIDE
@@ -73,6 +75,8 @@ data class DeploymentInfo(
7375
varitems:List<WorkspaceAgentListModel>? =null,
7476
// Null if there have not been any errors yet.
7577
varerror:String? =null,
78+
// Null if unable to ensure the CLI is downloaded.
79+
varcli:CoderCLIManager? =null,
7680
)
7781

7882
classCoderGatewayRecentWorkspaceConnectionsView(privatevalsetContentCallback: (Component)->Unit) :
@@ -232,10 +236,10 @@ class CoderGatewayRecentWorkspaceConnectionsView(private val setContentCallback:
232236
if (enableLinks) {
233237
cell(
234238
ActionLink(workspaceProjectIDE.projectPathDisplay) {
235-
withoutNull(deployment?.client, workspaceWithAgent?.workspace) {client, workspace->
239+
withoutNull(deployment?.cli, workspaceWithAgent?.workspace) {cli, workspace->
236240
CoderRemoteConnectionHandle().connect {
237241
if (listOf(WorkspaceStatus.STOPPED,WorkspaceStatus.CANCELED,WorkspaceStatus.FAILED).contains(workspace.latestBuild.status)) {
238-
client.startWorkspace(workspace)
242+
cli.startWorkspace(workspace.ownerName, workspace.name)
239243
}
240244
workspaceProjectIDE
241245
}
@@ -358,6 +362,19 @@ class CoderGatewayRecentWorkspaceConnectionsView(private val setContentCallback:
358362
throwException("Unable to make request; token was not found in CLI config.")
359363
}
360364

365+
val cli= ensureCLI(
366+
deploymentURL.toURL(),
367+
client.buildInfo().version,
368+
settings,
369+
)
370+
371+
// We only need to log the cli in if we have token-based auth.
372+
// Otherwise, we assume it is set up in the same way the plugin
373+
// is with mTLS.
374+
if (client.token!=null) {
375+
cli.login(client.token)
376+
}
377+
361378
// This is purely to populate the current user, which is
362379
// used to match workspaces that were not recorded with owner
363380
// information.
@@ -378,6 +395,7 @@ class CoderGatewayRecentWorkspaceConnectionsView(private val setContentCallback:
378395
}
379396

380397
deployment.client= client
398+
deployment.cli= cli
381399
deployment.items= items
382400
deployment.error=null
383401
}catch (e:Exception) {

‎src/main/kotlin/com/coder/gateway/views/steps/CoderWorkspacesStepView.kt‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,13 +303,13 @@ class CoderWorkspacesStepView :
303303
CoderIcons.RUN,
304304
) {
305305
overridefunactionPerformed(p0:AnActionEvent) {
306-
withoutNull(client, tableOfWorkspaces.selectedObject?.workspace) {c, workspace->
306+
withoutNull(cliManager, tableOfWorkspaces.selectedObject?.workspace) {cliManager, workspace->
307307
jobs[workspace.id]?.cancel()
308308
jobs[workspace.id]=
309309
cs.launch(ModalityState.current().asContextElement()) {
310310
withContext(Dispatchers.IO) {
311311
try {
312-
c.startWorkspace(workspace)
312+
cliManager.startWorkspace(workspace.ownerName, workspace.name)
313313
loadWorkspaces()
314314
}catch (e:Exception) {
315315
logger.error("Could not start workspace${workspace.name}", e)
@@ -659,7 +659,7 @@ class CoderWorkspacesStepView :
659659
cs.launch(ModalityState.current().asContextElement()) {
660660
while (isActive) {
661661
loadWorkspaces()
662-
delay(5000)
662+
delay(1000)
663663
}
664664
}
665665
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp