Capistrano 3 –



Capistrano 3 –

0 2


talks-capistrano3


On Github knapo / talks-capistrano3

Capistrano 3

Krzysztof Knapik

the first major release of Capistrano in almost 5 years

significant changes might make a lot of sites offline, and make a lot of people very...unhappy

Design goals

  • Get away from custom DSL solution
  • Better modularisation to make it more useful for non-rails apps (assets, db migrations)
  • Better modularisation to make it more useful for non-rails apps (assets, db migrations)
  • Easier Debugging (PTY, TTY, login shells, non-login shells, rvm rbenv)
  • Speed (better support for parallelism, rolling restarts)
  • Applicability (integration with chef, puupet)

What's new?

modularization & Rake integration

Rake raska & DSL

Rake tasks & DSL

helpers, command mapping, logging etc

Rake tasks & DSL

desc "Notify service of deployment"
task :notify do
  run_locally do
    with rails_env: :development do
      rake 'service:notify'
    end
  end
end

Rake tasks & DSL

desc "Ask about breakfast"
task :breakfast do
  ask(:breakfast, "kiełbasa")
  on roles(:all) do |h|
    execute "echo \"$(whoami) wants #{fetch(:breakfast)} for breakfast!\""
  end
end
bundle exec capify .
bundle exec cap install

Built-In Stage Support

bundle exec cap install STAGES=staging,production

Better magic variables support

set(:bundle_cmd) { File.join(bundle_dir, 'bin/bundle') }
set :bundle_cmd, -> { File.join(fetch(:bundle_dir), 'bin/bundle') }
set :application, 'massmailer'
fetch :mieso_type, 'kiełbasa'

auto magic stuff

fetch(:default_env).merge!(rails_env: :production)
set :linked_files, %w{config/database.yml}
set :linked_dirs, %w{pids log public/system}
on :all, in: :groups, max: 3, wait: 5 do
  # Take all servers, in groups of three which execute in parallel
  # wait five seconds between groups of servers.
  # This is perfect for rolling restarts
end

on :all, in: :sequence, wait: 15 do
  # This takes all servers, in sequence and waits 15 seconds between
  # each server, this might be perfect if you are afraid about
  # overloading a shared resource, or want to defer the asset compilation
  # over your cluster owing to worries about load
end

on :all, in: :parallel do
  # This will simply try and execute the commands contained within
  # the block in parallel on all servers. This might be perfect for kicking
  # off something like a Git checkout or similar.
end

SSHKit

require 'sshkit/dsl'
on %w{knapo.net knapo2.net}, in: :sequence, wait: 5 do
  within "/home/knapo" do
    with rails_env: :production do
      rake   "db:migrate"
      runner "S3::Sync.notify"
    end
  end
end

questions?