Quick and Dirty Remote Development Environment?

Is there a tutorial available on setting up a “quick and dirty” development environment on a remote machine. Let me explain.

  • I use Home Assistant in a Docker container on a Linux server I have in the basement.

  • There’s a core Integration that I want to modify, and it involves hardware that I cannot move (it is physically connected to that server via USB, but also hardwired to the house (security system).

  • I have VS Code install on my development machine (a Mac), but also installed as a web-based editor on the Linux server via a Docker container.

  • I’m interested in fixing this one particular Integration, but have no requirement to set up a leet dev environment that will make me the most productive mother-f’er in the world.

What’s a good approach? I really want to keep Home Assistant containerized on this machine. The development docs mention a devcontainer; is this essentially a containerized version of Home Assistant running from a cloned version of the repository I already forked? That is, I can run this instead of the Docker Hub homeassistant/home-assistant image?

Following the instructions on the linked page resulted in me having to install Docker on my Mac and building the image there. This isn’t what I want to do. I do use VS Code for remote debugging on a couple of other servers I have, but that’s all uncontainerized code. Can I somehow access devcontainer remotely from my Mac native VS Code? Assuming the devcontainer is what’s running my Home Assistant.

Sorry to sound like a newb, which I am in this ecosystem. I’m simply hoping to avoid spending 20 hours to figure out how to set up an environment that I’ll use for 8 hours to make a single fix.


Tbh, I’m kind of confused which one “this machine” is. Your mac or the linux machine you’re running your production HA on?

Yes. It builds/pulls a devcontainer image (not the same as HA image you typically pull off dockerhub), sets up a container and mounts your workspace into it. Then you’ll notice you have a few new tasks at the top as well as a number of new extensions required for HA development to meet code standards. The three most important tasks are:

  1. Install all requirements. Generally the first thing you should do unless you plan on changing the pip packages for an integration, then do that first. Takes a bit
  2. Install all test requirements. Probably the second thing you should do unless you don’t plan on making and running tests locally. Generally frowned upon but some integrations don’t have any still.
  3. Run Home Assistant. Runs HA within that devcontainer with the source code in your workspace.

Kind of lost me in here. But I think the clarification you’re looking for is a devcontainer is a container running on same machine as VSCode (your mac in this case) built from a devcontainer image, not the typical HA one.

No you cannot use your production HA as a devcontainer. However one thing you can do is if you click in the bottom left corner of vscode there’s an option to “attach to a running container” and “settings for remote containers”. It seems likely that you could build your own container from the devcontainer image on some other machine and then connect VSCode to it over the network. However I have never tried this and am not aware of anyone that has from forum and such so you’d have to do so searching.

If you want to try this remote approach you can find the Dockerfile used to build the devcontainer image here. And the settings used to create and run the container from it here.

Thanks. You’ve unmuddied a lot. I would launch my devcontainer on the Linux machine instead of my normal Home Assistant container. Assuming same compose settings, it will work like the “normal” image, except as a dev environment once I complete the tasks you say need to be done.

That’s promising.

I confused things by referring to my Mac as a development machine, since I actually want to develop on the Linux machine, remotely, from the Mac. Once I have the devcontainer running on the Linux machine, can I connect to it from VS Code on my Mac? Alternatively, I have VS Code server running on that same machine, and it provides a web-based version of VS Code that I could use if necessary.

Thanks, you’ve been immensely helpful so far!

Yea this the part I don’t know unfortunately. Like I mentioned there are options for attaching to an existing container as well as remote container settings in VSCode to get it to see a remote docker setup. It seems likely there’s a way to combine those two to make it so you can have your devcontainer on another machine. But I have never tried it myself so I don’t know.

The web-based one could work if the container is running on the linux machine. You’d have to give it permission to manage the docker setup its running in but assuming it supports devcontainers and doing that it seems feasible. Again not really something I’ve tried though.

If all else fails the “low tech” option is this:

  1. Run another HA container built from latest
  2. Exec into the container
  3. Replace the source code in /usr/src by doing a git clone of the branch you’re working on from your fork
  4. Restart the container

That’ll work although making changes is a bummer since you have to push them up and pull them down. But can do everything else that way. Can even attach a debugger by adding debugpy and then modifying .vscode/launch.json with a configuration that points at your deployment.