Skip to content

Instantly share code, notes, and snippets.

@mudge
Created November 19, 2012 14:53
Show Gist options
  • Save mudge/4111082 to your computer and use it in GitHub Desktop.
Save mudge/4111082 to your computer and use it in GitHub Desktop.
Capistrano task to use relative symlinks instead of absolute.
require "pathname"
namespace :deploy do
task :create_symlink, :except => { :no_release => true } do
deploy_to_pathname = Pathname.new(deploy_to)
on_rollback do
if previous_release
previous_release_pathname = Pathname.new(previous_release)
relative_previous_release = previous_release_pathname.relative_path_from(deploy_to_pathname)
run "rm -f #{current_path}; ln -s #{relative_previous_release} #{current_path}; true"
else
logger.important "no previous release to rollback to, rollback of symlink skipped"
end
end
latest_release_pathname = Pathname.new(latest_release)
relative_latest_release = latest_release_pathname.relative_path_from(deploy_to_pathname)
run "rm -f #{current_path} && ln -s #{relative_latest_release} #{current_path}"
end
end
@andrefigueira
Copy link

A Capistrano 3 equivalent would be cool!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment