【发布时间】:2014-05-23 13:12:29
【问题描述】:
我继承了一个 Rails 项目,托管在 Linode 上。
之前的开发人员使用 BitBucket 存储库以及 Capistrano 进行部署。
我已经在 GitHub 上设置了一个私有存储库,并且我正在尝试让 Capistrano 配方工作。我没有运气。我在部署期间继续收到公钥错误。
这是我采取的步骤 -
- 更新了 Linode 服务器上的 Git 远程(原始)URL 以指向我的新存储库
- 更新了 Capfile 中的存储库引用,以引用我的新存储库
- 确保
ssh_options[:forward_agent]在 Capfile 中设置为 true - 在本地生成 SSH 密钥 (id_rsa.pub) 并将其添加到我在 GitHub 中的用户帐户中
- 执行
ssh-add命令,确保身份已添加到身份验证代理 - 运行
ssh -T git@github.com以确认 ssh 已在本地正确设置 - 登录到我的 Linode 服务器并运行
ssh -T git@github.com以确保它也能正常工作
另外,为了以防 forward_agent 属性不起作用,我什至尝试在 Linode 服务器上生成一个 SSH 密钥,并将其也添加到 GitHub。没有运气。
在这一切之后,当我运行 cap deploy 时,我收到以下错误:
Permission denied (publickey).
fatal: The remote end hung up unexpectedly
以下是我正在使用的食谱 -
require "bundler/capistrano"
server "----SERVER IP----", :web, :app, :db, primary: true
set :application, "blog"
set :user, "deployer"
set :deploy_to, "/var/www/blog"
set :deploy_via, :remote_cache
set :use_sudo, false
set :scm, "git"
set :repository, "git@github.com:--MY USERNAME--/blog.git"
set :branch, "master"
default_run_options[:pty] = true
ssh_options[:forward_agent] = true
after "deploy", "deploy:cleanup" # keep only the last 5 releases
namespace :deploy do
task :start do; end
task :stop do; end
task :restart, roles: :app, except: {no_release: true} do
run "touch #{deploy_to}/current/tmp/restart.txt"
end
task :setup_config, roles: :app do
sudo "ln -nfs #{current_path}/config/apache.conf /etc/apache2/sites-available/blog"
run "mkdir -p #{shared_path}/config"
put File.read("config/database.example.yml"), "#{shared_path}/config/database.yml"
puts "Now edit the config files in #{shared_path}."
end
after "deploy:setup", "deploy:setup_config"
task :symlink_config, roles: :app do
run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
run "ln -nfs #{shared_path}/public/avatars #{release_path}/public/avatars"
end
after "deploy:finalize_update", "deploy:symlink_config"
desc "Make sure local git is in sync with remote."
task :check_revision, roles: :web do
unless `git rev-parse HEAD` == `git rev-parse origin/master`
puts "WARNING: HEAD is not the same as origin/master"
puts "Run `git push` to sync changes."
exit
end
end
before "deploy", "deploy:check_revision"
end
我似乎无法弄清楚我哪里出错了 - 任何帮助将不胜感激。
更新
我还确保将以下内容添加到我的本地 ~/.ssh/config 文件中...
Host mydomain.com
ForwardAgent yes
【问题讨论】:
-
你可以尝试在本地机器上运行“ssh-add”,然后重新运行
cap deploy吗?更多信息here
标签: ruby-on-rails github ssh capistrano linode