Getting this running in Docker has turned out to be way more of a pain than is usually the case. Here are my notes and there is an Ansible playbook below that will help.
The Docker instructions are very spare with very few details. So a lot of what it took to get it running required some trial and error.
The first problem was that the container runs VSCode as the user coder
. I really didn’t want to be coding as some other user on my host. The obvious stuff failed to work, running with the --user option to docker run, mounting /etc/passwd into the container, etc. All of that failed. Searching around on the repo and they off offhandedly say “build it yourself to use a different user”.
OK, so I try to do that. Turns out there are some undocumented ARGs in the Dockerfile that need to be properly set for the build commands to succeed. I couldn’t find exactly how to format and populate all these args. So building it myself also failed.
Before finally giving up I decided to see if I could make it work by creating a coder
user on my host with the same UID as my login. Thus coder and my login would essentially be the same account. That worked!
The next problem turned out to be my mistake. Long story short, Docker likes the host volume to already exist before you mount it into the container. I had to create ~/.local/share/code-server.
Next problem I encountered was that it comes up with authentication turned on with a randomly generated password. No defaults. It appears that there is no way to turn off authentication without rebuilding the image to change the entrypoint command (see above) so the only option appears to be to define a PASSWORD environment variable.
Finally, I’m in!
To my surprise and happiness, the openHAB was listed when I search for it.
Not actually. That appears to install/run code-server on a remote machine through an SSH connection. I want to use Developing on Remote Machines using SSH and Visual Studio Code
Most of my machines/vms don’t have enough RAM or CPU to run code-server but I’d like to access and edit the code files through SSH like that extension provides.
So I went to the VSCode Marketplace and downloaded the vsix file and put it in one of the folders that is mounted to the container and then chose the “install from vsix file”. Unfortunately that didn’t work. It says it’s not compatible with VS Code 1.39.2. The current version of VSCode is around 1.41.1 so it looks like code-server doesn’t get updated quite as often as the main one does. I’ll probably have to wait a bit before I can use this extension. In the mean time, I’ll use NFS mounts to access the files if I can’t find a compatible version of the extension or an alternative. It really has become central to my workflow so I’m hesitant to give it up.
Of course, I’ll need to mount my .ssh folder to the container. And there is a potential that it still won’t work if everything needed isn’t there, though there is a third party SSH extensions which are in the code-server marketplace so I have high hopes.
I haven’t spent any time actually working in it yet. And I’ve got some more messing around to do but everything seems to work. But I have noticed that it is causing my browser (Brave) to crash periodically. I guess more reports to follow.
NOTE: The extensions get saved to ~/.local/share/code-server/extensions.
Here’s my Ansible task:
---
- name: Get {{ share_user }} uid
getent:
database: passwd
key: "{{ share_user }}"
- name: Create coder user
user:
comment: 'VSCode Server User'
createhome: no
name: coder
shell: /usr/sbin/nologin
state: present
system: no
uid: "{{ getent_passwd['rich'][1] }}"
group: '{{ share_user }}'
non_unique: yes
become: yes
- name: Make sure config volumes exist on the host
file:
path: /home/rich/.local/share/code-server
state: directory
owner: rich
group: rich
- name: Install/update code-server
docker_container:
detach: true
env:
PASSWORD: "{{ share_pass }}"
hostname: huginn.koshak.net
image: codercom/code-server:latest
log_driver: syslog
name: code-server
published_ports:
- "8080:8080"
recreate: true
restart: true
restart_policy: always
state: started
user: coder
volumes:
- /home/rich/.local/share/code-server:/home/coder/.local/share/code-server:rw
- /home/rich/code:/home/coder/project:rw
- /etc/passwd:ro
- /home/rich/.gitconfig:/home/coder/.gitconfig:rw
- /home/rich/.ssh:/home/coder/.ssh:rw
The above is a bit sloppy as I couldn’t figure out how to access {{ share_user }} from inside the evaluation of “{{ getent_passwd[‘rich’][1] }}” so I had to list my actual user name. I also need to use {{ share_user }} for the volume paths as well. But this should be something you can use to see what I did and/or modify for your own purposes.
EDIT: I’ve made some more progress.
I discovered that I probably want to mount my .gitconfig folder into the container and in order to do ssh stuff I need to mount my .ssh folder as well. So I added those as volumes to the docker task above. This will keep the same .gitconfig settings as I have with my main user and gives me ssh access to all the same sites (e.g. github) using ssh certs. Because the coder and my main user share an ID, there were no permission problems. Finally, something worked like it’s supposed to.
I installed and did some minimal testing with a few extensions. I was able to verify that the openHAB extension installed through the marketplace works, as does some of the Python extensions, Markdown All in One, and Ansible extensions appear to work. The VSCode VIM extension does not work (I’m old school and like the way I can bulk edit files in VIM that isn’t really possible in other editors) though maybe I would experiment to make it work.
Finally I was able to get the SSH FS extension to work, but it took some doing. Apparently code-server isn’t all that great with working with workspaces. From reading the docs for VSCode there are menu options that just seem to be missing like being able to create a new workspace. Normally this doesn’t matter much; before now I’ve never paid attention to workspaces. But SSH FS needs it’s own workspace because you cannot have folders open from multiple sources in the same workspace. And the only way I could figure out to get to a place where I don’t have a folder opened already in a workspace was to create a new workspace file. So I created an openhab.workspace
and populated it with
{
}
Then I used “Open Workspace” and finally I had no folders opened in explorer. Then I was able to use SSH FS to connect to my OH server and open my openHAB config. And I was able to show that the openHAB extension works.
On Linux I still have a problem with code-server crashing Brave, but it appears to run just fine in Chrome (so far).
This is really awesome! If you’ve got the resources, this is a great way to set up the IDE. I’m hoping that I can get VIM key bindings working at some point, but for the rest of you normal people I think this is a perfect project.
And I did some snooping and it appears that they are working on an ARM version that has smaller memory requirements. You would still probably want to run in on an RPi 4 (or similar) with 4 GB RAM or more. But if it works, maybe this could be added as an option for openHABian. Then we can deploy it already set up and ready to use for OH development.