Skip to content
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

Set SSH working directory #738

Merged
merged 5 commits into from
Oct 23, 2023
Merged

Conversation

frangio
Copy link
Contributor

@frangio frangio commented Oct 12, 2023

Fixes #730

I didn't go as far as adding a --workdir argument to devpod ssh as suggested in #730 (comment) because it isn't strictly necessary.

Looking forward to feedback.

Should this be tested in any way?

cmd/ssh.go Outdated Show resolved Hide resolved
cmd/ssh.go Outdated
@@ -243,7 +244,7 @@ func (cmd *SSHCmd) startTunnel(ctx context.Context, devPodConfig *config.Config,
defer writer.Close()

log.Debugf("Run outer container tunnel")
command := fmt.Sprintf("'%s' helper ssh-server --track-activity --stdio", agent.ContainerDevPodHelperLocation)
command := fmt.Sprintf("'%s' helper ssh-server --track-activity --stdio --workdir '%s'", agent.ContainerDevPodHelperLocation, filepath.Join("workspaces", workspaceName))
Copy link
Contributor Author

@frangio frangio Oct 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On second thought filepath.Join("workspaces", workspaceName) is wrong because it's not an absolute path, but it's probably not right anyway... What would be the right way to get the directory?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ContainerWorkspaceFolder is the only thing I could find but it seems available at a very different point in the lifecycle.

ContainerWorkspaceFolder string `json:"ContainerWorkspaceFolder,omitempty"`

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You will need to make workspace dir absolute /workspaces.
I guess it's fine as a default, when users set workspaceFolder in the devcontainer.json, it won't be able to find this path and fall back to the default

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think at this time in cmd we already know the workspaceFolder, we could already use that?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah but we don't have a parsed devcontainer.json if I'm not mistaken

Copy link
Contributor Author

@frangio frangio Oct 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That seems correct to me there doesn't seem to be a parsed devcontainer.json, only a devpod config.

I guess it's fine as a default, when users set workspaceFolder in the devcontainer.json, it won't be able to find this path and fall back to the default

Ideally it would correctly use that path if set... but it may require larger changes than this PR.

@frangio frangio marked this pull request as draft October 12, 2023 19:38
cmd/ssh.go Outdated Show resolved Hide resolved
cmd/ssh.go Outdated
@@ -243,7 +244,7 @@ func (cmd *SSHCmd) startTunnel(ctx context.Context, devPodConfig *config.Config,
defer writer.Close()

log.Debugf("Run outer container tunnel")
command := fmt.Sprintf("'%s' helper ssh-server --track-activity --stdio", agent.ContainerDevPodHelperLocation)
command := fmt.Sprintf("'%s' helper ssh-server --track-activity --stdio --workdir '%s'", agent.ContainerDevPodHelperLocation, filepath.Join("workspaces", workspaceName))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You will need to make workspace dir absolute /workspaces.
I guess it's fine as a default, when users set workspaceFolder in the devcontainer.json, it won't be able to find this path and fall back to the default

pkg/ssh/server/ssh.go Show resolved Hide resolved
@frangio frangio marked this pull request as ready for review October 13, 2023 19:53
Copy link
Member

@pascalbreuninger pascalbreuninger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for your contribution 🙇

Edit: Pipelines are failing due to formatting, could you fix that pls?

@frangio
Copy link
Contributor Author

frangio commented Oct 16, 2023

Should be ready now. Thanks!

Do you have an idea when this might be released?

@pascalbreuninger
Copy link
Member

@frangio thank you. Not quite sure tbh but looking at the changes we've accumulated it's not too far away

@frangio
Copy link
Contributor Author

frangio commented Oct 16, 2023

Do you think the E2E test failures are caused by these changes?

@pascalbreuninger
Copy link
Member

Do you think the E2E test failures are caused by these changes?

Yep, will have a look tomorrow

@FabianKramm
Copy link
Member

We need to check if Fleet is still working after this check as they expect the SSH root to be in HOME as thats the default for SSH I think.

@pascalbreuninger
Copy link
Member

@FabianKramm fleet stilled worked for me and tests are passing now

@pascalbreuninger
Copy link
Member

@frangio PR is ready to be merged now, thanks for your contribution.
Do you participate in the hacktoberfest?

@pascalbreuninger pascalbreuninger merged commit fd6b4d3 into loft-sh:main Oct 23, 2023
3 checks passed
@frangio frangio deleted the ssh-workdir branch October 24, 2023 17:49
@pascalbreuninger
Copy link
Member

@frangio It's released in v0.4.0 now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SSH starting directory should be workspace directory
4 participants