Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[COOK-1252] Add a :force_deploy action that maps onto the correspondi…

…ng action of the deploy resource.
  • Loading branch information...
commit 9b8ebb10519b75446bbc1160af3caf5de59a4f47 1 parent c300569
@andreacampi andreacampi authored
Showing with 47 additions and 8 deletions.
  1. +2 −1  README.md
  2. +44 −6 providers/default.rb
  3. +1 −1  resources/default.rb
View
3  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
View
50 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 @@
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 @@
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
View
2  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)

3 comments on commit 9b8ebb1

@anentropic

run_restart method called on line #49 doesn't exist anywhere as far as I can tell...?

@andreacampi

Oops, good catch!

Actually, the :restart action wasn't supposed to be in this commit, although it's a good idea in general. It's not in the documentation either.
I will come up with a clean patch and send a pull request. Can you file a bug on Jira in the meantime?

Also, if you need to get this working now, run_restart is just lines 139 to 152: https://github.com/opscode-cookbooks/application/blob/master/providers/default.rb#L139

@anentropic

I'm using the code as-is above successfully at the moment. I was puzzled because I couldn't find run_restart yet it didn't seem to raise any errors

Please sign in to comment.
Something went wrong with that request. Please try again.