jeanp413 / open-remote-ssh

VSCode Remote Development: Open any folder on a remote machine using SSH.
MIT License
309 stars 43 forks source link

FR: Server setup hooks #120

Open StarLederer opened 11 months ago

StarLederer commented 11 months ago

First off, I'd like to express my appreciation for the work already done. I am extremely glad this extension exists and providers the first-party one some much needed community competition so thank you for your work! Even if this feature request is rejected this extension is already very useful and I know how to work around the limitations I am facing in my personal use-case.

As to the feature request, I'd like to be able to hook into the install script to customize the installation process on SSH connections where the default approach does not work for whatever reason.

Personally, I would like to run a VSCode server in a container managed by Nix and the node binary that comes bundled with the server does not work in Nix systems.

The NodeJS by default supplied by VS Code cannot be used within NixOS due to missing hardcoded paths. https://github.com/nix-community/nixos-vscode-server

There are multiple ways to solve this, in fact, the quote above comes from a project that solves this issue in NixOS, but I think the cleanest solution would be one powered by this extension itself and on top of solving the problem I'm having, it would open up possibilities to support more types of systems and prevent issues such as #116.

Personally I am looking only for one hook that is called after the server is installed and before it is attempted to start, perhaps patchServer would be a nice name for it. I would use it to rm the bundled node and ln one from the Nix store, but I imagine being able to overwrite how the server is downloaded (installServer) and started (startServer), or even a hook for after shutting it down (afterStopServer), would be very useful to some people. #116, for example, could be solved by replacing installServer hook to not use the missing wget options. On top of that, this would probably also make it possible to remove some options, like serverDownloadUrlTemplate to reduce technical debt.

I realize that there is currently no way to configure anything per-connection other than the SSH config and configuring this in the extension would probably be hard to develop and maintain so I would suggest to read this configuration from the remote shell, maybe just source .vscode-server/open-remote-ssh/hooks.sh to give the remote a chance to control how the server is managed on it?

Please let me know if you are interested in adding this and need any assistance or additional input. I've never built VSCode extensions before but can contribute by testing and trying various hook configs or, if needed, I am sure I can figure out how to develop a VSCode extension too.

StarLederer commented 11 months ago

I just realized that this feature could also solve #35. The users could modify the installServer or another hook before that, maybe beforeInstallServer or confiureInstall to either install to a shared directory or change SERVER_DATA_DIR and then modify startServer accordingly if needed

GitMensch commented 10 months ago

I agree that if the server variables are set before and used afterwards, this could solve #35 as a workaround (but an extension setting to have a configurable target directory that will also be used during "preparation" will work better for most users).

I definitely see this FR as a useful option also for other workarounds, and especially for replacing not-working node-versions, like here (docker) or #127 (which includes the workaround - a manual ssh after installation, then reconnect via the extension).

Would you place this server setup hook in the ssh config "somehow" or intend to have it as an extension setting (in which case it has to go into an array that includes the target name, because the hooks will be different per target)?

StarLederer commented 10 months ago

I have already made a fork where something similar is implemented that I am using in a highly experimental setup. My solution allows the remote to completely take over the server setup process.

Currently my fork breaks compatibility with Microsoft VS Code (so it is Codium-only) and unimlpements custom links.

I am planning to improve my fork and offer the change to the maintainer