我正在尝试使用 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 一起工作?
有人可以帮忙吗?
非常感谢!