Facilitate callbacks early in the deploy process #5

Closed
wants to merge 2 commits into
from
View
53 lib/railsless-deploy.rb
@@ -151,6 +151,7 @@ def try_runner(*args)
task, which handles the cold start specifically.
DESC
task :default do
+ logger.debug "Beginning railsless-deploy task - deploy:default"
update
end
@@ -167,6 +168,7 @@ def try_runner(*args)
will not destroy any deployed revisions or data.
DESC
task :setup, :except => { :no_release => true } do
+ logger.debug "Beginning railsless-deploy task - deploy:setup"
dirs = [deploy_to, releases_path, shared_path]
dirs += shared_children.map { |d| File.join(shared_path, d) }
run "#{try_sudo} mkdir -p #{dirs.join(' ')} && #{try_sudo} chmod g+w #{dirs.join(' ')}"
@@ -181,6 +183,7 @@ def try_runner(*args)
handy if you want to deploy, but not immediately restart your application.
DESC
task :update do
+ logger.debug "Beginning railsless-deploy task - deploy:update"
transaction do
update_code
symlink
@@ -200,12 +203,46 @@ def try_runner(*args)
defaults to :checkout).
DESC
task :update_code, :except => { :no_release => true } do
+ logger.debug "Beginning railsless-deploy task - deploy:update_code"
on_rollback { run "rm -rf #{release_path}; true" }
- strategy.deploy!
+ transaction do
+ update_cache
+ compress_bundle
+ upload_bundle
+ decompress_bundle
+ end
finalize_update
end
desc <<-DESC
+ [internal] Updates the local cached copy of the code
+ DESC
+ task :update_cache, :except => { :no_release => true } do
+ strategy.update_cache!
+ end
+
+ desc <<-DESC
+ [internal] Creates a compressed bundle from the local code cache
+ DESC
+ task :compress_bundle, :except => { :no_release => true } do
+ strategy.compress_bundle!
+ end
+
+ desc <<-DESC
+ [internal] Uploads the compressed bundle to the target node
+ DESC
+ task :upload_bundle, :except => { :no_release => true } do
+ strategy.upload_bundle!
+ end
+
+ desc <<-DESC
+ [internal] Decompress the uploaded bundle on the target node
+ DESC
+ task :decompress_bundle, :except => { :no_release => true } do
+ strategy.decompress_bundle!
+ end
+
+ desc <<-DESC
[internal] Touches up the released code. This is called by update_code \
after the basic deploy finishes. It assumes a Rails project was deployed, \
so if you are deploying something else, you may want to override this \
@@ -221,6 +258,7 @@ def try_runner(*args)
set to true, which is the default.
DESC
task :finalize_update, :except => { :no_release => true } do
+ logger.debug "Beginning railsless-deploy task - deploy:finalize_update"
run "chmod -R g+w #{latest_release}" if fetch(:group_writable, true)
end
@@ -234,6 +272,7 @@ def try_runner(*args)
except `restart').
DESC
task :symlink, :except => { :no_release => true } do
+ logger.debug "Beginning railsless-deploy task - deploy:symlink"
on_rollback do
if previous_release
run "rm -f #{current_path}; ln -s #{previous_release} #{current_path}; true"
@@ -264,6 +303,7 @@ def try_runner(*args)
$ cap deploy:upload FILES='config/apache/*.conf'
DESC
task :upload, :except => { :no_release => true } do
+ logger.debug "Beginning railsless-deploy task - deploy:upload"
files = (ENV["FILES"] || "").split(",").map { |f| Dir[f.strip] }.flatten
abort "Please specify at least one file or directory to update (via the FILES environment variable)" if files.empty?
@@ -277,6 +317,7 @@ def try_runner(*args)
ever) need to be called directly.
DESC
task :revision, :except => { :no_release => true } do
+ logger.debug "Beginning railsless-deploy task - rollback:upload"
if previous_release
run "rm #{current_path}; ln -s #{previous_release} #{current_path}"
else
@@ -290,6 +331,7 @@ def try_runner(*args)
(if ever) need to be called directly.
DESC
task :cleanup, :except => { :no_release => true } do
+ logger.debug "Beginning railsless-deploy task - rollback:cleanup"
run "if [ `readlink #{current_path}` != #{current_release} ]; then rm -rf #{current_release}; fi"
end
@@ -299,6 +341,7 @@ def try_runner(*args)
current release will be removed from the servers.
DESC
task :code, :except => { :no_release => true } do
+ logger.debug "Beginning railsless-deploy task - rollback:code"
revision
cleanup
end
@@ -309,6 +352,7 @@ def try_runner(*args)
back where you were, on the previously deployed version.
DESC
task :default do
+ logger.debug "Beginning railsless-deploy task - rollback:default"
revision
cleanup
end
@@ -322,6 +366,7 @@ def try_runner(*args)
for your environment, set the :use_sudo variable to false instead.
DESC
task :cleanup, :except => { :no_release => true } do
+ logger.debug "Beginning railsless-deploy task - deploy:cleanup"
count = fetch(:keep_releases, 5).to_i
if count >= releases.length
logger.important "no old releases to clean up"
@@ -348,6 +393,7 @@ def try_runner(*args)
depend :remote, :directory, "/u/depot/files"
DESC
task :check, :except => { :no_release => true } do
+ logger.debug "Beginning railsless-deploy task - deploy:check"
dependencies = strategy.check!
other = fetch(:dependencies, {})
@@ -382,6 +428,7 @@ def try_runner(*args)
invoke `deploy:start' to fire up the application servers.
DESC
task :cold do
+ logger.debug "Beginning railsless-deploy task - deploy:cold"
update
end
@@ -392,6 +439,7 @@ def try_runner(*args)
not be supported on all SCM's.
DESC
task :diff, :except => { :no_release => true } do
+ logger.debug "Beginning railsless-deploy task - pending:diff"
system(source.local.diff(current_revision))
end
@@ -401,11 +449,12 @@ def try_runner(*args)
might not be supported on all SCM's.
DESC
task :default, :except => { :no_release => true } do
+ logger.debug "Beginning railsless-deploy task - pending:default"
from = source.next_revision(current_revision)
system(source.local.log(from))
end
end
end
-end # Capistrano::Configuration.instance(:must_exist).load do
+end # Capistrano::Configuration.instance(:must_exist).load do