Using Taskfile (go-task) with Rancher
GitHub
- https://github.com/standardloop/knowledge-transfer/tree/main/03-running-rancher-with-go-task
Install and Setup
Rancher
Rancher Desktop is an app that provides container management and Kubernetes on the desktop. It is available for Mac (both on Intel and Apple Silicon), Windows, and Linux.
For this article, I will be using Rancher Desktop.
You can install Rancher Desktop with brew like this:
For other installation methods you can read the docs here.
go-task (Taskfile)
go-task is a task runner / build tool that aims to be simpler and easier to use than, for example, GNU Make.
task uses yaml syntax.
You can install task with brew like this:
For more install options you can view the docs here.
Getting started
To generate a quick boilerplate taskfile you can run the following:
You can then run the taskfile like this:
Create a task to launch Rancher
This task can be run with:
The problem is though, rdctl start will launch the app, but we do not know if the docker engine has started enough to use it
/ add photo here /
So after starting rancher let's add a loop to wait until docker is ready.
---
version: '3'
tasks:
default:
deps:
- run-rancher
run-rancher:
run: once
cmds:
- rdctl start
- |
until docker info > /dev/null 2>&1
do
echo "waiting for docker to come up...."
sleep 5
done
echo "docker is ready!"
We can use until here to check docker info until it is up and ready.
Running the task we will see something like this:
$ task
INFO[0000] About to launch /usr/bin/open -a /Applications/Rancher Desktop.app ...
waiting for docker to come up....
waiting for docker to come up....
waiting for docker to come up....
waiting for docker to come up....
waiting for docker to come up....
docker is ready!
task has a status feature where it won't re-run a task if a condition is true.
For us, we don't want to re-launch rancher if we know docker is running and the rancher cli is able to view it's own settings. Really only the former matters, but I will add both.
The taskfile should now look like this:
---
version: '3'
tasks:
default:
deps:
- run-rancher
run-rancher:
run: once
cmds:
- rdctl start
- |
until docker info > /dev/null 2>&1
do
echo "waiting for docker to come up...."
sleep 5
done
echo "docker is ready!"
status:
- rdctl list-settings > /dev/null 2>&1
- docker info > /dev/null 2>&1
Now when we one task again we will see the following:
Create a task to stop Rancher
In addition to rdctl having a start command, it also as a stop command which is rdctl shutdown.
Let's add a clean task using this:
Running task clean-rancher should show the following:
Similar to the default task I made, I like to make a clean task:
Now you can run task clean or task delete
The full Taskfile
---
version: '3'
tasks:
default:
aliases: [all, make]
deps:
- run-rancher
run-rancher:
run: once
cmds:
- rdctl start
- |
until docker info > /dev/null 2>&1
do
echo "waiting for docker to come up...."
sleep 5
done
echo "docker is ready!"
status:
- rdctl list-settings > /dev/null 2>&1
- docker info > /dev/null 2>&1
clean-rancher:
cmds:
- rdctl shutdown
clean:
aliases: [delete]
ignore_error: true
cmds:
- task: clean-rancher