Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Deploying with Capistrano

Deploying with Capistrano

Minimal presentation about how Capistrano works.
In case you want to know more please go to http://www.capistranorb.com

David Silva

August 07, 2013
Tweet

More Decks by David Silva

Other Decks in Programming

Transcript

  1. Capistrano was originally designed to simplify and automate deployment of

    web applications to distributed environments, and was originally created to work with Ruby on Rails applications.
  2. HOW IT WORKS $ bundle exec cap staging deploy SSH

    Remote push Update from Github
  3. HOW TO USE IT Capfile The default Capfile generated by

    capify is pretty minimal config/deploy.rb This is the file that contains your Rails application’s deployment configuration config/deploy/environment_name.rb This file have specific configurations for the specific environment
  4. Directory Structure [deploy_to] [deploy_to]/releases [deploy_to]/releases/20080819001122 [deploy_to]/releases/... [deploy_to]/shared [deploy_to]/shared/log [deploy_to]/shared/pids [deploy_to]/shared/system

    [deploy_to]/current -> [deploy_to]/releases/20100819001122 Where [deploy_to] is where you want Capistrano to be deploying to on your server
  5. config/deploy.rb set :protected_stages, %w(production) # Capistrano will ask to confirm

    deployment to those stages require 'capistrano/ext/multistage' require "bundler/capistrano" require 'capistrano_colors' set :application, "app_name" set :repository, "[email protected]:davidslv/app_name.git" set :scm, "git" set :ssh_options, { :forward_agent => true } set :use_sudo, false set :deploy_via, :remote_cache # Saves time, as it doesn't git clone the repository every time! desc 'restart' deploy.task :restart, :roles => :web do run "touch #{current_path}/tmp/restart.txt" end ...
  6. config/deploy/production.rb server 'hubberdb.domain.com', :app, :cron, :cdn, :backup, :db, :primary =>

    true server 'hubberweb.example.com', :app, :web, :sync_cdn server 'powerserver1.example.com', :app, :queue, :sync_cdn server 'powerserver2.example.com', :app, :scheduler, :sync_cdn set :user, "squid" set :env, 'production' set :rails_env, 'production' set :branch, "production" set :keep_releases, 10 set :deploy_to, "/var/www/#{application}" after "deploy:restart", "deploy:cleanup" after 'deploy:symlink' do run "ln -s #{shared_path}/lib/file_name.rb #{release_path}/config/environments/" end before "maintenance:enable", "newrelic:disable_monitoring" after "maintenance:disable", "newrelic:enable_monitoring"