Devcontainer (for use with GitHub Codespace) setup with asdf support
4.8K
I've been having fun playing with GitHub codespaces. One of the things that has seemed odd to me is the language-specific
development environments. Most projects—even small side projects—have multiple languages. Composing these images feels
messy. I've always enjoyed asdf for managing language versions in a unified fashion.
This project builds a devcontainer image (for use with GitHub Codespace) setup with asdf support. It also includes a nice
utility script for installing all asdf plugins, finding all .tool-versions files, installing the versions specified,
and starting up a docker-compose.yml if one exists.
Here's my blog post which walks through this in detail.
Main design goals:
Dockerfile is very aggressive with
including many packages so the container can install asdf packages in many languages. I am no sysadmin so there may be
negative side effects with this approach.apt-get update in the build, combined with a monthly
gh actions cron, fixes this./asdf-post-create.sh finds all .tool-versions included in the repo
and installs the relevant asdf plugins.docker-compose services. For instance, if your project requires postgres + redis, you can include a docker-compose.yml
file in .devcontainer/ and it will be started when you run /asdf-post-create.sh.Here are the languages I've confirmed compile and run via asdf on this image:
Check out devcontainer-example folder for how to use this in your application.
Here's how to easily copy the example into your project:
mkdir .devcontainer && cd .devcontainer && curl https://codeload.github.com/iloveitaly/asdf-devcontainer/tar.gz/main | tar -xz --strip=2 asdf-devcontainer-main/devcontainer-example
If you clone the repo locally, here's a quick script to copy:
cp -R ~/Projects/asdf-devcontainer/devcontainer-example your-new-project/.devcontainer
Here's what your devcontainer.json should look like:
{
"image": "iloveitaly/asdf-devcontainer:0-ubuntu-22.04",
"postCreateCommand": "/asdf-post-create.sh && bin/setup",
"remoteUser": "vscode",
"features": {
"homebrew": "latest",
"ghcr.io/devcontainers/features/sshd:1": {
"version": "latest"
},
"ghcr.io/devcontainers/features/docker-in-docker:1": {
"version": "latest",
"dockerDashComposeVersion":"v2"
}
}
}
Easiest way to iterate on this image is to setup a codespace and rebuild the Dockerfile. Some tips:
http https://mcr.microsoft.com/v2/vscode/devcontainers/base/tags/list | fzfdocker build -t asdf-devcontainer . --build-arg VARIANT=dev-ubuntudocker run --rm -it asdf-devcontainer bash -lc gh api repos/iloveitaly/asdf-devcontainer/eventsContent type
Image
Digest
sha256:63c6710f5…
Size
572.5 MB
Last updated
over 1 year ago
docker pull iloveitaly/asdf-devcontainer:0-ubuntu-22.04