【问题标题】:Rails 4 + Capistrano 3 : fatal: Could not read from remote repository while deployingRails 4 + Capistrano 3:致命:部署时无法从远程存储库读取
【发布时间】:2015-10-29 14:39:29
【问题描述】:

使用 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 配置。

config/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 命令也可以在远程服务器上运行。

【问题讨论】:

    标签: ruby-on-rails github deployment digital-ocean capistrano3


    【解决方案1】:

    当前解决方案

    最近我使用不同的解决方案。在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 forum post 中还有另一种解决方案也有效。

    【讨论】:

    • 我不会实施原始解决方案,但您的更新确实帮助我解决了我的问题。
    • 它可以工作,但这很糟糕,将它提交到 git 中的安全性真的很差
    【解决方案2】:

    如果您是第一次部署到服务器,并且 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
    

    【讨论】:

      【解决方案3】:

      我也有这个问题。原来我加载了错误的 SSH 密钥,它干扰了部署。通过像这样删除错误加载的 ssh 密钥来解决它:

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

      然后再次运行 Capistrano 部署。

      【讨论】:

        【解决方案4】:

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

        【讨论】:

        • 是的,这也行得通。最近我在部署之前开始使用ssh-agent。更新了我的答案。
        【解决方案5】:

        去服务器框获取 id_rsa.pub 并将其添加到 github 上的密钥

        【讨论】:

          【解决方案6】:

          一个常见的错误是您可能需要将服务器的公钥添加到存储库的访问密钥列表中。我总是忘记这一点,并添加了我本地环境的公钥,但它从来没有用过。

          【讨论】:

            猜你喜欢
            • 2018-03-06
            • 2014-11-25
            • 2012-11-10
            • 2015-10-31
            • 2015-01-19
            • 2020-09-14
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多