Browse Source

Merge branch 'master' into troy/application-rails-env-name

jtimberman 14 years ago
parent
commit
aad935f968
3 changed files with 37 additions and 5 deletions
  1. 3 0
      README.md
  2. 33 4
      recipes/rails.rb
  3. 1 1
      recipes/unicorn.rb

+ 3 - 0
README.md

@@ -58,6 +58,9 @@ Using the node's `run_state` that contains the current application in the search
 
 This recipe can be used on nodes that are going to run the application, or on nodes that need to have the application code checkout available such as supporting utility nodes or a configured load balancer that needs static assets stored in the application repository.
 
+For Gem Bundler: include `bundler` or `bundler08` in the gems list.  `bundle install` or `gem bundle` will be run before migrations.
+For config.gem in environment: `rake gems:install RAILS_ENV=<node environment>` will be run when a Gem Bundler command is not.
+
 unicorn
 -------
 

+ 33 - 4
recipes/rails.rb

@@ -169,16 +169,45 @@ deploy_revision app['id'] do
   user app['owner']
   group app['group']
   deploy_to app['deploy_to']
+  environment 'RAILS_ENV' => node.app_environment
   action app['force'][node.app_environment] ? :force_deploy : :deploy
   ssh_wrapper "#{app['deploy_to']}/deploy-ssh-wrapper" if app['deploy_key']
+
+  before_migrate do
+    if app['gems'].has_key?('bundler')
+      execute "bundle install" do
+        ignore_failure true
+        cwd release_path
+      end
+    elsif app['gems'].has_key?('bundler08')
+      execute "gem bundle" do
+        ignore_failure true
+        cwd release_path
+      end
+
+    elsif node.app_environment && app['databases'].has_key?(node.app_environment)
+      # chef runs before_migrate, then symlink_before_migrate symlinks, then migrations,
+      # yet our before_migrate needs database.yml to exist (and must complete before
+      # migrations).
+      #
+      # maybe worth doing run_symlinks_before_migrate before before_migrate callbacks,
+      # or an add'l callback.
+      execute "(ln -s ../../../shared/database.yml config/database.yml && rake gems:install); rm config/database.yml" do
+        ignore_failure true
+        cwd release_path
+      end
+    end
+  end
+
+  symlink_before_migrate({
+    "database.yml" => "config/database.yml",
+    "memcached.yml" => "config/memcached.yml"
+  })
+
   if app['migrate'][node.app_environment] && node[:apps][app['id']][node.app_environment][:run_migrations]
     migrate true
     migration_command "rake db:migrate"
   else
     migrate false
   end
-  symlink_before_migrate({
-    "database.yml" => "config/database.yml",
-    "memcached.yml" => "config/memcached.yml"
-  })
 end

+ 1 - 1
recipes/unicorn.rb

@@ -23,7 +23,7 @@ include_recipe "unicorn"
 
 node.default[:unicorn][:worker_timeout] = 60
 node.default[:unicorn][:preload_app] = false
-node.default[:unicorn][:worker_processes] = node[:cpu][:total].to_i * 4 
+node.default[:unicorn][:worker_processes] = [node[:cpu][:total].to_i * 4, 8].min
 node.default[:unicorn][:preload_app] = false
 node.default[:unicorn][:before_fork] = 'sleep 1' 
 node.default[:unicorn][:port] = '8080'