Prerequisites-
- An existing Rails application.
- Application is uploaded on a SCM preferably Git
- Deployment server is SSH enabled. Incase you are trying local deployment on Mac OS X, you can refer here
Now the Capistrano 3 setup –
- Install Capistrano and its related sub-modules by adding to Gemfile –
group :development, :test do
gem 'capistrano', '~> 3.4.0'
gem 'capistrano-rails', '~> 1.1.0'
gem 'capistrano-bundler'
endbundle install
- Create requisite directory structure pertaining to Capistrano
bundle exec cap install
- Update Capfile to include installed Capistrano helper modules
# Include default deployment tasks# Load DSL and set up stages
require 'capistrano/setup'
require ‘capistrano/deploy’
require ‘capistrano/rails’
require ‘capistrano/bundler’ - Update deploy.rb with general deployment settings. Uncomment and update the configuration as applicable.
- Now mention deployment server and SSH connection details, say for local environment, in app > config > deploy > local.rb
server '192.168.1.xx', user: 'username', roles: %w{db web app} , :primary => true
set :ssh_options, {
user: 'username', # overrides user setting above
# keys: %w(/home/user_name/.ssh/id_rsa),
forward_agent: false,
# auth_methods: %w(publickey password)
password: 'Use keys'
}
- Now that the bare-minimum configuration is complete, we can go ahead and test connectivity and structure creation.
cap staging deploy:check
- All looks good, now deploy –
cap staging deploy
References: