Capistrano - override default, get/copy source from local

I am working on getting Capistrano running for an app but need to ask it to download source to a local directory and then send it to the deployment server via scp/etc (there are reasons for this I won’t get into). Below is where I am and what I am trying — if anyone has done this or can show me where I am going wrong I’d appreciate it.

I found the following info but it does not seem to work, cap deploy seems to run the same as without it:

http://rdoc.info/rdoc/capistrano/capistrano/blob/6d540a5d4d04278312f96ae8276e9cacc2d826e5/Capistrano/Deploy/Strategy/Copy.html

set :copy_strategy, :export

set :copy_cache, true
  set :copy_exclude, ".git/*"
set :copy_cache, "/tmp/caches/myapp"

Following is my deploy.rb:

set :application, “compare” set :repository, “git@github.com:structuralartistry/compare.git”

set :scm, “git” set :user, “myuser” # The server’s user for deploys

set :scm_passphrase, “mypassphrase”

set :copy_strategy, :export set :copy_cache, true set :copy_exclude, “.git/*” set :copy_cache, “~/Documents/ror/deployment/compare”

set :use_sudo, false

set :branch, “master” #set :deploy_via, :remote_cache set :deploy_to, “/home/myuser/webapps/compare”

role :web, “xxx.xxx.xxx.xxx” # Your HTTP server, Apache/etc

role :app, “xxx.xxx.xxx.xxx” # This may be the same as your Web server role :db, “xxx.xxx.xxx.xxx”, :primary => true # This is where Rails migrations will run

namespace :deploy do task :start, :roles => :app do run “touch #{current_release}/tmp/restart.txt” end

task :stop, :roles => :app do # Do nothing. end

desc “Restart Application”

task :restart, :roles => :app do run “touch #{current_release}/tmp/restart.txt” end end

I use this script, and it works for me (although, I'm sure I could improve it..) - hope this helps! ================ START deploy.rb =============

set :application, "MY_APP" set :user, "your_username" set :admin_runner, user set :rails_env, 'test'

set :deploy_to, "/path/to/MY_APP/#{application}" # this is the path on your server you're deploying to set :deploy_via, :copy

set :scm, :git set :repository, "/My/local/git/repository" set :branch, "master" set :port, YOUR_PORT_HERE

set :location, "your_domain.com"

role :app, location role :web, location role :db, location, :primary => true

namespace :deploy do   desc "Restarting mod_rails with restart.txt"   task :restart, :roles => :app, :except => { :no_release => true } do     run "touch #{current_path}/tmp/restart.txt"   end

  [:start, :stop].each do |t|     desc "#{t} task is a no-op with mod_rails"     task t, :roles => :app do ; end   end

  # RailsEnv is set in apache my_app vhost config, but also set it in environment.rb,   # so applicaitons can acccess the RAILS_ENV constant.   task :set_rails_env do     tmp = "#{current_release}/MY_APP/tmp/environment.rb"     final = "#{current_release}/MY_APP/config/environment.rb"     run <<-BASH     echo "ENV['RAILS_ENV'] ||= '#{rails_env}'" > #{tmp};     cat #{final} >> #{tmp} && mv #{tmp} #{final};     BASH   end

end

# After the current release has been updated, re-create the symbolic links on the server # so that the database.yml and uploads (in shared directory) are "understood" by the current release namespace(:customs) do   task :config, :roles => :app do     run <<-CMD       ln -nfs #{shared_path}/system/database.yml #{release_path}/ MY_APP/config/database.yml     CMD   end   task :symlink, :roles => :app do     run <<-CMD       ln -nfs #{shared_path}/system/uploads #{release_path}/MY_APP/ public/uploads     CMD   end end

after "deploy:update_code", "customs:config" after "deploy:symlink","customs:symlink" after "deploy", "deploy:cleanup" after "deploy:finalize_update", "deploy:set_rails_env"

oops.. Replace this one line in the previous post I made to:

set :repository, "ssh://git@your_git_server:your_git_port/path/to/git/ repository"

This will get your source from your remote git server. The previous one is assuming that you already have a copy of the git repository locally.

Hi, thanks for the script, was very useful! I found that I was missing “set :deploy_via, :copy”. Got it working on the first try.

The part at the bottom on replacing the database.yml was useful too as I need to both replace this and config.rb. Really minor but found a slightly simpler way to do this (which puts the callback in the first line rather than having to place somewhere else) when I was googling around trying to understand this:

task :after_update_code do

link from our production/config directory to the release

run “ln -nfs #{deploy_to}/production/config/database.yml #{release_path}/config/database.yml” end

VS

task :config, :roles => :app do run <<-CMD ln -nfs #{shared_path}/system/database.yml #{release_path}/MY_APP/config/database.yml

CMD

end

after “deploy:update_code”, “customs:config”

Glad that helped, and thanks for the simpler script! I'll definitely try it on my deploy, too.