mirror of
https://github.com/harness/drone.git
synced 2025-05-06 15:21:49 +08:00
feat: [CDE-227]: Change SSH port for VSCode. (#2445)
* feat: [CDE-227]: Change SSH port for VSCode.
This commit is contained in:
parent
e400a6df44
commit
008aa5c17a
@ -1,5 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
|
|
||||||
echo "Running SSH Server"
|
|
||||||
|
|
||||||
/usr/sbin/sshd
|
|
@ -17,27 +17,29 @@ package ide
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"github.com/harness/gitness/app/gitspace/orchestrator/devcontainer"
|
"github.com/harness/gitness/app/gitspace/orchestrator/devcontainer"
|
||||||
"github.com/harness/gitness/app/gitspace/orchestrator/template"
|
"github.com/harness/gitness/app/gitspace/orchestrator/template"
|
||||||
"github.com/harness/gitness/types"
|
"github.com/harness/gitness/types"
|
||||||
"github.com/harness/gitness/types/enum"
|
"github.com/harness/gitness/types/enum"
|
||||||
|
|
||||||
_ "embed"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ IDE = (*VSCode)(nil)
|
var _ IDE = (*VSCode)(nil)
|
||||||
|
|
||||||
//go:embed script/run_ssh_server.sh
|
|
||||||
var runSSHScript string
|
|
||||||
|
|
||||||
const sshPort int = 22
|
|
||||||
const templateSetupSSHServer string = "setup_ssh_server.sh"
|
const templateSetupSSHServer string = "setup_ssh_server.sh"
|
||||||
|
const templateRunSSHServer string = "run_ssh_server.sh"
|
||||||
|
|
||||||
type VSCode struct{}
|
type VSCodeConfig struct {
|
||||||
|
Port int
|
||||||
|
}
|
||||||
|
|
||||||
func NewVsCodeService() *VSCode {
|
type VSCode struct {
|
||||||
return &VSCode{}
|
config *VSCodeConfig
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewVsCodeService(config *VSCodeConfig) *VSCode {
|
||||||
|
return &VSCode{config: config}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setup installs the SSH server inside the container.
|
// Setup installs the SSH server inside the container.
|
||||||
@ -73,6 +75,15 @@ func (v *VSCode) Setup(
|
|||||||
func (v *VSCode) Run(ctx context.Context, devcontainer *devcontainer.Exec) ([]byte, error) {
|
func (v *VSCode) Run(ctx context.Context, devcontainer *devcontainer.Exec) ([]byte, error) {
|
||||||
var output = ""
|
var output = ""
|
||||||
|
|
||||||
|
runSSHScript, err := template.GenerateScriptFromTemplate(
|
||||||
|
templateRunSSHServer, &template.RunSSHServerPayload{
|
||||||
|
Port: strconv.Itoa(v.config.Port),
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf(
|
||||||
|
"failed to generate scipt to run ssh server from template %s: %w", templateRunSSHServer, err)
|
||||||
|
}
|
||||||
|
|
||||||
execOutput, err := devcontainer.ExecuteCommand(ctx, runSSHScript, false, rootUser)
|
execOutput, err := devcontainer.ExecuteCommand(ctx, runSSHScript, false, rootUser)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to run SSH serverr: %w", err)
|
return nil, fmt.Errorf("failed to run SSH serverr: %w", err)
|
||||||
@ -85,7 +96,7 @@ func (v *VSCode) Run(ctx context.Context, devcontainer *devcontainer.Exec) ([]by
|
|||||||
|
|
||||||
// Port returns the port on which the ssh-server is listening.
|
// Port returns the port on which the ssh-server is listening.
|
||||||
func (v *VSCode) Port() int {
|
func (v *VSCode) Port() int {
|
||||||
return sshPort
|
return v.config.Port
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *VSCode) Type() enum.IDEType {
|
func (v *VSCode) Type() enum.IDEType {
|
||||||
|
@ -27,6 +27,6 @@ func ProvideVSCodeWebService(config *VSCodeWebConfig) *VSCodeWeb {
|
|||||||
return NewVsCodeWebService(config)
|
return NewVsCodeWebService(config)
|
||||||
}
|
}
|
||||||
|
|
||||||
func ProvideVSCodeService() *VSCode {
|
func ProvideVSCodeService(config *VSCodeConfig) *VSCode {
|
||||||
return NewVsCodeService()
|
return NewVsCodeService(config)
|
||||||
}
|
}
|
||||||
|
@ -56,6 +56,10 @@ type SetupSSHServerPayload struct {
|
|||||||
WorkingDirectory string
|
WorkingDirectory string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type RunSSHServerPayload struct {
|
||||||
|
Port string
|
||||||
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
err := LoadTemplates()
|
err := LoadTemplates()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -0,0 +1,15 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
SSH_PORT={{ .Port }}
|
||||||
|
|
||||||
|
config_file='/etc/ssh/sshd_config'
|
||||||
|
|
||||||
|
# Change the default SSH port
|
||||||
|
sed -i "s/^#Port 22/Port $SSH_PORT/" $config_file
|
||||||
|
if ! grep -q "^Port $SSH_PORT" $config_file; then
|
||||||
|
echo "Port $SSH_PORT" >> $config_file
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Running SSH Server on port $SSH_PORT"
|
||||||
|
|
||||||
|
/usr/sbin/sshd
|
@ -406,6 +406,13 @@ func ProvideIDEVSCodeWebConfig(config *types.Config) *ide.VSCodeWebConfig {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ProvideIDEVSCodeConfig loads the VSCode IDE config from the main config.
|
||||||
|
func ProvideIDEVSCodeConfig(config *types.Config) *ide.VSCodeConfig {
|
||||||
|
return &ide.VSCodeConfig{
|
||||||
|
Port: config.IDE.VSCode.Port,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ProvideGitspaceOrchestratorConfig loads the Gitspace orchestrator config from the main config.
|
// ProvideGitspaceOrchestratorConfig loads the Gitspace orchestrator config from the main config.
|
||||||
func ProvideGitspaceOrchestratorConfig(config *types.Config) *orchestrator.Config {
|
func ProvideGitspaceOrchestratorConfig(config *types.Config) *orchestrator.Config {
|
||||||
return &orchestrator.Config{
|
return &orchestrator.Config{
|
||||||
|
@ -235,6 +235,7 @@ func initSystem(ctx context.Context, config *types.Config) (*cliserver.System, e
|
|||||||
gitspaceinfraevents.WireSet,
|
gitspaceinfraevents.WireSet,
|
||||||
gitspaceservice.WireSet,
|
gitspaceservice.WireSet,
|
||||||
cliserver.ProvideGitspaceInfraProvisionerConfig,
|
cliserver.ProvideGitspaceInfraProvisionerConfig,
|
||||||
|
cliserver.ProvideIDEVSCodeConfig,
|
||||||
)
|
)
|
||||||
return &cliserver.System{}, nil
|
return &cliserver.System{}, nil
|
||||||
}
|
}
|
||||||
|
@ -361,7 +361,8 @@ func initSystem(ctx context.Context, config *types.Config) (*server.System, erro
|
|||||||
statefulLogger := logutil.ProvideStatefulLogger(logStream)
|
statefulLogger := logutil.ProvideStatefulLogger(logStream)
|
||||||
containerOrchestrator := container.ProvideEmbeddedDockerOrchestrator(dockerClientFactory, statefulLogger)
|
containerOrchestrator := container.ProvideEmbeddedDockerOrchestrator(dockerClientFactory, statefulLogger)
|
||||||
orchestratorConfig := server.ProvideGitspaceOrchestratorConfig(config)
|
orchestratorConfig := server.ProvideGitspaceOrchestratorConfig(config)
|
||||||
vsCode := ide.ProvideVSCodeService()
|
vsCodeConfig := server.ProvideIDEVSCodeConfig(config)
|
||||||
|
vsCode := ide.ProvideVSCodeService(vsCodeConfig)
|
||||||
vsCodeWebConfig := server.ProvideIDEVSCodeWebConfig(config)
|
vsCodeWebConfig := server.ProvideIDEVSCodeWebConfig(config)
|
||||||
vsCodeWeb := ide.ProvideVSCodeWebService(vsCodeWebConfig)
|
vsCodeWeb := ide.ProvideVSCodeWebService(vsCodeWebConfig)
|
||||||
orchestratorOrchestrator := orchestrator.ProvideOrchestrator(scmSCM, infraProviderResourceStore, infraProvisioner, containerOrchestrator, reporter4, orchestratorConfig, vsCode, vsCodeWeb)
|
orchestratorOrchestrator := orchestrator.ProvideOrchestrator(scmSCM, infraProviderResourceStore, infraProvisioner, containerOrchestrator, reporter4, orchestratorConfig, vsCode, vsCodeWeb)
|
||||||
|
@ -400,9 +400,14 @@ type Config struct {
|
|||||||
|
|
||||||
IDE struct {
|
IDE struct {
|
||||||
VSCodeWeb struct {
|
VSCodeWeb struct {
|
||||||
// Port is the port on which the VS Code Web will be accessible.
|
// Port is the port on which the VSCode Web will be accessible.
|
||||||
Port int `envconfig:"GITNESS_IDE_VSCODEWEB_PORT" default:"8089"`
|
Port int `envconfig:"GITNESS_IDE_VSCODEWEB_PORT" default:"8089"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VSCode struct {
|
||||||
|
// Port is the port on which the SSH server for VSCode will be accessible.
|
||||||
|
Port int `envconfig:"GITNESS_IDE_VSCODE_PORT" default:"8088"`
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Gitspace struct {
|
Gitspace struct {
|
||||||
|
Loading…
Reference in New Issue
Block a user