Created
March 6, 2012 23:17
-
-
Save jeremy2/1989695 to your computer and use it in GitHub Desktop.
Engine Yard custom Chef Recipe for generating database.yml configuration file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# This file should be in .../cookbooks/database/templates/default/database.yml.erb | |
# | |
<%= @environment %>: | |
adapter: <%= @adapter %> | |
database: <%= @database %> | |
username: <%= @username %> | |
password: <%= @password %> | |
host: <%= @host %> | |
reconnect: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Cookbook Name: database | |
# Recipe: default | |
# | |
# Description: | |
# Configure application servers to use mysql2 adapter for the database.yml config. | |
# All parameters except the adapter are pulled from the EY node JSON element. See | |
# http://docs.engineyard.com/use-deploy-hooks-with-engine-yard-cloud.html for an | |
# example of the node JSON object. This object is also used for by deploy hooks | |
# at Engine Yard. | |
# | |
# This file should be in .../cookbooks/database/recipes/default.rb | |
# | |
# | |
# Q: Why do we need this custom recipe? | |
# | |
# A: We needed to generate our own database.yml file because Engine Yard's default | |
# database.yml file generator always generates a config file that uses the mysql | |
# adapter for Rails 2 apps and always uses the mysql2 adapter for Rails 3 apps. | |
# | |
# In our case we needed to use the mysql2 adapter with our existing Rails 2 app. | |
# | |
# Apps using a replicated DB setup on EY may also need a custom Chef recipe to | |
# generate a database.yml | |
# | |
if ['solo', 'app_master', 'app', 'util'].include?(node[:instance_role]) | |
# for each application | |
node[:engineyard][:environment][:apps].each do |app| | |
# create new database.yml | |
template "/data/#{app[:name]}/shared/config/database.yml" do | |
source 'database.yml.erb' | |
owner node[:users][0][:username] | |
group node[:users][0][:username] | |
mode 0644 | |
variables({ | |
:environment => node[:environment][:framework_env], | |
:adapter => 'mysql2', | |
:database => app[:database_name], | |
:username => node[:users][0][:username], | |
:password => node[:users][0][:password], | |
:host => node[:db_host] | |
}) | |
end | |
end | |
end |
Thanks Josh.
I'm glad you found the gist useful and I appreciate the correction.
I updated the gist.
…On Tue, Jul 31, 2012 at 4:09 PM, joshuapinter ***@***.*** wrote:
Thanks for writing and sharing this. Exactly what I needed.
Little typo I found in the database.yml.erb snippet:
`es/default/databases.yml.erb` should be `es/default/database.yml.erb`
---
Reply to this email directly or view it on GitHub:
https://gist.github.com/1989695
+1 on the useful front, we needed a custom pool size for Sidekiq. Many thanks!
+1 Helped me for Sidekiq as well. I proposed EY to add it to their knowledge base.
Thanks a lot!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for writing and sharing this. Exactly what I needed.
Little typo I found in the database.yml.erb snippet:
default/databases.yml.erb
should bedefault/database.yml.erb