Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 轨道4+;Capistrano 3:致命:部署时无法从远程存储库读取_Ruby On Rails_Github_Deployment_Digital Ocean_Capistrano3 - Fatal编程技术网

Ruby on rails 轨道4+;Capistrano 3:致命:部署时无法从远程存储库读取

Ruby on rails 轨道4+;Capistrano 3:致命:部署时无法从远程存储库读取,ruby-on-rails,github,deployment,digital-ocean,capistrano3,Ruby On Rails,Github,Deployment,Digital Ocean,Capistrano3,在使用Capistrano3部署Rails4应用程序时,我遇到以下错误 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 second

在使用Capistrano3部署Rails4应用程序时,我遇到以下错误

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
set :stage, :production
server 'xx.xx.xx.xx', user: 'deploy', roles: %w{web app}
production.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
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部署密钥

更新 我确认我能够访问远程repo,也能够访问GIT_ASKPASS=/bin/echo GIT_SSH=/tmp/globalize/GIT-SSH.sh/usr/bin/env GIT ls remote--headsgit@github.com:BoTreeConsultingTeam/globalize.git命令在远程服务器上工作。

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

  • eval“$(ssh代理-s)”
  • ssh add~/.ssh/id\u rsa
  • 先前的解决方案 我可以通过替换

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

    注意如果密码包含特殊字符,则应使用url编码。您可以在irb中使用
    URI::encode
    快速编码

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

    有人能告诉我为什么必须在
    repo\u url
    中指定git用户名/密码吗


    在中还有一个解决方案同样有效。

    我也有类似的问题(ubuntu)。ssh代理应该处于启用状态。您可以将其添加到启动应用程序中。

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

    ssh add-d~/.ssh/错误的ssh密钥


    然后再次运行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
    

    转到服务器框get id_rsa.pub并将其添加到github上的密钥中一个常见错误是,您可能需要将服务器的公钥添加到repo的访问密钥列表中。我总是忘记这一点,并添加本地环境中从未工作过的公钥。

    是的,这也是有效的。最近,在部署之前,我开始使用
    ssh代理。更新了我的答案。我本来不会实现原来的解决方案,但你的更新确实帮助我解决了问题。它是有效的,但这很糟糕,将其提交到git中的安全性真的很差