0

我正在尝试设置 Capistrano 以使用多个 git 用户部署我的项目。我工作的地方没有(也不想拥有)一个通用的 git 用户,比如“git”。所以部署配置与运行“cap deploy”的用户有关。

正如您可以在 config.rb 文件中看到的那样:

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

发展.rb

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

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

和 cat ~/.caprc 文件:

set :scm_user, "myuser"

它适用于进行第一次部署的用户。当其他用户尝试在他们自己的机器上做同样的事情时,它就不起作用了。

该错误与git有关。似乎 Git 正在捆绑在第一次部署时进行 git clone 的用户

基本上在这些行中:

executing locally: "git ls-remote ssh://THEOTHERUSER@myserver.com/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://THEOTHERUSER@myserver.com/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"

当我尝试调试此问题时,我使用 THEOTHERUSER ssh 帐户访问了服务器机器并输入了git fetch --tags origin. 它要求输入其他用户的密码。

有谁知道我可以做些什么来允许任何用户进行部署?

更新:

需要做什么:

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

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

4

2 回答 2

1

如果您想以非通用用户的身份部署私有 repo,则必须设置 ssh-agent 转发。这样,您的 ssh 密钥也将在服务器上使用。

查看有关该主题的大量 GitHub 文档。

于 2013-05-10T20:38:53.597 回答
1

如果您将存储库行替换为此怎么办?

set :repository,  "ssh://myserver.com/repo.git"
于 2013-05-10T20:22:27.500 回答