- Installation and Setup
- Setup Keys
- Deploying different stages
We love to automate things and we want to have fun while we deploy, therefore we use Capistrano. It is a fun, smooth and geeky way to deploy apps and even web sites. We deploy and build our blog this way. Interested? Keep on reading.
Little bit about Capistrano
Capistrano is a Ruby program, and we love Ruby, that gives you a set of advanced tools to deploy web applications to your servers.
- an open source tool,
- a server management tool,
- and most importantly an application deployment tool.
Capistrano in action
Watch the video below to see Capistrano in action when deploying this very blog.
Check for Ruby
Install Ruby before Capistrano installation
Test the Ruby version.
The version should be something current like
2.5.1 or higher.
Installation and Setup
Capistrano is packaged as a Ruby gem so the istallation is really simple. Use the following command.
gem install capistrano
Make your project directory where we will generate the project files.
mkdir ~/project cd ~/project
Generate all needed files with this command:
This is the project tree that Capistrano generates.
To customize the generation of stages use the following command.
cap install STAGES=production,development
This will generate
production.rb files as seen below.
config/deploy ├── development.rb └── production.rb
Basic info on generated files.
- config/deploy.rb - This file is where shared setting for all stages go
- config/deploy/ - This directory holds stage specific settings like branch names etc.
Edit generated files
This file is used to setup shared setting between different stages. For example both production and development stage can share the application name or git repository url but not the branch name.
Add values to file
Config valid for current version and patch releases of Capistrano
Default value for :format is :airbrussh
Edit file config/deploy/production.rb
To deploy, must be in root of project
Setup SSH based key auth
Key based ssh logins need to be setup in order to login to the server where we will deploy our app to.
Copy local user’s public key to remote server where we depoy our app.
ssh-copy-id -i ~/.ssh/id_rsa.pub inservio_blog@server_deploy_blog
Test if the connection work
Setup Deploy Key
Deploy key needs to be setup for the git repository so that the server where we deploy the app to can access the git server.
Once we are logged on the the server where the app will be deployed we need to add the user’s public key to the git repository as the deploy key. In this case the user is
Get the key from the remote server where we will deploy the app to
Copy and add the key to the git repository.
Deploying different stages
To deploy the production stage use command below.
cap production deploy
To deploy the development stage use the command below.
cap development deploy