## True old school * Rsync * SCP * FTP
## Not so old * ssh → git pull * [Fabric](http://www.fabfile.org/)
## MONSTAZ! * [Puppet](http://puppetlabs.com/) * [Chef](https://www.chef.io/) * [Salt](https://www.saltstack.com/) * [Ansible](http://www.ansible.com/)

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 /node_modules /node_modules"
  end
end

desc 'Install npm modules'
task :npm do
  on roles(:app) do
    execute "cd  && npm install"
  end
end

desc 'Compile assets'
task :compile_assets do
  on roles(:app) do
    execute "cd  && /node_modules/.bin/gulp compile:production"
  end
end
I ship what I want
## Alternatives * [Vlad the Deployer](http://rubyhitsquad.com/Vlad_the_Deployer.html) – Ruby * [Mina](https://github.com/mina-deploy/mina) – Ruby * [Shipit.js](https://github.com/shipitjs/shipit) – Javascript * [Rocketeer](http://rocketeer.autopergamene.eu/) – PHP
## Reading * [Capistrano official site](http://capistranorb.com/) * [Repository on GitHub](https://github.com/capistrano/capistrano) * [How To Use Capistrano to Automate Deployments](https://www.digitalocean.com/community/tutorials/how-to-use-capistrano-to-automate-deployments-getting-started)