Remote development

Remote Software Development with code-server

Mickey Boxell
Oracle Developers
Published in
6 min readSep 12, 2019

--

Why Develop on a Remote Environment?

Running a development environment on a remote server benefits your software engineering process through accessibility, standardization, and scalability. These benefits come with little change to your development experience. Simply connect to the remote server, checkout code, and use the editor locally to make changes through the browser window while everything happens centrally.

Accessible

Because the server is remotely accessible and decoupled from your local workstation, you can connect to the environment from anywhere with a secure connection rather than being constrained to a single physical system. This can also contribute to the durability of your system, because it is much harder to spill coffee on the cloud than it is onto your laptop. It is still possible to install your favorite plugins and configure the editor to your liking just as you would if it were running on your local machine.

Standardized

A remote server can be pre-configured or templated with organization-standard tools. This provides an easier way to get started on day one by skipping past the steps required to configure your local environment. It also provides a clean slate when starting a new project — one that can be created for a variety of languages and development configurations. An added benefit of this approach is that company source code is never stored on a developer’s local machine, but rather in a secure server, which can be useful for compliance purposes.

Scalable

Connecting to a remote server in the cloud provides access to scalable infrastructure. Rather than tying up your machine running a compilation or a long test, you can run the process in the cloud on performant hardware and scale the hardware as needed. One of my coworkers mentioned his past experience running compile/test jobs that took ~13 hours on their remote build servers, which is something you would never do that on your local machine.

code-server

One tool for remote development is code-server by Coder. This is an open source option that provides users with the ability to run a Visual Studio Code development environment on a remote server accessed through your browser. code-server comes with numerous documented installation options including pre-built binaries, a simplified set up using sshcode, a Digital Ocean droplet, a Docker image, and more. To get started quickly, I would recommend starting with the Docker image or installing the binary. The sshcode option provides additional syncing functionality to keep the settings and extensions in your local VS Code environment consistent with the remote one.

Docker

Using the Docker image is as simple as having Docker installed and running:

$ docker run -it -p 127.0.0.1:8443:8443 -v "${PWD}:/home/coder/project" codercom/code-server --allow-http --no-auth

This will create a Docker container running code-server with a port-forward to 8443 and no password protection enabled. You can check out the Dockerfile at /Dockerfile in the code-server GitHub repo. Navigate to http://localhost:8443 to access the VS Code environment. code-server uses a self-signed SSL certificate that may prompt your browser to ask you some additional questions before you proceed.

Cloud Virtual Machine with code-server Binary

Begin by connecting to the target development server and download a binary. In this case I provisioned an Ubuntu 18.04 VM running on Oracle Cloud Infrastructure. You can forward a remote port from the server to your local client by using SSH. To save time you can connect to the VM and run a port-forward even before code-server is installed:

$ ssh [username]@[IP address] -L 8443:localhost:8443

Add the binary to your path and start the binary with the project directory as the first argument:

$ code-server [initial directory to open]

Navigate to http://localhost:8443 and enter the password shown in the terminal.

The process is fairly straightforward, but for those looking for additional assistance, Coder put together a troubleshooting guide for self-hosted code-server.

Once you have the VM configured with code-server I recommend creating a custom image using the image creation tools available from Oracle Cloud and other cloud providers. This approach produces a template can be used as a standard starting point for your development environments.

Cloud VM with sshcode

sshcode provides a CLI to automatically install code-server to a remote server over SSH. It also automatically syncs your local VS Code settings and extensions to the remote server by means of rsync.

To install sshcode onto your local machine either download a pre-built binary or use go:

$ go get -u go.coder.com/sshcode$ sshcode
Usage: sshcode [FLAGS] HOST [DIR]

Start VS Code via code-server over SSH.

Environment variables:
VSCODE_CONFIG_DIR use special VS Code settings dir.
VSCODE_EXTENSIONS_DIR use special VS Code extensions dir.

More info: https://github.com/cdr/sshcode

Arguments:
HOST is passed into the ssh command. Valid formats are '<ip-address>' or 'gcp:<instance-name>'.
DIR is optional.

sshcode flags:
--b sync extensions back on termination
--bind string local bind address for SSH tunnel, in [HOST][:PORT] syntax (default: 127.0.0.1)
--no-reuse-connection do not reuse SSH connection via control socket
--skipsync skip syncing local settings and extensions to remote host
--ssh-flags string custom SSH flags
--upload-code-server string custom code-server binary to upload to the remote host
--version print version information and exit

To run sshcode pass in the username and address of your remote server, in this case another VM running on Oracle Cloud, and optionally specify a project directory on the remote server to open.

$ sshcode [username]@[IP address] [initial directory to open]

Go make a cup of coffee or maybe three. The installation and sync will take a few minutes.

When this installation is complete a browser window will open with VS Code running. If you have Chrome installed, it will open in the borderless application mode, which makes it appear almost identical to VS Code running on your desktop.

sshcode will use rsync to transfer and synchronize your local VS Code settings and extensions to the remote server every time you connect. As I mentioned above, this operation will likely take some time the first time you connect. It will be faster on subsequent connections to the same server. Pass the --skipsync flag in to skip syncing. By default, VS Code changes on the remote server will not be sync back to your local environment when the connection closes. Pass the -b flag to enable local sync back when the connection ends. If you are using alternate release of VS Code, such as VS Code Insiders, there are options for setting a custom directory.

Other Remote Development Options

Google Cloud Shell code editor is another option for a remote, browser-based code editor. This tool, which is currently in beta, runs Eclipse Theia an IDE framework implemented in TypeScript. Launch the code editor either by clicking the pencil icon in the toolbar or by typing cloudshell edit in the Cloud Shell terminal.

Similarly, Microsoft Azure includes a file editor based on the Monaco Editor, which is generated straight from VS Code sources and designed to work in the browser. Launch the editor either by clicking the {} icon from the toolbar or by typing code . in the Cloud Shell terminal. Both tools allow you to directly open a file by passing in a file path after the edit command (e.g. cloudshell edit ~/.bashrc).

Google Cloud and Microsoft Azure Cloud Shell code editors enable the user to browse file directories as well as view and edit files and are available by default with every Cloud Shell instance.

Conclusion

Remote development environments, such as those provided by code-server and the Google Cloud and Microsoft Azure Cloud Shell code editors, provide users with multiple benefits over local development environments. They can be connected to from anywhere, standardized across your team, and scaled to meet your performance needs. All of this can be accomplished with little to no changes to your existing development flow.

--

--

Mickey Boxell
Oracle Developers

Product Manager — OCI Container Engine for Kubernetes (OKE)