Install vscode (visual studio code) as a separate docker container

In your configuration.yaml file do this

panel_iframe:
vscode:
title: ‘VisualCode’
url: 'http://IPOFVSCODECONTAINER(HA):8443
icon: mdi:visual-studio-code

6 Likes

Solved it and wrote the following comment elsewhere:

Notice that the docker file is automatically installed for amd64 architectures. If you have an arm64 system you’ll get “standard_init_linux.go:211: exec user process caused “exec format error””. The repo also had a problem with fixuid which was not supporting arm64 until the latest revision. I’ve got this to work with the very latest rc. Simply change the last part of docker run call to codercom/code-server:3.3.0-rc.7-arm64 and make sure to check the current releases for the latest (ideally officially stable) version https://hub.docker.com/r/codercom/code-server/tags

All went well until i finally reloaded HA . the VScode item is on the panel on lft, clicking it opens vscode in the iframe and it asks for a password. it will not accept the password - which works fine when i go to the vscode container from the host (ubuntu)

1 Like

I’m also getting that

Hi guys,
In case someone would need that. Instead of searching for the package names in the marketplace search them by their display name (in this case no need to download vsix file):

Log File Highlighter” = emilast.LogFileHighlighter
ESPHome VSCode” = ESPHome.esphome-vscode
Home Assistant Config Helper” = keesschollaart.vscode-home-assistant
Material Design Icons Intellisense” = lukas-tr.materialdesignicons-intellisense
indent-rainbow” = oderwat.indent-rainbow
YAML” or “YAML Language Support by Red Hat” = redhat.vscode-yaml
Error Lens” = usernamehw.errorlens
vscode-icons” = vscode-icons-team.vscode-icons

Good luck,
Dmitry

14 Likes

I’d like to have this too, is this any setup instructions? Thanks.

The cool thing about using a linuxserver image is that it is already set up to support docker-mods. You simply add a DOCKER_MODS environment variable with a list of the mods you want to apply and start it up.

I made one to add the HA specific add-ons. So you can do something like:

docker run --name vscode -d -p 8443:8443 -v /vscode:/config -v /path_to_hass_config_folder:/config/workspace -e DOCKER_MODS=stecky/mods:code-server-home-assistant -e HOMEASSISTANT_URL=http://localhost:8123 -e HOMEASSISTANT_TOKEN=put_your_long_lived_access_token_here linuxserver/code-server

Check the logs to see when it finishes starting up (it will take a minute or two the first time it starts up) and then launch http://localhost:8443 in your browser.

Done… easy peasy

3 Likes

Thanks for the code, that has saved me loads of searching and it works great. I did have to change ‘config/workspace’ to ‘/ha_config’ on your script to get it to work.

3 Likes

Cool… Glad it worked out for you.

Thanks for the code and also for the hint about using the Docker-mod. Works like a charm on my raspberryPi 3B+…Thanks for the good work.

@stecky could you please share the source of your Docker-mod? Mainly out of interest on how to create such a mod and to perform some maintenance in the future

Here you go: https://github.com/stecky/docker-mods/tree/code-server-home-assistant

Thanks for the mod. There is a problem with it though, when using this mod it invalidates the PASSWORD arg, meaning when using this mod vscode doesn’t ask for a password anymore when you connect to it.

Is there a way to make both work?

would be interested in this as well.

My workaround now:
What I do is point my reverse proxy also to that codeserver container, and I log in directly on it.
Then I should disable the reverse proxy redirect (but I’m lazy)
Then it keeps that cookie for ages and you’re all set.

1 Like

This is really great, thank you. I’m still new to vscode and am trying to figure out where the editor is being told to open HA_CONFIG by default if that makes sense. I didn’t find any references to this folder in your repo.

Take a look a the last line of this file

1 Like

Can you explain a little more about what you are needing? Are you talking about a password to access vscode or the password that vscode uses to connect to home assistant?

Yes, I am talking about the password needed to access vscode. The issue is that if you install your mod there is no password anymore and you need to hide the vscode-container away in a custom network for it to not be available without password anymore. If you just follow the instructions in the top of this thread and install the mod then everybody on the network has access to vscode.

I’d also rather not have another icon in my already cluttered sidebar :wink:

I see… You can simply add an environment variable named PASSWORD and set it equal to whatever you want your password to be. That will fix your issue.

That option has no effect. It looks to me like the mod intentionally removes that option:

grep auth /etc/services.d/code-server/run
# Disable code authentication, we use HA authentication
options+=(--auth none)
1 Like

Gotcha. Unfortunately it will be a while before I can get to it, but feel free to send me a pull request