Rails 4 + Capistrano 3:致命:部署时无法从远程存储库读取

我在使用Capistrano 3部署Rails 4应用程序时遇到以下错误

INFO [87512eb8] Running /usr/bin/env chmod +x /tmp/magnificent/git-ssh.sh as deploy@104.236.6.180 DEBUG [87512eb8] Command: /usr/bin/env chmod +x /tmp/magnificent/git-ssh.sh INFO [87512eb8] Finished in 0.444 seconds with exit status 0 (successful). INFO [1ec94dd1] Running /usr/bin/env git ls-remote --heads git@github.com:BoTreeConsultingTeam/magnificent.git as deploy@104.236.6.180 DEBUG [1ec94dd1] Command: ( GIT_ASKPASS=/bin/echo GIT_SSH=/tmp/magnificent/git-ssh.sh /usr/bin/env git ls-remote --heads git@github.com:BoTreeConsultingTeam/magnificent.git ) DEBUG [1ec94dd1] ERROR: Repository not found. DEBUG [1ec94dd1] fatal: Could not read from remote repository. DEBUG [1ec94dd1] DEBUG [1ec94dd1] Please make sure you have the correct access rights DEBUG [1ec94dd1] and the repository exists. 

这是capistrano配置。

配置/ deploy.rb

 # config valid only for current version of Capistrano lock '3.4.0' set :application, 'magnificent' set :repo_url, 'git@github.com:BoTreeConsultingTeam/magnificent.git' set :deploy_to, '/home/deploy/magnificent' set :linked_files, %w{config/database.yml config/secrets.yml} set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system} set :branch, 'develop' #set/ :branch,`git rev-parse --abbrev-ref HEAD`.chomp set :ssh_options, { forward_agent: true } 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 namespace :deploy do after :restart, :clear_cache do on roles(:web), in: :groups, limit: 3, wait: 10 do # Here we can do anything such as: # within release_path do # execute :rake, 'cache:clear' # end end end end 

production.rb

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

Capfile

 require 'capistrano/setup' require 'capistrano/deploy' require 'capistrano/rvm' require 'capistrano/bundler' require 'capistrano/rails' require 'capistrano/rails/assets' require 'capistrano/rails/migrations' Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r } set :rvm_type, :user set :rvm_ruby_version, '2.2.2' 

我还将远程服务器的/home/deploy/.ssh/id_rsa.pub复制到github部署密钥。

更新我确认我能够访问远程GIT_ASKPASS=/bin/echo GIT_SSH=/tmp/magnificent/git-ssh.sh /usr/bin/env git ls-remote --heads git@github.com:BoTreeConsultingTeam/magnificent.git以及GIT_ASKPASS=/bin/echo GIT_SSH=/tmp/magnificent/git-ssh.sh /usr/bin/env git ls-remote --heads git@github.com:BoTreeConsultingTeam/magnificent.git命令适用于远程服务器。

当前解决方案

最近我使用不同的解决方案。 在cap production deploy之前,我运行以下命令。

  1. eval "$(ssh-agent -s)"
  2. ssh-add ~/.ssh/id_rsa

以前的方案

我可以通过替换来解决这个问题

 set :repo_url, 'git@github.com:BoTreeConsultingTeam/magnificent.git' 

 set :repo_url, 'https://my_github_username:my_github_password@github.com/BoTreeConsultingTeam/magnificent' 

请注意,如果您的密码包含特殊字符,那么它应该是url编码的。 您可以使用irb中的URI::encode快速编码。

通过使用Capistrano 2的其他部署,我永远不需要提供github凭据。

任何人都可以告诉我为什么要在repo_url指定git用户名/密码?

在upcase论坛post中还有一个解决方案也有效。

我有类似的问题(ubuntu)。 ssh-agent应该开启。 您可以将其添加到启动应用程序。

我也有这个问题。 结果我加载了错误的SSH密钥,它干扰了部署。 通过删除错误加载的ssh键解决它,如下所示:

ssh-add -d ~/.ssh/wrong-ssh-key

然后再次运行Capistrano部署。

如果您是第一次部署到服务器,并且git服务器不在部署服务器的已知主机列表中,也可能发生这种情况。

因此,登录到远程服务器然后对存储库执行git请求将导致将git服务器添加到已知主机列表中。

像这样:

 git ls-remote git@bitbucket.org:your_gitbucket_user_id/your_repo.git master The authenticity of host 'bitbucket.org (104.192.143.2)' can't be established. RSA key fingerprint is SHA256:zzXQOXSRBEiUtuE8AikJYKwbHaxvSc0ojabwzha. Are you sure you want to continue connecting (yes/no)? yes 

你应该确认连接。

 Warning: Permanently added 'bitbucket.org,104.192.143.2' (RSA) to the list of known hosts. 

现在尝试使用capistrano任务进行部署。

 cap production deploy