Browse Source

use chef 0.10.0 environments

* Replaces all occurrances of node app_environment attribute with
node.chef_environment in recipes.
* Still need to update readmes for using environments instead of roles.
jtimberman 13 years ago
parent
commit
cdd11fbd7a

+ 9 - 9
recipes/django.rb

@@ -1,6 +1,6 @@
 #
 # Cookbook Name:: application
-# Recipe:: wsgi
+# Recipe:: django
 #
 # Copyright 2011, Opscode, Inc.
 #
@@ -26,7 +26,7 @@ include_recipe "python"
 # default application recipe work it's mojo for you.
 ###
 
-node.default[:apps][app['id']][node.app_environment][:run_migrations] = false
+node.default[:apps][app['id']][node.chef_environment][:run_migrations] = false
 
 # the Django split-settings file name varies from project to project...+1 for standardization
 local_settings_full_path = app['local_settings_file'] || 'settings_local.py'
@@ -107,7 +107,7 @@ if app["database_master_role"]
     dbm = node
   else
   # Find the database master
-    results = search(:node, "run_list:role\\[#{app["database_master_role"][0]}\\] AND app_environment:#{node[:app_environment]}", nil, 0, 1)
+    results = search(:node, "run_list:role\\[#{app["database_master_role"][0]}\\] AND chef_environment:#{node.chef_environment}", nil, 0, 1)
     rows = results[0]
     if rows.length == 1
       dbm = rows[0]
@@ -130,7 +130,7 @@ if app["database_master_role"]
       mode "644"
       variables(
         :host => dbm['fqdn'],
-        :database => app['databases'][node.app_environment],
+        :database => app['databases'][node.chef_environment],
         :django_version => django_version
       )
     end
@@ -141,12 +141,12 @@ end
 
 ## Then, deploy
 deploy_revision app['id'] do
-  revision app['revision'][node.app_environment]
+  revision app['revision'][node.chef_environment]
   repository app['repository']
   user app['owner']
   group app['group']
   deploy_to app['deploy_to']
-  action app['force'][node.app_environment] ? :force_deploy : :deploy
+  action app['force'][node.chef_environment] ? :force_deploy : :deploy
   ssh_wrapper "#{app['deploy_to']}/deploy-ssh-wrapper" if app['deploy_key']
   shallow_clone true
   purge_before_symlink([])
@@ -155,8 +155,8 @@ deploy_revision app['id'] do
   before_migrate do
     requirements_file = nil
     # look for requirements.txt files in common locations
-    if ::File.exists?(::File.join(release_path, "requirements", "#{node[:app_environment]}.txt"))
-      requirements_file = ::File.join(release_path, "requirements", "#{node[:app_environment]}.txt")
+    if ::File.exists?(::File.join(release_path, "requirements", "#{node[:chef_environment]}.txt"))
+      requirements_file = ::File.join(release_path, "requirements", "#{node.chef_environment}.txt")
     elsif ::File.exists?(::File.join(release_path, "requirements.txt"))
       requirements_file = ::File.join(release_path, "requirements.txt")
     end
@@ -174,7 +174,7 @@ deploy_revision app['id'] do
     local_settings_file_name => local_settings_full_path
   })
 
-  if app['migrate'][node.app_environment] && node[:apps][app['id']][node.app_environment][:run_migrations]
+  if app['migrate'][node.chef_environment] && node[:apps][app['id']][node.chef_environment][:run_migrations]
     migrate true
     migration_command app['migration_command'] || "#{::File.join(ve.path, "bin", "python")} manage.py migrate"
   else

+ 9 - 9
recipes/java_webapp.rb

@@ -1,8 +1,8 @@
 #
 # Cookbook Name:: application
-# Recipe:: java
+# Recipe:: java_webapp
 #
-# Copyright 2010, Opscode, Inc.
+# Copyright 2010-2011, Opscode, Inc.
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -24,7 +24,7 @@ app = node.run_state[:current_app]
 # default application recipe work it's mojo for you.
 ###
 
-node.default[:apps][app['id']][node.app_environment][:run_migrations] = false
+node.default[:apps][app['id']][node.chef_environment][:run_migrations] = false
 
 ## First, install any application specific packages
 if app['packages']
@@ -75,7 +75,7 @@ if app["database_master_role"]
     dbm = node
   else
   # Find the database master
-    results = search(:node, "run_list:role\\[#{app["database_master_role"][0]}\\] AND app_environment:#{node[:app_environment]}", nil, 0, 1)
+    results = search(:node, "run_list:role\\[#{app["database_master_role"][0]}\\] AND chef_environment:#{node.chef_environment}", nil, 0, 1)
     rows = results[0]
     if rows.length == 1
       dbm = rows[0]
@@ -92,8 +92,8 @@ if app["database_master_role"]
       variables(
         :host => dbm['fqdn'],
         :app => app['id'],
-        :database => app['databases'][node.app_environment],
-        :war => "#{app['deploy_to']}/releases/#{app['war'][node.app_environment]['checksum']}.war"
+        :database => app['databases'][node.chef_environment],
+        :war => "#{app['deploy_to']}/releases/#{app['war'][node.chef_environment]['checksum']}.war"
       )
     end
   end
@@ -101,8 +101,8 @@ end
 
 ## Then, deploy
 remote_file app['id'] do
-  path "#{app['deploy_to']}/releases/#{app['war'][node.app_environment]['checksum']}.war"
-  source app['war'][node.app_environment]['source']
+  path "#{app['deploy_to']}/releases/#{app['war'][node.chef_environment]['checksum']}.war"
+  source app['war'][node.chef_environment]['source']
   mode "0644"
-  checksum app['war'][node.app_environment]['checksum']
+  checksum app['war'][node.chef_environment]['checksum']
 end

+ 1 - 1
recipes/passenger_apache2.rb

@@ -37,7 +37,7 @@ web_app app['id'] do
   server_name "#{app['id']}.#{node[:domain]}"
   server_aliases server_aliases
   log_dir node[:apache][:log_dir]
-  rails_env node.app_environment
+  rails_env node.chef_environment
 end
 
 if ::File.exists?(::File.join(app['deploy_to'], "current"))

+ 6 - 6
recipes/php.rb

@@ -26,7 +26,7 @@ include_recipe "php"
 # default application recipe work it's mojo for you.
 ###
 
-node.default['apps'][app['id']][node.app_environment]['run_migrations'] = false
+node.default['apps'][app['id']][node.chef_environment]['run_migrations'] = false
 
 # the PHP projects have no standard local settings file name..or path in the project
 local_settings_full_path = app['local_settings_file'] || 'LocalSettings.php'
@@ -98,7 +98,7 @@ if app["database_master_role"]
     dbm = node
   else
   # Find the database master
-    results = search(:node, "run_list:role\\[#{app['database_master_role'][0]}\\] AND app_environment:#{node['app_environment']}", nil, 0, 1)
+    results = search(:node, "run_list:role\\[#{app['database_master_role'][0]}\\] AND chef_environment:#{node.chef_environment}", nil, 0, 1)
     rows = results[0]
     if rows.length == 1
       dbm = rows[0]
@@ -116,7 +116,7 @@ if app["database_master_role"]
       variables(
         :path => "#{app['deploy_to']}/current",
         :host => dbm['fqdn'],
-        :database => app['databases'][node['app_environment']],
+        :database => app['databases'][node.chef_environment],
         :app => app
       )
     end
@@ -127,12 +127,12 @@ end
 
 ## Then, deploy
 deploy_revision app['id'] do
-  revision app['revision'][node.app_environment]
+  revision app['revision'][node.chef_environment]
   repository app['repository']
   user app['owner']
   group app['group']
   deploy_to app['deploy_to']
-  action app['force'][node.app_environment] ? :force_deploy : :deploy
+  action app['force'][node.chef_environment] ? :force_deploy : :deploy
   ssh_wrapper "#{app['deploy_to']}/deploy-ssh-wrapper" if app['deploy_key']
   shallow_clone true
   purge_before_symlink([])
@@ -141,4 +141,4 @@ deploy_revision app['id'] do
   symlink_before_migrate({
     local_settings_file_name => local_settings_full_path
   })
-end
+end

+ 13 - 26
recipes/rails.rb

@@ -2,7 +2,7 @@
 # Cookbook Name:: application
 # Recipe:: rails
 #
-# Copyright 2009, Opscode, Inc.
+# Copyright 2009-2011, Opscode, Inc.
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -24,13 +24,7 @@ app = node.run_state[:current_app]
 # default application recipe work it's mojo for you.
 ###
 
-# Are we using REE?
-use_ree = false
-if node.run_state[:seen_recipes].has_key?("ruby_enterprise")
-  use_ree = true
-end
-
-node.default[:apps][app['id']][node.app_environment][:run_migrations] = false
+node.default[:apps][app['id']][node.chef_environment][:run_migrations] = false
 
 ## First, install any application specific packages
 if app['packages']
@@ -45,16 +39,9 @@ end
 ## Next, install any application specific gems
 if app['gems']
   app['gems'].each do |gem,ver|
-    if use_ree
-      ree_gem gem do
-        action :install
-        version ver if ver && ver.length > 0
-      end
-    else
-      gem_package gem do
-        action :install
-        version ver if ver && ver.length > 0
-      end
+    gem_package gem do
+      action :install
+      version ver if ver && ver.length > 0
     end
   end
 end
@@ -116,7 +103,7 @@ if app["database_master_role"]
     dbm = node
   else
   # Find the database master
-    results = search(:node, "run_list:role\\[#{app["database_master_role"][0]}\\] AND app_environment:#{node[:app_environment]}", nil, 0, 1)
+    results = search(:node, "run_list:role\\[#{app["database_master_role"][0]}\\] AND chef_environment:#{node.chef_environment}", nil, 0, 1)
     rows = results[0]
     if rows.length == 1
       dbm = rows[0]
@@ -141,7 +128,7 @@ if app["database_master_role"]
 end
 
 if app["memcached_role"]
-  results = search(:node, "role:#{app["memcached_role"][0]} AND app_environment:#{node[:app_environment]} NOT hostname:#{node[:hostname]}")
+  results = search(:node, "role:#{app["memcached_role"][0]} AND chef_environment:#{node.chef_environment} NOT hostname:#{node[:hostname]}")
   if results.length == 0
     if node.run_list.roles.include?(app["memcached_role"][0])
       results << node
@@ -161,13 +148,13 @@ end
 
 ## Then, deploy
 deploy_revision app['id'] do
-  revision app['revision'][node.app_environment]
+  revision app['revision'][node.chef_environment]
   repository app['repository']
   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
+  environment 'RAILS_ENV' => node.chef_environment
+  action app['force'][node.chef_environment] ? :force_deploy : :deploy
   ssh_wrapper "#{app['deploy_to']}/deploy-ssh-wrapper" if app['deploy_key']
   shallow_clone true
   before_migrate do
@@ -176,7 +163,7 @@ deploy_revision app['id'] do
         to "#{app['deploy_to']}/shared/vendor_bundle"
       end
       common_groups = %w{development test cucumber staging production}
-      execute "bundle install --deployment --without #{(common_groups -([node.app_environment])).join(' ')}" do
+      execute "bundle install --deployment --without #{(common_groups -([node.chef_environment])).join(' ')}" do
         ignore_failure true
         cwd release_path
       end
@@ -186,7 +173,7 @@ deploy_revision app['id'] do
         cwd release_path
       end
 
-    elsif node.app_environment && app['databases'].has_key?(node.app_environment)
+    elsif node.chef_environment && app['databases'].has_key?(node.chef_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).
@@ -205,7 +192,7 @@ deploy_revision app['id'] do
     "memcached.yml" => "config/memcached.yml"
   })
 
-  if app['migrate'][node.app_environment] && node[:apps][app['id']][node.app_environment][:run_migrations]
+  if app['migrate'][node.chef_environment] && node[:apps][app['id']][node.chef_environment][:run_migrations]
     migrate true
     migration_command app['migration_command'] || "rake db:migrate"
   else

+ 1 - 1
templates/default/context.xml.erb

@@ -1,6 +1,6 @@
 <Context docBase="<%= @war %>" path="/"
         debug="5" reloadable="true" crossContext="true" allowLinking="true">
-  <Environment name="appEnvironment" value="<%= node['app_environment'] %>"
+  <Environment name="appEnvironment" value="<%= node.chef_environment %>"
           type="java.lang.String" override="false"/>
   <Resource name="jdbc/<%= @app %>" auth="Container" type="javax.sql.DataSource"
                maxActive="<%= @database['max_active'] %>" maxIdle="<%= @database['max_idle'] %>" maxWait="<%= @database['max_wait'] %>"

+ 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[:app_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 <%= node.chef_environment %> -c /etc/unicorn/<%= @options[:app]['id'] %>.rb