As a Cloud Architect I often need to be platform independent - although I tend to focus a lot on Microsoft products, the simple fact is I need to be conversant across platforms.
The same goes for development - I don’t code now as a full time job, but I do sometimes need to create proof of concepts, or even just learn a new technology to better my architectural understanding of it.
However, my choice of laptop is an Apple Macbook, and a few years ago this caused me issues as I had to write .NET code I couldn’t - not on my Macbook.
Over the years this has of course become much easier - .NET core of course runs on OSX, Linux and also increasing on ARM hardware. However, when I’m travelling for work I don’t always want to carry around multiple laptops (I often need to use client specific laptops). What would be great would be if I could use my other tech of choice - and iPad!
Unfortunately, even Visual Studio Core wont’ run on that, what I need is a way to remotely code from my iPad. The simplest, but arguably most expensive option, is to use a Windows VM running in Azure - and in fact I do that sometimes. But if my network is patchy is isn’t ideal.
GitHub Codespaces are a great alternative - but unless you have a team or enterprise account you can’t do this yet.
So instead I’ve been looking at my own self-hosted Codespaces - which is thankfully possible to do now thanks to Visual Studio Code Server.
This allows you to host your own Code Server instance, and then access that instance over a browser using
Basically, from a logical point of view, it looks like this
In this tutorial I’m going to show you how to set it up, set it to run automatically (it doesn’t do that out of the box), and then connect to it.
First we’re going to build a new Linux Server in Azure. I’ll assume you know how to do this this - I’ve built a really basic Standard B2s VM (2 vCPUS, 4GiB RAM) running Ubuntu 22_04.
Once deployed, I’ll connect to it over ssh and run update to get the latest packages; Sudo apt-get update
Now download and install VSCodeServer with the following command.
wget -O- https://aka.ms/install-vscode-server/setup.sh | sh
Next, we need to run code server and set it up - this creates some certificates and other authentication bits - so type this;
You’ll be prompted to authenticate to the server with you github recentials - this helps protect your remote machine - so you’ll see this
Please enter the code xxxx-xxxx on https://github.com/login/device
Go to the Url, enter the code, and you’ll be promted to login to GitHub - once successful - you need to name your server - you need this to connect from vscode.dev. Either accept the generated name, or enter your own.
What would you like to call this machine? (purple-pizza)
In your browser you can now go to https://vscode.dev/tunnel/purple-pizza/ (or whatever your machine is called).
Yeah! VS Code now running in a browser with a fully hosted remote dev environment!
Next, we need to start up the vs-code server everytime you boot your server.
First - you’ll need to quit the code-server that’s running by pressing
Now, still in SSH, create a service file using nano
sudo nano /etc/systemd/system/code-service.service
In this file paste the following
[Unit] Description=Code-Server Service After=network.target [Service] Type=simple Restart=always User= yourUser ExecStart=/usr/local/bin/code-server [Install] WantedBy=multi-user.target
Next, we can start the service in the background with sudo service code-server start And check it’s status with
sudo service code-server status
Finally, we can make the service start automatically every time with
sudo systemctl enable code-service
Voila! A remote dev environment, when I need it!
It’s actually cheaper that github code spaces - Github code spaces for a 2 core instance is $0.18 per hour, whereas an Azure VM b2s with 2 cores is only $0.05 per hour.
Of course you need to manually start up and shutodwn the server to ensure you aren’t racking up costs when you’re not using it - but I always create an autoshutdown function in Azure in case I forget.
Because it’s so cheaper - I can also have multiple servers for different environments when I need them - for example one for .net, one for Python etc.
Next, I think I’ll look at doing this in containers - watch this space!
Did you enjoy this article? Please Subscribe here so I can let you know when I post new one’s.
For those who are interested, I perform most of my work on an Apple Macbook M1, and I use Parrallels to run Windows and Linux VMs when I need it.