Skip to content

Instantly share code, notes, and snippets.

@avidenov
Created April 24, 2016 17:39
Show Gist options
  • Save avidenov/4d73c2ad2ac25d8c4ee19b46c565fd17 to your computer and use it in GitHub Desktop.
Save avidenov/4d73c2ad2ac25d8c4ee19b46c565fd17 to your computer and use it in GitHub Desktop.
Capistrano recipe
require 'capistrano/recipes/deploy/strategy/copy'
set :stages, %w(staging production)
set :default_stage, "staging"
# options parsing & validation
set :stage_name, (ARGV.first if ARGV.first != "deploy") || default_stage
# basic settings
set :application, "Appname"
set :repository, "git.repo.url"
set :scm, :git
set :branch, "master"
set :use_sudo, true
set :user, "deployer"
set :group, "www-data"
set :deploy_via, :copy
set :deploy_to, "/var/www/#{application}"
default_run_options[:pty] = true
ssh_options[:port] = 22
# put callbacks here
after "deploy:update_code", "db:symlink", "deploy:after_deploy"
namespace :db do
desc "Make symlink for wp-config.php"
task :symlink, :roles => :app do
run "ln -nfs #{shared_path}/wp-config.php #{release_path}/wwwroot/wp-config.php"
run "ln -nfs #{shared_path}/plugins #{release_path}/wwwroot/wp-content/plugins"
run "ln -nfs #{shared_path}/upgrade #{release_path}/wwwroot/wp-content/upgrade"
run "ln -nfs #{shared_path}/uploads #{release_path}/wwwroot/wp-content/uploads"
end
end
namespace :deploy do
task :default do
transaction do
update_code
symlink
end
end
task :update_code, :except => { :no_release => true } do
on_rollback { run "rm -rf #{release_path}; true" }
strategy.deploy!
end
task :after_deploy do
run "#{try_sudo} chgrp -R #{group} #{release_path}/wwwroot"
run "#{try_sudo} chgrp -R #{group} #{shared_path}/plugins"
run "#{try_sudo} chgrp -R #{group} #{shared_path}/upgrade"
run "#{try_sudo} chgrp -R #{group} #{shared_path}/uploads"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment