Created
July 16, 2013 05:54
-
-
Save paulredmond/6006112 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# After running cap deploy:cold, You'll need to remove all files from the | |
# domains/yourdomain.com/html directory and turn the html directory into a | |
# symlink that links to ./current which is also a symlink setup by capistrano. | |
# | |
# install the mt-capistrano gem, not sure if it is really needed in most situations | |
require 'mt-capistrano' | |
# Configure these | |
set :site, "12345" # this is your site number, for example if your access domain is s12345.gridserver.com | |
set :application, "example.com" # typically the same as the domain | |
set :webpath, "example.com" # the domain you are deploying the site as | |
# Shouldn't have to change anything below | |
set :domain, "s#{site}.gridserver.com" | |
set :user, "serveradmin@#{webpath}" | |
set :password, "xxxxxx" # or you can add your public ssh key, just forward the agent in this recipe | |
# Other options | |
default_run_options[:pty] = true | |
default_run_options[:shell] = false | |
set :use_sudo, false # MediaTemple doesn't allow sudo command | |
# Repo stuff | |
set :scm, :git | |
set :repository, "." # assumes you are running cap deploy while your current working directory is the repo | |
set :deploy_via, :copy | |
set :copy_cache, true | |
set :copy_exclude, [".git"] # no need to include the git config directory | |
set :branch, "master" # you can change this if you would like to use another branch | |
# Path stuff, make sure to symlink html to ./current | |
set :deploy_to, "/home/#{site}/users/.home/domains/#{application}" | |
set :current_deploy_dir, "#{deploy_to}/current" | |
# make sure you have added a tmp directory inside domains/example.com with correct permissions (i.e 755) | |
set :copy_remote_dir, "#{deploy_to}/tmp" | |
set :keep_releases, 2 # keep this low for larger sites, can be up to 5 if you are really nervous | |
# Roles | |
role :web, domain | |
role :app, domain | |
role :db, domain, :primary => true | |
# we need a relative path for the current symlink, without this | |
# current is set to link to the release starting from the /home directory | |
# which has a directory that is not owned by the serveradmin and apache | |
# won't have access | |
def relative_path(from_str, to_str) | |
require 'pathname' | |
Pathname.new(to_str).relative_path_from(Pathname.new(from_str)).to_s | |
end | |
# overwrite the symlink method to use the relative path method above | |
namespace :deploy do | |
desc "Relative symlinks for current, so we don't use full path" | |
task :symlink, :except => { :no_release => true } do | |
if releases[-2] # not the first release | |
previous_release_relative = relative_path(deploy_to, previous_release) | |
on_rollback { run "rm -f #{current_path}; ln -s #{previous_release_relative} #{current_path}; true" } | |
end | |
latest_release_relative = relative_path(deploy_to, latest_release) | |
run "rm -f #{current_path} && ln -s #{latest_release_relative} #{current_path}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment