Search code examples
rubygitdeploymentcapistrano

Capistrano - deployment with git shared repository


I'm trying to setup Capistrano to deploy my project with multiples git users. Where I work for, doesn't have (and doesn't wanna have) a generic git user, like 'git'. So the deploy config is related to the user that runs 'cap deploy'.

As you can se in config.rb file:

set :application, "mywebsite"

set :repository,  "ssh://#{scm_user}@myserver.com/repo.git"

set :scm, :git
set :scm_verbose, true
set :deploy_via, :remote_cache
set :git_enable_submodules, 1

development.rb

set :deploy_to, "/var/www/html"

set :user, "myuser"
set :password, "mypassword"
set :scm_passphrase, "mypassword"

And cat ~/.caprc file:

set :scm_user, "myuser"

It works for the user that did the first deploy. When others users that try to do the same in their own machines, it isn't working.

The error is related to git. It seems that Git is tying the user that made the git clone on the first deploy

The basicaly in these lines:

executing locally: "git ls-remote ssh://[email protected]/repo.git HEAD"
* executing "if [ -d /var/www/html/shared/cached-copy ]; 
    then cd /var/www/html/shared/cached-copy 
    && git fetch  origin 
    && git fetch --tags  origin 
    && git reset  --hard 88d6aa98c52babe9368cf2bed36741f0f0b93ff2 
    && git submodule  init 
    && git submodule  sync 
    && export GIT_RECURSIVE=$([ ! \"`git --version`\" \\< \"git version 1.6.5\" ]
     && echo --recursive) 
    && git submodule  update --init $GIT_RECURSIVE 
    && git clean  -d -x -f; else git clone ssh://[email protected]/repo.git /var/www/html/shared/cached-copy && cd /var/www/html/shared/cached-copy 
    && git checkout -b deploy 88d6aa98c52babe9368cf2bed36741f0f0b93ff2 
    && git submodule init 
    && git submodule sync 
    && export GIT_RECURSIVE=$([ ! \"`git --version`\" \\< \"git version 1.6.5\" ] 
    && echo --recursive) 
    && git submodule update --init $GIT_RECURSIVE; fi"

When I tried to debug this problem, I accessed the server machine with THEOTHERUSER ssh account and typed git fetch --tags origin. It asks to type the passwork of other user.

Does anyone know what can I do to allow any user to be able to do a deploy?

UPDATE:

What was need to do:

set :remote, "#{scm_user}"
set :branch, "master"

http://ruby-doc.org/gems/docs/c/capistrano-edge-2.5.6/Capistrano/Deploy/SCM/Git.html


Solution

  • If you want to deploy a private repo as a non-generic user, you have to set up ssh-agent forwarding. That way your ssh keys will be used on the server as well.

    Check out the extensive GitHub documentation on that topic.