jetify-com / devbox

Instant, easy, and predictable development environments
https://www.jetify.com/devbox/
Apache License 2.0
8.2k stars 192 forks source link

[Question]: Can I remotely connect to devbox services using Visual Studio Code's remote connection extentions? #1781

Open ts0818 opened 6 months ago

ts0818 commented 6 months ago

I checked the FAQ, but I couldn't find out whether devbox services support Visual Studio Code's remote connection. I would like to add to the documentation whether or not remote connections from Visual Studio Code to devbox services are supported. If you support it, please add instructions to the documentation.

https://www.jetpack.io/devbox/docs/faq/https://www.jetpack.io/devbox/docs/ide_configuration/vscode/

mohsenari commented 6 months ago

Hey @ts0818 can you expand on what you mean by devbox services? Are you running a web server as a devbox service locally? or is it hosted somewhere else? We have built support to connect to devbox.sh instances from VSCode. But I need to understand your use case a bit better to see if what you're asking is possible and just lacks documentation, or if we need to build it.

ts0818 commented 6 months ago

Thanks for the quick reply.

I don't understand the devbox service very well.

It said that it was inspired by docker compose, so I thought I could connect using something like docker exec. As an image, a connection like Visual Studio Code's devContainer, I would like to know if it is possible for devbox service as well.

I have two machines, local and remote, the devbox service is conducted remotely and I want to connect remotely from my local Visual Studio Code.

mohsenari commented 6 months ago

@ts0818 oh I see. Devbox service and devbox shell don't create a virtualization layer like Docker to run your processes. What you're running in a devbox service is running on your machine as a process. So if you want to connect your VSCode to the remote environment, you should connect to the host machine that is running your devbox process via SSH following this guide. If you want to actively develop using your local VSCode but in the remote environment, you can connect your VSCode to the remote machine using VSCode's remote ssh extension. Hope this helps. If your use case is different than this, let me know if I can help.

ts0818 commented 6 months ago

@mohsenari Thank you for your detailed explanation. I understand. your explanation is very good, For many people, it would be great if you could add it to the documentation. I think it's useful.

em-jones commented 5 months ago

If I should start a new thread, please let me know. My question is about the Reopen in devbox shell environment command that gets added by this plugin. When I attempt to run this from a machine that's in a devbox project on a remote machine (using the ssh remote tooling), vscode closes as though it's about to restart, but never restarts.

Details: local machine - pop-os remote machine - windows wsl ubuntu ssh - tailscale

Probably goes without saying, but this is an issue for VSCode tools that depend on a devbox-managed package (vale in my case).

Would love to hear from anybody that has this working/sees an obvious issue I'm not considering.

mohsenari commented 4 months ago

@em-jones apologies for late response, I missed this message somehow. The Reopen in devbox shell environment command doesn't work if your VSCode is connected to a remote environment. The reason for that is because when Reopen in devbox is called, devbox extension in VSCode does the following steps (excluding other details):

  1. VSCode spawns a devbox CLI subprocess in the host machine (same machine that is running VSCode).
  2. VSCode opens an inter-process communication channel between the newly opened subprocess and VSCode.
  3. The subprocess sets up devbox shell environment (as if you called devbox shell via devbox CLI).
  4. Once done, lets VSCode know that the new devbox shell environment is ready so VSCode closes itself.
  5. Subprocess then calls runs code . to open VSCode in the new devbox shell environment.
  6. Subprocess terminates itself.

This "dance" between VSCode and a devbox subprocess gets very fragile and error-prone when I tried testing it in VSCode connected to a remote environment as well as VSCode (in Windows) connecting WSL environment. So at least for the time being we don't have these 2 use cases figured out. Sorry for disappointing answer but I thought I should at least give you context on why it doesn't work. For your case, I think the subprocess creates a new devbox shell environment, VSCode closes itself, but the subprocess fails to open a new VSCode window.