部署时我需要相对符号链接而不是绝对符号链接。
我认为需要覆盖的树任务是。
Rake::Task["deploy:symlink:linked_dirs"]
Rake::Task["deploy:symlink:linked_files"]
Rake::Task["deploy:symlink:release"]
我想要的是我可以放入deploy.rb的DSL,所以当我部署创建的链接时都是相对的。
答案 0 :(得分:3)
您可以在deploy.rb中使用它来覆盖默认行为
## Use relative path instead of absolute
Rake::Task["deploy:symlink:linked_dirs"].clear
Rake::Task["deploy:symlink:linked_files"].clear
Rake::Task["deploy:symlink:release"].clear
namespace :deploy do
namespace :symlink do
desc 'Symlink release to current'
task :release do
on release_roles :all do
tmp_current_path = release_path.parent.join(current_path.basename)
execute :ln, '-s', release_path.relative_path_from(current_path.dirname), tmp_current_path
execute :mv, tmp_current_path, current_path.parent
end
end
desc 'Symlink files and directories from shared to release'
task :shared do
invoke 'deploy:symlink:linked_files'
invoke 'deploy:symlink:linked_dirs'
end
desc 'Symlink linked directories'
task :linked_dirs do
next unless any? :linked_dirs
on release_roles :all do
execute :mkdir, '-p', linked_dir_parents(release_path)
fetch(:linked_dirs).each do |dir|
target = release_path.join(dir)
source = shared_path.join(dir)
unless test "[ -L #{target} ]"
if test "[ -d #{target} ]"
execute :rm, '-rf', target
end
execute :ln, '-s', source.relative_path_from(target.dirname), target
end
end
end
end
desc 'Symlink linked files'
task :linked_files do
next unless any? :linked_files
on release_roles :all do
execute :mkdir, '-p', linked_file_dirs(release_path)
fetch(:linked_files).each do |file|
target = release_path.join(file)
source = shared_path.join(file)
unless test "[ -L #{target} ]"
if test "[ -f #{target} ]"
execute :rm, target
end
execute :ln, '-s', source.relative_path_from(target.dirname), target
end
end
end
end
end
end