I was recently working on a Sinatra-based web app. Some backend pages used Tailwind CSS, so I had to compile Tailwind assets after every change.

I was deploying the API with Kamal, and every time I deployed, I had to run the Tailwind build command by hand:

bundle exec rake tailwind:build

That got old pretty fast, especially when I was deploying often during development.

Automating with Post-Deploy Hooks

I wanted to automate this so Tailwind assets would build after every deployment. After digging a bit, I found post-deploy hooks in Kamal.

With a post-deploy hook, you can run a command on the remote server right after deployment. For my Tailwind build, the hook looks like this:

kamal app exec --roles web --reuse "bundle exec rake tailwind:build"

Here is what each part of the command does:

  • kamal app exec → Run a command on the deployed app.
  • --roles web → Target only the web server(s) where the assets need to be built.
  • --reuse → Reuse an existing SSH connection instead of creating a new one.
  • "bundle exec rake tailwind:build" → The actual command that compiles Tailwind CSS on the server.

This makes sure Tailwind compiles after every deploy, so I do not have to remember it manually.

Benefits:

✅ Automated workflow: No manual commands after deploy.
✅ Reduced errors: Assets are always up to date.
✅ Streamlined development: Focus on code changes rather than deployment chores.

Using Kamal post-deploy hooks made the deploy process much simpler and kept the builds consistent without extra effort.