By Sajith Venkit.
Are you as much of a fan of Visual Studio Code (VSC), as I am, and are looking for a viable option to get access to your favourite IDE from just about anywhere, such as from your mobile phone? Well, this post was written to help you with just that. In this post, you'll learn how you can host VSC on an Alibaba Cloud Elastic Compute Service (ECS) instance along with Terraform, Cloud CLI, Packer, and Ansible.
For a bit of context, Visual Studio Code is my favourite IDE, hands down. I love the option of having my favorite apps accessible over a browser or mobile app, and so I am happy to explore options for having VSC online.
Without looking too hard, I found the three options below to have VSC online but finally settled on the third one which met all my requirements. This post follows my search. It looks at how you can set up VSC on the cloud, sync your working files to OneDrive and give yourself on-demand access to your favourite IDE at anytime and from anywhere.
The following are the three options I explored to have VSC Online.
1. Visual Studio Code Online by Microsoft
Microsoft has released a Public Preview of VSC Online. If you need just a VSC online without any customisations or additional tools and already have an Azure subscription, you could try this one. I did not select this for the following reasons:
2. Code Server on Container
It was a great relief for me to find Code Server on GitHub. After doing some initial tests, I figured this is the one that will finally get my favourite IDE accessible from my iPad. I just had to decide if I should run Code server in a container or on a Linux server. Though I got it working on a Container and also wrote two functions to start and stop the Container on demand, I did not select this for the following reasons:
3. Code Server on Linux server
This option ticked all my boxes. With it, I can run Code Server on my favourite Linux version on any Cloud and also get all my favourite DevOps tools installed on this Linux server to be accessible from VSC. Setting up OneDrive client on Linux server was a breeze and as the Linux servers on AliCloud start in less than 2 minutes, I can start or stop VSC only when I need it, making this also the most cost-effective option.
Last, as all files are synced to OneDrive, I can also get access to the latest files on my Mac and seamlessly switch between either the Desktop App or the Online version
In this post, to host VSC on an Alibaba Cloud, we will be following these steps:
Follow the steps in this GitHub repo to build the Linux server.
1. Set up a non-root user vsc-user
to run OneDrive client and Code Server.
Login as the root
user and execute the following:
adduser --disabled-password --gecos "" vsc-user
cp -pr .ssh ~vsc-user
chown -R vsc-user:vsc-user ~vsc-user/.ssh
sudo usermod -aG sudo vsc-user
echo "vsc-user ALL=(ALL) NOPASSWD:ALL" | tee -a /etc/sudoers
2. Login as vsc-user
, using this: ssh -i vsc-linux-alicloud vsc-user@ip-address-of-server
3. Install OneDrive client: sudo apt-get -y install onedrive
4. Configure the OneDrive client:
mkdir -p ~/.config/onedrive
mkdir ~/onedrive
~/.config/onedrive/config
with the following contents:# folder on Linux server that will sync with Onedrive
sync_dir = "/home/vsc-user/onedrive"
# to ensure .files are not skipped, require for syncing git folders
skip_dotfiles = "false"
# to skip the .DS_Store files in Mac, also can add any other files that must be skipped
skip_file = ".DS_Store"
~/.config/onedrive/sync_list
with the list of folders in OneDrive you want to sync:# The specific folder that must be sync from OneDrive (path to start from Documents as in example below)
Documents/hands-on/1-Docs
onedrive
.Enter the response uri:
.Note: Depending on the volume of Onedrive, it can take 15-30 mins to complete. Even if you are syncing only one folder, it will stil scan your entire OneDrive.
5. To ensure OneDrive is started on boot, execute the following command:
systemctl --user enable onedrive
Note: As the service is enabled with user startup, onedrive was not starting until user vsc-user logged in. To resolve this issue, following steps were done.
vsc-user
.systemctl --user disable onedrive
mkdir -p ~/.config/systemd/user
cp /usr/lib/systemd/user/onedrive.service ~/.config/systemd/user
vi ~/.config/systemd/user/onedrive.service
After=user@1000.service
under Unit as shown below.[Unit]
Description=OneDrive Free Client
After=user@1000.service
Documentation=https://github.com/skilion/onedrive
systemctl --user enable onedrive
systemctl --user start onedrive
sudo loginctl enable-linger vsc-user
6. Check the logs of Onedrive client: journalctl --user-unit onedrive -f
You should see a message stating Started OneDrive Free Client
.
1. Create a separate folder and download the latest version of Code Server.
mkdir -p ~/vscode-server
cd ~/vscode-server
export version="2.1698"
export release="2.1698-vsc1.41.1"
wget https://github.com/cdr/code-server/releases/download/${version}/code-server${release}-linux-x86_64.tar.gz
tar -xvzf code-server${release}-linux-x86_64.tar.gz
ls code-server${release}-linux-x86_64
2. Generate a self-signed certificate to use with the code server.
Note: Use a self-signed certificate if you do not have your own domain and are relying on your server's FQDN to access Code Server. You will get privacy warning error, when accessing the URL if you are using self-signed certificate.
cd ~/vscode-server
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout vscode-selfsigned.key -out vscode-selfsigned.crt
sudo chown vsc-user:vsc-user vscode-selfsigned*
3. If you own a domain and would like to point that to the Linux server (such as https://dev.mydomain.com
), you can create a certificate signed by Let's Encrypt using Certbot, instead of using a self-signed certificate.
sudo apt-get update
sudo apt-get install software-properties-common
sudo add-apt-repository universe
sudo add-apt-repository ppa:certbot/certbot
sudo apt-get update
sudo apt-get install certbot
Before executing the following command, log into your Domain provider and access the DNS settings.
sudo certbot certonly --server https://acme-v02.api.letsencrypt.org/directory --manual --preferred-challenges dns -d dev.mydomain.com
~/vscode-server
.sudo cp /etc/letsencrypt/live/dev.mydomain.com/cert.pem ~/vscode-server
sudo cp /etc/letsencrypt/live/dev.mydomain.com/privkey.pem ~/vscode-server
chown vsc-user:vsc-user ~/vscode-server/*.pem
4. Create a script to start the code server
dir
for the code server.mkdir ~/code-server2.1698
~/vscode-server/start-vscode-standalone-server.sh
, and copy the following lines.#!/bin/bash
export PASSWORD="test.1234567!"
/home/vsc-user/vscode-server/code-server2.1698-vsc1.41.1-linux-x86_64/code-server --auth password --user-data-dir /home/vsc-user/code-server2.1698 --cert /home/vsc-user/vscode-server/vscode-selfsigned.crt --cert-key /home/vsc-user/vscode-server/vscode-selfsigned.key
If you're using the certificate generated by certbot, use the following script.
#!/bin/bash
export PASSWORD="test.1234567!"
/home/vsc-user/vscode-server/code-server2.1698-vsc1.41.1-linux-x86_64/code-server --auth password --user-data-dir /home/vsc-user/code-server2.1698 --cert /home/vsc-user/vscode-server/cert.pem --cert-key /home/vsc-user/vscode-server/privkey.pem
chmod 755 ~/vscode-server/start-vscode-standalone-server.sh
5. Test access to Code Server/Visual Studio Code.
~/vscode-server/start-vscode-standalone-server.sh
.https://ip-address-of-server:8080
.Note: If it is self signed certificate, there will be a warning.
Press ctrl+c
to stop the server, create the folder for logfiles: mkdir -p ~/vscode-server/log
, and edit ~/.config/systemd/user/startCodeServer.service
and insert the following lines:
[Unit]
Description=Visual Studio Code Server
After=network.target
[Service]
ExecStart=/home/vsc-user/vscode-server/start-vscode-standalone-server.sh
StandardOutput=file:/home/vsc-user/vscode-server/log/code-server-output.log
StandardError=file:/home/vsc-user/vscode-server/log/code-server-error.log
[Install]
WantedBy=default.target
systemctl --user enable startCodeServer.service
systemctl --user start startCodeServer.service
It is best to install the required Extensions manually. The following are a few initial recommendations:
To install an extension manually, follow the steps below:
1. Search for the required extension using a browser window, go to the relevant site and write down the following information:
For example, to install the Terraform extension manually, go to the URL and write down the following information:
2. Use above information to generate the URL using the following template URL
https://ms-vscode.gallery.vsassets.io/_apis/public/gallery/publisher/publisher/extension/extension/version/assetbyname/Microsoft.VisualStudio.Services.VSIXPackage
Following this, for the terraform
example above the URL would be (https://ms-vscode.gallery.vsassets.io/_apis/public/gallery/publisher/mauve/extension/terraform/1.4.0/assetbyname/Microsoft.VisualStudio.Services.VSIXPackage
).
3. Download the extension to a specific folder in your Linux server.
mkdir -p ~/vscode-server/extensions
cd ~/vscode-server/extensions
PUBLISHER="mauve"
EXTENSION="terraform"
VERSION="1.4.0"
wget https://ms-vscode.gallery.vsassets.io/_apis/public/gallery/publisher/${PUBLISHER}/extension/${EXTENSION}/${VERSION}/assetbyname/Microsoft.VisualStudio.Services.VSIXPackage -O ${PUBLISHER}.${EXTENSION}-${VERSION}.vsix
4. On Visual Studio Code, go to Extensions, click on the hamburger icon (...
), select install from VSIX and select the downloaded file from the extensions folder: /home/vsc-user/vscode-server/extensions
.
5. For the Terraform extension to work properly, perform the following additional steps.
settings.json
by going to Settings and selecting edit in settings.json
and add the following:"terraform.languageServer": {
"enabled": true,
"args": []
}
"terraform.indexing": {
"enabled": false,
"liveIndexing": false
}
Reload
and Reload Window
to reload Visual Studio CodeNow that you have set up VSC on Alibaba Cloud, it is quite easy to access your IDE whenever you want.
When you need access to VSC Online, start the VM on Alibaba Cloud. You should then be able to connect to it from any browser on your PC, Mac, or template using the FQDN URL that you have configured. When you access it, VM should start in less than 1 minute.
Once you have done the work, stop the VM on Alibaba Cloud. This will ensure the VM is stopped and also de-allocated, so that you are not charged for this VM anymore. The only costs that will incur will be for the storage associated with the storage disk allocated for this VM.
The views expressed herein are for reference only and don't necessarily represent the official views of Alibaba Cloud.
Alibaba Researcher Wu Hanqing: What Kind of Intelligent System Does the World Need?
Alibaba Group Announces 2020 Spring Thunder Initiative to Help SMEs during the COVID-19 Pandemic
2,599 posts | 764 followers
FollowAlibaba Clouder - September 16, 2019
Alibaba Clouder - March 6, 2019
Alibaba Clouder - September 16, 2019
Alibaba Clouder - March 6, 2019
AlenaS - June 9, 2021
JwdShah - December 16, 2024
2,599 posts | 764 followers
FollowElastic and secure virtual cloud servers to cater all your cloud hosting needs.
Learn MoreLearn More
Alibaba Cloud Function Compute is a fully-managed event-driven compute service. It allows you to focus on writing and uploading code without the need to manage infrastructure such as servers.
Learn MoreMore Posts by Alibaba Clouder