mirror of
https://github.com/capistrano/capistrano
synced 2023-03-27 23:21:18 -04:00
namespaces are great, but backwards-compatibility must trump niftiness from time to time
git-svn-id: http://svn.rubyonrails.org/rails/tools/capistrano@6466 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
68e6b64f8c
commit
09ad893c19
1 changed files with 61 additions and 63 deletions
|
@ -30,20 +30,24 @@ set(:revision) { source.head } unless exists?(:revision)
|
|||
# changes if you do decide to muck with these!
|
||||
# =========================================================================
|
||||
|
||||
set(:source) { Capistrano::Deploy::SCM.new(scm, self) }
|
||||
set(:real_revision) { source.query_revision(revision) { |cmd| `#{cmd}` } }
|
||||
set(:source) { Capistrano::Deploy::SCM.new(scm, self) }
|
||||
set(:real_revision) { source.query_revision(revision) { |cmd| `#{cmd}` } }
|
||||
|
||||
set(:strategy) { Capistrano::Deploy::Strategy.new(deploy_via, self) }
|
||||
set(:strategy) { Capistrano::Deploy::Strategy.new(deploy_via, self) }
|
||||
|
||||
set(:release_name) { Time.now.utc.strftime("%Y%m%d%H%M%S") }
|
||||
set(:releases_path) { File.join(deploy_to, "releases") }
|
||||
set(:shared_path) { File.join(deploy_to, "shared") }
|
||||
set(:current_path) { File.join(deploy_to, "current") }
|
||||
set(:release_path) { File.join(releases_path, release_name) }
|
||||
set(:release_name) { Time.now.utc.strftime("%Y%m%d%H%M%S") }
|
||||
set(:releases_path) { File.join(deploy_to, "releases") }
|
||||
set(:shared_path) { File.join(deploy_to, "shared") }
|
||||
set(:current_path) { File.join(deploy_to, "current") }
|
||||
set(:release_path) { File.join(releases_path, release_name) }
|
||||
|
||||
set(:releases) { capture("ls -x #{releases_path}").split.sort }
|
||||
set(:current_release) { File.join(releases_path, releases.last) }
|
||||
set(:previous_release) { File.join(releases_path, releases[-2]) }
|
||||
set(:releases) { capture("ls -x #{releases_path}").split.sort }
|
||||
set(:current_release) { File.join(releases_path, releases.last) }
|
||||
set(:previous_release) { File.join(releases_path, releases[-2]) }
|
||||
|
||||
set(:current_revision) { capture("cat #{current_path}/REVISION").chomp }
|
||||
set(:latest_revision) { capture("cat #{current_release}/REVISION").chomp }
|
||||
set(:previous_revision) { capture("cat #{previous_release}/REVISION").chomp }
|
||||
|
||||
namespace :deploy do
|
||||
desc "Deploys your project. This calls both `update' and `restart'. Note that \
|
||||
|
@ -51,7 +55,7 @@ this will generally only work for applications that have already been deployed \
|
|||
once. For a \"cold\" deploy, you'll want to take a look at the `cold_deploy' \
|
||||
task, which handles the cold start specifically."
|
||||
task :default do
|
||||
update.default
|
||||
update
|
||||
restart
|
||||
end
|
||||
|
||||
|
@ -71,19 +75,18 @@ not destroy any deployed revisions or data."
|
|||
run "umask 02 && mkdir -p #{dirs.join(' ')}"
|
||||
end
|
||||
|
||||
namespace :update do
|
||||
desc "Copies your project and updates the symlink. It does this in a transaction, \
|
||||
so that if either `update_code' or `symlink' fail, all changes made to the \
|
||||
remote servers will be rolled back, leaving your system in the same state it \
|
||||
was in before `update' was invoked. Usually, you will want to call `deploy' \
|
||||
instead of `update', but `update' can be handy if you want to deploy, but not \
|
||||
immediately restart your application."
|
||||
task :default do
|
||||
transaction do
|
||||
code
|
||||
symlink
|
||||
end
|
||||
task :update do
|
||||
transaction do
|
||||
update_code
|
||||
symlink
|
||||
end
|
||||
end
|
||||
|
||||
desc "Copies your project to the remote servers. This is the first stage \
|
||||
of any deployment; moving your updated code and assets to the deployment \
|
||||
|
@ -94,11 +97,11 @@ want to perform the `restart' task separately).
|
|||
You will need to make sure you set the :scm variable to the source control \
|
||||
software you are using (it defaults to :subversion), and the :deploy_via \
|
||||
variable to the strategy you want to use to deploy (it defaults to :checkout)."
|
||||
task :code, :except => { :no_release => true } do
|
||||
on_rollback { run "rm -rf #{release_path}; true" }
|
||||
strategy.deploy!
|
||||
finalize
|
||||
end
|
||||
task :update_code, :except => { :no_release => true } do
|
||||
on_rollback { run "rm -rf #{release_path}; true" }
|
||||
strategy.deploy!
|
||||
finalize_update
|
||||
end
|
||||
|
||||
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 \
|
||||
|
@ -111,20 +114,20 @@ to the shared directory for the log, system, and tmp/pids directories, and \
|
|||
will lastly touch all assets in public/images, public/stylesheets, and \
|
||||
public/javascripts so that the times are consistent (so that asset timestamping \
|
||||
works)."
|
||||
task :finalize, :except => { :no_release => true } do
|
||||
run "chmod -R g+w #{release_path}" if group_writable
|
||||
task :finalize_update, :except => { :no_release => true } do
|
||||
run "chmod -R g+w #{release_path}" if group_writable
|
||||
|
||||
run <<-CMD
|
||||
rm -rf #{release_path}/log #{release_path}/public/system #{release_path}/tmp/pids &&
|
||||
ln -s #{shared_path}/log #{release_path}/log &&
|
||||
ln -s #{shared_path}/system #{release_path}/public/system &&
|
||||
ln -s #{shared_path}pids #{release_path}/tmp/pids
|
||||
CMD
|
||||
run <<-CMD
|
||||
rm -rf #{release_path}/log #{release_path}/public/system #{release_path}/tmp/pids &&
|
||||
ln -s #{shared_path}/log #{release_path}/log &&
|
||||
ln -s #{shared_path}/system #{release_path}/public/system &&
|
||||
ln -s #{shared_path}pids #{release_path}/tmp/pids
|
||||
CMD
|
||||
|
||||
stamp = Time.now.utc.strftime("%Y%m%d%H%M.%S")
|
||||
asset_paths = %w(images stylesheets javascripts).map { |p| "#{release_path}/public/#{p}" }.join(" ")
|
||||
run "find #{asset_paths} -exec touch -t #{stamp} {} \\;; true", :env => { "TZ" => "UTC" }
|
||||
end
|
||||
stamp = Time.now.utc.strftime("%Y%m%d%H%M.%S")
|
||||
asset_paths = %w(images stylesheets javascripts).map { |p| "#{release_path}/public/#{p}" }.join(" ")
|
||||
run "find #{asset_paths} -exec touch -t #{stamp} {} \\;; true", :env => { "TZ" => "UTC" }
|
||||
end
|
||||
|
||||
desc "Updates the symlink to the deployed version. Capistrano works by putting \
|
||||
each new release of your application in its own directory. When you deploy a \
|
||||
|
@ -132,10 +135,10 @@ new version, this task's job is to update the `current' symlink to point at \
|
|||
the new version. You will rarely need to call this task directly; instead, use \
|
||||
the `deploy' task (which performs a complete deploy, including `restart') or \
|
||||
the 'update' task (which does everything except `restart')."
|
||||
task :symlink, :except => { :no_release => true } do
|
||||
on_rollback { run "rm -f #{current_path}; ln -s #{previous_release} #{current_path}; true" }
|
||||
run "rm -f #{current_path} && ln -s #{release_path} #{current_path}"
|
||||
end
|
||||
task :symlink, :except => { :no_release => true } do
|
||||
on_rollback { run "rm -f #{current_path}; ln -s #{previous_release} #{current_path}; true" }
|
||||
run "rm -f #{current_path} && ln -s #{release_path} #{current_path}"
|
||||
end
|
||||
|
||||
desc "Copy files to the currently deployed version. This is useful for updating \
|
||||
files piecemeal, such as when you need to quickly deploy only a single file. \
|
||||
|
@ -148,19 +151,18 @@ comma-delimited list in the FILES environment variable. All directories will \
|
|||
be processed recursively, with all files being pushed to the deployment \
|
||||
servers. Any file or directory starting with a '.' character will be ignored.
|
||||
|
||||
$ cap deploy:update:inplace FILES=templates,controller.rb"
|
||||
task :inplace, :except => { :no_release => true } do
|
||||
files = (ENV["FILES"] || "").
|
||||
split(",").
|
||||
map { |f| f.strip!; File.directory?(f) ? Dir["#{f}/**/*"] : f }.
|
||||
flatten.
|
||||
reject { |f| File.directory?(f) || File.basename(f)[0] == ?. }
|
||||
$ cap deploy:update_files FILES=templates,controller.rb"
|
||||
task :update_files, :except => { :no_release => true } do
|
||||
files = (ENV["FILES"] || "").
|
||||
split(",").
|
||||
map { |f| f.strip!; File.directory?(f) ? Dir["#{f}/**/*"] : f }.
|
||||
flatten.
|
||||
reject { |f| File.directory?(f) || File.basename(f)[0] == ?. }
|
||||
|
||||
abort "Please specify at least one file to update (via the FILES environment variable)" if files.empty?
|
||||
abort "Please specify at least one file to update (via the FILES environment variable)" if files.empty?
|
||||
|
||||
files.each do |file|
|
||||
put File.read(file), File.join(current_path, file)
|
||||
end
|
||||
files.each do |file|
|
||||
put File.read(file), File.join(current_path, file)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -175,26 +177,24 @@ you can indicate that restarts should use `run' instead by setting the \
|
|||
invoke_command "#{current_path}/script/process/reaper", :via => restart_via
|
||||
end
|
||||
|
||||
namespace :rollback do
|
||||
desc "Rolls back to the previously deployed version. The `current' symlink will \
|
||||
be updated to point at the previously deployed version, and then the current \
|
||||
release will be removed from the servers. You'll generally want to call \
|
||||
`rollback' instead, as it performs a `restart' as well."
|
||||
task :code, :except => { :no_release => true } do
|
||||
if releases.length < 2
|
||||
abort "could not rollback the code because there is no prior release"
|
||||
else
|
||||
run "rm #{current_path}; ln -s #{previous_release} #{current_path} && rm -rf #{current_release}"
|
||||
end
|
||||
task :rollback_code, :except => { :no_release => true } do
|
||||
if releases.length < 2
|
||||
abort "could not rollback the code because there is no prior release"
|
||||
else
|
||||
run "rm #{current_path}; ln -s #{previous_release} #{current_path} && rm -rf #{current_release}"
|
||||
end
|
||||
end
|
||||
|
||||
desc "Rolls back to a previous version and restarts. This is handy if you ever \
|
||||
discover that you've deployed a lemon; `cap rollback' and you're right back \
|
||||
where you were, on the previously deployed version."
|
||||
task :default do
|
||||
code
|
||||
restart
|
||||
end
|
||||
task :rollback do
|
||||
rollback_code
|
||||
restart
|
||||
end
|
||||
|
||||
namespace :pending do
|
||||
|
@ -202,7 +202,6 @@ desc "Displays the `diff' since your last deploy. This is useful if you want \
|
|||
to examine what changes are about to be deployed. Note that this might not be \
|
||||
supported on all SCM's."
|
||||
task :diff, :except => { :no_release => true } do
|
||||
current_revision = capture("cat #{current_path}/REVISION").chomp
|
||||
system(source.diff(current_revision))
|
||||
end
|
||||
|
||||
|
@ -210,7 +209,6 @@ desc "Displays the commits since your last deploy. This is good for a summary \
|
|||
of the changes that have occurred since the last deploy. Note that this might \
|
||||
not be supported on all SCM's."
|
||||
task :default, :except => { :no_release => true } do
|
||||
current_revision = capture("cat #{current_path}/REVISION").chomp
|
||||
system(source.log(current_revision))
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue