Browse Source

make the _default chef_environment look like production rails env

Seth Chisamore 13 years ago
parent
commit
e801ba5b01

+ 7 - 2
recipes/rails.rb

@@ -19,6 +19,10 @@
 
 app = node.run_state[:current_app]
 
+# make the _default chef_environment look like the Rails production environment
+rails_env = (node.chef_environment =~ /_default/ ? "production" : node.chef_environment)
+node.run_state[:rails_env] = rails_env
+
 ###
 # You really most likely don't want to run this recipe from here - let the
 # default application recipe work it's mojo for you.
@@ -119,7 +123,8 @@ if app["database_master_role"]
       mode "644"
       variables(
         :host => dbm['fqdn'],
-        :databases => app['databases']
+        :databases => app['databases'],
+        :rails_env => rails_env
       )
     end
   else
@@ -153,7 +158,7 @@ deploy_revision app['id'] do
   user app['owner']
   group app['group']
   deploy_to app['deploy_to']
-  environment 'RAILS_ENV' => node.chef_environment
+  environment 'RAILS_ENV' => rails_env
   action app['force'][node.chef_environment] ? :force_deploy : :deploy
   ssh_wrapper "#{app['deploy_to']}/deploy-ssh-wrapper" if app['deploy_key']
   shallow_clone true

+ 1 - 0
recipes/unicorn.rb

@@ -43,6 +43,7 @@ runit_service app['id'] do
   cookbook 'application'
   options(
     :app => app,
+    :rails_env => node.run_state[:rails_env] || node.chef_environment,
     :smells_like_rack => ::File.exists?(::File.join(app['deploy_to'], "current", "config.ru"))
   )
   run_restart false

+ 1 - 1
templates/default/database.yml.erb

@@ -1,5 +1,5 @@
 <%- @databases.each do |env, db| %>
-<%= env %>:
+<%= (env =~ /_default/ ? "production" : env) %>:
   adapter: <%= db['adapter'] %>
   host: <%= @host %>
   database: <%= db['database'] %>

+ 1 - 1
templates/default/sv-unicorn-run.erb

@@ -3,5 +3,5 @@
 cd <%= @options[:app]['deploy_to'] %>/current
 
 exec 2>&1
-exec chpst -u <%= @options[:app]["owner"] %>:<%= @options[:app]["group"] %> <%= @options[:smells_like_rack] ? 'unicorn' : 'unicorn_rails' %> -E <%= node.chef_environment %> -c /etc/unicorn/<%= @options[:app]['id'] %>.rb
+exec chpst -u <%= @options[:app]["owner"] %>:<%= @options[:app]["group"] %> <%= @options[:smells_like_rack] ? 'unicorn' : 'unicorn_rails' %> -E <%= @options[:rails_env] %> -c /etc/unicorn/<%= @options[:app]['id'] %>.rb