intellidiot
intellidiot

Reputation: 11228

rvm and Capistrano: unable to clone git repository on Bitbucket "conq: repository access denied." but can manually acces from inside server

I have developed a new Rails (4.1.4) app in JRuby (1.7.10) and I have been deploying it with Capistrano v3 on a remote vps for sometime. Now all of a sudden the deployer script can't access the repository at Bitbucket. The error looks like:

DEBUG[a45f3340] Running /usr/bin/env git ls-remote -h [email protected]:ACCNAME/APPNAME.git on APPNAME.cloudapp.net
DEBUG[a45f3340] Command: ( GIT_ASKPASS=/bin/echo GIT_SSH=/tmp/USER/git-ssh.sh /usr/bin/env git ls-remote -h [email protected]:ACCNAME/APPNAME.git )
DEBUG[a45f3340]     conq: repository access denied.
DEBUG[a45f3340]     
DEBUG[a45f3340]     fatal: Could not read from remote repository.
DEBUG[a45f3340]     
DEBUG[a45f3340]     
DEBUG[a45f3340]     Please make sure you have the correct access rights
DEBUG[a45f3340]     
DEBUG[a45f3340]     and the repository exists.
DEBUG[a45f3340]     
DEBUG[a45f3340] Finished in 4.289 seconds with exit status 128 (failed).

Although when I log into the remote server and run the same command it successfully executes and connects Bitbucket repo.

This is how the Gemfile looks like:

source 'https://rubygems.org'

ruby '1.9.3', :engine => 'jruby', :engine_version => '1.7.10'

gem 'rails', '4.1.4'
gem 'sass-rails', '~> 4.0.3'
gem 'uglifier', '>= 1.3.0'
gem 'therubyrhino'
gem 'jquery-rails'
gem 'jbuilder', '~> 2.0'
gem 'sdoc', '~> 0.4.0', group: :doc
gem 'activerecord-jdbcmysql-adapter'
gem 'devise'
gem 'devise_invitable', :github => 'scambra/devise_invitable'
gem "paperclip"
gem 'acts_as_list'
gem 'pry-rails', group: :development
gem 'rubyzip'
gem 'to_bool', '~> 1.0.1'
gem "jquery-fileupload-rails"

# Use Capistrano for deployment
gem 'capistrano', group: :development
gem 'capistrano-rvm', group: :development
gem 'capistrano-bundler', group: :development
gem 'capistrano-rails', group: :development
gem 'trinidad', require: false
gem 'rvm1-capistrano3', require: false

Capfile:

require 'capistrano/setup'
require 'capistrano/deploy'
require 'capistrano/rvm'
require 'capistrano/bundler'
require 'capistrano/rails'
require 'capistrano/rails/assets'
require 'capistrano/rails/migrations'
require 'rvm1/capistrano3'

Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }

deploy.rb:

# config valid only for Capistrano 3.1
lock '3.2.1'

set :bundle_flags, '--deployment' # tried removing switch deployment if installing as system gem helps

set :deploy_user, "deployer"
set :application, 'APPNAME'
set :repo_url, '[email protected]:user/repo.git'
server "example.net", user: 'deployer', roles: [:web, :app, :db]

set :rvm_type, :user                   
set :rvm1_ruby_version, 'jruby-1.7.10'

set :scm, :git
set :pty, true
set :deploy_to, "/home/#{fetch(:deploy_user)}/apps/#{fetch(:application)}"
set :linked_files, %w{config/database.yml}
set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}
set :keep_releases, 5
after "deploy", "deploy:cleanup"

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, :restart

  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

namespace :deploy do
  desc "Install everything onto the server"
  task :install do
    on roles(:all), in: :sequence, wait: 1 do
      execute 'mkdir', '-p', fetch(:deploy_to)
      execute :sudo, 'apt-get', '-y', "update"
      execute :sudo, 'apt-get', '-y', "install", "build-essential zlib1g-dev libssl-dev libreadline-gplv2-dev python-software-properties curl git-core openjdk-7-jdk jsvc"
    end
  end
end

One thing to note here, I was constantly getting an warning from rvm

Warning! PATH is not properly set up, '/Users/username/.rvm/gems/ruby-2.1.0/bin' is not at first place,
         usually this is caused by shell initialization files - check them for 'PATH=...' entries,
         it might also help to re-add RVM to your dotfiles: 'rvm get stable --auto-dotfiles',
         to fix temporarily in this shell session run: 'rvm use ruby-2.1.0'.

So I ran rvm get stable --auto-dotfiles and I think the issue started after this point. But this is what I am assuming. I might be wrong. I tried to reinstall the rvm of the server by cap production rvm1:install:rvm, but that didn't help.

Can anybody suggest what went wrong?

Upvotes: 1

Views: 351

Answers (1)

Yohan G.
Yohan G.

Reputation: 1186

In my case it was an ssh-agent issue, I fixed the problem by adding eval $(ssh-agent) > /dev/null in my capistrano ssh-user .bashrc.

This article helped me : https://peteoliveira.com/deploying-with-capistrano-3-failing-permission-denied-publickey/

Upvotes: 1

Related Questions