Browse Source

Merge pull request #4 from andreacampi/COOK-1252

[COOK-1252] Add a :force_deploy action that maps onto the corresponding ...
Joshua Timberman 12 years ago
parent
commit
845fa3a89a
3 changed files with 47 additions and 8 deletions
  1. 2 1
      README.md
  2. 44 6
      providers/default.rb
  3. 1 1
      resources/default.rb

+ 2 - 1
README.md

@@ -64,7 +64,8 @@ Configuration of framework-specific aspects of the application are performed by
 
 # Actions
 
-- :deploy: deploy an application, including any necessary configuration, restarting the associated service if necessary.
+- :deploy: deploy an application, including any necessary configuration, restarting the associated service if necessary
+- :force_deploy: same as :deploy, but it will send a :force\_deploy action to the deploy resource, directing it to deploy the application even if the same revision is already deployed
 
 # Attribute Parameters
 

+ 44 - 6
providers/default.rb

@@ -21,15 +21,49 @@
 include Chef::Provider::ApplicationBase
 
 action :deploy do
-  # Alias to a variable so I can use in sub-resources
-  new_resource = @new_resource
-  app_provider = self
 
+  before_compile
+
+  before_deploy
+
+  run_deploy
+
+end
+
+action :force_deploy do
+
+  before_compile
+
+  before_deploy
+
+  run_deploy(true)
+
+end
+
+action :restart do
+
+  before_compile
+
+  run_actions_with_context(:before_restart, @run_context)
+
+  run_restart
+
+  run_actions_with_context(:after_restart, @run_context)
+
+  @new_resource.updated_by_last_action(true)
+
+end
+
+protected
+
+def before_compile
   new_resource.sub_resources.each do |resource|
     resource.application_provider self
     resource.run_action :before_compile
   end
+end
 
+def before_deploy
   new_resource.packages.each do |pkg,ver|
     package pkg do
       action :install
@@ -77,8 +111,15 @@ action :deploy do
       callback(:before_deploy, new_resource.before_deploy)
     end
   end
+end
+
+def run_deploy(force = false)
+  # Alias to a variable so I can use in sub-resources
+  new_resource = @new_resource
+  app_provider = self
 
   @deploy_resource = send(new_resource.strategy.to_sym, new_resource.name) do
+    action force ? :force_deploy : :deploy
     scm_provider new_resource.scm_provider
     revision new_resource.revision
     repository new_resource.repository
@@ -126,11 +167,8 @@ action :deploy do
       app_provider.send(:run_actions_with_context, :after_restart, @run_context)
     end
   end
-
 end
 
-protected
-
 def run_actions_with_context(action, context)
   new_resource.sub_resources.each do |resource|
     saved_run_context = resource.instance_variable_get :@run_context

+ 1 - 1
resources/default.rb

@@ -28,7 +28,7 @@ def initialize(*args)
   @sub_resources = []
 end
 
-actions :deploy
+actions :deploy, :force_deploy
 
 attribute :name, :kind_of => String, :name_attribute => true
 attribute :environment_name, :kind_of => String, :default => (node.chef_environment =~ /_default/ ? "production" : node.chef_environment)