Skip to content

Instantly share code, notes, and snippets.

@bigsweater
Created March 2, 2014 14:11
Show Gist options
  • Save bigsweater/9307075 to your computer and use it in GitHub Desktop.
Save bigsweater/9307075 to your computer and use it in GitHub Desktop.
Capfile for deploying Bedrock on MediaTemple's GridServer
# Load DSL and Setup Up Stages
require 'capistrano/setup'
# Includes default deployment tasks
require 'capistrano/deploy'
# Load tasks from gems
require 'capistrano/composer'
# Loads custom tasks from `lib/capistrano/tasks' if you have any defined.
# Customize this path to change the location of your custom tasks.
Dir.glob('lib/capistrano/tasks/*.cap').each { |r| import r }
# Define a relative path
def relative_path(from_str, to_str)
require 'pathname'
Pathname.new(to_str).relative_path_from(Pathname.new(from_str)).to_s
end
Rake::Task["deploy:symlink:linked_dirs"].clear
namespace :deploy do
# Overwrite symlink directory functions
namespace :symlink do
desc 'Symlink release to current (relative)'
task :release do
puts 'Symlink release to current (relative)'.upcase
rel_release_path = relative_path(deploy_to, release_path)
on release_roles :all do
execute :rm, '-rf', current_path
execute :ln, '-s', rel_release_path, current_path
end
end
desc 'Symlink relatively linked directories'
task :linked_dirs do
puts 'Symlink relatively linked directories'.upcase
next unless any? :linked_dirs
on release_roles :all do
execute :mkdir, '-pv', linked_dir_parents(release_path)
fetch(:linked_dirs).each do |dir|
target = release_path.join(dir)
source = shared_path.join(dir)
rel_source = relative_path(deploy_to, source)
rel_target = relative_path(deploy_to, target)
unless test "[ -L #{target} ]"
if test "[ -d #{target} ]"
execute :rm, '-rf', target
end
execute :ln, '-s', '../../../' + rel_source, target
end
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment