Rails 4 + Capistrano 3:致命:部署时无法从远程存储库读取 [英] Rails 4 + Capistrano 3 : fatal: Could not read from remote repository while deploying
问题描述
使用Capistrano 3部署Rails 4应用程序时出现以下错误
$ b
INFO [87512eb8]正在运行/ usr / bin / env chmod + x /tmp/magnificent/git-ssh.sh as deploy@104.236.6.180
DEBUG [87512eb8]命令:/ usr / bin / env chmod + x /tmp/magnificent/git-ssh.sh
INFO [87512eb8]在0.444秒内完成,退出状态为0(成功)。
INFO [1ec94dd1]运行/ usr / bin / env git ls-remote - 头文件git@github.com:BoTreeConsultingTeam / magnificent.git as deploy@104.236.6.180
DEBUG [1ec94dd1]命令:( 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 ]错误:找不到存储库。
DEBUG [1ec94dd1]致命:无法从远程存储库读取。
DEBUG [1ec94dd1]
DEBUG [1ec94dd1]请确保您拥有正确的访问权限
DEBUG [1ec94dd1]并存在存储库。
这里是capistrano的配置。
config / deploy.rb
#config仅对当前版本的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 /缓存tmp / sockets vendor / bundle public / system}
set:branch,'develop'#set /:branch,`git rev-parse --abbrev-ref HEAD`.chomp
set:ssh_options, {forward_agent:true}
名称空间:deploy do
desc'重新启动应用程序'
任务:重新启动
对角色(:app),in ::sequence,wait:5 do
execute:touch,release_path.join('tmp / restart.txt')
end
end
after:publishing, 'deploy:restart'
after:finish,'deploy:cleanup'
end
$ b namespace:deploy do
after:restart,:clear_cache do
on roles(:web ),在::groups,limit:3,wait:10 do
#在这里,我们可以做任何事情,例如:
#在release_path中执行
#execute:rake,'cache:clear'
#end
end
end
end
production.rb
set:stage,:production
server' xx.xx.xx.xx',user:'deploy',roles:%w {web app}
< Capist
require'capistrano / setup'
require'capistrano / deploy'
要求'capistrano / rvm'
要求'capistrano / bundler'
要求'capistrano / rails'
要求'capistrano / rails / assets'
要求'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
命令适用于远程服务器。
< h3>当前解决方案
最近我使用了不同的解决方案。在 cap production deploy
之前运行以下命令。
-
eval$(ssh-agent -s)
-
ssh-add〜/ .ssh / id_rsa
以前的解决方案
我可以通过替换
set:repo_url,'git@github.com:BoTreeConsultingTeam / magnificent.git'
$ c $
$ p $ 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论坛帖子也有效。
I am getting following error while deploying Rails 4 application using Capistrano 3
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.
Here is capistrano configuration.
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'
I also copied /home/deploy/.ssh/id_rsa.pub of remote server to github deploy keys.
UPDATE
I confirm that I am able to access remote repo and also GIT_ASKPASS=/bin/echo GIT_SSH=/tmp/magnificent/git-ssh.sh /usr/bin/env git ls-remote --heads git@github.com:BoTreeConsultingTeam/magnificent.git
command works on remote server.
Current Solution
Lately I use different solution. Before cap production deploy
I run following commands.
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_rsa
Previous Solution
I am able to fix this issue by replacing
set :repo_url, 'git@github.com:BoTreeConsultingTeam/magnificent.git'
with
set :repo_url, 'https://my_github_username:my_github_password@github.com/BoTreeConsultingTeam/magnificent'
Note if your password contains special characters then thet should be url encoded. You can quickly encode using URI::encode
in irb.
With other deployments using Capistrano 2, I never need to supply github credentials.
Can anybody please tell why should I have to specify git username/password in repo_url
?
There is one more solution in the upcase forum post which also worked.
这篇关于Rails 4 + Capistrano 3:致命:部署时无法从远程存储库读取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!