From a0f2e84ec94f794b48d5322b0ad6879187f405a4 Mon Sep 17 00:00:00 2001 From: Pascal Breuninger Date: Thu, 19 Dec 2024 13:34:57 +0100 Subject: [PATCH] fix(pro): restart workspace with local agent on runner if it's not running already --- cmd/ssh.go | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/cmd/ssh.go b/cmd/ssh.go index b3a0aee1a..9f85575ee 100644 --- a/cmd/ssh.go +++ b/cmd/ssh.go @@ -21,6 +21,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" @@ -650,21 +651,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 {