2. What is Capistrano?
A remote server automation and deployment
tool.
Version 2 is mostly Rails specific and used a
custom DSL.
Version 3 is re-written from the ground up
and is trying to be more agnostic.
Version 3 uses Rake with methods included to
easily run tasks “on” servers.
3. Breaking It Up
capistrano
capistrano-rails
capistrano-bundler
capistrano-rbenv / rvm / chruby
4. Nice
In general, less configuration to deploy rails.
Multi-Stage by default
Easily sym link files and folders (e.g.,
config/database.yml, log)
Rails: database migrations automatically run
during deploy
Deployments have more granularity for
defining when tasks occur
Easily setup parallelism for tasks.
5. Where does my config go???
Version 2
Gemfile -> only capistrano
Capfile -> no changes
config/deploy.rb -> all configuration
Version 3
Gemfile -> capistrano + others
Capfile -> require dependencies
config/deploy.rb -> shared configuration (set)
config/deploy/[env].rb -> server role configuration
lib/capistrano/tasks -> Rake files for tasks
10. config/deploy.rb, part 2
set :user, 'deploy_username'
set :linked_files, %w{config/database.yml}
set :linked_dirs, %w{bin log tmp/pids tmp/cache
tmp/sockets vendor/bundle}
11. config/deploy.rb, part 3
namespace :deploy do
desc 'Restart application'
task :restart do
on roles(:app), in: :sequence, wait: 5 do
# execute :touch, release_path.join('tmp/restart.txt')
end
end
after :publishing, :restart
end
13. Task Example
desc 'Create a new sitemap'
task :create_sitemap do
on roles(:app) do
within release_path do
with rails_env: fetch(:stage) do
execute :rake, ‘sitemap:create’
end
end
end
end
after :finished, :create_sitemap
14. Deploying
Ensure your web (apache, nginx) and app (unicorn,
puma, passenger) are configured.
bundle exec cap production git:check
bundle exec cap production deploy:check
Create ~/shared/config/database.yml
bundle exec cap production deploy
15. Gotchas
Shared directory structure on the server has
changed from version 2.
Shared
[linked files / folders]
Assets
Bundle
Migrations happen automatically
Deployment flow terminology has changed