Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
59 lines (44 sloc) 1.62 KB
dep 'switch current repo', :current, :alt do
# Capistrano symlink - if we don't replace 'current' with 'alt', the symlink breaks
fix_capistrano_symlinks '~/current', true
# Blue-Green symlink
log_shell "Removing link ~/current", "rm ~/current"
log_shell "Creating link ~/current = " + current, "ln -s " + current + " ~/current"
# Capistrano symlink - if we don't replace 'alt' with 'current', the symlink breaks
fix_capistrano_symlinks '~/alt', false
# Blue-Green symlink
log_shell "Removing link ~/alt", "rm ~/alt"
log_shell "Creating link ~/alt= " + alt, "ln -s " + alt + " ~/alt"
end
def fix_capistrano_symlinks(base, is_current)
['current/log', 'current/tmp/pids', 'current/public/system', 'current/public/assets', 'current'].each do |symlink|
fix_capistrano_symlink(base, symlink, is_current)
end
end
def fix_capistrano_symlink(base, symlink, is_current)
new_link = ''
if is_current
new_link = shell("readlink #{base}/#{symlink}").sub('/current/', '/alt/')
else
new_link = shell("readlink #{base}/#{symlink}").sub('/alt/', '/current/')
end
log_shell "Removing link #{base}/#{symlink}", "rm #{base}/#{symlink}"
log_shell "Linking #{base}/#{symlink} to #{new_link}", "ln -s #{new_link} #{base}/#{symlink}"
end
dep 'switch.repo' do
def current
shell("readlink ~/current")
end
def is_blue?
!current.split('\n').grep(/blue/).empty?
end
if is_blue?
requires 'switch current repo'.with('~/green', '~/blue')
else
requires 'switch current repo'.with('~/blue', '~/green')
end
requires 'current.repo'
end
dep 'current.repo' do
log shell "readlink ~/current"
end