当我尝试通过 capistrano 部署 rails 应用程序时遇到问题。以下是我当前的配置文件,其中的服务器名称已删除:
配置/部署.rb
lock '3.2.1'
set :application, "my_app"
set :repo_url, "my.server.example.com:/path/to/my_app.git"
set :branch, 'master'
set :use_sudo, false
set :deploy_to, "/srv/#{fetch(:application)}"
配置/部署/生产.rb
role :app, "my.server.example.com"
role :web, "my.server.example.com"
role :db, "my.server.example.com", :primary => true
server 'my.server.example.com',
user: 'root',
roles: %w{web app},
ssh_options: {
user: 'me', # overrides user setting above
keys: %w(/home/me/.ssh/id_rsa),
forward_agent: false,
auth_methods: %w(publickey),
verbose: :debug
}
基本上涉及三台计算机:
- 本地主机,我的工作站
- my.server.example.com,托管 rails 应用程序
- 我的.git.example.com,托管 git 存储库。
当我尝试部署时出现以下错误:
[me@localhost my_app]$ cap production deploy
INFO [d2263887] Running /usr/bin/env mkdir -p /tmp/my_app/ on my.server.example.com
DEBUG [d2263887] Command: /usr/bin/env mkdir -p /tmp/my_app/
INFO [d2263887] Finished in 0.713 seconds with exit status 0 (successful).
DEBUG Uploading /tmp/my_app/git-ssh.sh 0.0%
INFO Uploading /tmp/my_app/git-ssh.sh 100.0%
INFO [acbfa48d] Running /usr/bin/env chmod +x /tmp/my_app/git-ssh.sh on my.server.example.com
DEBUG [acbfa48d] Command: /usr/bin/env chmod +x /tmp/my_app/git-ssh.sh
INFO [acbfa48d] Finished in 0.005 seconds with exit status 0 (successful).
DEBUG [b2d0392c] Running /usr/bin/env git ls-remote -h my.git.example.com:/path/to/repos/my_app.git on my.server.example.com
DEBUG [b2d0392c] Command: ( GIT_ASKPASS=/bin/echo GIT_SSH=/tmp/my_app/git-ssh.sh /usr/bin/env git ls-remote -h my.git.example.com:/path/to/repos/my_app.git )
DEBUG [b2d0392c] fatal: '/path/to/repos/my_app.git' does not appear to be a git repository
DEBUG [b2d0392c] fatal: The remote end hung up unexpectedly
DEBUG [b2d0392c] Finished in 1.025 seconds with exit status 128 (failed).
进一步的调查让我相信
git ls-remote -h my.git.example.com:/path/to/repos/my_app.git
产生错误,因为当我尝试执行它时,它给出了完全相同的错误消息my.server.example.com。如果我将其修改为:
git ls-remote -h me@my.git.example.com:/path/to/repos/my_app.git
因此,我强烈地感觉到我的用户配置有误,并希望得到任何正确的指示。
答案1
这个问题的解决办法其实很简单。配置/部署.rb我必须设置转发代理设置为真的。
ssh_options: {
user: 'me', # overrides user setting above
keys: %w(/home/me/.ssh/id_rsa),
forward_agent: true,
auth_methods: %w(publickey),
verbose: :debug
}