Skip to content
This repository has been archived by the owner on Nov 23, 2017. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jtimberman committed May 21, 2011
1 parent 802de90 commit 93aedac
Show file tree
Hide file tree
Showing 19 changed files with 91 additions and 146 deletions.
18 changes: 9 additions & 9 deletions application/recipes/django.rb
@@ -1,6 +1,6 @@
#
# Cookbook Name:: application
# Recipe:: wsgi
# Recipe:: django
#
# Copyright 2011, Opscode, Inc.
#
Expand All @@ -26,7 +26,7 @@
# 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'
Expand Down Expand Up @@ -107,7 +107,7 @@
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]
Expand All @@ -130,7 +130,7 @@
mode "644"
variables(
:host => dbm['fqdn'],
:database => app['databases'][node.app_environment],
:database => app['databases'][node.chef_environment],
:django_version => django_version
)
end
Expand All @@ -141,12 +141,12 @@

## 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([])
Expand All @@ -155,8 +155,8 @@
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
Expand All @@ -174,7 +174,7 @@
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
Expand Down
18 changes: 9 additions & 9 deletions application/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.
Expand All @@ -24,7 +24,7 @@
# 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']
Expand Down Expand Up @@ -75,7 +75,7 @@
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]
Expand All @@ -92,17 +92,17 @@
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
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
2 changes: 1 addition & 1 deletion application/recipes/passenger_apache2.rb
Expand Up @@ -37,7 +37,7 @@
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"))
Expand Down
12 changes: 6 additions & 6 deletions application/recipes/php.rb
Expand Up @@ -26,7 +26,7 @@
# 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'
Expand Down Expand Up @@ -98,7 +98,7 @@
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]
Expand All @@ -116,7 +116,7 @@
variables(
:path => "#{app['deploy_to']}/current",
:host => dbm['fqdn'],
:database => app['databases'][node['app_environment']],
:database => app['databases'][node.chef_environment],
:app => app
)
end
Expand All @@ -127,12 +127,12 @@

## 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([])
Expand All @@ -141,4 +141,4 @@
symlink_before_migrate({
local_settings_file_name => local_settings_full_path
})
end
end
39 changes: 13 additions & 26 deletions application/recipes/rails.rb
Expand Up @@ -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.
Expand All @@ -24,13 +24,7 @@
# 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']
Expand All @@ -45,16 +39,9 @@
## 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
Expand Down Expand Up @@ -116,7 +103,7 @@
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]
Expand All @@ -141,7 +128,7 @@
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
Expand All @@ -161,13 +148,13 @@

## 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
Expand All @@ -176,7 +163,7 @@
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
Expand All @@ -186,7 +173,7 @@
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).
Expand All @@ -205,7 +192,7 @@
"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
Expand Down
2 changes: 1 addition & 1 deletion application/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'] %>"
Expand Down
2 changes: 1 addition & 1 deletion application/templates/default/sv-unicorn-run.erb
Expand Up @@ -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

4 changes: 2 additions & 2 deletions database/recipes/ebs_backup.rb
Expand Up @@ -35,7 +35,7 @@
db_master_role = app["database_master_role"]
end

ebs_info = Chef::DataBagItem.load(:aws, "ebs_#{db_master_role}_#{node['app_environment']}")
ebs_info = Chef::DataBagItem.load(:aws, "ebs_#{db_master_role}_#{node.chef_environment}")

gem_package "dbi"
gem_package "dbd-mysql"
Expand Down Expand Up @@ -78,7 +78,7 @@
end
end

if db_type == "master" && node['app_environment'] == "production"
if db_type == "master" && node.chef_environment == "production"
template "/etc/cron.d/db-backup" do
source "ebs-backup-cron.erb"
owner "root"
Expand Down
22 changes: 11 additions & 11 deletions database/recipes/ebs_volume.rb
Expand Up @@ -44,8 +44,8 @@
if (app["database_master_role"] & node.run_list.roles).length == 1 || (app["database_slave_role"] & node.run_list.roles).length == 1
master_role = app["database_master_role"]
slave_role = app["database_slave_role"]
root_pw = app["mysql_root_password"][node.app_environment]
snapshots_to_keep = app["snapshots_to_keep"][node.app_environment]
root_pw = app["mysql_root_password"][node.chef_environment]
snapshots_to_keep = app["snapshots_to_keep"][node.chef_environment]

if (master_role & node.run_list.roles).length == 1
db_type = "master"
Expand All @@ -60,27 +60,27 @@
end

begin
ebs_info = Chef::DataBagItem.load(:aws, "ebs_#{db_role}_#{node[:app_environment]}")
ebs_info = Chef::DataBagItem.load(:aws, "ebs_#{db_role}_#{node.chef_environment}")
Chef::Log.info("Loaded #{ebs_info['volume_id']} from DataBagItem aws[#{ebs_info['id']}]")
rescue
Chef::Log.warn("Could not find the 'ebs_#{db_role}_#{node[:app_environment]}' item in the 'aws' data bag")
Chef::Log.warn("Could not find the 'ebs_#{db_role}_#{node.chef_environment}' item in the 'aws' data bag")
ebs_info = Hash.new
end

begin
master_info = Chef::DataBagItem.load(:aws, "ebs_#{master_role}_#{node.app_environment}")
master_info = Chef::DataBagItem.load(:aws, "ebs_#{master_role}_#{node.chef_environment}")
Chef::Log.info "Loaded #{master_info['volume_id']} from DataBagItem aws[#{master_info['id']}]"
rescue
Chef::Application.fatal! "Could not load replication masters snapshot details", -41 if db_type == "slave"
end

ruby_block "store_#{db_role}_#{node[:app_environment]}_volid" do
ruby_block "store_#{db_role}_#{node.chef_environment}_volid" do
block do
ebs_vol_id = node[:aws][:ebs_volume]["#{db_role}_#{node[:app_environment]}"][:volume_id]
ebs_vol_id = node[:aws][:ebs_volume]["#{db_role}_#{node.chef_environment}"][:volume_id]

unless ebs_info['volume_id']
item = {
"id" => "ebs_#{db_role}_#{node[:app_environment]}",
"id" => "ebs_#{db_role}_#{node.chef_environment}",
"volume_id" => ebs_vol_id
}
Chef::Log.info "Storing volume_id #{item.inspect}"
Expand All @@ -94,7 +94,7 @@
action :nothing
end

aws_ebs_volume "#{db_role}_#{node[:app_environment]}" do
aws_ebs_volume "#{db_role}_#{node.chef_environment}" do
aws_access_key aws['aws_access_key_id']
aws_secret_access_key aws['aws_secret_access_key']
size 50
Expand All @@ -111,7 +111,7 @@
else
action [ :create, :attach ]
end
notifies :create, resources(:ruby_block => "store_#{db_role}_#{node[:app_environment]}_volid")
notifies :create, resources(:ruby_block => "store_#{db_role}_#{node.chef_environment}_volid")
when "slave"
if master_info['volume_id']
snapshot_id master_info['volume_id']
Expand Down Expand Up @@ -141,7 +141,7 @@
'db_snapshot' => {
'ebs_vol_dev' => node.mysql.ec2_path,
'db_role' => db_role,
'app_environment' => node.app_environment,
'app_environment' => node.chef_environment,
'username' => 'root',
'password' => root_pw,
'aws_access_key_id' => aws['aws_access_key_id'],
Expand Down

0 comments on commit 93aedac

Please sign in to comment.