I am getting following error while deploying Rails 4 application using Capistrano 3
INFO [87512eb8] Running /usr/bin/env chmod +x /tmp/magnificent/git-ssh.sh as [email protected]
DEBUG [87512eb8] Command: /usr/bin/env chmod +x /tmp/magnificent/git-ssh.sh
INFO [87512eb8] Finished in 0.444 seconds with exit status 0 (successful).
INFO [1ec94dd1] Running /usr/bin/env git ls-remote --heads [email protected]:BoTreeConsultingTeam/magnificent.git as [email protected]
DEBUG [1ec94dd1] Command: ( GIT_ASKPASS=/bin/echo GIT_SSH=/tmp/magnificent/git-ssh.sh /usr/bin/env git ls-remote --heads [email protected]:BoTreeConsultingTeam/magnificent.git )
DEBUG [1ec94dd1] ERROR: Repository not found.
DEBUG [1ec94dd1] fatal: Could not read from remote repository.
DEBUG [1ec94dd1]
DEBUG [1ec94dd1] Please make sure you have the correct access rights
DEBUG [1ec94dd1] and the repository exists.
Here is capistrano configuration.
config/deploy.rb
# config valid only for current version of Capistrano
lock '3.4.0'
set :application, 'magnificent'
set :repo_url, '[email protected]:BoTreeConsultingTeam/magnificent.git'
set :deploy_to, '/home/deploy/magnificent'
set :linked_files, %w{config/database.yml config/secrets.yml}
set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}
set :branch, 'develop' #set/ :branch,`git rev-parse --abbrev-ref HEAD`.chomp
set :ssh_options, { forward_agent: true }
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
namespace :deploy do
after :restart, :clear_cache do
on roles(:web), in: :groups, limit: 3, wait: 10 do
# Here we can do anything such as:
# within release_path do
# execute :rake, 'cache:clear'
# end
end
end
end
production.rb
set :stage, :production
server 'xx.xx.xx.xx', user: 'deploy', roles: %w{web app}
Capfile
require 'capistrano/setup'
require 'capistrano/deploy'
require 'capistrano/rvm'
require 'capistrano/bundler'
require 'capistrano/rails'
require 'capistrano/rails/assets'
require 'capistrano/rails/migrations'
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }
set :rvm_type, :user
set :rvm_ruby_version, '2.2.2'
I also copied /home/deploy/.ssh/id_rsa.pub of remote server to github deploy keys.
UPDATE
I confirm that I am able to access remote repo and also GIT_ASKPASS=/bin/echo GIT_SSH=/tmp/magnificent/git-ssh.sh /usr/bin/env git ls-remote --heads [email protected]:BoTreeConsultingTeam/magnificent.git
command works on remote server.
Lately I use different solution. Before cap production deploy
I run following commands.
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_rsa
I am able to fix this issue by replacing
set :repo_url, '[email protected]:BoTreeConsultingTeam/magnificent.git'
with
set :repo_url, 'https://my_github_username:[email protected]/BoTreeConsultingTeam/magnificent'
Note if your password contains special characters then thet should be url encoded. You can quickly encode using URI::encode
in irb.
With other deployments using Capistrano 2, I never need to supply github credentials.
Can anybody please tell why should I have to specify git username/password in repo_url
?
There is one more solution in the upcase forum post which also worked.