Introducing spin terminal plugin
Rajat Jindal
Nov 14th 2024, 02:00PM
In this blog, I will explain the new spin terminal
plugin, and how it helps with the local DX.
Disclaimer: This is not an official plugin. I wrote this plugin as a personal project.
tl;dr;
Use spin terminal
to set up a local container with the required toolchains installed:
spin new -t http-go terminal-demo --accept-defaults
cd terminal-demo
cat >> .toolchains<<EOF
golang=1.23.2
tinygo=0.34.0
spin=canary
EOF
spin plugin install -u https://github.com/rajatjindal/spin-plugin-terminal/releases/download/canary/terminal.json
spin terminal
$ go version
1.23.2
$ tinygo version
0.34.0
$ spin --version
spin 3.1.0-pre0
Why
The WebAssembly ecosystem is moving very fast, and every week there are new releases for tooling as the community adds new features. While this is great, it also sometimes creates problems. e.g.
I was working on one of my old projects and was trying to fix a bug in it. Bug fixing was easy,
but now to make sure I can test it on my local setup, I needed a specific version of tinygo
,
which further needs a specific version of golang
. While the CI is set up to install specific versions
in GitHub actions, the toolchain on my dev box has already evolved to the latest and greatest versions.
🎉 Enter spin terminal
🎉
Spin Terminal
spin terminal
is a plugin that helps set up the toolchain required for working on a spin
app.
It leverages programmable modules provided by dagger using which one can selectively build
up a container image with the tooling that can be selected at runtime.
While one can argue that this is possible with Dockerfile
as well (and as almost everyone I have used Dockerfile
for setting up similar projects). While it works, the resulting Dockerfile
is not very readable.
spin terminal
is essentially a sugar wrapper on top of the dagger call
command. You can read more about that
here.
Installing it
You can install the spin terminal
plugin using the following command:
$ spin plugin install -u https://github.com/rajatjindal/spin-plugin-terminal/releases/download/canary/terminal.json
You are trying to install the `terminal` plugin with Apache-2.0 license from
https://github.com/rajatjindal/spin-plugin-terminal/releases/download/canary/spin-plugin-terminal-canary-darwin-arm64.tar.gz
Are you sure you want to continue? yes
Plugin 'terminal' was installed successfully!
Description:
A plugin to provide a terminal for the toolchain required by spin app
Homepage:
https://github.com/rajatjindal/spin-plugin-terminal
How to use it
The spin terminal
expects a .toolchains
file in the current directory with name=version
format. e.g.
spin=3.0.0
golang=1.23.2
tinygo=0.34.0
Now when we trigger spin terminal
command, it reads that file and sets up a container with those toolchains installed. e.g.
$ cat .toolchains
spin=canary
golang=1.20.14
tinygo=0.30.0
rust=1.82.0
$ spin terminal
dagger /app $
dagger /app $ spin --version
spin 3.1.0-pre0 (509d8d1 2024-11-13)
dagger /app $ go version
go version go1.20.14 linux/arm64
dagger /app $ tinygo version
tinygo version 0.30.0 linux/arm64 (using go version go1.20.14 and LLVM version 16.0.1)
dagger /app $ cargo --version
cargo 1.82.0 (8f40fc59f 2024-08-21)
This is it. Let me know if you find this plugin to be useful and star the repo.
Ask me how I can help you leverage the bleeding edge technologies such as dagger
, webassembly
, spin
for scaling your services and infrastructure and improve productivity of your teams.