|
| 1 | +# Deploying an OpenVSCode Server to Digital Ocean |
| 2 | + |
| 3 | +## Creating the Droplet |
| 4 | + |
| 5 | +First, you need to create a Virtual Machine to host your server. If you don't have one already, you can start with [our template](https://cloud.digitalocean.com/droplets/new?use_case=droplet&i=59c3b0&fleetUuid=a8fdcc26-2bf0-449d-8113-e458327192fe&distro=ubuntu&distroImage=ubuntu-20-04-x64&size=s-1vcpu-1gb-amd®ion=fra1&options=ipv6), then change a couple of settings as explained below. |
| 6 | + |
| 7 | +- You either need to set a password or add an SSH key. For demonstration purposes, it's easier to use a password. **Caution**: This is for demo purposes, please follow security best practices for a production environment. |
| 8 | +- We need to do is to check the checkbox <kbd>User data</kbd> and add the following script to the text field below: **TODO: What script, cc @filiptronicek** |
| 9 | + |
| 10 | +## Initial setup |
| 11 | + |
| 12 | +- First things first, you need to turn on the Droplet by selecting it in the dashboard and toggling the switch on the top right of the page. |
| 13 | +- Then, you need to copy the Droplet's IP address, available on the same page in the top bar. If you are unsure whether to copy the **ipv4** or **ipv6** address, select **ipv4**. |
| 14 | +- Now you can connect to your droplet via SSH, which you can do straight from your terminal by executing the following commands (you will need to replace `DROPLET_IP` with the actual address you copied in the previous step): |
| 15 | + ``` |
| 16 | + ssh root@DROPLET_IP |
| 17 | + ``` |
| 18 | +- When prompted, enter the password you chose during the configuration. |
| 19 | + |
| 20 | +### Downloading OpenVSCode Server |
| 21 | + |
| 22 | +**Caution**: Make sure you successfully connected to the Droplet before you execute the following commands. |
| 23 | + |
| 24 | +First, let's define the release version we want to download. You can find the latest version on the [Releases](https://github.com/gitpod-io/openvscode-server/releases) page. |
| 25 | + |
| 26 | +```bash |
| 27 | +export SERVER_VERSION=1.60.0 # Replace with the latest version |
| 28 | +``` |
| 29 | + |
| 30 | +With that in place, let's download & extract OpenVSCode server: |
| 31 | + |
| 32 | +```bash |
| 33 | +wget https://github.com/gitpod-io/openvscode-server/releases/download/openvscode-server-v$SERVER_VERSION/openvscode-server-v$SERVER_VERSION-linux-x64.tar.gz -O code-server.tar.gz |
| 34 | +tar -xzf code-server.tar.gz |
| 35 | +rm code-server.tar.gz |
| 36 | +``` |
| 37 | + |
| 38 | +While you are still connected to the VM, execute the following commands to start OpenVSCode Server: |
| 39 | + |
| 40 | +```bash |
| 41 | +cd openvscode-server-v$SERVER_VERSION-linux-x64 |
| 42 | +./server.sh |
| 43 | +``` |
| 44 | + |
| 45 | +> Gotcha: If you close the SSH session, the server will stop as well. To avoid this, you can run the server script in the background with the command shown below. If you want to do things like kill the process or bring it back to the foreground, refer to [Run a Linux Command in the Background](https://linuxize.com/post/how-to-run-linux-commands-in-background/#run-a-linux-command-in-the-background) or use a multiplexer such as [tmux](https://en.wikipedia.org/wiki/Tmux) [[tmux - a very simple beginner's guide](https://www.ocf.berkeley.edu/~ckuehl/tmux/)]. |
| 46 | +``` |
| 47 | +./server.sh >/dev/null 2>&1 & |
| 48 | +``` |
| 49 | + |
| 50 | +You're all set! You can now access your IDE at `http://<your-droplet-ip>:3000`. |
| 51 | + |
| 52 | +## Further steps |
| 53 | + |
| 54 | +### Running OpenVSCode Server on startup |
| 55 | + |
| 56 | +If you want to run the server on boot, you can add this to your Crontab file (`crontab -e`): |
| 57 | + |
| 58 | +``` |
| 59 | +@reboot /root/openvscode-server-v<REPLACE_WITH_LATEST_VERSION>-linux-x64/server.sh |
| 60 | +``` |
| 61 | + |
| 62 | +Make sure you replace `REPLACE_WITH_LATEST_VERSION` with the version you used earlier. |
| 63 | + |
| 64 | +### Adding a custom domain |
| 65 | + |
| 66 | +You can follow the official [DNS Quickstart](https://docs.digitalocean.com/products/networking/dns/quickstart/) guide for setting up a custom domain with your Droplet. |
| 67 | + |
| 68 | +### Securing the Droplet |
| 69 | + |
| 70 | +There is an awesome video by Mason Egger called [Securing Your Droplet](https://youtu.be/L8e_eAm4fFM), which explains some key steps for hardening the security of the Droplet. |
0 commit comments