HelloWorld
HelloWorld

Reputation: 4349

Capistrano deploy using remote_cache - Permission denied

I am modifying a functional Capistrano script trying to speed it up since my home internet upload speed is horrendous. I have a git server (not github), and a ubuntu dev server, when I run cap deploy it currently grabs the latest from my git repo and makes a local copy then uploads that to my ubuntu server and restarts passenger without an issue. My capistrano code contains...

set :deploy_via, :copy

But if I try to use this instead...

set :deploy_via, :remote_cache

I get this error...

 ** transaction: start
  * ←[32m2014-03-13 08:43:36 executing `deploy:update_code'←[0m
    updating the cached checkout on all servers
    ←[33mexecuting locally: "git ls-remote ssh://[email protected]/opt/git/hub/app.git master"←[0m
[email protected]'s password:
    ←[2;37mcommand finished in 6880ms←[0m
  * ←[33mexecuting "if [ -d /srv/www/app/shared/cached-copy ]; then cd /srv/www/app/shared/cached-copy && git fetch -q origin && git fetch --tags -q origin && git reset
-q --hard efe4a94f5a4f1354edb0f4b516e9ea1d627e5101 && git clean -q -d -x -f; else git clone -q -b master ssh://[email protected]/opt/git/hub/app.git /s
rv/www/app/shared/cached-copy && cd /srv/www/app/shared/cached-copy && git checkout -q -b deploy efe4a94f5a4f1354edb0f4b516e9ea1d627e5101; fi"←[0m
    servers: ["12.34.56.78"]
    [12.34.56.78] executing command
 ** ←[31m[12.34.56.78 :: err] Permission denied, please try again.←[0m
 ** ←[31m[12.34.56.78 :: err] Permission denied, please try again.←[0m
 ** ←[31m[12.34.56.78 :: err] Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).←[0m
 ** [12.34.56.78 :: err] fatal: The remote end hung up unexpectedly

It prompts for the git password - [email protected]'s password:

which I enter and it proceeds ok, then it seems to error out on the next command above. I'm guessing I need to setup some ssh keys somehow? Again this is not hosted on github, the repo and dev server are two separate boxes on my company servers. Locally I am running windows 7. If I try adding...

set :ssh_options, { :forward_agent => true }
default_run_options[:pty] = true 

I get the same distance but this time instead of automatically saying permission denied, it prompts for the gitadmin password, I enter it correctly and it says "permission denied".

Upvotes: 2

Views: 955

Answers (1)

jamesc
jamesc

Reputation: 12837

It would help if you posted your full capistrano scipt (minus any passwords, ip addresses) but I suspect that you need to introduce your server to the remote repository. You don't need deploy_via option at all

To introduce your server to your repo ssh into your server and from there ssh into the repository service, there should be documentation on the url to use for this. You would get a access denied message but the point is that this process adds ssh public key to your server

It might also be worth watching Ryan Bates Railscast on deploying, he uses github but the process is pretty similar for any remote repo

http://railscasts.com/episodes/335-deploying-to-a-vps Pay attention to how he introduces his server to github, like I say, your service should provide you with instructions for similar introduction

There is a revised (pro) cast that you would need a subscription for but Ryan is on an extended break (possibly indefinitely right now) so a subscription would be extremely good value right now and well worth thinking about.

The revised (pro) cast on capstrano, how to set variables etc... is here http://railscasts.com/episodes/133-capistrano-tasks-revised

This is a working script for one of my apps just replace xxx and paths as you see fit, I assume you have all the start and restart stuff already set up but this should point you to at least the minimum settings needed. I say this because you possibly have other setting that you don't need, but as you haven't posted your script it is impossible to tell.

require "bundler/capistrano"

server "146.185.182.228", :web, :app, :db, primary: true
set :application, "xxx"
set :user, "xxxx"

# adjust if you are using RVM, remove if you are not
set :rvm_type, :user
set :rvm_ruby_string, 'ruby-2.0.0-p353'
set :ssh_options, {:forward_agent => true}

default_run_options[:pty] = true


# file paths
set :repository, "[email protected]:xxxx.git"
set :deploy_to, "/home/#{user}/apps/#{application}"
# 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`
set :scm, :git
set :use_sudo, false
set :rails_env, :production
set :password, "xxxxxxx"

#role :web, "your web-server here"                          # Your HTTP server, Apache/etc
#role :app, "your app-server here"                          # This may be the same as your `Web` server
#role :db,  "your primary db-server here", :primary => true # This is where Rails migrations will run
#role :db,  "your slave db-server here"

# 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
  %w[start stop restart].each do |command|
    desc "#{command} unicorn server"
    task command, roles: :app, except: {no_release: true} do
      run "cd #{release_path} && bundle install"
      run "/etc/init.d/unicorn_#{application} #{command}"
      run "#{sudo} service nginx #{command}"
    end
  end

  task :setup_config, roles: :app do
    sudo "ln -nfs #{current_path}/config/nginx.conf /etc/nginx/sites-enabled/#{application}"
    sudo "ln -nfs #{current_path}/config/init_unicorn.sh /etc/init.d/unicorn_#{application}"
    sudo "ln -nfs #{current_path}/config/sidekiq.conf /etc/init/sidekiq.conf"
    run "mkdir -p #{shared_path}/config"
  end
  after "deploy:setup", "deploy:setup_config"

  desc "Make sure local git is in sync with remote."
  task :check_revision, roles: :web do
    unless `git rev-parse HEAD` == `git rev-parse origin/master`
      puts "WARNING: HEAD is not the same as origin/master"
      puts "Run `git push` to sync changes."
      exit
    end
  end

  before "deploy", "deploy:check_revision"
  after "deploy:update_code", "deploy:symlink_shared"

end

Upvotes: 2

Related Questions