You all know GitHub Codespaces, right?

Everyone enjoys working with GitHub codespaces, where you can spin up developer environments, work on your repositories without worrying about dependencies, and work from anywhere in the browser. You can use the editor of your choice, Jupyter, and VSCode without worrying much about the dependencies. In short, you can start coding in just a few minutes with a complete environment dedicated to that repository.

Now, Codespace is not free, and you cannot run it our your infrastructure, so you lack some control.

Introducing DevPod

Today, my friends at Loft Labs have introduced a new open-source tool - DevPod - that creates reproducible developer environments. This means that you can run DevPod in your choice of infrastructure (they have many providers already integrated), and each environment runs as a container in your choice of provider.

Everything is specified in a file called devcontainer.json; this is the key file with all the configuration.

With DevPod, you have the flexibility to create multiple workspaces, each residing in its own separate environment, while being managed through DevPod in a unified manner. Whether you prefer working locally or in the cloud, you can effortlessly access your desired environment and IDE. While numerous providers are already available upon launch, you also have the option to create your own provider.

Coming to some of the benefits of why DevPod might be attractive to many is that:

  • It's open source, so there is more collaboration and a feedback loop.
  • Pricing depends on your choice of infrastructure, so if you choose Civo as the provider, you get the cost-benefit to a greater extent.
  • No vendor lock-in with the flexibility of choosing any cloud provider.
  • You can also have the same experience locally with a local provider.
  • Only client-side installation - available as a CLI and sweet desktop application.
  • Many features like Docker git credentials sync, prebuilds, inactivity shutdown shipping DAY1.

Let's see DevPod in action and get to know its superpowers!

Installation

You can download the Desktop application from here or install the CLI using the command:

curl -L -o devpod "https://github.com/loft-sh/devpod/releases/latest/download/devpod-darwin-arm64" && sudo install -c -m 0755 devpod /usr/local/bin && rm -f devpod

Once installed, you can run DevPod to see the list of available commands and get started.

DevPod

Usage:
  devpod [command]

Available Commands:
  build       Builds a workspace
  completion  Generate the autocompletion script for the specified shell
  context     DevPod Context commands
  delete      Deletes an existing workspace
  help        Help about any command
  ide         DevPod IDE commands
  list        Lists existing workspaces
  machine     DevPod Machine commands
  provider    DevPod Provider commands
  ssh         Starts a new ssh session to a workspace
  status      Shows the status of a workspace
  stop        Stops an existing workspace
  up          Starts a new workspace
  use         Use DevPod resources
  version     Prints the version

Provider installation - Civo

The first step after installing the CLI or the Desktop application is to add a provider.

List of providers for DevPod

In the interface shown above, you will find Civo listed as a provider. You have the option to either install it directly from the interface or through the CLI (Command Line Interface).

Here's how to install the Civo provider using the CLI:

devpod provider add civo
10:15:58 info Download binary CIVO_PROVIDER from https://github.com/loft-sh/devpod-provider-civo/releases/download/v0.0.1/devpod-provider-civo-darwin-arm64
10:16:00 done Successfully installed provider civo
10:16:00 info The civo cloud region to create the VM in. E.g. LON1

? Please enter a value for CIVO_REGION FRA1
10:16:07 info The civo api key to use

? Please enter a value for CIVO_API_KEY ***************************************
10:16:14 done Successfully configured provider 'civo'

Screen view of the DevPod desktop application screen

The image above illustrates what the process looks like when you add the Civo provider via the Desktop application. You have the flexibility to specify the instance type you wish to initialize and reuse the same machine for multiple workspaces. For each workspace, a new VM will be spun up in the provider you configured.

To verify your installed providers, you can use the following command:

devpod provider list

    NAME | VERSION | DEFAULT | INITIALIZED |     DESCRIPTION       
  -------+---------+---------+-------------+-----------------------
    civo | v0.0.1  | true    | true        | DevPod on CIVO Cloud  

Creating your first workspace

Embarking on your journey with DevPod, the next step is to create your first developer environment. This can be done either via the desktop application or the command line interface (CLI).

If you opt to use the desktop application, you simply add a source repository and create a workspace.

DevPod workspace

As we love terminal, I will be hoing you how to do it via the CLI. You can kick-start your first workspace by entering the following command:

devpod up https://github.com/saiyam1814/OSS-japan
10:37:41 info Create machine 'oss-japan' with provider 'civo'...
10:37:44 done Successfully created machine 'oss-japan' with provider 'civo'
10:37:56 info Waiting for workspace to come up...
10:39:36 info Creating devcontainer...
10:39:43 info Waiting for devpod agent to come up...
10:40:51 info Credentials server started on port 16323...
10:40:52 info Download binary CIVO_PROVIDER from https://github.com/loft-sh/devpod-provider-civo/releases/download/v0.0.1/devpod-provider-civo-linux-amd64
10:40:52 info # Executing docker install script, commit: 1d97565eca92bb523082b7d4f530c74104e05d35
10:40:52 info + sh -c apt-get update -qq >/dev/null
10:40:53 info Cloning into '/root/.devpod/agent/contexts/default/workspaces/oss-japan/content'...
10:40:54 info Successfully installed DevPod daemon into server
10:41:10 info + sh -c DEBIAN_FRONTEND=noninteractive apt-get install -y -qq apt-transport-https ca-certificates curl >/dev/null
10:41:32 info + sh -c mkdir -p /etc/apt/keyrings && chmod -R 0755 /etc/apt/keyrings
10:41:32 info + sh -c curl -fsSL "https://download.docker.com/linux/ubuntu/gpg" | gpg --dearmor --yes -o /etc/apt/keyrings/docker.gpg
10:41:32 info + sh -c chmod a+r /etc/apt/keyrings/docker.gpg
10:41:32 info + sh -c echo "deb [arch=amd64 signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu focal stable" > /etc/apt/sources.list.d/docker.list
10:41:32 info + sh -c apt-get update -qq >/dev/null
10:41:34 info + sh -c DEBIAN_FRONTEND=noninteractive apt-get install -y -qq --no-install-recommends docker-ce docker-ce-cli containerd.io docker-compose-plugin docker-buildx-plugin >/dev/null
10:42:18 info + sh -c docker version
10:42:18 info Client: Docker Engine - Community
10:42:18 info Version:           23.0.6
10:42:18 info Couldn't find a devcontainer.json
10:42:18 info API version:       1.42
10:42:18 info Try detecting project programming language...
10:42:19 info Go version:        go1.19.9
10:42:19 info Detected project language 'Python'
10:42:19 info Git commit:        ef23cbc
10:42:19 info Built:             Fri May  5 21:18:22 2023
10:42:19 info OS/Arch:           linux/amd64
10:42:19 info Context:           default
10:42:23 info 
10:42:23 info b55c25e7fa1a: Pulling fs layer
10:42:23 info ================================================================================
10:42:23 info f53ed7c65120: Pulling fs layer
10:42:23 info 
10:42:23 info 303ce839a42e: Pulling fs layer
10:42:23 info To run Docker as a non-privileged user, consider setting up the
10:42:23 info fca60b251028: Pulling fs layer
10:42:23 info Docker daemon in rootless mode for your user:
10:42:24 info 85526a03761a: Pulling fs layer
10:42:24 info 
10:42:24 info 2fbacb953f34: Pulling fs layer
10:42:24 info dockerd-rootless-setuptool.sh install
10:42:24 info 31b17fa13257: Pulling fs layer
10:42:24 info 
10:42:24 info 1482df7bd7bf: Pulling fs layer
10:42:24 info Visit https://docs.docker.com/go/rootless/ to learn about rootless mode.
10:42:26 info ================================================================================
10:42:26 info 9db6fec76270: Waiting
10:42:27 info 127e97b4daf7: Verifying Checksum
10:42:27 info 127e97b4daf7: Download complete
10:42:34 info b0248cf3e63c: Pull complete
10:43:44 info Digest: sha256:9852a5096c748fc6a4bf0d4e350d07122190c8125c9ca12b211e6172da0dee29
10:43:44 info Status: Downloaded newer image for mcr.microsoft.com/devcontainers/python:3
10:43:49 info ca4d10acad2cc92b5b83d6af6ab561b7aae4d808550ee8746a58a5c9e3433c02
10:43:50 info Setup container...
10:43:50 info Chown workspace...
10:43:50 info Download vscode...
10:43:54 info Successfully downloaded vscode
10:43:54 info Install extensions 'dbaeumer.vscode-eslint,ms-python.python,ms-python.vscode-pylance' in the background
10:43:55 info Run 'ssh oss-japan.devpod' to ssh into the devcontainer
10:43:55 info Starting VSCode...

From this, the devpod up https://github.com/saiyam1814/OSS-japan command created an instance in the FRA region which can be seen in the image below:

Instance being created in the FRA region

devpod machine list

      NAME    | PROVIDER |  AGE    
  ------------+----------+---------
    oss-japan | civo     | 23m44s  

devpod list

      NAME    |                 SOURCE                  |  MACHINE  | PROVIDER |  IDE   | LAST USED |  AGE    
  ------------+-----------------------------------------+-----------+----------+--------+-----------+---------
    oss-japan | https://github.com/saiyam1814/OSS-japan | oss-japan | civo     | vscode | 3m41s     | 24m12s  

The 'machine list' command displays all the machines associated with your DevPod. In the example provided, 'oss-japan' is the only machine listed, meaning it was created successfully.

The 'list' command shows all the workspaces in your DevPod. The 'oss-japan' workspace, which is linked to the 'oss-japan' machine and the source repository 'https://github.com/saiyam1814/OSS-japan', should be visible in the list.

For those instances where you may need to debug or interact directly with the instance, DevPod offers the 'ssh' command:

devpod ssh

? Please select a workspace from the list below oss-japan
vscode ➜ ~ $ 

This command allows you to securely access your workspace instance directly. After running this command, you will be asked to select a workspace from a list. Upon selecting 'oss-japan', you will be logged in and presented with a new shell prompt, indicating you are now inside the workspace.

DevPod starting the VsCode

The final image above showcases the Visual Studio Code (VsCode) interface, launched and ready for you to begin coding in your new workspace. With your environment set up and your code editor launched, you can now start your development work in your new DevPod workspace.

Running the application

Once you've created your workspace and all the necessary setup has been completed, it's time to run your application. For the purpose of this demonstration, we're going to install Flask, a lightweight web application framework for Python, and run our application.

DevPod running the application with Flas installed

One of the key features of DevPod is its ability to automatically detect and forward ports. This feature simplifies the process of accessing your application as it runs within your DevPod environment.

DevPod running application

What if you want to run a different project as a separate container on the same machine? DevPod makes this process effortless. Simply use the following command:

devpod up https://github.com/saiyam1814/argo-demo --machine oss-japan

By specifying the --machine flag followed by the machine name oss-japan, you instruct DevPod to run the new project in a separate container but on the same machine. If you don't specify a machine, DevPod will create a new one for every new workspace. The command provided reuses the compute instance created initially with the first workspace, ensuring efficient resource utilization and ease of management.

Understanding devcontainer.json

DevPod takes the guesswork out of setting up your development environment. If you do not have a devcontainer.json file, DevPod automatically generates one for you. You can find this file in VsCode when the editor opens up.

{"image":"mcr.microsoft.com/devcontainers/python:3","build":{}}

This is a basic devcontainer.json file without any customizations. Despite its simplicity, the devcontainer.json file is powerful, offering you the ability to specify many settings tailored to your needs. It can define your programming language, custom tooling, runtimes, and much more, all for your developer environment running as a container on your chosen provider.

You can also specify the path to your devcontainer.json file using the --devcontainer-path flag. This feature allows you to maintain various versions of the file for different projects, providing flexibility in managing your environments.

Another powerful feature is the ability to use a Dockerfile within your devcontainer.json file. This is particularly useful if you want to add custom libraries or modify your container's environment.

{
  "build": {
    "dockerfile": "Dockerfile"
  },
  ...
}

Take note, if you make changes to the devcontainer.json file, it's recommended to delete and recreate the workspace to ensure the changes take effect. However, be aware that this action will result in the loss of all local data. Therefore, it's crucial to back up any important data before making such modifications.

To learn more about the variety of fields you can specify in a devcontainer.json file, check out the official JSON reference guide. This resource provides a comprehensive list of supported fields and a detailed explanation of their uses, helping you leverage the full potential of DevPod's capabilities.

Summary

Loft Labs have various open-source projects, including devspace, vcluster, that are already popular. Open-sourcing DevPod will bring another impact to make developers' life easy by creating developer environments on demand on your favorite provider of choice. With more and more features, DevPod will be widely adopted by the community and users. People already love Codespaces, and with more control and following the same Microsoft standards, it stands out.

Get started today using DevPod and try using Civo as your provider. Want to see a live demo? See below: