DEV Community

Juan Carlos García Martínez
Juan Carlos García Martínez

Posted on • Edited on

Oracle Cloud free tier: Set up a free web Visual Studio Code

Using the free tier of Oracle Cloud, you can create an instance with up to 4 cores and 24 GB of RAM! That's enough for most of my development tasks, and this comes included in Free Tier!.
If you can't switch to ARM architecture, there is option for 2 VMs with 1-core AMD x64 and 1 GB of RAM.

This kind of setup might be useful if you're someone that wants to have a development environment on-the-go, and code in your iPad or a laptop with limited resources, or if you're someone who likes to experiment just like me.

In this guide, we will configure a VM with an Ampere ARM processor to run visual studio code on the web.


First of all, you need to create an account in Oracle Cloud, and remember to select the "Always free" option, that does not asks you for a credit card. This is way more beginner-friendy than other clouds, such as AWS that don't allow a hard-limit on budgets.

Creating an ARM VM

Go to Compute > Instances
Instance section is under Compute section

Push "Create an Instance", and a new dialog will appear.

First, you'll need to input a name for the instance.

Next, you can choose the OS image and the VM shape. I choose Ubuntu for this one, and also used Ampere ARM instance type, which you can max out to 4CPUs with 24GB of RAM!

You can choose over a variety of Linux distros, and there is also a free tier for x86 instances

You'll also need to setup the SSH keys you have, or if you prefer you can also create a new one. In this case, I'll use the keys I already have

If you do want to create a new pair of SSH keys, pick the 'Generate a key pair for me' option

Click Create, and the instance will start provisioning

Status of the VM is now Running, so you're now able to log in through SSH

Once your VM state is Running, connect to the instance through SSH, using your local terminal:

ssh ubuntu@${PUBLIC_IP}

First and foremost, let's update the packages already installed with the following commands



sudo apt update

sudo apt upgrade -y


Enter fullscreen mode Exit fullscreen mode

Configuring code-server

Then, let's install code-server , which allow us to run vscode as a web server in this instance and connect from our local machines.

Copy the following into the remote session:

curl -fsSL [https://code-server.dev/install.sh](https://code-server.dev/install.sh) | sh

You'll see something similar to this in your shell:



Ubuntu 20.04.3 LTS
Installing v3.12.0 of the arm64 deb package from GitHub.

- Reusing ~/.cache/code-server/code-server_3.12.0_arm64.deb
- sudo dpkg -i ~/.cache/code-server/code-server_3.12.0_arm64.deb
(Reading database ... 112463 files and directories currently installed.)
Preparing to unpack .../code-server_3.12.0_arm64.deb ...
Unpacking code-server (3.12.0) over (3.12.0) ...
Setting up code-server (3.12.0) ...

deb package has been installed.

To have systemd start code-server now and restart on boot:
sudo systemctl enable --now code-server@$USER
Or, if you don't want/need a background service you can run:
code-server


Enter fullscreen mode Exit fullscreen mode

After this, execute in your terminal:

code-server

this will create a default configuration and then start an HTTP server at port 8080. We need to make some changes to the configuration before code is ready to use.

Now, stop the running server with Ctrl+C, then open the configuration file to enable the self-signed TLS certificate, and also run in the default HTTPS port (443).

Open the ~/.config/code-server/config.yaml file, and perform two changes in this YAML file:

  • Change the cert field to true.
  • Change the bind-addr field to 0.0.0.0:443

Before starting the server, we need to give proper permissions for the server to run in port 443 and allow the incoming traffic from the internet.

Let's use the setcap command to allow this binary to use the privileged port 443, without running with complete root permissions.

sudo setcap cap_net_bind_service=+ep /usr/lib/code-server/lib/node

Then, we will enable the code-server service and start it.



sudo systemctl enable --now code-server@$USER
sudo systemctl start code-server@ubuntu


Enter fullscreen mode Exit fullscreen mode

Verify that the service is now running

systemctl status code-server@ubuntu.service

Your console will print out something similar to this



● code-server@ubuntu.service - code-server
     Loaded: loaded (/lib/systemd/system/code-server@.service; enabled; vendor preset: enabled)
     Active: active (running) since Mon 2021-11-15 23:41:32 UTC; 3min 46s ago
   Main PID: 34764 (node)
      Tasks: 22 (limit: 21304)
     Memory: 40.2M
     CGroup: /system.slice/system-code\x2dserver.slice/code-server@ubuntu.service
             ├─34764 /usr/lib/code-server/lib/node /usr/lib/code-server
             └─34783 /usr/lib/code-server/lib/node /usr/lib/code-server

Nov 15 23:41:32 vscode-remote systemd[1]: Starting code-server...
Nov 15 23:41:32 vscode-remote systemd[1]: Started code-server.
Nov 15 23:41:33 vscode-remote code-server[34783]: [2021-11-15T23:41:33.119Z] info  code-server 3.12.0 b37ff28a0a582aee84a8f961755d0cb40a4081db
Nov 15 23:41:33 vscode-remote code-server[34783]: [2021-11-15T23:41:33.121Z] info  Using user-data-dir ~/.local/share/code-server
Nov 15 23:41:33 vscode-remote code-server[34783]: [2021-11-15T23:41:33.144Z] info  Using config file ~/.config/code-server/config.yaml
Nov 15 23:41:33 vscode-remote code-server[34783]: [2021-11-15T23:41:33.145Z] info  HTTP server listening on http://0.0.0.0:443
Nov 15 23:41:33 vscode-remote code-server[34783]: [2021-11-15T23:41:33.145Z] info    - Authentication is enabled
Nov 15 23:41:33 vscode-remote code-server[34783]: [2021-11-15T23:41:33.145Z] info      - Using password from ~/.config/code-server/config.yaml
Nov 15 23:41:33 vscode-remote code-server[34783]: [2021-11-15T23:41:33.145Z] info    - Using certificate for HTTPS: ~/.local/share/code-server/localhost.crt


Enter fullscreen mode Exit fullscreen mode

Configure the VNC Ingress rules

Even if the server is running, we're not able to access it from the external IP address, because of the firewall rules are not allowing the incoming connections.

Let's configure the network rules in order to allow connections to the running port.

Go back to Oracle Cloud web UI, go to Virtual Cloud Networks:

Firewall rules are under Networking section

There is a vnc created by default, click on it and next click on the only subnet it has.

There is a section called Security Lists. Click on the only security list and next, click on Add Ingress Rules and configure the fields as displayed below:

This is the section when we allow inbound or outbound traffic though Internet, or another networks.

This will allow any TCP connection for 443 port (HTTPS) from any IP address (that is what CIDR means)

Click again on Add Ingress Rules inside the dialog.

And after this, we finished the configuration for the server.

You can now use the public IP for your instance in your browser to connect to your VS Code web server:

https://PUBLIC_IP

You'll see a warning about a self-signed certificate. That is fine right now, because we don't have a public domain linked to this IP address, and code-server baked a self-signed one.

We're almost there! The vscode web is up and running

Go grab the password specified in~/.config/code-server/config.yaml inside the VM instance, and paste it in the password field.

Give it a few seconds and then you'll have a complete version of visual studio code running in your browser, with a VM up to 4 cores / 24 GB of RAM 🎉

After this setup, it's up and running!

Hope you find useful this guide, I'll keep posting other uses for your free tier Oracle Cloud, and hope this attracts more people that is starting in the cloud journey.

Top comments (9)

Collapse
 
ahmadkhaled11 profile image
Ahmadkhaled11 • Edited

Thank you for the clear walkthrough, J!
I followed the steps and got to this point shown in the attached pic and still can't access vscode, any idea on how to troubleshoot it?
dev-to-uploads.s3.amazonaws.com/up...
I had a good few hours trying though..
Thanks again

Collapse
 
thewraven profile image
Juan Carlos García Martínez

Hi! Did you added the firewall rules for incoming https? Could you share a screenshot of that setup?

Collapse
 
alexandersingh profile image
Sanjot Singh

I have the same problem. Did you solve it?

Collapse
 
alexandersingh profile image
Sanjot Singh

I solved it by running "sudo ufw disable", this turns of the firewall and is therefore probably not a preferred way to do it

Thread Thread
 
thewraven profile image
Juan Carlos García Martínez

Hi Sanjot, if that fixed up, I probably missed the firewall setup. Will review and update accordingly, thanks for sharing 🌟

Collapse
 
nicolashd07 profile image
nicolashd07

por si les sirve, ingresen con todo y puerto una ves finalizado, ejemplo https://you-ip:443/

Collapse
 
srinivasaraog30 profile image
srinivasarao.gurram

execute below command to enable to trafic which is missing as part of the steps
sudo iptables -I INPUT 6 -m state --state NEW -p tcp --dport 443 -j ACCEPT
sudo netfilter-persistent save

Collapse
 
srinivasaraog30 profile image
srinivasarao.gurram

sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --reload

Collapse
 
srinivasaraog30 profile image
srinivasarao.gurram

After adding about command it started working for me