Deploying Rails + SQLite with Kamal
Today I learnt about Kamal's ability to map Docker volumes into containers.
When you're using SQLite, without using volumes, your SQLite database will be trapped inside your image, forever being replaced every time you deploy your app.
Rails 8 seems to like storing SQLite databases in storage/
- which makes things pretty easy when writing your Kamal deploy.yml
file:
volumes:
- /data/storage:/rails/storage
Make sure to create the /data/storage
directory on your host and that it's owned by a user the Docker container can read and write to.
Now we have a permanent space for SQLite to store its files. Nice!
As a bonus, if you're using solid_queue
or solid_cache
you'll now be able to run seperate worker containers to process your jobs, rather than relying on Puma's in-process solid_queue processor, because they too, can access the shared SQLite databases. Double Nice!