6. 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.
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'
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
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