mirror of https://github.com/harness/drone.git
feat: [CDE-576]: intellij code improvements (#3237)
* feat: [CDE-576]: fix lint * feat: [CDE-576]: intellij code improvementsBT-10437
parent
083a24d8eb
commit
9989a5a589
app/gitspace
|
@ -195,7 +195,7 @@ func ExtractLifecycleCommands(actionType PostAction, devcontainerConfig types.De
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ExtractIDECustomizations(
|
func AddIDECustomizationsArg(
|
||||||
ideService ide.IDE,
|
ideService ide.IDE,
|
||||||
devcontainerConfig types.DevcontainerConfig,
|
devcontainerConfig types.DevcontainerConfig,
|
||||||
args map[gitspaceTypes.IDEArg]interface{},
|
args map[gitspaceTypes.IDEArg]interface{},
|
||||||
|
@ -208,7 +208,7 @@ func ExtractIDECustomizations(
|
||||||
return args
|
return args
|
||||||
}
|
}
|
||||||
|
|
||||||
func ExtractIDEDownloadURL(
|
func AddIDEDownloadURLArg(
|
||||||
ideService ide.IDE,
|
ideService ide.IDE,
|
||||||
args map[gitspaceTypes.IDEArg]interface{},
|
args map[gitspaceTypes.IDEArg]interface{},
|
||||||
) map[gitspaceTypes.IDEArg]interface{} {
|
) map[gitspaceTypes.IDEArg]interface{} {
|
||||||
|
@ -222,7 +222,7 @@ func ExtractIDEDownloadURL(
|
||||||
return args
|
return args
|
||||||
}
|
}
|
||||||
|
|
||||||
func ExtractIDEDirName(
|
func AddIDEDirNameArg(
|
||||||
ideService ide.IDE,
|
ideService ide.IDE,
|
||||||
args map[gitspaceTypes.IDEArg]interface{},
|
args map[gitspaceTypes.IDEArg]interface{},
|
||||||
) map[gitspaceTypes.IDEArg]interface{} {
|
) map[gitspaceTypes.IDEArg]interface{} {
|
||||||
|
|
|
@ -561,10 +561,10 @@ func (e *EmbeddedDockerOrchestrator) buildSetupSteps(
|
||||||
) error {
|
) error {
|
||||||
// Run IDE setup
|
// Run IDE setup
|
||||||
args := make(map[gitspaceTypes.IDEArg]interface{})
|
args := make(map[gitspaceTypes.IDEArg]interface{})
|
||||||
args = ExtractIDECustomizations(ideService, resolvedRepoDetails.DevcontainerConfig, args)
|
args = AddIDECustomizationsArg(ideService, resolvedRepoDetails.DevcontainerConfig, args)
|
||||||
args[gitspaceTypes.IDERepoNameArg] = resolvedRepoDetails.RepoName
|
args[gitspaceTypes.IDERepoNameArg] = resolvedRepoDetails.RepoName
|
||||||
args = ExtractIDEDownloadURL(ideService, args)
|
args = AddIDEDownloadURLArg(ideService, args)
|
||||||
args = ExtractIDEDirName(ideService, args)
|
args = AddIDEDirNameArg(ideService, args)
|
||||||
|
|
||||||
return ideService.Setup(ctx, exec, args, gitspaceLogger)
|
return ideService.Setup(ctx, exec, args, gitspaceLogger)
|
||||||
},
|
},
|
||||||
|
@ -579,7 +579,7 @@ func (e *EmbeddedDockerOrchestrator) buildSetupSteps(
|
||||||
) error {
|
) error {
|
||||||
args := make(map[gitspaceTypes.IDEArg]interface{})
|
args := make(map[gitspaceTypes.IDEArg]interface{})
|
||||||
args[gitspaceTypes.IDERepoNameArg] = resolvedRepoDetails.RepoName
|
args[gitspaceTypes.IDERepoNameArg] = resolvedRepoDetails.RepoName
|
||||||
args = ExtractIDEDirName(ideService, args)
|
args = AddIDEDirNameArg(ideService, args)
|
||||||
return ideService.Run(ctx, exec, args, gitspaceLogger)
|
return ideService.Run(ctx, exec, args, gitspaceLogger)
|
||||||
},
|
},
|
||||||
StopOnFailure: true,
|
StopOnFailure: true,
|
||||||
|
|
|
@ -16,6 +16,7 @@ package ide
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/harness/gitness/app/gitspace/orchestrator/devcontainer"
|
"github.com/harness/gitness/app/gitspace/orchestrator/devcontainer"
|
||||||
gitspaceTypes "github.com/harness/gitness/app/gitspace/types"
|
gitspaceTypes "github.com/harness/gitness/app/gitspace/types"
|
||||||
|
@ -51,4 +52,12 @@ type IDE interface {
|
||||||
|
|
||||||
// Type provides the IDE type to which the service belongs.
|
// Type provides the IDE type to which the service belongs.
|
||||||
Type() enum.IDEType
|
Type() enum.IDEType
|
||||||
|
|
||||||
|
// GenerateURL returns the url to redirect user to ide from gitspace
|
||||||
|
GenerateURL(absoluteRepoPath, host, port, user string) string
|
||||||
|
}
|
||||||
|
|
||||||
|
func getHomePath(absoluteRepoPath string) string {
|
||||||
|
pathList := strings.Split(absoluteRepoPath, "/")
|
||||||
|
return strings.Join(pathList[:len(pathList)-1], "/")
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,8 @@ package ide
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/url"
|
||||||
|
"path"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/harness/gitness/app/gitspace/orchestrator/devcontainer"
|
"github.com/harness/gitness/app/gitspace/orchestrator/devcontainer"
|
||||||
|
@ -31,6 +33,8 @@ var _ IDE = (*Intellij)(nil)
|
||||||
const (
|
const (
|
||||||
templateSetupIntellij string = "setup_intellij.sh"
|
templateSetupIntellij string = "setup_intellij.sh"
|
||||||
templateRunRemoteIDEIntellij string = "run_intellij.sh"
|
templateRunRemoteIDEIntellij string = "run_intellij.sh"
|
||||||
|
|
||||||
|
intellijURLScheme string = "jetbrains-gateway"
|
||||||
)
|
)
|
||||||
|
|
||||||
type IntellijConfig struct {
|
type IntellijConfig struct {
|
||||||
|
@ -234,6 +238,28 @@ func (ij *Intellij) Port() *types.GitspacePort {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GenerateURL returns the url to redirect user to ide(here to jetbrains gateway application).
|
||||||
|
func (ij *Intellij) GenerateURL(absoluteRepoPath, host, port, user string) string {
|
||||||
|
homePath := getHomePath(absoluteRepoPath)
|
||||||
|
idePath := path.Join(homePath, ".cache", "JetBrains", "RemoteDev", "dist", "intellij")
|
||||||
|
ideURL := url.URL{
|
||||||
|
Scheme: intellijURLScheme,
|
||||||
|
Host: "", // Empty since we include the host and port in the path
|
||||||
|
Path: "connect",
|
||||||
|
Fragment: fmt.Sprintf("idePath=%s&projectPath=%s&host=%s&port=%s&user=%s&type=%s&deploy=%s",
|
||||||
|
idePath,
|
||||||
|
absoluteRepoPath,
|
||||||
|
host,
|
||||||
|
port,
|
||||||
|
user,
|
||||||
|
"ssh",
|
||||||
|
"false",
|
||||||
|
),
|
||||||
|
}
|
||||||
|
|
||||||
|
return ideURL.String()
|
||||||
|
}
|
||||||
|
|
||||||
func (ij *Intellij) Type() enum.IDEType {
|
func (ij *Intellij) Type() enum.IDEType {
|
||||||
return enum.IDETypeIntellij
|
return enum.IDETypeIntellij
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,10 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/url"
|
||||||
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/harness/gitness/app/gitspace/orchestrator/devcontainer"
|
"github.com/harness/gitness/app/gitspace/orchestrator/devcontainer"
|
||||||
"github.com/harness/gitness/app/gitspace/orchestrator/utils"
|
"github.com/harness/gitness/app/gitspace/orchestrator/utils"
|
||||||
|
@ -33,6 +36,8 @@ var _ IDE = (*VSCode)(nil)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
templateSetupVSCodeExtensions string = "setup_vscode_extensions.sh"
|
templateSetupVSCodeExtensions string = "setup_vscode_extensions.sh"
|
||||||
|
|
||||||
|
vSCodeURLScheme string = "vscode-remote"
|
||||||
)
|
)
|
||||||
|
|
||||||
type VSCodeConfig struct {
|
type VSCodeConfig struct {
|
||||||
|
@ -223,3 +228,20 @@ func (v *VSCode) handleVSCodeCustomization(
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GenerateURL returns the url to redirect user to ide(here to vscode application).
|
||||||
|
func (v *VSCode) GenerateURL(absoluteRepoPath, host, port, user string) string {
|
||||||
|
relativeRepoPath := strings.TrimPrefix(absoluteRepoPath, "/")
|
||||||
|
ideURL := url.URL{
|
||||||
|
Scheme: vSCodeURLScheme,
|
||||||
|
Host: "", // Empty since we include the host and port in the path
|
||||||
|
Path: fmt.Sprintf(
|
||||||
|
"ssh-remote+%s@%s:%s",
|
||||||
|
user,
|
||||||
|
host,
|
||||||
|
filepath.Join(port, relativeRepoPath),
|
||||||
|
),
|
||||||
|
}
|
||||||
|
|
||||||
|
return ideURL.String()
|
||||||
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ import (
|
||||||
"embed"
|
"embed"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"net/url"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -52,11 +53,15 @@ type VSCodeWebConfig struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type VSCodeWeb struct {
|
type VSCodeWeb struct {
|
||||||
config *VSCodeWebConfig
|
urlScheme string
|
||||||
|
config *VSCodeWebConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewVsCodeWebService(config *VSCodeWebConfig) *VSCodeWeb {
|
func NewVsCodeWebService(config *VSCodeWebConfig, urlScheme string) *VSCodeWeb {
|
||||||
return &VSCodeWeb{config: config}
|
return &VSCodeWeb{
|
||||||
|
urlScheme: urlScheme,
|
||||||
|
config: config,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setup runs the installScript which downloads the required version of the code-server binary.
|
// Setup runs the installScript which downloads the required version of the code-server binary.
|
||||||
|
@ -267,3 +272,15 @@ func embedToTar(tarWriter *tar.Writer, baseDir, prefix string) error {
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GenerateURL returns the url to redirect user to ide(here to another ta).
|
||||||
|
func (v *VSCodeWeb) GenerateURL(absoluteRepoPath, host, port, _ string) string {
|
||||||
|
relativeRepoPath := strings.TrimPrefix(absoluteRepoPath, "/")
|
||||||
|
ideURL := url.URL{
|
||||||
|
Scheme: v.urlScheme,
|
||||||
|
Host: host + ":" + port,
|
||||||
|
RawQuery: filepath.Join("folder=", relativeRepoPath),
|
||||||
|
}
|
||||||
|
|
||||||
|
return ideURL.String()
|
||||||
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ var WireSet = wire.NewSet(
|
||||||
)
|
)
|
||||||
|
|
||||||
func ProvideVSCodeWebService(config *VSCodeWebConfig) *VSCodeWeb {
|
func ProvideVSCodeWebService(config *VSCodeWebConfig) *VSCodeWeb {
|
||||||
return NewVsCodeWebService(config)
|
return NewVsCodeWebService(config, "http")
|
||||||
}
|
}
|
||||||
|
|
||||||
func ProvideVSCodeService(config *VSCodeConfig) *VSCode {
|
func ProvideVSCodeService(config *VSCodeConfig) *VSCode {
|
||||||
|
|
|
@ -17,17 +17,13 @@ package orchestrator
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/url"
|
|
||||||
"path"
|
|
||||||
"path/filepath"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/harness/gitness/app/gitspace/orchestrator/container"
|
"github.com/harness/gitness/app/gitspace/orchestrator/container"
|
||||||
|
"github.com/harness/gitness/app/gitspace/orchestrator/ide"
|
||||||
"github.com/harness/gitness/app/gitspace/secret"
|
"github.com/harness/gitness/app/gitspace/secret"
|
||||||
secretenum "github.com/harness/gitness/app/gitspace/secret/enum"
|
secretenum "github.com/harness/gitness/app/gitspace/secret/enum"
|
||||||
gitspaceTypes "github.com/harness/gitness/app/gitspace/types"
|
|
||||||
"github.com/harness/gitness/app/paths"
|
"github.com/harness/gitness/app/paths"
|
||||||
"github.com/harness/gitness/types"
|
"github.com/harness/gitness/types"
|
||||||
"github.com/harness/gitness/types/enum"
|
"github.com/harness/gitness/types/enum"
|
||||||
|
@ -85,8 +81,6 @@ func (o Orchestrator) ResumeStartGitspace(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
idePort := ideSvc.Port()
|
|
||||||
|
|
||||||
err = o.infraProvisioner.PostInfraEventComplete(ctx, gitspaceConfig, provisionedInfra, enum.InfraEventProvision)
|
err = o.infraProvisioner.PostInfraEventComplete(ctx, gitspaceConfig, provisionedInfra, enum.InfraEventProvision)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
o.emitGitspaceEvent(ctx, gitspaceConfig, enum.GitspaceEventTypeInfraProvisioningFailed)
|
o.emitGitspaceEvent(ctx, gitspaceConfig, enum.GitspaceEventTypeInfraProvisioningFailed)
|
||||||
|
@ -172,7 +166,7 @@ func (o Orchestrator) ResumeStartGitspace(
|
||||||
|
|
||||||
o.emitGitspaceEvent(ctx, gitspaceConfig, enum.GitspaceEventTypeAgentGitspaceCreationCompleted)
|
o.emitGitspaceEvent(ctx, gitspaceConfig, enum.GitspaceEventTypeAgentGitspaceCreationCompleted)
|
||||||
|
|
||||||
ideURLString := generateIDEURL(provisionedInfra, idePort, startResponse, gitspaceConfig)
|
ideURLString := generateIDEURL(provisionedInfra, ideSvc, startResponse)
|
||||||
gitspaceInstance.URL = &ideURLString
|
gitspaceInstance.URL = &ideURLString
|
||||||
|
|
||||||
now := time.Now().UnixMilli()
|
now := time.Now().UnixMilli()
|
||||||
|
@ -188,12 +182,10 @@ func (o Orchestrator) ResumeStartGitspace(
|
||||||
|
|
||||||
func generateIDEURL(
|
func generateIDEURL(
|
||||||
provisionedInfra types.Infrastructure,
|
provisionedInfra types.Infrastructure,
|
||||||
idePort *types.GitspacePort,
|
ideSvc ide.IDE,
|
||||||
startResponse *container.StartResponse,
|
startResponse *container.StartResponse,
|
||||||
gitspaceConfig types.GitspaceConfig,
|
|
||||||
) string {
|
) string {
|
||||||
var ideURL url.URL
|
idePort := ideSvc.Port()
|
||||||
|
|
||||||
var forwardedPort string
|
var forwardedPort string
|
||||||
|
|
||||||
if provisionedInfra.GitspacePortMappings[idePort.Port].PublishedPort == 0 {
|
if provisionedInfra.GitspacePortMappings[idePort.Port].PublishedPort == 0 {
|
||||||
|
@ -202,59 +194,12 @@ func generateIDEURL(
|
||||||
forwardedPort = strconv.Itoa(provisionedInfra.GitspacePortMappings[idePort.Port].ForwardedPort)
|
forwardedPort = strconv.Itoa(provisionedInfra.GitspacePortMappings[idePort.Port].ForwardedPort)
|
||||||
}
|
}
|
||||||
|
|
||||||
scheme := provisionedInfra.GitspaceScheme
|
|
||||||
host := provisionedInfra.GitspaceHost
|
host := provisionedInfra.GitspaceHost
|
||||||
if provisionedInfra.ProxyGitspaceHost != "" {
|
if provisionedInfra.ProxyGitspaceHost != "" {
|
||||||
host = provisionedInfra.ProxyGitspaceHost
|
host = provisionedInfra.ProxyGitspaceHost
|
||||||
}
|
}
|
||||||
|
|
||||||
relativeRepoPath := strings.TrimPrefix(startResponse.AbsoluteRepoPath, "/")
|
return ideSvc.GenerateURL(startResponse.AbsoluteRepoPath, host, forwardedPort, startResponse.RemoteUser)
|
||||||
|
|
||||||
switch gitspaceConfig.IDE {
|
|
||||||
case enum.IDETypeVSCodeWeb:
|
|
||||||
ideURL = url.URL{
|
|
||||||
Scheme: scheme,
|
|
||||||
Host: host + ":" + forwardedPort,
|
|
||||||
RawQuery: filepath.Join("folder=", relativeRepoPath),
|
|
||||||
}
|
|
||||||
case enum.IDETypeVSCode:
|
|
||||||
// TODO: the following userID is hard coded and should be changed.
|
|
||||||
ideURL = url.URL{
|
|
||||||
Scheme: gitspaceTypes.VSCodeURLScheme,
|
|
||||||
Host: "", // Empty since we include the host and port in the path
|
|
||||||
Path: fmt.Sprintf(
|
|
||||||
"ssh-remote+%s@%s:%s",
|
|
||||||
startResponse.RemoteUser,
|
|
||||||
host,
|
|
||||||
filepath.Join(forwardedPort, relativeRepoPath),
|
|
||||||
),
|
|
||||||
}
|
|
||||||
case enum.IDETypeIntellij:
|
|
||||||
homePath := getHomePath(startResponse.AbsoluteRepoPath)
|
|
||||||
idePath := path.Join(homePath, ".cache", "JetBrains", "RemoteDev", "dist", "intellij")
|
|
||||||
ideURL = url.URL{
|
|
||||||
Scheme: gitspaceTypes.IntellijURLScheme,
|
|
||||||
Host: "", // Empty since we include the host and port in the path
|
|
||||||
Path: "connect",
|
|
||||||
Fragment: fmt.Sprintf("idePath=%s&projectPath=%s&host=%s&port=%s&user=%s&type=%s&deploy=%s",
|
|
||||||
idePath,
|
|
||||||
startResponse.AbsoluteRepoPath,
|
|
||||||
host,
|
|
||||||
forwardedPort,
|
|
||||||
startResponse.RemoteUser,
|
|
||||||
"ssh",
|
|
||||||
"false",
|
|
||||||
),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ideURLString := ideURL.String()
|
|
||||||
return ideURLString
|
|
||||||
}
|
|
||||||
|
|
||||||
func getHomePath(absoluteRepoPath string) string {
|
|
||||||
pathList := strings.Split(absoluteRepoPath, "/")
|
|
||||||
return strings.Join(pathList[:len(pathList)-1], "/")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o Orchestrator) getSecretResolver(accessType enum.GitspaceAccessType) (secret.Resolver, error) {
|
func (o Orchestrator) getSecretResolver(accessType enum.GitspaceAccessType) (secret.Resolver, error) {
|
||||||
|
|
|
@ -28,9 +28,6 @@ const (
|
||||||
IDERepoNameArg IDEArg = "IDE_REPO_NAME"
|
IDERepoNameArg IDEArg = "IDE_REPO_NAME"
|
||||||
IDEDownloadURLArg IDEArg = "IDE_DOWNLOAD_URL"
|
IDEDownloadURLArg IDEArg = "IDE_DOWNLOAD_URL"
|
||||||
IDEDIRNameArg IDEArg = "IDE_DIR_NAME"
|
IDEDIRNameArg IDEArg = "IDE_DIR_NAME"
|
||||||
|
|
||||||
VSCodeURLScheme string = "vscode-remote"
|
|
||||||
IntellijURLScheme string = "jetbrains-gateway"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type GitspaceLogger interface {
|
type GitspaceLogger interface {
|
||||||
|
|
Loading…
Reference in New Issue