我继承了一个托管在 Linode 上的 Rails 项目。
之前的开发人员使用 BitBucket 存储库以及 Capistrano 进行部署。
我已经在 GitHub 上设置了一个私人存储库,并且正在尝试让 Capistrano 配方发挥作用。我运气不好。我在部署期间继续收到公钥错误。
以下是我已采取的步骤 –
- 更新了 Linode 服务器上的 Git 远程(原始)URL 以指向我的新存储库
- 更新了 Capfile 中的存储库引用,以引用我的新存储库
- Ensured
ssh_options[:forward_agent]
在 Capfile 中设置为 true
- 在本地生成 SSH 密钥 (id_rsa.pub) 并将其添加到我在 GitHub 中的用户帐户
- 执行了
ssh-add
命令,以确保为身份验证代理添加身份
- Ran
ssh -T [email protected] /cdn-cgi/l/email-protection
确认 ssh 已在本地正确设置
- 登录我的 Linode 服务器并运行
ssh -T [email protected] /cdn-cgi/l/email-protection
确保它也能正常工作
此外,为了防止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, "[email protected] /cdn-cgi/l/email-protection:--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
我似乎不知道我哪里出了问题——任何帮助将不胜感激。
UPDATE
我还确保将以下内容添加到我的本地 ~/.ssh/config 文件中...
Host mydomain.com
ForwardAgent yes