Skip to content

Commit e698d27

Browse files
committed
Add setting to ignore setup command failures
1 parent 44ab013 commit e698d27

File tree

6 files changed

+44
-6
lines changed

6 files changed

+44
-6
lines changed

src/main/kotlin/com/coder/gateway/CoderRemoteConnectionHandle.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,11 @@ class CoderRemoteConnectionHandle {
6262
// indicator.text is the text above the progress bar.
6363
indicator.text = CoderGatewayBundle.message("gateway.connector.coder.connecting.retry", attempt)
6464
}
65-
val deployInputs = parameters.deploy(indicator, Duration.ofMinutes(10), settings.setupCommand)
65+
val deployInputs = parameters.deploy(
66+
indicator,
67+
Duration.ofMinutes(10),
68+
settings.setupCommand,
69+
settings.ignoreSetupFailure)
6670
SshMultistagePanelContext(deployInputs)
6771
},
6872
retryIf = {

src/main/kotlin/com/coder/gateway/CoderSettingsConfigurable.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,14 @@ class CoderSettingsConfigurable : BoundConfigurable("Coder") {
124124
CoderGatewayBundle.message("gateway.connector.settings.setup-command.comment")
125125
)
126126
}.layout(RowLayout.PARENT_GRID)
127+
row {
128+
cell() // For alignment.
129+
checkBox(CoderGatewayBundle.message("gateway.connector.settings.ignore-setup-failure.title"))
130+
.bindSelected(state::ignoreSetupFailure)
131+
.comment(
132+
CoderGatewayBundle.message("gateway.connector.settings.ignore-setup-failure.comment")
133+
)
134+
}.layout(RowLayout.PARENT_GRID)
127135
}
128136
}
129137

src/main/kotlin/com/coder/gateway/models/WorkspaceProjectIDE.kt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,11 @@ class WorkspaceProjectIDE(
6565
* necessary. If a deployment was necessary, the IDE path on the host will
6666
* be updated to reflect the location on disk.
6767
*/
68-
suspend fun deploy(indicator: ProgressIndicator, timeout: Duration, setupCommand: String): HostDeployInputs {
68+
suspend fun deploy(
69+
indicator: ProgressIndicator,
70+
timeout: Duration,
71+
setupCommand: String,
72+
ignoreSetupFailure: Boolean): HostDeployInputs {
6973
this.lastOpened = localTimeFormatter.format(LocalDateTime.now())
7074
indicator.text = "Connecting to remote worker..."
7175
logger.info("Connecting to remote worker on $hostname")
@@ -108,7 +112,13 @@ class WorkspaceProjectIDE(
108112
// The accessor does not appear to provide a generic exec.
109113
indicator.text = "Running setup command..."
110114
logger.info("Running setup command `$setupCommand` in $path on $hostname...")
111-
exec(setupCommand)
115+
try {
116+
exec(setupCommand)
117+
} catch (ex: Exception) {
118+
if (!ignoreSetupFailure) {
119+
throw ex
120+
}
121+
}
112122
} else {
113123
logger.info("No setup command to run on $hostname")
114124
}

src/main/kotlin/com/coder/gateway/settings/CoderSettings.kt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,11 @@ open class CoderSettingsState(
6161
open var disableAutostart: Boolean = getOS() == OS.MAC,
6262
// Extra SSH config options.
6363
open var sshConfigOptions: String = "",
64-
// An external command that is ran in the directory of the IDE before
65-
// connecting to it.
64+
// An external command to run in the directory of the IDE before connecting
65+
// to it.
6666
open var setupCommand: String = "",
67+
// Whether to ignore setup command failures.
68+
open var ignoreSetupFailure: Boolean = false,
6769
)
6870

6971
/**
@@ -132,6 +134,12 @@ open class CoderSettings(
132134
val setupCommand: String
133135
get() = state.setupCommand
134136

137+
/**
138+
* Whether to ignore a failed setup command.
139+
*/
140+
val ignoreSetupFailure: Boolean
141+
get() = state.ignoreSetupFailure
142+
135143
/**
136144
* Where the specified deployment should put its data.
137145
*/

src/main/resources/messages/CoderGatewayBundle.properties

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,5 +125,11 @@ gateway.connector.settings.ssh-config-options.comment=Extra SSH config options \
125125
gateway.connector.settings.setup-command.title=Setup command:
126126
gateway.connector.settings.setup-command.comment=An external command that \
127127
will be executed on the remote in the bin directory of the IDE before \
128-
connecting to it.
128+
connecting to it. If the command exits with non-zero, the exit code, stdout, \
129+
and stderr will be displayed to the user and the connection will be aborted \
130+
unless configured to be ignored below.
131+
gateway.connector.settings.ignore-setup-failure.title=Ignore setup command failure
132+
gateway.connector.settings.ignore-setup-failure.comment=Checking this box will \
133+
cause the plugin to ignore failures (any non-zero exit code) from the setup \
134+
command and continue connecting.
129135

src/test/kotlin/com/coder/gateway/settings/CoderSettingsTest.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ internal class CoderSettingsTest {
199199
tlsAlternateHostname = "tls alt hostname",
200200
disableAutostart = true,
201201
setupCommand = "test setup",
202+
ignoreSetupFailure = true,
202203
)
203204
)
204205

@@ -211,5 +212,6 @@ internal class CoderSettingsTest {
211212
assertEquals("tls alt hostname", settings.tls.altHostname)
212213
assertEquals(true, settings.disableAutostart)
213214
assertEquals("test setup", settings.setupCommand)
215+
assertEquals(true, settings.ignoreSetupFailure)
214216
}
215217
}

0 commit comments

Comments
 (0)