ВЫКЛАДКА 
БЕЗ БОЛИ С 
CAPISTRANO 
PAINLESS DEPLOYMENT WITH CAPISTRANO 
Николай Кугаевский / @kugaevsky
TRUE OLD SCHOOL 
Rsync 
SCP 
FTP
NOT SO OLD 
ssh → git pull 
Fabric
MONSTAZ! 
Puppet 
Chef 
Salt 
Ansible
CAPISTRANO TO THE RESCUE
CAPISTRANO 
Capistrano is a remote server automation and deployment tool 
written in Ruby. 
It supports the scripting and execution of arbitrary tasks, and 
includes a set of sane-default deployment workflows.
CAPISTRANO 
Ruby 
Open source 
Expressive DSL 
Simity 
0-time deploy/rollback 
Multistaging 
Roles
INSTALL AND INIT 
$ cd my_perfect_app 
$ gem install capistrano 
$ cap install
CONFIG 
# config/deploy.rb 
set :application, 'slides' 
set :repo_url, 'git@github.com:kugaevsky/slides.git' 
# config/deploy/staging.rb 
role :app, %w{nick@kugaevsky.ru} 
set :deploy_to, '/home/kugaevsky/www/slides.kugaevsky.ru' 
set :user, 'nick'
ANATOMY LOCAL 
my_perfect_app 
├── Capfile 
├── config 
│ ├── deploy 
│ │ ├── production.rb 
│ │ ├── staging.rb 
│ │ └── ... 
│ └── deploy.rb 
└── lib 
└── capistrano 
└── tasks
ANATOMY HOST 
my_perfect_app 
├── current → ../releases/20141209222103 
├── releases 
│ ├── 20141209220703 
│ ├── 20141209222103 
│ └── ... 
├── repo 
│ ├── branches 
│ ├── config 
│ ├── description 
│ └── ... 
└── shared 
├── node_modules 
├── uploads 
├── vendor 
└── ...
DEPLOY FLOW 
deploy:starting # start a deployment, make sure everything is ready 
deploy:started # started hook (for custom tasks) 
deploy:updating # update server(s) with a new release 
deploy:updated # updated hook 
deploy:publishing # publish the new release 
deploy:published # published hook 
deploy:finishing # finish the deployment, clean up everything 
deploy:finished # finished hook
ROLLBACK FLOW 
deploy:starting 
deploy:started 
deploy:reverting # revert server(s) to previous release 
deploy:reverted # reverted hook 
deploy:publishing 
deploy:published 
deploy:finishing_rollback # finish the rollback, clean up everything 
deploy:finished
PLUGINS! 
# Capfile 
require 'capistrano/rvm' 
require 'capistrano/rbenv' 
require 'capistrano/chruby' 
require 'capistrano/bundler' 
require 'capistrano/rails/assets' 
require 'capistrano/rails/migrations'
REAL WORLD EXAMPLE 
# config/deploy.rb 
desc 'Create symlinks for npm modules' 
task :npm do 
on roles(:app) do 
execute "ln -nfs #{shared_path}/node_modules #{release_path}/node_modules" 
end 
end 
desc 'Install npm modules' 
task :npm do 
on roles(:app) do 
execute "cd #{release_path} && npm install" 
end 
end 
desc 'Compile assets' 
task :compile_assets do 
on roles(:app) do 
execute "cd #{release_path} && #{shared_path}/node_modules/.bin/gulp compile:production" 
end 
end
ALTERNATIVES 
Vlad the Deployer 
Mina
READING 
Capistrano official site 
Repository on GitHub 
How To Use Capistrano to Automate Deployments
СПАСИБО 
ВЫКЛАДКА БЕЗ БОЛИ С CAPISTRANO 
PAINLESS DEPLOYMENT WITH CAPISTRANO 
http://slides.kugaevsky.ru/ 
для 
Николай Кугаевский rannts#3

Painless Deployment with Capistrano

  • 1.
    ВЫКЛАДКА БЕЗ БОЛИС CAPISTRANO PAINLESS DEPLOYMENT WITH CAPISTRANO Николай Кугаевский / @kugaevsky
  • 2.
    TRUE OLD SCHOOL Rsync SCP FTP
  • 3.
    NOT SO OLD ssh → git pull Fabric
  • 4.
    MONSTAZ! Puppet Chef Salt Ansible
  • 5.
  • 6.
    CAPISTRANO Capistrano isa remote server automation and deployment tool written in Ruby. It supports the scripting and execution of arbitrary tasks, and includes a set of sane-default deployment workflows.
  • 7.
    CAPISTRANO Ruby Opensource Expressive DSL Simity 0-time deploy/rollback Multistaging Roles
  • 8.
    INSTALL AND INIT $ cd my_perfect_app $ gem install capistrano $ cap install
  • 9.
    CONFIG # config/deploy.rb set :application, 'slides' set :repo_url, 'git@github.com:kugaevsky/slides.git' # config/deploy/staging.rb role :app, %w{nick@kugaevsky.ru} set :deploy_to, '/home/kugaevsky/www/slides.kugaevsky.ru' set :user, 'nick'
  • 10.
    ANATOMY LOCAL my_perfect_app ├── Capfile ├── config │ ├── deploy │ │ ├── production.rb │ │ ├── staging.rb │ │ └── ... │ └── deploy.rb └── lib └── capistrano └── tasks
  • 11.
    ANATOMY HOST my_perfect_app ├── current → ../releases/20141209222103 ├── releases │ ├── 20141209220703 │ ├── 20141209222103 │ └── ... ├── repo │ ├── branches │ ├── config │ ├── description │ └── ... └── shared ├── node_modules ├── uploads ├── vendor └── ...
  • 12.
    DEPLOY FLOW deploy:starting# start a deployment, make sure everything is ready deploy:started # started hook (for custom tasks) deploy:updating # update server(s) with a new release deploy:updated # updated hook deploy:publishing # publish the new release deploy:published # published hook deploy:finishing # finish the deployment, clean up everything deploy:finished # finished hook
  • 13.
    ROLLBACK FLOW deploy:starting deploy:started deploy:reverting # revert server(s) to previous release deploy:reverted # reverted hook deploy:publishing deploy:published deploy:finishing_rollback # finish the rollback, clean up everything deploy:finished
  • 14.
    PLUGINS! # Capfile require 'capistrano/rvm' require 'capistrano/rbenv' require 'capistrano/chruby' require 'capistrano/bundler' require 'capistrano/rails/assets' require 'capistrano/rails/migrations'
  • 15.
    REAL WORLD EXAMPLE # config/deploy.rb desc 'Create symlinks for npm modules' task :npm do on roles(:app) do execute "ln -nfs #{shared_path}/node_modules #{release_path}/node_modules" end end desc 'Install npm modules' task :npm do on roles(:app) do execute "cd #{release_path} && npm install" end end desc 'Compile assets' task :compile_assets do on roles(:app) do execute "cd #{release_path} && #{shared_path}/node_modules/.bin/gulp compile:production" end end
  • 17.
    ALTERNATIVES Vlad theDeployer Mina
  • 18.
    READING Capistrano officialsite Repository on GitHub How To Use Capistrano to Automate Deployments
  • 19.
    СПАСИБО ВЫКЛАДКА БЕЗБОЛИ С CAPISTRANO PAINLESS DEPLOYMENT WITH CAPISTRANO http://slides.kugaevsky.ru/ для Николай Кугаевский rannts#3