ASDF, Toolchains and a Single Plugin as Package Database

Creating a distributed tool database using ASDF plugins

Table Of Contents

Today I Explained

asdf is a CLI tool that can manage multiple language runtime versions on a per-project basis, it does this by making use of per-tool plugins, which are bash scripts that perform the installation of the tools into a developer workstation. When asdf is installed, this works by first installing the plugin from a git URL:

asdf plugin add nodejs https://github.com/asdf-vm/asdf-nodejs.git

Using this plugin for the tool (nodejs), it is then possible to install a version of the tool within the workstation:

asdf install nodejs latest

Most of these plugins follow the same pattern of downloading the tool package using curl (or wget), then extracting the files into the asdf binary paths. Some of these tools may have post-install actions, such as fixing permissions or setting up environment variables.

For the tools that are rather simple, on of the alternatives to having dedicated plugins for installing each tool, is to have a single plugin that is compatible with multiple tools. For this proposed approach, a single plugin acts as a database containing directories for each tool. Within these directories, are all of the known versions of the tool, with metadata such as where to download & how to extract the files.

.
├── docs
├── tools/
│   ├── terraform/
│   │   ├── v1.4.0/
│   │   │   └── toolchain.lock.json
│   │   ├── v1.5.0/
│   │   │   └── toolchain.lock.json
│   │   └── ...
│   ├── helm/
│   │   ├── v3.9.4/
│   │   │   └── toolchain.lock.json
│   │   ├── v3.9.5/
│   │   │   └── toolchain.lock.json
│   │   ├── v3.9.6/
│   │   │   └── toolchain.lock.json
│   │   └── ...
│   ├── jq/
│   │   └── ...
│   ├── yq/
│   │   └── ...
│   └── gomplate/
│       └── ...
└── scripts

The generic plugin is then responsible for looking up any given tool & version within the directory structure, then following the steps within toolchain.lock.json to install. This can include URLs to download the tool archives, as well as any checksums or files to take note of.