Recently, I have been working on a Sinatra-based web app. Some backend pages were designed using Tailwind CSS, which meant I needed to compile Tailwind assets after every change.
I was deploying the API using Kamal, and every time I deployed, I had to run the Tailwind build command manually:
bundle exec rake tailwind:build
This quickly became tedious, especially when deploying frequently during development.
Automating with Post-Deploy Hooks
I wanted to automate this process so that Tailwind assets are built automatically after every deployment. After digging a bit, I discovered post-deploy hooks in Kamal.
With a post-deploy hook, you can run any command on the remote server immediately after deployment. For my Tailwind build, the hook looks like this:
kamal app exec --roles web --reuse "bundle exec rake tailwind:build"
Here’s 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 ensures that every time I deploy the app, Tailwind automatically compiles, saving me manual steps and reducing the chance of forgetting to build assets.
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 has simplified my deployment process for this Sinatra app and ensured consistent builds without extra effort.