Reputation: 2210
I'm having trouble using Capistrano to deploy a Rails app to an EC2 instance. I am developing the new app for my work on my personal laptop. I have two Github accounts (personal and work). I tried to add my personal public key but Github refused because my personal Github account was already associated with it. So, as a result I have two sets of private/public keys on my laptop.
I added my work public key (~/.ssh/work_rsa.pub
) to my work Github account. I created a new private repository under a Github Organization (referred to as WorkOrg) that my work Github account owns (I'm an admin user in that org).
Then I had to create an alias so that git would use my work private key when pushing to Github. Here's how my ~/.ssh/config
looks:
# work account
Host github.com-work
HostName github.com
User git
IdentityFile ~/.ssh/work_rsa
I then had to change the remote origin url to: [email protected]:WorkOrg/work_reports.git
so that I could run $ git push
without having to supply my username and password info every time. So, I can now push/pull just fine in this new repo (work_reports
) on my laptop.
I also setup an EC2 instance (ubuntu 14.04) and created a user deploy
that I can SSH into (using the same ~/.ssh/work_rsa
key). I copied over my work_rsa
into /home/deploy/.ssh/work_rsa
so that I could push/pull from that EC2 instance.
I'm now ready to use Capistrano to setup automated deployments to my EC2 instance. When I run $ cap production deploy:check --trace
it fails after this:
INFO [bb69f764] Running /usr/bin/env chmod +x /tmp/work_reports/git-ssh.sh as [email protected]
DEBUG [bb69f764] Command: ( RBENV_ROOT=~/.rbenv RBENV_VERSION=2.2.2 /usr/bin/env chmod +x /tmp/work_reports/git-ssh.sh )
INFO [bb69f764] Finished in 0.046 seconds with exit status 0 (successful).
** Execute git:check
DEBUG [943f7c42] Running /usr/bin/env git ls-remote -h [email protected]:WorkOrg/work_reports.git as [email protected]
DEBUG [943f7c42] Command: ( RBENV_ROOT=~/.rbenv RBENV_VERSION=2.2.2 GIT_ASKPASS=/bin/echo GIT_SSH=/tmp/work_reports/git-ssh.sh /usr/bin/env git ls-remote -h [email protected]:WorkOrg/work_reports.git )
DEBUG [943f7c42] Error: Repository not found.
DEBUG [943f7c42] fatal: Could not read from remote repository.
DEBUG [943f7c42]
DEBUG [943f7c42] Please make sure you have the correct access rights
DEBUG [943f7c42] and the repository exists.
Here's my Capfile
:
require 'capistrano/setup'
require 'capistrano/deploy'
require 'capistrano/bundler'
require 'capistrano/rails'
require 'capistrano/rbenv'
set :rbenv_type, :user
set :rbenv_ruby, '2.2.2'
Here's my /config/deploy.rb
file:
lock '3.2.1'
set :application, 'work_reports'
set :deploy_user, 'deploy'
set :scm, :git
#set :repo_url, '[email protected]:WorkOrg/work_reports.git'
set :repo_url, '[email protected]:WorkOrg/work_reports.git'
set :branch, ENV['REVISION'] || ENV['BRANCH'] || "master"
set :ssh_options, { forward_agent: true, paranoid: true, keys: "~/.ssh/work_rsa" }
set :deploy_to, '/home/deploy/work_reports'
set :linked_files, %w{config/database.yml}
set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}
namespace :deploy do
desc 'Restart application'
task :restart do
on roles(:app), in: :sequence, wait: 5 do
execute :touch, release_path.join('tmp/restart.txt')
end
end
after :publishing, 'deploy:restart'
after :finishing, 'deploy:cleanup'
end
And here's my /config/deploy/production.rb
file:
set :stage, :production
server 'xx.xxx.xxx.xxx', user: 'deploy', roles: %w{web app db}
I even tried using the aliased remote origin url (set :repo_url, '[email protected]:WorkOrg/work_reports.git'
) in the deploy.rb
file but I got the same error.
Is there something I'm not configuring properly so that I can deploy my Rails app to EC2 using Capistrano?
Upvotes: 0
Views: 1731
Reputation: 3065
Late in the train here.
My problem turned out to be changed repo name. This was fixed when I SSH'd to the server, then changed the repo URI in git config located at /to/project/repo/config
.
Weird thing that this was only happening in Travis CI build. Also, no problem when I checked with capistrano-ssh-doctor
.
Upvotes: 0
Reputation: 2210
I had to change my /config/deploy.rb
file in order for Capistrano to actually use the work_rsa
private key :
set :ssh_options, { forward_agent: false, paranoid: true, keys: "~/.ssh/work_rsa" }
Upvotes: 1