| [ Web Proxy ] |
| Viewing: https://containerlab.dev/cmd/../../lab-examples/../../cmd/../../../manual/codespaces/ | [Back] [Original] |
The best labs are the labs that you can run anywhere, anytime, with a single click and preferably for free.
Containerlab commoditized the labbing experience by providing a simple and easy to use tool to create and manage network topologies. But still you have to think a machine to run the lab on.
Or, rather, you had.
We started to ship a Dev Container1 package for Containerlab that allows you to run containerlab-based labs in a GitHub Codespaces for free2 unlocking a whole new level of flexibility and convenience for users.
GitHub Codespaces is a cloud-based development environment by GitHub that allows you to spin up a fully configured personal dev environment in the cloud and start coding in seconds. If you think about Containerlab as a Lab-as-Code solution, you can quickly see how these two can be a perfect match.
With Containerlab in Codespaces you can:
Here is a quick demo how anyone can run the full SR Linux Streaming Telemetry lab by just clicking on a link. It is hard to imagine an easier way to run your labs in the cloud.
Fancy a full demo? Check out the 17min video by Roman. Would you rather straight try it yourself, please go ahead.
The key ingredients in this recipe are GitHub codespaces and the Dev Container image that we provide for Containerlab. When a user clicks on a link3 to open the lab in Codespaces, GitHub spins up a Codespace environment and uses the Dev Container image to set it up. The Containerlab' Dev Container image has all the necessary tools and dependencies to run Containerlab:
A user can choose to open the Codespace in a browser or in the local VS Code instance. In both cases, you get a fully functional environment with Containerlab installed and ready to use.
Codespaces environment boots for a couple of minutes, but once it is up and running, you see the familiar VS Code interface with the terminal window where you can run containerlab (and any other) commands.
As we mentioned, the Codespaces environment is a VM in the cloud; you can install packages, run other workloads, and use the VM in any way you like, you have the full control of it. What makes Codespaces VM different from a any other VM in the cloud is that it is tightly integrated with GitHub and VS Code, and provides a configurable and ready-to-use environment.
We said it is free, but it is free to a certain extent, let's dig in.
The best part about Codespaces is that it has a suitable free tier. GitHub offers 120 cpu-hours/month and 15 GB storage for free4 to all users. This means that you can run a Codespace environment for 120 cpu-hours per month without any charges. This is a compelling offer for those who
You can select which GitHub machine type you want to use for your project; each machine type is characterized by the amount of CPUs/RAM/Storage that it is equipped with, and based on that you can calculate how many cpu-hours you would consume running a lab with a chosen machine type. By the time of this writing (Jun 2024) the following machine types were available for GitHub users by default and beefier machines can be requested via GitHub support form.
| Machine type | Memory (GB) | Storage (GB) | Run time included in the free tier5 (hours/month) |
|---|---|---|---|
| 2 core | 4 | 32 | 60 (2cpu*60h=120 cpu/hours) |
| 4 core | 8 | 32 | 30 |
| 8 core | 16 | 32 | 15 |
| 16 core | 32 | 64 | 7.5 |
| 32 core | 64 | 128 | 3.75 (may not be available in your account) |
If you need more than 120 cpu-hours, you can pay for the additional usage (consult with pricing), and you can always stop the environment when you don't need it to save the quota.
Your cpu-hours counter is reset at the beginning of each month, so you can use the free plan every month. And by default you have a $0 spending limit, so you won't be charged unless you explicitly allowed it. Good!
Whenever you need to check what Codespaces environments you have running or created, you can do it in the Codespaces panel.
The panel allows you to see and interact with the available Codespaces environments, including starting, stopping, and deleting them. You can also check what repositories are associated with each environment which is useful for a Containerlab user to quickly identify the lab environments.
Codespaces expose a bunch of per-user settings at the github.com/settings/codespaces page. The following settings are worth mentioning:
It is always a good idea to periodically check how much of the cpu-hours you've consumed and check the remaining quota. Your billing information is available in the Billing settings.
The screenshot shows that 10 cpu-hours out of 120 available were consumed in the current month' period and the codespaces environments occupy 8.15 GB of storage out of 15 GB included. So far it is all well within the free tier limits.6
Note
All users by default have a $0 spending limit7, which means that if you exceed the free tier limits, your environments will be stopped and you will not be charged. You can change this limit to a higher value if you want to be able to use Codespaces even after you exceed the free tier limits.
To avoid any surprises and lower your anxiety levels, GitHub Codespaces have two important settings that you configure at github.com/settings/codespaces:
Safe settings
To keep a tight control on the Codespaces free quota usage you can set the following in your Codespaces Settings:
That way you can be sure that the environment is not running when you don't need it and it will be deleted after a day of inactivity saving up on the storage space.
By now you should be willing to try running your labs in Codespaces. To our luck, it is super simple, all you need to do is create a .devcontainer/devcontainer.json file in your lab repository that will define the Codespaces environment. The file should look similar to this:
{
"image": "ghcr.io/srl-labs/containerlab/devcontainer-dind-slim:0.68.0",
"hostRequirements": {
"cpus": 4, // (1)!
"memory": "8gb",
"storage": "32gb"
}
}
For a complete Dev Container specification, check out the official docs.
The image field points to the Containerlab Dev Container image that would define your Codespaces environment. Containerlab provides devcontainer images, and you can see all available tags on the package' page.
The image tag corresponds to the containerlab release version that is pre-installed in the image. You can choose the version that you want to use in your lab.
Another important part of the devcontainer.json file is the hostRequirements field that defines the machine type that Codespaces environment will run on. Codespaces offer a small selection of machine types that differ in the number of CPUs, RAM, and storage. You can choose the machine type that fits your lab requirements.
By the time of this writing (Jun 2024) the following machine types were available for GitHub users by default and beefier machines can be requested via GitHub support form.
| Machine type | CPU | Memory (GB) | Storage (GB) |
|---|---|---|---|
| 2 core | 2 | 8 | 32 |
| 4 core | 4 | 16 | 32 |
| 8 core | 8 | 32 | 64 |
| 16 core | 16 | 64 | 128 |
Using the machine types displayed above you can tune the hostRequirements section by choosing the machine type that fits the requirements of your lab.
Note
Codespaces VMs do not support nested virtualization, so you can't run VM-based kinds
Once you added the .devcontainer/devcontainer.json file to your lab repository, you can test the environment locally and in Codespaces.
Testing the environment locally is a litmus test to ensure that the devcontainer.json file is correct and the environment can be started. But since the environment runs locally, it doesn't test the Codespaces-specific settings like the machine type and CPU/RAM requirements.
To deploy the environment locally, make sure you have Dev Containers VS Code extension installed and then use the VS Code command panel (Cmd/Ctrl+Shift+P) to execute Dev Containers: Rebuild And Reopen In Container action. This will trigger the VS Code to build the container and open the environment in the container.
Once you tested the environment locally, you should test it in Codespaces to ensure that the selected machine type is sufficient for your lab.
Hopefully you've been adding the Codespaces support in a git branch and created a PR for it. You can open the PR in the GitHub UI and click on the "Code" -> "Create codespace on codespaces" button to start the environment for the branch you're working on:
You'll get the environment up and running in a couple of minutes and you can test it to ensure that it works as expected.
Once you are satisfied with the environment, you can add a nice button to the README file that will allow users to start the environment with a single click.
Run this lab in GitHub Codespaces for free.
Learn more about Containerlab for Codespaces.
Machine type: 2 vCPU 8 GB RAM
The URL used in the link uses deep link configuration provided by Codespaces, read more about it in the official docs.
Do not forget to change the lab repo URL and machine type in the code below!
---
<div align=center markdown>
<a href="https://codespaces.new/srl-labs/srlinux-vlan-handling-lab?quickstart=1">
<img src="https://gitlab.com/rdodin/pics/-/wikis/uploads/d78a6f9f6869b3ac3c286928dd52fa08/run_in_codespaces-v1.svg?sanitize=true" style="width:50%"/></a>
**[Run](https://codespaces.new/srl-labs/srlinux-vlan-handling-lab?quickstart=1) this lab in GitHub Codespaces for free**.
[Learn more](https://containerlab.dev/manual/codespaces) about Containerlab for Codespaces.
<small>Machine type: 2 vCPU 8 GB RAM</small>
</div>
---
Check out srl-labs/srl-streaming-telemetry README where this button is used to start the lab in Codespaces.
And of course, you can always launch the Codespace using the GitHub UI by clicking on the "Code" button.
main branch using the devcontainer settings defined in the .devcontainer/devcontainer.json file.The key pillar behind Codespaces is the Containerlab' Dev Container image that defines the environment in which the lab will run. The Dev Container image is a Docker image that contains all the necessary tools and dependencies to run Containerlab and other tools that you might need in the lab.
Containerlab has four devcontainer images that differ in the way the docker is setup and the tools installed (slim and regular variants):
You will find the devcontainer definition files in containerlab/.devcontainer directory where:
The resulting Dev Container image (in a non-slim variant) contains the following tools and dependencies:
uvgh CLI toolHaving a codespace-enabled lab makes it super easy for users to start the lab and get to the fun part of the labbing.
We encourage lab authors to add codespaces and clab-topo topics to the lab repository that supports Codespaces; that way users would be able to find the labs that they can run in Codespaces by following this link.
If you happen to have a private image that you want to use in Codespaces you can push this image to your personal GitHub registry.
To be able to access a private image you would need to (re)authenticate with the read:packages token entitlement against the GitHub registry. Thankfully, it is a matter of a copy-paste exercise.
First, unset the existing token and request the one with read:packages capability:
You will be prompted to authenticate with your GitHub account and the new token will be generated for you. Then you can login to the registry using the newly acquired token:
gh auth token | \
docker login ghcr.io -u $(cat /home/vscode/.config/gh/hosts.yml | \
grep user: | awk '{print $2}') --password-stdin
Of course you can also install tailscale or any other 0-tier VPN to access any other self-hosted private registry.
Check out the Dev Container section to learn more about the Containerlab' Dev Container package. ↩
At the moment of writing, GitHub Codespaces offer 120 cpu-hours/month and 15 GB storage for free to all users. See here for more details. ↩
A link points to the codespaces environment and refers a repo with the .devcontainer folder that defines the environment. For example: https://codespaces.new/srl-labs/srl-telemetry-lab?quickstart=1 ↩
The terms of the free plan may be subject to change, consult with the official documentation for the most recent information. ↩
The runtime assumes no other environments are running at the same time and storage quota is not exceeded. ↩
You can also see message about when the quota reset happens. ↩
As indicated by the "Monthly spending limit" text at the very bottom of the report table. ↩
| Web Proxy Viewer | New URL | Original Page |