Skip to content

Commit

Permalink
fix(pro): restart workspace with local agent on runner if it's not ru…
Browse files Browse the repository at this point in the history
…nning already
  • Loading branch information
pascalbreuninger committed Dec 19, 2024
1 parent 5508a24 commit bcbe87c
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions cmd/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
client2 "github.com/loft-sh/devpod/pkg/client"
"github.com/loft-sh/devpod/pkg/client/clientimplementation"
"github.com/loft-sh/devpod/pkg/config"
"github.com/loft-sh/devpod/pkg/devcontainer"
dpFlags "github.com/loft-sh/devpod/pkg/flags"
"github.com/loft-sh/devpod/pkg/gpg"
"github.com/loft-sh/devpod/pkg/port"
Expand Down Expand Up @@ -665,21 +666,38 @@ func (cmd *SSHCmd) setupGPGAgent(
//
// WARN: This is considered experimental for the time being!
func (cmd *SSHCmd) jumpLocalProxyContainer(ctx context.Context, devPodConfig *config.Config, client client2.WorkspaceClient, log log.Logger, exec func(ctx context.Context, command string, sshClient *ssh.Client) error) error {
_, workspaceInfo, err := client.AgentInfo(provider.CLIOptions{Proxy: true})
encodedWorkspaceInfo, _, err := client.AgentInfo(provider.CLIOptions{Proxy: true})
if err != nil {
return fmt.Errorf("prepare workspace info: %w", err)
}

workspaceDir, err := agent.CreateAgentWorkspaceDir(workspaceInfo.Agent.DataPath, workspaceInfo.Workspace.Context, workspaceInfo.Workspace.ID)
shouldExit, workspaceInfo, err := agent.WorkspaceInfo(encodedWorkspaceInfo, log)
if err != nil {
return fmt.Errorf("create agent workspace dir: %w", err)
return err
} else if shouldExit {
return nil
}
workspaceInfo.Origin = workspaceDir

runner, err := workspace.CreateRunner(workspaceInfo, log)
if err != nil {
return err
}

containerDetails, err := runner.Find(ctx)
if err != nil {
return err
}

if containerDetails == nil || containerDetails.State.Status != "running" {
log.Info("Workspace isn't running, starting up...")
_, err := runner.Up(ctx, devcontainer.UpOptions{
CLIOptions: workspaceInfo.CLIOptions,
NoBuild: true}, workspaceInfo.InjectTimeout)
if err != nil {
return err
}
log.Info("Successfully started workspace")
}

// create readers
stdoutReader, stdoutWriter, err := os.Pipe()
if err != nil {
Expand Down

0 comments on commit bcbe87c

Please sign in to comment.