Capistrano and Git Deploy Rails App - ruby-on-rails

When trying to deploy a Rails app to a production server with Capistrano, it doesn't seem to recognize my project as being a git repo, despite me having cloned the project directly from GitHub.
THE GIT LOG:
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean
CAP LOG:
$ cap production deploy
triggering load callbacks
* 2016-06-01 16:30:26 executing `production'
triggering start callbacks for `deploy'
* 2016-06-01 16:30:26 executing `multistage:ensure'
* 2016-06-01 16:30:26 executing `deploy'
* 2016-06-01 16:30:26 executing `deploy:update'
** transaction: start
* 2016-06-01 16:30:26 executing `deploy:update_code'
executing locally: "git ls-remote git#github.com:mitigation/mpm.git r1"
command finished in 662ms
* refreshing local cache to revision 8c86d067abde1464f88902566324a99e22cd3147 at /var/folders/xs/5qz1glwj30v51rwpxhyclw880000gn/T/mpm
executing locally: cd /var/folders/xs/5qz1glwj30v51rwpxhyclw880000gn/T/mpm && git fetch -q origin && git fetch --tags -q origin && git reset -q --hard 8c86d067abde1464f88902566324a99e22cd3147 && git clean -q -d -x -f
fatal: Not a git repository (or any of the parent directories): .git
command finished in 13ms
shell command failed with return code pid 52560 exit 128
Here's my Capfile:
load 'deploy'
load 'deploy/assets'
load 'config/deploy'
Here's my DEPLOY.RB:
require 'soprano'
require 'bundler/capistrano'
require 'capistrano/ext/multistage'
require 'whenever/capistrano'
require 'leipreachan/capistrano2'
set :default_environment, {
'PATH' => '/home/deploy/.rbenv/shims:/home/deploy/.rbenv/bin:$PATH'
}
set :web_server, :nginx
set :keep_releases, 3
set :repository, 'git#github.com:mitigation/mpm.git'
set :deploy_via, :copy
set :copy_exclude, %w(.git .idea .yardoc tmp log .DS_Store doc/* public/uploads.tar db/*.sql vendor/cache)
set :copy_cache, true
set :bundle_without, [:development, :test]
set :bundle_flags, '--deployment --binstubs'
set :user, 'deploy'
before 'deploy:setup', :db
after 'deploy:create_symlink', 'utils:version'
after 'deploy:update_code', 'db:symlink'
#For troubleshooting only
namespace :deploy do
task :update_code, :except => { :no_release => true } do
#on_rollback { run "rm -rf #{release_path}; true" }
strategy.deploy!
finalize_update
end
end

During deploys to various environments, capistrano3 creates a directory tree and puts the git information in a folder called repo_path. You'd have to travel inside that directory on your production server and "$git log" would work indicated its a .git repo
You also shouldn't need .git in your copy_exclude.
Try running through the capistrano3 set up process all over again with your app for different environments.

Related

Rails Capistrano Deploy - REVISION: No such file or directory

I'm using the Capistrano gem and this tutorial to deploy my application to my remote server. Everything works fine until the end of the cap deploy command. I'm receiving this error:
** [ps123456.dreamhostps.com :: out] sh: myapp.git/releases/20130916201449/REVISION: No such file or directory
command finished in 2266ms
*** [deploy:update_code] rolling back
* executing "rm -rf myapp.git/releases/20130916201449; true"
servers: ["ps123456.dreamhostps.com"]
[ps123456.dreamhostps.com] executing command
command finished in 254ms
failed: "sh -c 'git clone --depth 1 ssh://username#ps123456.dreamhostps.com/~/myapp.git myapp.git/releases/20130916201449 && cd myapp.git/releases/20130916201449 && git checkout -b deploy 497af4d996358f8d1f42dc9658e276ee8d9fa64f && git submodule init && git submodule sync && export GIT_RECURSIVE=$([ ! \"`git --version`\" \\< \"git version 1.6.5\" ] && echo --recursive) && git submodule update --init $GIT_RECURSIVE && rm -Rf myapp.git/releases/20130916201449/.git && (echo 497af4d996358f8d1f42dc9658e276ee8d9fa64f > myapp.git/releases/20130916201449/REVISION)'" on ps123456.dreamhostps.com
Here is my deploy.rb:
require 'bundler/capistrano'
set :user, 'username'
set :domain, 'ps123456.dreamhostps.com'
set :applicationdir, "myapp.git"
default_run_options[:pty] = true
set :scm, 'git'
set :repository, "ssh://username#ps123456.dreamhostps.com/~/myapp.git"
set :git_enable_submodules, 1 # if you have vendored rails
set :branch, 'master'
set :git_shallow_clone, 1
set :scm_verbose, true
# roles (servers)
role :web, domain
role :app, domain
role :db, domain, :primary => true
# deploy config
set :deploy_to, applicationdir
set :deploy_via, :export
# additional settings
default_run_options[:pty] = true # Forgo errors when deploying from windows
# Passenger
namespace :deploy do
task :start do ; end
task :stop do ; end
task :restart, :roles => :app, :except => { :no_release => true } do
run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
end
end
What is going wrong?
It's hard to say exactly, but it's clear that your releases/#{revision} dir is missing by the time you try to push the git revision into the file REVISION.
One likely issue that should probably get fixed is your :deploy_to dir is the same directory on the same machine as the git repo you are cloning from. Try this instead:
In your deploy.rb
set :deploy_to, "/home/#{user}/app/#{application}"
Then make sure to run this the first time:
cap deploy:setup
Then feel free to:
cap deploy
After a lot of head scratching, oddly enough, it was cap deploy:setup that was my downfall. I am still unsure as to what was going on, but I have thoroughly tested and verified that deleting the deployment directory and redeploying the application without running cap deploy:setup will work.
For some reason, running cap deploy:setup, even after successful deploys, will cause permission errors and causes cap deploy to be unable to create and write to directories.

Whenever Gem Fails to Run "bundle exec" Correctly in Capistrano

I'm having problems deploying the Whenever gem to my production environment using Capistrano.
The problem is stemming from a bundle exec whenever command that's triggering some 'missing gem' issues (yet running bundle install from the shell shows that everything is in fact there!).
My feeling is that one of two things is happening: that Bundler isn't fully loading before bundle exec is being called, or that somehow there's a path issue that's running it in the wrong place.
Here's what's going on:
* executing `deploy'
* executing `deploy:update'
** transaction: start
* executing `deploy:update_code'
executing locally: "git ls-remote git#my-source-repository:mysource.git HEAD"
command finished in 1847ms
* executing "git clone -q git#my-source-repository:mysource.git /domains/myapp/releases/20130124211036 && cd /domains/myapp/releases/20130124211036 && git checkout -q -b deploy 90238bbcb993e3e7df2374ffaa13e7ed701c202e && (echo 90238bbcb993e3e7df2374ffaa13e7ed701c202e > /domains/myapp/releases/20130124211036/REVISION)"
servers: ["myip"]
[myip] executing command
** [myip :: out] Enter passphrase for key '/home/deploy/.ssh/id_rsa':
** [myip :: out]
command finished in 9294ms
* executing `deploy:finalize_update'
triggering before callbacks for `deploy:finalize_update'
* executing `whenever:update_crontab'
* executing "cd /domains/myapp/releases/20130124211036 && bundle exec whenever --update-crontab My App --set environment=production --roles db"
servers: ["myip"]
[myip] executing command
** [out :: myip] Could not find carrierwave-0.5.8 in any of the sources
** [out :: myip] Run `bundle install` to install missing gems.
command finished in 1967ms
*** [deploy:update_code] rolling back
* executing "rm -rf /domains/myapp/releases/20130124211036; true"
servers: ["myip"]
[myip] executing command
command finished in 998ms
failed: "rvm_path=/usr/local/rvm /usr/local/rvm/bin/rvm-shell '1.9.3' -c 'cd /domains/myapp/releases/20130124211036 && bundle exec whenever --update-crontab My App --set environment=production --roles db'" on myip
You can see that the failure is coming from this line:
bundle exec whenever --update-crontab
Which is in turn being run by my Capistrano deploy.rb.
# Your Application's "Name"
set :application, [My App]
# The URL to your application's repository
set :repository, [repo]
set :scm, :git
set :scm_passphrase, [password]
# The user you are using to deploy with (This user should have SSH access to your server)
set :user, "deploy"
# We want to deploy everything under your user, and we don't want to use sudo
set :use_sudo, false
# Where to deploy your application to.
set :deploy_to, "/domains/myapp/"
# Load RVM's capistrano plugin.
require "rvm/capistrano"
set :rvm_ruby_string, '1.9.3'
set :rvm_type, :system # use system-wide RVM
# Require that we use bundler to install necessary gem dependencies
require "bundler/capistrano"
set :whenever_command, "bundle exec whenever"
require "whenever/capistrano"
# -------------------------------- Server Definitions --------------------------------
# Define the hostname of your server. If you have multiple servers for multiple purposes, we can define those below as well.
set :server_name, [server]
# We're assuming you're using a single server for your site, but if you have a seperate asset server or database server, you can specify that here.
role :app, server_name
role :web, server_name
role :db, server_name, :primary => true
# -------------------------------- Final Config --------------------------------
# This configuration option is helpful when using svn+ssh but doesn't hurt anything to leave it enabled always.
default_run_options[:pty] = true
namespace :deploy do
desc "Tell Passenger to restart the app."
task :restart do
run "touch #{deploy_to}current/tmp/restart.txt"
end
task :start do
run "cd #{deploy_to} && ln -s current/public public_html"
run "touch #{deploy_to}current/tmp/restart.txt"
end
task :symlink do
run "cd #{deploy_to} && rm current ; ln -s releases/#{release_name} current"
end
task :stop do
run "rm #{deploy_to}public_html"
end
namespace :web do
task :disable do
run "cd #{deploy_to} && rm public_html && ln -s static_site public_html"
end
task :enable do
run "cd #{deploy_to} && rm public_html && ln -s current/public public_html"
end
end
desc "Symlink shared configs and folders on each release."
task :symlink_shared do
run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
run "ln -nfs #{shared_path}/assets #{release_path}/public/assets"
# create symlink to uploads folder for Carrierwave resources (i.e., book cover images)
run "ln -nfs #{shared_path}/uploads #{release_path}/public/uploads"
end
desc "Sync the public/assets directory."
task :assets do
system "rsync -vr --exclude='.DS_Store' public/assets #{user}##{application}:#{shared_path}/"
end
end
after "deploy", "deploy:migrate"
after 'deploy:update_code', 'deploy:symlink_shared'
after(:setup) do
run "rm -rf #{deploy_to}public_html"
run "mkdir #{deploy_to}static_site"
end
Now, the error that I'm getting about CarrierWave is bogus - I've been using CarrierWave for ages - and the issue clearly stems (as you can see by the command that triggers the error) from either Whenever itself or Bundler.
And I'm thinking that it actually may have something to do with paths related to RVM. At any rate, the bundle exec whenever isn't working.
Any ideas?
It turns out there were a couple problems, both of which needed addressing:
Whenever ~> 0.8 introduced a bug with Capistrano roles
The Whenever cap task was firing before bundle:install (this is confirmed in your code above)
See issues here: https://github.com/javan/whenever/issues/275 and here: https://github.com/javan/whenever/issues/269
To fix the problem, you most likely need to
Update bundler on your server (-v 1.2.3)
Update bundler locally
Update to the newest Whenever (-v 0.8.2)
#ideaoforder's answer helped me too, previously though I had the same trouble caused by require 'whenever/capistrano' being on the top of the config/deploy.rb followed by require 'bundler/capistrano'. Swapping those two helped.
I have require 'bundler/capistrano' always on top of the deploy script as a rule.

cap deploy upload via sftp failed

Good day! I'll try to be very specific with this. I'm sorry, but I've had experience a lot of troubles while trying to deploy my application. I'm totally new at rails, so I followed the Agile Web Development with Rails 4th Edition and I'm trapped on the segment of deploy with capistrano I've tried the exact code on the book, didn't work, and take some advices from this and others forums that prove to be helpful, but I'm still can't deploy correctly my deploy.rb goes like this:
require 'bundler/capistrano'
set :user, 'user_created_for_this_example'
set :domain, 'IPADDRESS'
set :application, 'depot'
# file paths
set :repository, "#{user}##{domain}:depot.git"
set :deploy_to, "/home/#{user}/#{domain}"
# set :scm, :git # You can set :scm explicitly or Capistrano will make an intelligent guess
based on known version control directory names
# Or: `accurev`, `bzr`, `cvs`, `darcs`, `git`, `mercurial`, `perforce`, `subversion` or `none`
#roles server
role :web, domain
role :app, domain
role :db, domain, :primary => true
#deploy config
set :deploy_to, "/home/#{user}/#{domain}"
set :deploy_via, :copy
set :scm, 'git'
set :branch, 'master'
set :scm_verbose, true
set :use_sudo, false
# if you want to clean up old releases on each deploy uncomment this:
# after "deploy:restart", "deploy:cleanup"
# if you're still using the script/reaper helper you will need
# these http://github.com/rails/irs_process_scripts
# If you are using Passenger mod_rails uncomment this:
namespace :deploy do
task :start do ; end
task :stop do ; end
task :restart, :roles => :app, :except => { :no_release => true } do
run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
end
end
after "deploy:update_code", :bundle_install
desc "install the necesary prerequisites"
task :bundle_install, :roles => :app do
run "cd #{release_path} && bundle install"
end
When i run the cap deploy:setup and cap deploy:check all seems to be working fine:
~/rails_projects/depot$ cap deploy:setup
* 2012-11-13 10:37:35 executing `deploy:setup'
* executing "mkdir -p /home/git/xx.xx.xx.xx /home/git/xx.xx.xx.xx/releases /home/git
/xx.xx.xx.xx/shared /home/git/xx.xx.xx.xx/shared/system /home/git/xx.xx.xx.xx/shared/log
/home/git/xx.xx.xx.xx/shared/pids"
servers: ["xx.xx.xx.xx"]
[xx.xx.xx.xx] executing command
command finished in 158ms
* executing "chmod g+w /home/git/xx.xx.xx.xx /home/git/xx.xx.xx.xx/releases /home/git/xx.xx.xx.xx/shared /home/git/xx.xx.xx.xx/shared/system /home/git/xx.xx.xx.xx/shared/log /home/git/xx.xx.xx.xx/shared/pids"
servers: ["xx.xx.xx.xx"]
[xx.xx.xx.xx] executing command
command finished in 7ms
~/rails_projects/depot$ cap deploy:check
* 2012-11-13 10:37:39 executing `deploy:check'
* executing "test -d /home/git/xx.xx.xx.xx/releases"
servers: ["xx.xx.xx.xx"]
[xx.xx.xx.xx] executing command
command finished in 152ms
* executing "test -w /home/git/xx.xx.xx.xx"
servers: ["xx.xx.xx.xx"]
[xx.xx.xx.xx] executing command
command finished in 5ms
* executing "test -w /home/git/xx.xx.xx.xx/releases"
servers: ["xx.xx.xx.xx"]
[xx.xx.xx.xx] executing command
command finished in 5ms
* executing "which tar"
servers: ["xx.xx.xx.xx"]
[xx.xx.xx.xx] executing command
command finished in 6ms
You appear to have all necessary dependencies installed
But when the cap deploy:migrations, cap deploy or cap deploy:cold command comes the next pops up:
~/rails_projects/depot$ cap deploy:migrations
* 2012-11-13 10:37:42 executing `deploy:migrations'
* 2012-11-13 10:37:42 executing `deploy:update_code'
executing locally: "git ls-remote git#xx.xx.xx.xx:depot.git master"
command finished in 241ms
* getting (via checkout) revision c3f88ca97e5868dd476f20e9a044b7dad800274a to /tmp/20121113173743
executing locally: git clone git#xx.xx.xx.xx:depot.git /tmp/20121113173743 && cd /tmp/20121113173743 && git checkout -b deploy c3f8
8ca97e5868dd476f20e9a044b7dad800274a
Cloning into '/tmp/20121113173743'...
remote: Counting objects: 392, done.
remote: Compressing objects: 100% (257/257), done.
remote: Total 392 (delta 111), reused 392 (delta 111)
Receiving objects: 100% (392/392), 8.59 MiB, done.
Resolving deltas: 100% (111/111), done.
Switched to a new branch 'deploy'
command finished in 769ms
* Compressing /tmp/20121113173743 to /tmp/20121113173743.tar.gz
executing locally: tar czf 20121113173743.tar.gz 20121113173743
command finished in 652ms
servers: ["xx.xx.xx.xx"]
** sftp upload /tmp/20121113173743.tar.gz -> /tmp/20121113173743.tar.gz
[xx.xx.xx.xx] /tmp/20121113173743.tar.gz
*** upload via sftp failed on xx.xx.xx.xx: Net::SFTP::StatusException
(Net::SFTP::StatusException open /tmp/20121113173743.tar.gz (3, "permission denied"))
upload via sftp failed on xx.xx.xx.xx: Net::SFTP::StatusException (Net::SFTP::StatusException open /tmp/20121113173743.tar.gz (3, "permission denied"))
I'm sorry if this is some dummy issue, an easy-fix or an already posted one, but I don't know what else to try, again I'm just starting with this stuff and I'm truly lost. I'm running all from the same machine and all the xx.xx.xx.xx stands for my ip address. Any suggestions will be really appreciated. I've tried to be specific as possible, but if something is missing I'll post it. Thanks beforehand for your time and help.
Your problem here is that your source and destination locations for sftp are the same:
** sftp upload /tmp/20121113173743.tar.gz -> /tmp/20121113173743.tar.gz
in order to fix the issue you may specify parameter copy_dir in your config/deploy.rb file, something like this:
set :copy_dir, "/tmp/sftp"
no need to create that folder manually then.
Try adding this line to your deploy.rb configuration file:
default_run_options[:pty] = true
We changed the Capfile from
set :deploy_via, :copy
to
set :deploy_via, :remote_cache
and this worked for us. We did not add the below line
default_run_options[:pty] = true

Deploying with capistrano and 'Host key verification failed.' promble

I'm trying to setup my Rails app on Linode and I'm at the stage of trying to get Capistrano setup.
I have a git server setup on the same server as where I'm deploying. I have my SSH keys setup (I think) -- at least I can SSH in no problem.
Both 'cap deploy:setup' and 'cap deploy:check' run without error.
But then when I try to run 'cap deploy:migrations' I get the following:
ray#ray-ThinkPad-SL:~/mini-saler$ cap deploy:migrations
* executing `deploy:migrations'
* executing `deploy:update_code'
updating the cached checkout on all servers
executing locally: "git ls-remote git#XX.207.243.215:mini-saler.git master"
command finished in 12446ms
* executing "if [ -d /home/railsu/bianbian.com/shared/cached-copy ]; then cd /home/railsu/bianbian.com/shared/cached-copy && git fetch origin && git fetch --tags origin && git reset --hard 8e8aa8f849a9438851a3767b338ab711d6470299 && git clean -d -x -f; else git clone git#XX.207.243.215:mini-saler.git /home/railsu/bianbian.com/shared/cached-copy && cd /home/railsu/bianbian.com/shared/cached-copy && git checkout -b deploy 8e8aa8f849a9438851a3767b338ab711d6470299; fi"
servers: ["XX.207.243.215"]
[XX.207.243.215] executing command
** [XX.207.243.215 :: out] Cloning into /home/railsu/bianbian.com/shared/cached-copy...
** [XX.207.243.215 :: err] Host key verification failed.
** [XX.207.243.215 :: err] fatal: The remote end hung up unexpectedly
command finished in 2009ms
failed: "rvm_path=$HOME/.rvm/ $HOME/.rvm/bin/rvm-shell '1.9.3' -c 'if [ -d /home/railsu/bianbian.com/shared/cached-copy ]; then cd /home/railsu/bianbian.com/shared/cached-copy && git fetch origin && git fetch --tags origin && git reset --hard 8e8aa8f849a9438851a3767b338ab711d6470299 && git clean -d -x -f; else git clone git#XX.207.243.215:mini-saler.git /home/railsu/bianbian.com/shared/cached-copy && cd /home/railsu/bianbian.com/shared/cached-copy && git checkout -b deploy 8e8aa8f849a9438851a3767b338ab711d6470299; fi'" on XX.207.243.215
deploy.rb
set :user, 'railsu'
set :domain, 'XX.207.243.215'
set :application, 'mini-saler'
# adjust if you are using RVM, remove if you are not
$:.unshift(File.expand_path('./lib', ENV['rvm_path']))
require "rvm/capistrano"
set :rvm_ruby_string, '1.9.3'
set :rvm_type, :user
# file paths
set :repository, "git##{domain}:mini-saler.git"
set :deploy_to, "/home/railsu/bianbian.com"
# distribute your applications across servers (the instructions below put them
# all on the same server, defined above as 'domain', adjust as necessary)
role :app, domain
role :web, domain
role :db, domain, :primary => true
# miscellaneous options
set :deploy_via, :remote_cache
set :scm, 'git'
set :branch, 'master'
set :scm_verbose, true
set :use_sudo, false
set :rails_env, :production
namespace :deploy do
desc "cause Passenger to initiate a restart"
task :restart do
run "touch #{current_path}/tmp/restart.txt"
end
desc "reload the database with seed data"
task :seed do
run "cd #{current_path}; rake db:seed RAILS_ENV=#{rails_env}"
end
end
after "deploy:update_code", :bundle_install
desc "install the necessary prerequisites"
task :bundle_install, :roles => :app do
run "cd #{release_path} && bundle install"
end
I can use ssh to connect my vps.
I don't recall if any git commands are called on cap deploy:setup or cap deploy:check - I don't think there are.
Assuming you're using gitolite, check to make sure that your configuration has your railsu user's public key is in the keydir directory.
Or perhaps agent forwarding is what you want? Deploying with Capistrano can help you there.

capistrano + git deployment: could not create work tree dir : Permission denied

I'm deploying using git and capistrano with passenger. I've been banging my head for a few hours trying to make this work, and haven't made much progress. cap deploy:setup works ok, but cap deploy is failing with Permission issues. I tried changing permissions/ownership on my slice, but it's still failing.
require 'bundler/capistrano'
set :user, 'some_user'
set :domain, 'example.com'
set :applicationdir, "/home/some_user/public_html/example"
set :port, 30000
set :scm, 'git'
set :repository, "ssh://git#123.45.678.910:50000/home/git/example"
set :branch, 'master'
set :scm_verbose, true
# roles (servers)
role :web, domain
role :app, domain
role :db, domain, :primary => true
# deploy config
set :deploy_to, applicationdir
set :deploy_via, :remote_cache
# additional settings
default_run_options[:pty] = true
ssh_options[:forward_agent] = true
# Passenger
namespace :deploy do
task :start do ; end
task :stop do ; end
task :restart, :roles => :app, :except => { :no_release => true } do
run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
end
end
results in the following error:
executing `deploy'
* executing `deploy:update'
** transaction: start
* executing `deploy:update_code'
updating the cached checkout on all servers
executing locally: "git ls-remote ssh://git#123.45.678.910:50000/home/git/example.com master"
/Users/some_user/.rvm/gems/ruby-1.9.2-p0/gems/capistrano-2.6.0/lib/capistrano/recipes/deploy.rb:104: warning: Insecure world writable dir /usr/local/bin in PATH, mode 040777
command finished in 78068ms
* executing "if [ -d /home/some_user/public_html/example.com/shared/cached-copy ]; then cd /home/some_user/public_html/example.com/shared/cached-copy && git fetch origin && git fetch --tags origin && git reset --hard c7f73668d0656c665a6445c33870d05a8550ab2c && git clean -d -x -f; else git clone ssh://git#123.45.678.910:50000/home/git/example.com /home/some_user/public_html/example.com/shared/cached-copy && cd /home/some_user/public_html/example.com/shared/cached-copy && git checkout -b deploy c7f73668d0656c665a6445c33870d05a8550ab2c; fi"
servers: ["example.com"]
[example.com] executing command
** [example.com :: out] fatal: could not create work tree dir '/home/some_user/public_html/example.com/shared/cached-copy'.: Permission denied
command finished in 353ms
*** [deploy:update_code] rolling back
* executing "rm -rf /home/some_user/public_html/example.com/releases/20110610173027; true"
servers: ["example.com"]
[example.com] executing command
command finished in 218ms
failed: "sh -c 'if [ -d /home/some_user/public_html/example.com/shared/cached-copy ]; then cd /home/some_user/public_html/example.com/shared/cached-copy && git fetch origin && git fetch --tags origin && git reset --hard c7f73668d0656c665a6445c33870d05a8550ab2c && git clean -d -x -f; else git clone ssh://git#123.45.678.910:50000/home/git/example.com /home/some_user/public_html/example.com/shared/cached-copy && cd /home/some_user/public_html/example.com/shared/cached-copy && git checkout -b deploy c7f73668d0656c665a6445c33870d05a8550ab2c; fi'" on example.com
Not sure how much this will help, but I always have a permissions issue after a deploy:setup
When you run deploy:setup it creates the initial directories for you. However those folders it creates are usually owned by root (In most of my situations anyway).
webapp/
shared root:root
releases root:root
To remedy this I will change ownership of those new folders to the user that will be using.
webapp/
shared myuser:myuser
releases myuser:myuser
Once this is done, I'll continue with my deploy:update
I've just encountered this problem as well. Here's what I found out.
If you have not yet been able to deploy successfully, you might want to temporarily move your deploy folder (in your server) to another location (or simply rename it)
Make sure you have this inside your recipe: set :use_sudo, false
Run this again: cap deploy:setup
Then try another run of cap deploy
You will definitely run into other troubles with permissions if you have built your deploy folders using the wrong user and tell capistrano that it has sudo permissions.
I hope this works for you, as it worked for me.

Resources