Skip to content

Upgrade GW platform to latest EAP, i.e 2022.x #34

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Aug 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
uses: actions/setup-java@v3
with:
distribution: zulu
java-version: 11
java-version: 17
cache: gradle

# Set environment variables
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ jobs:
with:
ref: ${{ github.event.release.tag_name }}

# Setup Java 11 environment for the next steps
# Setup Java 17 environment for the next steps
- name: Setup Java
uses: actions/setup-java@v2
with:
distribution: zulu
java-version: 11
java-version: 17
cache: gradle

# Set environment variables
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@

## [Unreleased]
### Added
- support for Gateway 2022.2

### Changed
- Java 17 is now required to run the plugin
- adapted the code to the new SSH API provided by Gateway

## [1.0.0]
### Added
- initial scaffold for Gateway plugin
- browser based authentication on Coder environments
- REST client for Coder V2 public API
Expand Down
5 changes: 5 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ tasks {
compilerVersion.set(properties("instrumentationCompiler"))
}

// TODO - this fails with linkage error, remove when it works
buildSearchableOptions {
isEnabled = false
}

patchPluginXml {
version.set(properties("pluginVersion"))
sinceBuild.set(properties("pluginSinceBuild"))
Expand Down
14 changes: 7 additions & 7 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@
pluginGroup=com.coder.gateway
pluginName=coder-gateway
# SemVer format -> https://semver.org
pluginVersion=1.0.0
pluginVersion=2.0.0
# See https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
# for insight into build numbers and IntelliJ Platform versions.
pluginSinceBuild=213
pluginUntilBuild=221.*
pluginSinceBuild=222.3345.108
pluginUntilBuild=222.*
# IntelliJ Platform Properties -> https://github.com/JetBrains/gradle-intellij-plugin#intellij-platform-properties
# Gateway available build versions https://www.jetbrains.com/intellij-repository/snapshots and https://www.jetbrains.com/intellij-repository/releases
platformType=GW
platformVersion=221.5921.22-CUSTOM-SNAPSHOT
instrumentationCompiler=221.5921.22
platformVersion=222.3345.108-CUSTOM-SNAPSHOT
instrumentationCompiler=222.3345.108-CUSTOM-SNAPSHOT
platformDownloadSources=true
# Plugin Dependencies -> https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html
# Example: platformPlugins = com.intellij.java, com.jetbrains.php:203.4449.22
platformPlugins=
# Java language level used to compile sources and to generate the files for - Java 11 is required since 2020.3
javaVersion=11
# Java language level used to compile sources and to generate the files for - Java 17 is required since 2022.2
javaVersion=17
# Gradle Releases -> https://github.com/gradle/gradle/releases
gradleVersion=7.4
# Opt-out flag for bundling Kotlin standard library.
Expand Down
79 changes: 37 additions & 42 deletions src/main/kotlin/com/coder/gateway/CoderGatewayConnectionProvider.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,34 @@ package com.coder.gateway

import com.coder.gateway.models.RecentWorkspaceConnection
import com.coder.gateway.services.CoderRecentWorkspaceConnectionsService
import com.coder.gateway.views.CoderGatewayConnectionComponent
import com.intellij.openapi.components.service
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.rd.util.launchUnderBackgroundProgress
import com.intellij.remote.AuthType
import com.intellij.remote.RemoteCredentialsHolder
import com.intellij.ssh.config.unified.SshConfig
import com.intellij.ssh.config.unified.SshConfigManager
import com.jetbrains.gateway.api.ConnectionRequestor
import com.jetbrains.gateway.api.GatewayConnectionHandle
import com.jetbrains.gateway.api.GatewayConnectionProvider
import com.jetbrains.gateway.ssh.HighLevelHostAccessor
import com.jetbrains.gateway.ssh.HostDeployInputs
import com.jetbrains.gateway.ssh.IdeInfo
import com.jetbrains.gateway.ssh.IntelliJPlatformProduct
import com.jetbrains.gateway.ssh.SshCommandsExecutor
import com.jetbrains.gateway.ssh.SshDeployFlowUtil
import com.jetbrains.gateway.ssh.SshDownloadMethod
import com.jetbrains.gateway.ssh.SshMultistagePanelContext
import com.jetbrains.gateway.ssh.deploy.DeployTargetInfo.DeployWithDownload
import com.jetbrains.rd.util.lifetime.LifetimeDefinition
import kotlinx.coroutines.launch
import java.net.URI
import java.time.Duration
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
import javax.swing.JComponent

class CoderGatewayConnectionProvider : GatewayConnectionProvider {
private val recentConnectionsService = service<CoderRecentWorkspaceConnectionsService>()
private val sshConfigService = service<SshConfigManager>()

private val connections = mutableSetOf<CoderConnectionMetadata>()
private val localTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MMM-dd HH:mm")

Expand All @@ -46,62 +49,54 @@ class CoderGatewayConnectionProvider : GatewayConnectionProvider {
logger.warn("There is already a connection started on ${connection.workspaceHostname}")
return null
}
val clientLifetime = LifetimeDefinition()

val credentials = RemoteCredentialsHolder().apply {
setHost(coderWorkspaceHostname)
userName = "coder"
authType = AuthType.OPEN_SSH
}

val sshConfiguration = SshConfig(true).apply {
setHost(coderWorkspaceHostname)
setUsername("coder")
port = 22
authType = AuthType.OPEN_SSH
}

val ideConfig = IdeInfo(
product = IntelliJPlatformProduct.fromProductCode(ideProductCode)!!,
buildNumber = ideBuildNumber
)

val clientLifetime = LifetimeDefinition()
clientLifetime.launchUnderBackgroundProgress("Coder Gateway Deploy", canBeCancelled = true, isIndeterminate = true, project = null) {
val context = SshMultistagePanelContext().apply {
deploy = true
sshConfig = sshConfiguration
remoteProjectPath = projectPath
remoteCommandsExecutor = SshCommandsExecutor.Companion.create(credentials)
downloadMethod = SshDownloadMethod.CustomizedLink
customDownloadLink = ideDownloadLink
ide = ideConfig
}
val context = SshMultistagePanelContext(
HostDeployInputs.FullySpecified(
remoteProjectPath = projectPath,
deployTarget = DeployWithDownload(
URI(ideDownloadLink),
null,
IdeInfo(
product = IntelliJPlatformProduct.fromProductCode(ideProductCode)!!,
buildNumber = ideBuildNumber
)
),
remoteInfo = HostDeployInputs.WithDeployedWorker(
HighLevelHostAccessor.create(
RemoteCredentialsHolder().apply {
setHost(coderWorkspaceHostname)
userName = "coder"
port = 22
authType = AuthType.OPEN_SSH
},
true
),
HostDeployInputs.WithHostInfo(sshConfiguration)
)
)
)
launch {
@Suppress("UnstableApiUsage")
SshDeployFlowUtil.fullDeployCycle(
clientLifetime,
context,
Duration.ofMinutes(10)
@Suppress("UnstableApiUsage") SshDeployFlowUtil.fullDeployCycle(
clientLifetime, context, Duration.ofMinutes(10)
)
}
}

recentConnectionsService.addRecentConnection(
RecentWorkspaceConnection(
coderWorkspaceHostname,
projectPath,
localTimeFormatter.format(LocalDateTime.now()),
ideProductCode,
ideBuildNumber,
ideDownloadLink,
webTerminalLink,
coderWorkspaceHostname, projectPath, localTimeFormatter.format(LocalDateTime.now()), ideProductCode, ideBuildNumber, ideDownloadLink, webTerminalLink
)
)

return object : GatewayConnectionHandle(clientLifetime) {
override fun createComponent(): JComponent {
return CoderGatewayConnectionComponent(clientLifetime, coderWorkspaceHostname)
}

override fun getTitle(): String {
return "Connection to Coder Workspaces"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ import com.jetbrains.gateway.ssh.CachingProductsJsonWrapper
import com.jetbrains.gateway.ssh.DeployTargetOS
import com.jetbrains.gateway.ssh.DeployTargetOS.OSArch
import com.jetbrains.gateway.ssh.DeployTargetOS.OSKind
import com.jetbrains.gateway.ssh.HighLevelHostAccessor
import com.jetbrains.gateway.ssh.IdeStatus
import com.jetbrains.gateway.ssh.IdeWithStatus
import com.jetbrains.gateway.ssh.IntelliJPlatformProduct
import com.jetbrains.gateway.ssh.guessOs
import com.jetbrains.gateway.ssh.deploy.guessOs
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.cancel
Expand Down Expand Up @@ -116,11 +117,15 @@ class CoderLocateRemoteProjectStepView(private val disableNextAction: () -> Unit
logger.info("Retrieving available IDE's for ${selectedWorkspace.name} workspace...")
val workspaceOS = if (selectedWorkspace.agentOS != null && selectedWorkspace.agentArch != null) withContext(Dispatchers.IO) { toDeployedOS(selectedWorkspace.agentOS, selectedWorkspace.agentArch) } else withContext(Dispatchers.IO) {
try {
RemoteCredentialsHolder().apply {
val credentialsHolder = RemoteCredentialsHolder().apply {
setHost("coder.${selectedWorkspace.name}")
userName = "coder"
authType = AuthType.OPEN_SSH
}.guessOs
}
HighLevelHostAccessor.create(
credentialsHolder,
true
).hostCommandExecutor.guessOs()
} catch (e: Exception) {
logger.error("Could not resolve any IDE for workspace ${selectedWorkspace.name}. Reason: $e")
null
Expand All @@ -141,7 +146,7 @@ class CoderLocateRemoteProjectStepView(private val disableNextAction: () -> Unit
IntelliJPlatformProduct.values()
.filter { it.showInGateway }
.flatMap { CachingProductsJsonWrapper.getAvailableIdes(it, workspaceOS) }
.map { ide -> IdeWithStatus(ide.product, ide.buildNumber, IdeStatus.DOWNLOAD, ide.downloadLink, ide.presentableVersion) }
.map { ide -> IdeWithStatus(ide.product, ide.buildNumber, IdeStatus.DOWNLOAD, ide.download, null, ide.presentableVersion) }
}

if (idesWithStatus.isEmpty()) {
Expand All @@ -158,20 +163,20 @@ class CoderLocateRemoteProjectStepView(private val disableNextAction: () -> Unit
return when (os) {
OS.LINUX -> when (arch) {
Arch.AMD64 -> DeployTargetOS(OSKind.Linux, OSArch.X86_64)
Arch.ARM64 -> DeployTargetOS(OSKind.Linux, OSArch.Aarch64)
Arch.ARMV7 -> DeployTargetOS(OSKind.Linux, OSArch.Unknown)
Arch.ARM64 -> DeployTargetOS(OSKind.Linux, OSArch.ARM_64)
Arch.ARMV7 -> DeployTargetOS(OSKind.Linux, OSArch.UNKNOWN)
}

OS.WINDOWS -> when (arch) {
Arch.AMD64 -> DeployTargetOS(OSKind.Windows, OSArch.X86_64)
Arch.ARM64 -> DeployTargetOS(OSKind.Windows, OSArch.Aarch64)
Arch.ARMV7 -> DeployTargetOS(OSKind.Windows, OSArch.Unknown)
Arch.ARM64 -> DeployTargetOS(OSKind.Windows, OSArch.ARM_64)
Arch.ARMV7 -> DeployTargetOS(OSKind.Windows, OSArch.UNKNOWN)
}

OS.MAC -> when (arch) {
Arch.AMD64 -> DeployTargetOS(OSKind.MacOs, OSArch.X86_64)
Arch.ARM64 -> DeployTargetOS(OSKind.MacOs, OSArch.Aarch64)
Arch.ARMV7 -> DeployTargetOS(OSKind.MacOs, OSArch.Unknown)
Arch.ARM64 -> DeployTargetOS(OSKind.MacOs, OSArch.ARM_64)
Arch.ARMV7 -> DeployTargetOS(OSKind.MacOs, OSArch.UNKNOWN)
}
}
}
Expand All @@ -187,7 +192,7 @@ class CoderLocateRemoteProjectStepView(private val disableNextAction: () -> Unit
"project_path" to tfProject.text,
"ide_product_code" to selectedIDE.product.productCode,
"ide_build_number" to selectedIDE.buildNumber,
"ide_download_link" to selectedIDE.source,
"ide_download_link" to selectedIDE.download!!.link,
"web_terminal_link" to "${terminalLink.url}"
)
)
Expand Down