我正在尝试使用Capistrano,私有bitbucket存储库和mercurial将代码部署到Amazon EC2实例。
我从开发框中成功运行了cap deploy:setup
。
然后我尝试运行cap deploy:cold
。我被提示输入bitbucket密码,我做的正确,但我收到“授权失败”错误消息。因此,我尝试部署代码的机器无法“克隆”bitbucket存储库中的代码。
这就是详细情况:
% cap deploy:cold
triggering load callbacks
* 2013-01-10 18:44:07 executing 'production'
triggering start callbacks for 'deploy:cold'
* 2013-01-10 18:44:07 executing 'multistage:ensure'
* 2013-01-10 18:44:07 executing 'deploy:cold'
* 2013-01-10 18:44:07 executing 'deploy:update'
** transaction: start
* 2013-01-10 18:44:07 executing 'deploy:update_code'
updating the cached checkout on all servers
executing locally: "hg log --verbose -r default --template \"{node|short}\""
command finished in 797ms
* executing "if -d /home/ec2-user/my_project/shared/cached-copy ; then hg pull --verbose --repository /home/ec2-user/my_project/shared/cached-copy https://bitbucket_user_id@bitbucket.org/bitbucket_user_id/my_project && hg update --verbose --repository /home/ec2-user/my_project/shared/cached-copy --clean 2ec0193d60ff; else hg clone --verbose --noupdate https://bitbucket_user_id@bitbucket.org/bitbucket_user_id/my_project /home/ec2-user/my_project/shared/cached-copy && hg update --verbose --repository /home/ec2-user/my_project/shared/cached-copy --clean 2ec0193d60ff; fi"
servers: "ec2-123-456-78-999.compute-1.amazonaws.com"
ec2-123-456-78-999.compute-1.amazonaws.com executing command
** ec2-123-456-78-999.compute-1.amazonaws.com :: out http authorization required
** ec2-123-456-78-999.compute-1.amazonaws.com :: out realm: Bitbucket.org HTTP
** ec2-123-456-78-999.compute-1.amazonaws.com :: out user: bitbucket_user_id
** ec2-123-456-78-999.compute-1.amazonaws.com :: out password:
hg password:
** ec2-123-456-78-999.compute-1.amazonaws.com :: out
** ec2-123-456-78-999.compute-1.amazonaws.com :: out abort: authorization failed
command finished in 5410ms
*** deploy:update_code rolling back
* executing "rm -rf /home/ec2-user/my_project/releases/20130110184415; true"
servers: "ec2-123-456-78-999.compute-1.amazonaws.com"
ec2-123-456-78-999.compute-1.amazonaws.com executing command
command finished in 431ms
failed: "sh -c 'if -d /home/ec2-user/my_project/shared/cached-copy ; then hg pull --verbose --repository /home/ec2-user/my_project/shared/cached-copy https://bitbucket_user_id@bitbucket.org/bitbucket_user_id/my_project && hg update --verbose --repository /home/ec2-user/my_project/shared/cached-copy --clean 2ec0193d60ff; else hg clone --verbose --noupdate https://bitbucket_user_id@bitbucket.org/bitbucket_user_id/my_project /home/ec2-user/my_project/shared/cached-copy && hg update --verbose --repository /home/ec2-user/my_project/shared/cached-copy --clean 2ec0193d60ff; fi'" on ec2-123-456-78-999.compute-1.amazonaws.com
这是我的Capistrano deploy.rb文件
set :application, "my_project"
set :repository, "https://bitbucket_user_id@bitbucket.org/bitbucket_user_id/my_project"
set :keep_releases, 4
set :scm, :mercurial
set :scm_username, "bitbucket_user_id"
default_run_options:pty = true
set :scm_prefer_prompt, :true
set :scm_verbose, :true
set :deploy_to, "/home/ec2-user/#{application}"
set :deploy_via, :remote_cache
set :user, "ec2-user"
set :use_sudo, false
namespace :deploy do
desc "Gracefully restarting unicorn"
task :restart, :roles => :app do
run "sudo /etc/init.d/start_script upgrade"
end
task :start, :roles => :app do
run "sudo /etc/init.d/start_script start"
end
task :stop, :roles => :app do
run "sudo /etc/init.d/start_script stop"
end
task :link, :roles => :app do
run "mkdir -p #{shared_path}/images"
run "ln -nfs #{shared_path}/images #{release_path}/tmp/images"
end
end
我在命令行上手动尝试了这个
ssh ec2-user@ec2-123-456-78-999.compute-1.amazonaws.com "hg clone --verbose --noupdate https://bitbucket_user_id@bitbucket.org/bitbucket_user_id/my_project /home/ec2-user/my_project/shared/cached-copy"
我得到了(没有提示输入bitbucket密码)
abort: http authorization required
我试过
ssh -t ec2-user@ec2-123-456-78-999.compute-1.amazonaws.com "hg clone --verbose --noupdate https://bitbucket_user_id@bitbucket.org/bitbucket_user_id/my_project /home/ec2-user/my_project/shared/cached-copy"
并且有效。
我相信Capistrano正在使用ssh(在我的deploy.rb中这行被伪tty打开)
default_run_options[:pty] = true
所以它应该有效,但为什么它不与Capistrano合作?
有人可以帮忙吗?
非常感谢!
答案 0 :(得分:1)
我遇到了类似的问题并通过查看这个问题解决了这个问题:Capistrano deploy failed after moving to bitbucket.org
那里的回答者建议该人检查他们是否在BitBucket中制作了部署密钥。在您的BitBucket仓库中,单击您的设置轮,在左侧边栏中单击“部署密钥”:使用部署密钥获得对此存储库的只读访问权限。
如果您不知道如何设置SSH密钥,请在此处阅读BitBucket指南:https://confluence.atlassian.com/pages/viewpage.action?pageId=270827678
希望这有帮助!