我試圖使用Capistrano,專用bitbucket存儲庫和mercurial將代碼部署到Amazon EC2實例。Capistrano從bitbucket存儲庫部署代碼獲取「授權失敗」
我成功地從我的開發箱中運行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://[email protected]/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://[email protected]/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://[email protected]/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://[email protected]/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://[email protected]/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 [email protected] "hg clone --verbose --noupdate https://[email protected]/bitbucket_user_id/my_project /home/ec2-user/my_project/shared/cached-copy"
和我(沒有提示bitbucket密碼)
abort: http authorization required
我試圖
ssh -t [email protected] "hg clone --verbose --noupdate https://[email protected]/bitbucket_user_id/my_project /home/ec2-user/my_project/shared/cached-copy"
和它的工作。
我相信Capistrano的是使用ssh(含僞TTY打開在我的deploy.rb此行)
default_run_options[:pty] = true
所以它應該工作,但爲什麼它不與Capistrano的工作?
有人可以幫忙嗎?
非常感謝!