From a2bb8515f909f71a1fe4b9d9fcaab5fa2bc29760 Mon Sep 17 00:00:00 2001 From: Raphael <raphael@joindiaspora.com> Date: Mon, 31 Jan 2011 11:34:53 -0800 Subject: [PATCH] Update cap scripts to have separate staging and production environments, use bundler --- Gemfile | 3 +- Gemfile.lock | 3 ++ config/deploy.rb | 44 +++++++++++++++++--------- config/deploy/production.rb | 11 +++++++ config/deploy/staging.rb | 11 +++++++ config/deploy_config.yml.example | 9 ++++++ config/environments/staging.rb | 53 ++++++++++++++++++++++++++++++++ 7 files changed, 118 insertions(+), 16 deletions(-) create mode 100644 config/deploy/production.rb create mode 100644 config/deploy/staging.rb create mode 100644 config/environments/staging.rb diff --git a/Gemfile b/Gemfile index cfc2dc2b12..206f018857 100644 --- a/Gemfile +++ b/Gemfile @@ -30,7 +30,8 @@ gem 'roxml', :git => 'git://github.com/Empact/roxml.git', :ref => '7ea9a9ffd2338 gem 'addressable', '2.2.2', :require => 'addressable/uri' gem 'json', '1.4.6' gem 'http_accept_language', :git => 'git://github.com/iain/http_accept_language.git', :ref => '0b78aa7849fc90cf9e12' -gem 'capistrano', '2.5.19' +gem 'capistrano', '2.5.19', :require => false +gem 'capistrano-ext', '1.2.1', :require => false gem 'thin', '1.2.7', :require => false diff --git a/Gemfile.lock b/Gemfile.lock index 48ab016849..1d4d876676 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -110,6 +110,8 @@ GEM net-sftp (>= 2.0.0) net-ssh (>= 2.0.14) net-ssh-gateway (>= 1.0.0) + capistrano-ext (1.2.1) + capistrano (>= 1.0.0) capybara (0.3.9) culerity (>= 0.2.4) mime-types (>= 1.16) @@ -379,6 +381,7 @@ DEPENDENCIES aws (= 2.3.32) bundler (>= 1.0.0) capistrano (= 2.5.19) + capistrano-ext (= 1.2.1) capybara (~> 0.3.9) carrierwave! chef (= 0.9.12) diff --git a/config/deploy.rb b/config/deploy.rb index 58b22cae28..8fb72797a7 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -2,26 +2,22 @@ # licensed under the Affero General Public License version 3 or later. See # the COPYRIGHT file. -config = YAML.load_file(File.dirname(__FILE__) + '/deploy_config.yml') -config = config['production'] +set :config_yaml, YAML.load_file(File.dirname(__FILE__) + '/deploy_config.yml') -set :rails_env, 'production' +require 'bundler/capistrano' +set :bundle_dir, '' -set :application, 'diaspora' -set :deploy_to, config['deploy_to'] -set :current_dir, config['current_dir'] +set :stages, ['production', 'staging'] +set :default_stage, 'staging' +require 'capistrano/ext/multistage' +set :application, 'diaspora' set :scm, :git -set :user, config['user'] -set :password, config['password'] set :use_sudo, false set :scm_verbose, true -set :repository, config['repo'] set :repository_cache, "remote_cache" set :deploy_via, :checkout -server config['server'], :app, :web, :db, :primary => true - namespace :deploy do task :symlink_config_files do run "ln -s -f #{shared_path}/config/database.yml #{current_path}/config/database.yml" @@ -39,16 +35,34 @@ namespace :deploy do end task :restart do - run "killall ruby" + thins = run "svstat /service/thin*" + matches = thins.match(/(thin_\d+)/).to_a + + matches.each_with_index do |thin, index| + unless index == 0 + puts "sleeping for 10 seconds" + sleep(10) + end + run "svc -t /service/#{thin}" + end + + run "svc -t /service/resque_worker*" + end + + task :kill do + run "svc -k /service/thin*" + run "svc -k /service/resque_worker*" end task :start do - # daemontools FTW + run "svc -u /service/thin*" + run "svc -u /service/resque_worker*" end task :stop do - run "killall ruby" + run "svc -d /service/thin*" + run "svc -d /service/resque_worker*" end end -after "deploy:symlink", "deploy:symlink_config_files", "deploy:symlink_cookie_secret", "deploy:bundle_static_assets" \ No newline at end of file +after "deploy:symlink", "deploy:symlink_config_files", "deploy:symlink_cookie_secret", "deploy:bundle_static_assets" diff --git a/config/deploy/production.rb b/config/deploy/production.rb new file mode 100644 index 0000000000..93a356c2bb --- /dev/null +++ b/config/deploy/production.rb @@ -0,0 +1,11 @@ +set :config, config_yaml['production'] + +set :deploy_to, config['deploy_to'] +set :current_dir, config['current_dir'] +set :rails_env, config['rails_env'] +set :user, config['user'] +if config['password'] + set :password, config['password'] +end +set :repository, config['repo'] +server config['server'], :app, :web, :db, :primary => true diff --git a/config/deploy/staging.rb b/config/deploy/staging.rb new file mode 100644 index 0000000000..9b04b862b1 --- /dev/null +++ b/config/deploy/staging.rb @@ -0,0 +1,11 @@ +set :config, config_yaml['staging'] + +set :deploy_to, config['deploy_to'] +set :current_dir, config['current_dir'] +set :rails_env, config['rails_env'] +set :user, config['user'] +if config['password'] + set :password, config['password'] +end +set :repository, config['repo'] +server config['server'], :app, :web, :db, :primary => true diff --git a/config/deploy_config.yml.example b/config/deploy_config.yml.example index 7aaea7dc9f..d6cf3fe1eb 100644 --- a/config/deploy_config.yml.example +++ b/config/deploy_config.yml.example @@ -8,4 +8,13 @@ production: current_dir: 'diaspora' user: 'diaspora' password: 'password' + rails_env: 'production' + repo: 'git://github.com/diaspora/diaspora.git' +staging: + server: 'staging.example.com' + deploy_to: '/var/www/diaspora' + current_dir: 'diaspora' + user: 'diaspora' + password: 'password' + rails_env: 'staging' repo: 'git://github.com/diaspora/diaspora.git' diff --git a/config/environments/staging.rb b/config/environments/staging.rb new file mode 100644 index 0000000000..d8a3051ba3 --- /dev/null +++ b/config/environments/staging.rb @@ -0,0 +1,53 @@ +# Copyright (c) 2010, Diaspora Inc. This file is +# licensed under the Affero General Public License version 3 or later. See +# the COPYRIGHT file. + +Diaspora::Application.configure do + # Settings specified here will take precedence over those in config/environment.rb + + # The production environment is meant for finished, "live" apps. + # Code is not reloaded between requests + config.cache_classes = true + + # Full error reports are disabled and caching is turned on + config.consider_all_requests_local = true + config.action_controller.perform_caching = true + + # Specifies the header that your server uses for sending files + #config.action_dispatch.x_sendfile_header = "X-Sendfile" + + config.active_support.deprecation = :notify + + # For nginx: + config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' + + # If you have no front-end server that supports something like X-Sendfile, + # just comment this out and Rails will serve the files + + # See everything in the log (default is :info) + # config.log_level = :debug + + # Use a different logger for distributed setups + # config.logger = SyslogLogger.new + + # Use a different cache store in production + # config.cache_store = :mem_cache_store + + # Disable Rails's static asset server + # In production, Apache or nginx will already do this + config.serve_static_assets = false + + # Enable serving of images, stylesheets, and javascripts from an asset server + # config.action_controller.asset_host = "http://assets.example.com" + + # Disable delivery errors, bad email addresses will be ignored + # config.action_mailer.raise_delivery_errors = false + + # Enable locale fallbacks for I18n (makes lookups for any locale fall back to + # the I18n.default_locale when a translation can not be found) + config.i18n.fallbacks = true + config.threadsafe! +end + +# Sacrifice readability for a 10% performance boost +Haml::Template::options[:ugly] = true -- GitLab