Local Capistrano Deployment Issue
I have an inssue when deploying PHP application on "local" machine (e.g. deploying app to same machine where executing capistrano deploy.) using Capistrano.The cause is when capistrano creates temporary directory for destination (remote) directory and directory for source (local) directory point to same directory.
This problem does not happen when you deploy to different machine.
Solution
Add the below code to your deploy.rb!! Just change the name for temoprary directory used during deployment name.
# put this line at the top of app.yml in order to use SecureRandom methods
require "securerandom"
# set flag true when local deployment
set :deploy_to_self, "true"
# hook tasks
before :deploy, "local:create_dir"
after :deploy, "local:clean_dir"
####################################
# setup copy_dir, copy_remote_dir
# when deploying to machine which this script is running on to avoid copy issue
#
namespace :local do
desc <<-DESC
set copy_dir, copy_remote_dir when deploying to machine which this script is running on (e.g. same machine)
DESC
task :create_dir do
set :random_str, SecureRandom.base64(6).gsub(/[$=+\/]/,65.+(rand(25)).chr)
set :cap_temp_dir, "/tmp/capistrano_#{random_str}"
if exists?(:local_deploy) && local_deploy == "true"
set :copy_dir, "#{cap_temp_dir}/local/"
set :copy_remote_dir, "#{cap_temp_dir}/remote"
print " creating #{copy_dir}.\n"
run "mkdir -p #{copy_dir}"
print " creating #{copy_remote_dir}.\n"
run "mkdir -p #{copy_remote_dir}"
end
end
end
####################################
# clean up temp dir created when deploying
#
namespace :local do
desc <<-DESC
clean up temp dirs created when deploying
DESC
task :clean_dir do
if exists?(:cap_temp_dir)
print " cleaning up temp directory... #{cap_temp_dir}"
run "rm -r -f #{cap_temp_dir}"
end
end
end
コメント