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:
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
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.
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.
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.
Replace the source code in /usr/src by doing a git clone of the branch you’re working on from your fork
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.
sorry for opening an old thread, but did you ever get this to work? I am on a mac and have a proxmox server with a vm running docker and docker compose and have spent countless hours trying to get a home assistant devcontainer running on docker, with debugging, so I can continue developing my custom component in a more standard way than the way I have been doing it - on a home assistant os install on a proxmox vm with no debugging abilities. This is the only conversation I have read where someone else is trying to do something similar to what I am.
When I started out to try to improve my environment a few days ago, I never dreamed I would be hammering on this days later, not able to setup a remote devcontainer to develop my code, and that I wouldn’t be able to find anyone else on the internet trying to do this either.
So my end goal would be to run the devcontainer on Debian (LXC) on Proxmox, and then access the devcontainer from VSCode on my laptop.
I tried to make it reproducible, so I made a small script that I can run in a new Debian install (script is run as root):
#!/bin/bash
# Load the self-defined support functions
source <(curl -fsSL [ OWN REPO ])
# Ensure the script stops on errors
set -e
# Install required dependencies (based on Chat GPT's suggestion)
apt install -y curl git nodejs npm bash unzip gnupg ca-certificates
# Install Docker
curl -fsSL https://get.docker.com | sh
# Setup docker to auto start on boot
systemctl enable docker
systemctl start docker
usermod -aG docker $USER
# Make a config file for code-server
mkdir -p ~/.config/code-server
echo "bind-addr: 0.0.0.0:8080
auth: password
password: $(openssl rand -base64 12)
cert: false" > ~/.config/code-server/config.yaml
# Download and install code-server
curl -fsSL https://code-server.dev/install.sh | sh
GITHUB_REPOSITORY=$(get_input "Enter your forked Home Assistant repository" "GitHub repository" ) || error_exit "Failed to get GitHub repository"
git clone "$GITHUB_REPOSITORY" homeassistant-dev
cd homeassistant-dev
systemctl enable --now code-server@$USER
systemctl restart code-server@$USER
echo "Setup complete!"
echo "You can access code-server at http://<your-lxc-ip>:8080"
echo "The password is stored in ~/.config/code-server/config.yaml"
echo "For simplicity, this is the password: $(cat ~/.config/code-server/config.yaml | grep password | cut -d ' ' -f 2)"
There are some functions that I’ve defined in a separate file (e.g. get_input and error_exit), but hopefully you understand what I’m doing
If I eventually figure it out, I will update the script so others can also use it.
So my primary things I still need to figure out:
Do I need to clone the forked Home Assistant core in the Debian itself, or to a docker container running on Debian?
How to setup the code-server install on Debian to serve as a remote-container?
(switching to my new persona from applesauce to answer) I kept copious notes on what I did, and just spent some time trying to sort them out to post, but that will take me a ton of time to make a proper tutorial. It’s a junk drawer full of things that worked, things that didn’t, and lots and lots of notes
I will try to do that sometime in the near future, but like all things it’s relatively easy when you know how.
get your proxmox server running with ssh access to it, preferably with public ssh key from dev machine installed on dev server
open vs code on your dev workstation, install ssh plugin, and ssh to your dev server in the terminal.
update the package list with sudo apt update
install Docker with sudo apt install -y docker.io
enable and start Docker with sudo systemctl enable docker followed by sudo systemctl start docker
verify Docker with docker --version
install Docker Compose with sudo apt install -y docker-compose
verify Docker Compose with docker-compose --version.
in the developer menu in vs code, open ssh connection to your dev server
navigate the directory with ha core
click yes when prompted “it looks like you just opened a dev container, do you want to start it?”
use python debugging plug-in to restart ha dev container when needed.
from developer menu in vs code select your python interpreter (from ha dev container)
there may be a few missed details, but it’s basically just magic when it launches the devcontainer, (I had no idea that would happen until I did it), with ha running and able to log in from a browser too. feel free to modify these instructions and repost a more detailed version here after working through it. let me know if that works or if you have additional questions.