Deploying Rails App with Capistrano - "ERROR: Repository not found."

Deploying Rails App with Capistrano - "ERROR: Repository not found."

我在使用 Capistrano 将 Rails 应用程序部署到 EC2 实例时遇到问题。我正在为我的个人笔记本电脑上的工作开发新的应用程序。我有两个 Github 帐户(个人和工作)。我试图添加我的个人 public 密钥,但 Github 拒绝了,因为我的个人 Github 帐户已经与之相关联。因此,结果我的笔记本电脑上有两组 private/public 键。

我将我的工作 public 密钥 (~/.ssh/work_rsa.pub) 添加到我的工作 Github 帐户。我在我的工作 Github 帐户拥有的 Github 组织(称为 WorkOrg)下创建了一个新的私有存储库(我是该组织的管理员用户)。

然后我必须创建一个别名,以便 git 在推送到 Github 时使用我的工作私钥。这是我的 ~/.ssh/config 的样子:

# work account
Host github.com-work
   HostName github.com
   User git
   IdentityFile ~/.ssh/work_rsa

然后我不得不将远程源 url 更改为:git@github.com-work:WorkOrg/work_reports.git 这样我就可以 运行 $ git push 而不必每次都提供我的用户名和密码信息.所以,我现在可以 push/pull 在我的笔记本电脑上的这个新 repo (work_reports) 中很好。

我还设置了一个 EC2 实例 (ubuntu 14.04) 并创建了一个用户 deploy,我可以通过 SSH 进入(使用相同的 ~/.ssh/work_rsa 密钥)。我将 work_rsa 复制到 /home/deploy/.ssh/work_rsa 中,这样我就可以从那个 EC2 实例中 push/pull。

我现在已准备好使用 Capistrano 为我的 EC2 实例设置自动部署。当我 运行 $ cap production deploy:check --trace 之后它失败了:

INFO [bb69f764] Running /usr/bin/env chmod +x /tmp/work_reports/git-ssh.sh as deploy@xx.xxx.xxx.xxx
DEBUG [bb69f764] Command: ( RBENV_ROOT=~/.rbenv RBENV_VERSION=2.2.2 /usr/bin/env chmod +x /tmp/work_reports/git-ssh.sh )
INFO [bb69f764] Finished in 0.046 seconds with exit status 0 (successful).
** Execute git:check
DEBUG [943f7c42] Running /usr/bin/env git ls-remote -h git@github.com:WorkOrg/work_reports.git as deploy@xx.xxx.xxx.xxx 
DEBUG [943f7c42] Command: ( RBENV_ROOT=~/.rbenv RBENV_VERSION=2.2.2 GIT_ASKPASS=/bin/echo GIT_SSH=/tmp/work_reports/git-ssh.sh /usr/bin/env git ls-remote -h git@github.com:WorkOrg/work_reports.git )
DEBUG [943f7c42] Error: Repository not found.
DEBUG [943f7c42]    fatal: Could not read from remote repository.
DEBUG [943f7c42]    
DEBUG [943f7c42]    Please make sure you have the correct access rights
DEBUG [943f7c42]    and the repository exists.

这是我的 Capfile:

require 'capistrano/setup'
require 'capistrano/deploy'
require 'capistrano/bundler'
require 'capistrano/rails'
require 'capistrano/rbenv'
set :rbenv_type, :user 
set :rbenv_ruby, '2.2.2'

这是我的 /config/deploy.rb 文件:

lock '3.2.1'
set :application, 'work_reports'
set :deploy_user, 'deploy'
set :scm, :git
#set :repo_url, 'git@github.com-work:WorkOrg/work_reports.git'
set :repo_url, 'git@github.com:WorkOrg/work_reports.git'
set :branch, ENV['REVISION'] || ENV['BRANCH'] || "master"
set :ssh_options, { forward_agent: true, paranoid: true, keys: "~/.ssh/work_rsa" }
set :deploy_to, '/home/deploy/work_reports'
set :linked_files, %w{config/database.yml}
set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}

namespace :deploy do

  desc 'Restart application'
  task :restart do
    on roles(:app), in: :sequence, wait: 5 do
      execute :touch, release_path.join('tmp/restart.txt')
    end
  end

  after :publishing, 'deploy:restart'
  after :finishing, 'deploy:cleanup'
end

这是我的 /config/deploy/production.rb 文件:

set :stage, :production
server 'xx.xxx.xxx.xxx', user: 'deploy', roles: %w{web app db}

我什至尝试在 deploy.rb 文件中使用别名远程源 url (set :repo_url, 'git@github.com-work:WorkOrg/work_reports.git'),但我遇到了同样的错误。

我是否没有正确配置某些东西,以便我可以使用 Capistrano 将我的 Rails 应用程序部署到 EC2?

为了让 Capistrano 实际使用 work_rsa 私钥,我不得不更改我的 /config/deploy.rb 文件:

set :ssh_options, { forward_agent: false, paranoid: true, keys: "~/.ssh/work_rsa" }

这里的火车晚点了。

我的问题原来是更改了repo 名称。这是在我通过 SSH 连接到服务器时修复的,然后更改了位于 /to/project/repo/config.

的 git 配置中的 repo URI

奇怪的是,这只发生在 Travis CI build 中。另外,当我检查 capistrano-ssh-doctor.

时没问题