Capistrano deploy from local repository
Posted by Jim Morris on Fri May 26 17:08:00 -0700 2006
UPDATE 2006-12-06 I have replaced this with a full blown SCM module that works much better, see this posting
It seems that many people are in the same position as I was, they want to deploy to a remote server farm that does not have access to the SCCM (subversion,CVS,perforce etc), which is usually behind a corporate firewall.
The following recipe overcomes this by checking out the source code from the local repository (using svn in this case) and goes into your deploy.rb.
What it does is checkout the latest copy of the application from your local subversion repository, tars it up, and copies the tar file to the remote server, then detars it and does the normal deploy tasks from then on.
desc <<DESC
Update all servers with the latest release of the source code.
This is a modified version that copies a local copy to the remote site
DESC
task :update_code, :roles => [:app, :db, :web] do
on_rollback { delete release_path, :recursive => true }
#puts "doing my update_code"
temp_dest= "tmp_code"
#puts "...get a local copy of the code into #{temp_dest} from local svn"
# but this could also just be your local development folder
system("svn export -q #{configuration.repository} #{temp_dest}")
#puts "...tar the folder"
# you could exclude files here that you don't want on your production server
system("tar -C #{temp_dest} -c -z -f code_update.tar.gz .")
#puts "...Sending tar file to remote server"
put(File.read("code_update.tar.gz"), "code_update.tar.gz")
#puts "...detar code on server"
run <<-CMD
mkdir -p #{release_path} &&
tar -C #{release_path} -x -z -f code_update.tar.gz &&
rm -rf code_update.tar.gz &&
rm -rf #{release_path}/log #{release_path}/public/system &&
ln -nfs #{shared_path}/log #{release_path}/log &&
ln -nfs #{shared_path}/system #{release_path}/public/system
CMD
#puts "...cleanup"
system("rm -rf #{temp_dest} code_update.tar.gz")
end
This recipe does what many people need todo which is replace the database.yml with the production version, and also repalces the .htaccess with the production version (YMMV)
desc "fix up database and .htaccess"
task :after_update_code do
run "cp #{release_path}/config/database.yml.templ #{release_path}/config/database.yml"
run "cp #{release_path}/public/dot.htaccess.deploy #{release_path}/public/.htaccess"
end