Kickstarting with Capistrano
Problem I wanted to solve was to minimize the deployment overheads.
Deployment overheads on the server:
- Bundle install if there are any new gems installed
- Run db migrations
- Precompile Assets
- Restart puma with the new codebase
Below I’m providing code snippets and some useful info for anyone who is new to the Capistrano and want to automate some deployment process (or it can be any process. Read Capistrano documentation for more details)
Adding capistrano to the rails project
That will lay down the Capfile, deploy.rb (common config for all environments) and a sample config one for production and one for staging.
Some variables I had to set in deploy.rb for the deployment to work
The only variable I had to configure in staging.rb
Bundle install, Precompile Assets, DB Migrations
Open capfile and uncomment the below lines
They will take care of doing bundle install before the deployment process starts, precompiles assets and run db migrations as part of the deployment process.
To know more about where they actually hook in their tasks in the deployment process, read this
Restarting server after deployment
We store puma pid in a .pid file. We used to cat that file, find the pid, kill it and then restart after each deployment.
So, I wanted to automate that process. It was pretty simple.
Caveat about executing commands on the server:
For heaven’s sake, please read and understand this. It will come back and bite you otherwise.
RVM on server
If you have RVM installed on the server, do check out this gem.
Configuration changes I had to do:
and done!!! I was able to automate the deployment process.
###Some more references