PodDev

Git-based Dev workflow in the Cloud

Srinivasa Vasu
The Startup
5 min readMar 4, 2021

--

Developer experience and onboarding is a space that is getting simplified every day in different forms and shapes. Though we practice vcs driven development, 12-factor, cloud-native, etc. dev onboarding is still a challenging affair. We still have to install tools, sometimes might have to run some services locally, etc as part of the development workflow. We often hit roadblocks like access issues, permission issues, resource constraints, etc. The experience is never been smooth. To that end, GitHub Codespaces is one of the ways we can steer into that problem space to have a better developer experience.

Codespaces is a cloud environment accessible via a browser that provisions the entire development environment in a ready to use container

It is an online hosted environment that simplifies the developer workflow. It provides a pre-built/customizable runtime environment with the bundled dev-driven toolsets that devs can leverage to build, test and deploy applications via a browser interface. No need to install CLIs, IDEs, or any other applications on the laptop/workstation. All we need is a browser to sail through the entire development cycle in no time. The business code and the config to create the dev environment live in a git repository.

To get started quickly, we can use one of the readily available pre-built containers. It can be customized to our needs either by extending these pre-built containers or creating a new one. A simple click provisions the entire development environment in the cloud with an integrated powerful vscode server editor in a container form factor.

Complete development lifecycle happens via a browser tab.

Let’s explore how Codespaces provisions a fully functional development environment with a K8s runtime, an integrated registry, and the relevant dev toolsets to build, test and deploy our application. The app source is available at spring-boot-k8s. This needs to be deployed to a K8s runtime.

Getting Started

Codespaces as of writing this is still a beta feature. If activated, we can create the codespace environment at https://github.com/codespaces by selecting the right git repository and branch. Codespaces comes with a lot of pre-built containers that can be referenced at codespaces-containers. If we don’t specify anything in the source repository, then by default a dev environment gets created with a Ubuntu 20.04 base with dev tools like git, docker, kubectl, etc pre-installed.

Codespaces

As this app needs to be deployed to a K8s runtime, the default codespace runtime is not sufficient. It doesn’t provide tools like skaffold, kind, etc to test the application (as in this the chosen path is based on skaffold). If the convention provided by the codespaces is not sufficient, then we can provide our own configuration. We don’t need to write everything from scratch. Instead, we can start with the base-provided configuration and apply our changes on top of it.

Open the source in the local vscode editor. In the command palette (fn+F1), type Remote-containers: Addand select Add Development Container Configuration files

Remote-containers

Type Ubuntu in the prompt,

Base environment

It creates a .devcontainer folder with a JSON metadata file at the root of the source repo.

Custom config

devcontainer.json holds the instructions on how to provision the development container with the pre-defined tools and runtime stack.

Customization

We can define our own Dockerfile with the needed toolsets to be part of the provisioned dev container. We can use an image instead of a Dockerfile as well. Refer to the documentation for more information.

This extends the base universal image with the needed toolsets like skaffold, kind, etc. Commit the changes; recreate the codespaces environment again.

Voila, this time it comes with all the needed toolsets. A running K8s cluster and the skaffold binary being part of the dev environment.

Integrated environment

Container Registry

GitHub recently rolled-out Container Registry that can be seamlessly integrated to manage container images in our organization/account. To integrate this feature, enable it under Feature Preview

To push and pull images from the registry, a personal access token (PAT) is required. Create a PAT via settings -> developer settings -> Personal access token with the following scopes,

Personal access token

We need to authenticate using this token in the development environment to seamlessly integrate with the container registry. To secure this token, it needs to be tagged with the development repository. Go to settings ->Codespaces to create a new secret with the above PAT and make it available as an environment variable in the source code repository.

Secret Management

To get the container access activated by default when the dev environment gets provisioned, add the below line to the Dockerfile

This provisions the development pod with vscode editor, git, skaffold, k8s runtime, and the integrated container registry.

skaffold run -n spring --default-repo=ghcr.io/srinivasa-vasu

will build the application using cloud native buildpacks, push it to the registry and deploy it to the running kind cluster.

We can do a kubectl port-forward to test the application right in the same browser interface.

Auto port mapping

It detects the running processes and automatically creates an access endpoint.

Codespaces has upped the developer experience to the next level and has been one of the productive ways that distributed teams can develop applications from anywhere.

--

--

Srinivasa Vasu
The Startup

Aspiring Software Artist | views expressed on this blog are solely mine |