I was recently working on a small Sinatra application that used Tailwind CSS for a few internal pages.
The application itself was deployed using Kamal, and the deployment process was pretty smooth. The only annoying part was that after every deployment, I had to SSH into the server and run:
bundle exec rake tailwind:build
It isn’t a difficult command to run.
The problem is remembering to run it.
After forgetting a couple of times and wondering why my UI changes weren’t showing up, I figured this was exactly the kind of repetitive task that should be automated.
So I started looking through Kamal’s documentation to see if there was a way to execute commands after a deployment completed.
That’s when I came across post-deploy hooks.
For my use case, all I needed was:
kamal app exec --roles web --reuse "bundle exec rake tailwind:build"
I added this as a post-deploy hook, and that was it.
Now every deployment automatically builds the Tailwind assets without me having to think about it.
For anyone unfamiliar with the command:
kamal app execexecutes a command inside the deployed application.--roles webtargets only the web servers.--reusereuses the existing SSH connection instead of creating a new one."bundle exec rake tailwind:build"is the command that compiles the Tailwind CSS.
It’s a tiny change, but it removed one more manual step from my deployment process.
I generally like looking for these kinds of improvements. If I find myself running the same command after every deployment, I take it as a sign that the deployment process can probably handle it for me.
In this case, Kamal already had exactly what I needed—I just hadn’t taken advantage of it yet.