Browse Source

recipe tweaks for rails quick start guide

jtimberman 13 years ago
parent
commit
10f8961bf9
3 changed files with 42 additions and 7 deletions
  1. 30 5
      README.md
  2. 1 1
      metadata.rb
  3. 11 1
      recipes/rails.rb

+ 30 - 5
README.md

@@ -39,8 +39,8 @@ Searches the `apps` data bag and checks that a server role in the app exists on
 
 See below regarding the application data bag structure.
 
-passenger_apache2
------------------
+`passenger_apache2`
+-------------------
 
 Requires `apache2` and `passenger_apache2` cookbooks. The `recipe[apache2]` entry should come before `recipe[application]` in the run list.
 
@@ -59,8 +59,33 @@ Using the node's `run_state` that contains the current application in the search
 This recipe can be used on nodes that are going to run the application, or on nodes that need to have the application code checkout available such as supporting utility nodes or a configured load balancer that needs static assets stored in the application repository.
 
 For Gem Bundler: include `bundler` or `bundler08` in the gems list.  `bundle install` or `gem bundle` will be run before migrations.
+
 For config.gem in environment: `rake gems:install RAILS_ENV=<node environment>` will be run when a Gem Bundler command is not.
 
+In order to manage running database migrations (rake db:migrate), you can use a role that sets the `run_migrations` attribute for the application (`my_app`, below) in the correct environment (production, below). Note the data bag item needs to have migrate set to true. See the data bag example below.
+
+    {
+      "name": "my_app_run_migrations",
+      "description": "Run db:migrate on demand for my_app",
+      "json_class": "Chef::Role",
+      "default_attributes": {
+      },
+      "override_attributes": {
+        "apps": {
+          "my_app": {
+            "production": {
+              "run_migrations": true
+            }
+          }
+        }
+      },
+      "chef_type": "role",
+      "run_list": [
+      ]
+    }
+
+Simply apply this role to the node's run list when it is time to run migrations, and the recipe will remove the role when done.
+
 unicorn
 -------
 
@@ -79,8 +104,8 @@ passenger-nginx
 
 Builds passenger as an nginx module, drops off the configuration file and sets up the site to run the application under nginx with passenger. Does not deploy the code automatically.
 
-rails_nginx_ree_passenger
--------------------------
+`rails_nginx_ree_passenger`
+---------------------------
 
 Sets up the application stack with Ruby Enterprise Edition, Nginx and Passenger.
 
@@ -197,7 +222,7 @@ To use the application cookbook, we recommend creating a role named after the ap
       }
     }
 
-Also recommended is a site-cookbook named after the application, e.g. `my_app`, for additional application specific setup such as other config files for queues, search engines and other components of your application. The `my_app` recipe can be used in the run list of the role, if it includes the `application` recipe.
+Also recommended is a cookbook named after the application, e.g. `my_app`, for additional application specific setup such as other config files for queues, search engines and other components of your application. The `my_app` recipe can be used in the run list of the role, if it includes the `application` recipe.
 
 You should also have a role for the environment(s) you wish to use this cookbook. Similar to the role above, create the Ruby DSL file in chef-repo, or create with knife directly.
 

+ 1 - 1
metadata.rb

@@ -3,7 +3,7 @@ maintainer_email "cookbooks@opscode.com"
 license          "Apache 2.0"
 description      "Deploys and configures a variety of applications defined from databag 'apps'"
 long_description  IO.read(File.join(File.dirname(__FILE__), 'README.md'))
-version          "0.6.3"
+version          "0.7.0"
 recipe           "application", "Loads application databags and selects recipes to use"
 recipe           "application::passenger-nginx", "Installs Ruby Enterprise with Passenger under Nginx"
 recipe           "application::passenger_apache2", "Sets up a deployed Rails application as a Passenger virtual host in Apache2"

+ 11 - 1
recipes/rails.rb

@@ -203,8 +203,18 @@ deploy_revision app['id'] do
 
   if app['migrate'][node.app_environment] && node[:apps][app['id']][node.app_environment][:run_migrations]
     migrate true
-    migration_command "rake db:migrate"
+    migration_command app['migration_command'] || "rake db:migrate"
   else
     migrate false
   end
+  before_symlink do
+    ruby_block "remove_run_migrations" do
+      block do
+        if node.role?("#{app['id']}_run_migrations")
+          Chef::Log.info("Migrations were run, removing role[#{app['id']}_run_migrations]")
+          node.run_list.remove("role[#{app['id']}_run_migrations]")
+        end
+      end
+    end
+  end
 end