I’ve done this a few times in the past for other projects and eventually get it working, but each time I can’t seem to remember exactly what to do.
I have an ec2 ubuntu server and am deploying with capistrano and have used rubber to set evertyhing up.
On my ec2 server, I’ve generated ssh keys, added to bitbucket (under my accounts, ssh key. at first i tried under the project and deployment keys, but that didn’t work either). On my ec2 server, I can successfully manually ssh in and clone my repo into my home directly. I’ve added the key to ssh agent.
I can deploy just fine if I do not use scm and set deploy_via to :copy. I believe this grabs my local project and deploys it.
I’ve read these: https://confluence.atlassian.com/display/BITBUCKET/Using+Deployment+Keys
https://confluence.atlassian.com/display/BITBUCKET/Troubleshooting+SSH+Issues
https://confluence.atlassian.com/pages/viewpage.action?pageId=270827678
This works fine:
ubuntu@production:~$ ssh -T hg@bitbucket.org
conq: logged in as myBitBucketUser.
You can use git or hg to connect to Bitbucket. Shell access is disabled.
Here’s the error message I get during deploy:
* executing "if [ -d /mnt/myProject-production/shared/cached-copy ]; then cd /mnt/myProject-production/shared/cached-copy && git fetch -q origin && git fetch --tags -q origin && git reset -q --hard f2b5b8b6cd1c7835d020d66fdc09b42b2870561e && git clean -q -d -x -f; else git clone -q git@bitbucket.org:myRepo.git /mnt/myProject-production/shared/cached-copy && cd /mnt/myProject-production/shared/cached-copy && git checkout -q -b deploy f2b5b8b6cd1c7835d020d66fdc09b42b2870561e; fi"
servers: ["production.myserver.com"]
[production.myserver.com] executing command
** [production.myserver.com :: out] Permission denied (publickey).
** fatal: The remote end hung up unexpectedly
Here’s my deploy.rb:
set :rails_env, Rubber.env
on :load do
set :application, rubber_env.app_name
set :runner, rubber_env.app_user
set :deploy_to, "/mnt/#{application}-#{Rubber.env}"
set :copy_exclude, [".git/*", ".bundle/*", "log/*", ".rvmrc"]
end
# Use a simple directory tree copy here to make demo easier.
# You probably want to use your own repository for a real app
#set :scm, :none
#set :repository, "."
#set :deploy_via, :copy
ssh_options[:forward_agent] = true # also tried false
set :repository, "git@bitbucket.org:myProject.git"
set :scm, "git"
set :deploy_via, :remote_cache
set :branch, 'master'
# Easier to do system level config as root - probably should do it through
# sudo in the future. We use ssh keys for access, so no passwd needed
set :user, 'root'
set :password, nil
# Use sudo with user rails for cap deploy:[stop|start|restart]
# This way exposed services (mongrel) aren't running as a privileged user
set :use_sudo, false # also tried true
I ran into this problem using rubber as well.
If you have multiple instances you’ll need to get SSH keys for all instances as rubber will deploy the code to all. Haven’t found a way to prevent this.
The ssh keys to use are under ~/.ssh or /root/.ssh if you the keys you generated are in a different directory or under a different user they are probably not being recognized as rubber deploys using the user ‘root’ and that’s the user fetching from the repo.
Hope this helps.