Skip to content

Instantly share code, notes, and snippets.

@zombor
Created March 21, 2011 18:05
Show Gist options
  • Save zombor/879895 to your computer and use it in GitHub Desktop.
Save zombor/879895 to your computer and use it in GitHub Desktop.
zombor's capistrano deploy scripts
set :stages, %w(production staging)
set :default_stage, "staging"
require 'capistrano/ext/multistage'
# --------------------------------------------
# Repository
# --------------------------------------------
set :scm, :git # I am using git, so I specify it here
set :repository, "<repo>" # This is the path to the repository on the server, we pushed the code here earlier.
# Default to develop branch
#set :branch, "develop"
# ask for a branch
set :branch do
default_tag = `git tag`.split("\n").last
tag = Capistrano::CLI.ui.ask "Tag to deploy (make sure to push the tag first): [#{default_tag}] "
tag = default_tag if tag.empty?
tag
end
# --------------------------------------------
# General
# --------------------------------------------
set :shared_children, %w(cache logs) # Shared directories, these directories contain generated content which should not be wiped out during deployments.
set :application, "<app-name>" # Application name
set :deploy_to, "<deploy-to>" # Path where files are deployed to ...
role :web, "<web-server-hostname>"
# --------------------------------------------
# SSH
# --------------------------------------------
#ssh_options[:keys] = %w(/home/user/.ssh/private_key) # SSH key
ssh_options[:port] = 22
# --------------------------------------------
# Server
# --------------------------------------------
# Commands on the server are run as the following user :
set :runner, "jeremybush"
set :user, "jeremybush"
set :use_sudo, false # sudo isn't required for my deployment.
# --------------------------------------------
# Overloaded Methods.
# --------------------------------------------
namespace :deploy do
task :finalize_update, :except => { :no_release => true } do
# Make sure the log and upload directories do not exist.
#run "rmdir #{latest_release}/application/logs"
#run "rmdir #{latest_release}/application/cache"
run "unlink #{deploy_to}/.htaccess"
# Symlink the shared directories to the directories in your application.
run "ln -s #{shared_path}/logs #{latest_release}/application/logs"
run "ln -s #{shared_path}/cache #{latest_release}/application/cache"
# Symlink the .htaccess
run "ln -s #{latest_release}/.htaccess #{deploy_to}/.htaccess"
# Symlink the staging database config
run "ln -s #{latest_release}/application/config/database.php.dev #{latest_release}/application/config/database.php"
# chmod the files and directories.
run "find #{deploy_to} -type d -exec chmod 0755 {} \\;"
run "find #{latest_release} -type d -exec chmod 0755 {} \\;"
run "find #{latest_release} -type f -exec chmod 644 {} \\;"
end
desc "Testing"
task :remote_time, :roles => :web do
puts capture("date")
end
# namespace :web do
# task :disable do
# # When cap deploy:web:disable is run, copy a maintenance.html page from the shared directory
# # to the webroot. You will typically have Apache check for this file and disable access to the
# # site if it exists.
# run "cp #{shared_path}/maintenance.html #{latest_release}"
# run "echo #{stage}"
# end
# task :enable do
# run "rm -f #{latest_release}/maintenance.html"
# end
# end
end
# Hook the web disable and disable events into the deployment.
#after "deploy:update_code", "deploy:web:disable"
#after "deploy:symlink", "deploy:web:enable"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment