Skip to content

Instantly share code, notes, and snippets.

@jeremy2
Created March 6, 2012 23:17
Show Gist options
  • Save jeremy2/1989695 to your computer and use it in GitHub Desktop.
Save jeremy2/1989695 to your computer and use it in GitHub Desktop.

Revisions

  1. jeremy2 revised this gist Aug 1, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion database.yml.erb
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    #
    # This file should be in .../cookbooks/database/templates/default/databases.yml.erb
    # This file should be in .../cookbooks/database/templates/default/database.yml.erb
    #

    <%= @environment %>:
  2. jeremy2 created this gist Mar 6, 2012.
    11 changes: 11 additions & 0 deletions database.yml.erb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    #
    # This file should be in .../cookbooks/database/templates/default/databases.yml.erb
    #

    <%= @environment %>:
    adapter: <%= @adapter %>
    database: <%= @database %>
    username: <%= @username %>
    password: <%= @password %>
    host: <%= @host %>
    reconnect: true
    47 changes: 47 additions & 0 deletions default.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,47 @@
    #
    # 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