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:

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, “”

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, “” # Your HTTP server, Apache/etc

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

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

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

desc “Restart Application”

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

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, ""

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"

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

  # RailsEnv is set in apache my_app vhost config, but also set it in
  # 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};


# 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}/
  task :symlink, :roles => :app do
    run <<-CMD
      ln -nfs #{shared_path}/system/uploads #{release_path}/MY_APP/

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

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

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

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

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”


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



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

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