title: Deploy Rails 5 App Using Bitbucket & Digital Ocean & Capistrano
body: <p>I am having problems with deploying a rails app onto Digital Ocean. The app uses Rails 5, ruby 2.4.0, capistrano, and passenger. I am trying to connect a private repository in bitbucket to digital ocean via SSH, which maybe my problem.</p>
  
  <p>Here is my deploy.rb</p>
  
  <pre><code>set :application, 'APP_NAME'
  set :repo_url, 'git@bitbucket.org:USERNAME/APP_NAME.git'
  
  set :user, "deploy"
  set "stages", %w(production staging)
  set :linked_dirs, fetch(:linked_dirs, []).push('log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', 'public/system')
  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
  </code></pre>
  
  <p>And here is my deploy/production.rb file:</p>
  
  <pre><code>role :app, %w{deploy@ADDRESS}
  role :web, %w{deploy@ADDRESS}
  role :db, %w{deploy@ADDRESS}, :primary =&gt; true
  set :branch, "master"
  set :rails_env, "staging"
  set :deploy_to, "var/www/APP_NAME_production"
  </code></pre>
  
  <p>I have been following the this <a href="https://rubythursday.com/episodes/ruby-snack-15-deploy-to-digital-ocean-part-4" rel="nofollow noreferrer">tutorial on how to setup a rails app on digital ocean</a>.</p>
  
  <p>I can complete a cap staging deploy:check but get the following error when I run a cap staging deploy:</p>
  
  <pre><code>fatal: destination path 'var/www/APP_NAME/repo' already exists and is not an empty directory.
  ...
  SSHKit::Command::Failed: git exit status: 128
  ...
  </code></pre>
  
  <p>Any help would be greatly appreciated!</p>
  
  <p>UPDATED:
  Gems - </p>
  
  <pre><code>gem 'rails', '~&gt; 5.0.0', '&gt;= 5.0.0.1'
  ruby '2.4.0'
  group :development do
    # Access an IRB console on exception pages or by using &lt;%= console %&gt; anywhere in the code.
    gem 'web-console'
    gem 'listen', '~&gt; 3.0.5'
   ...
    gem 'capistrano', '~&gt;3.4.0'
    gem 'capistrano-ssh-doctor', '~&gt; 1.0'
    gem 'capistrano-rails', '~&gt;1.1'
    gem 'capistrano-passenger' 
  end
  </code></pre>
  
  <p>Capfile:</p>
  
  <pre><code># Load DSL and set up stages
  require 'capistrano/setup'
  require 'capistrano/ssh_doctor'
  # Include default deployment tasks
  require 'capistrano/deploy'
  
  # Include tasks from other gems included in your Gemfile
  #
  # For documentation on these, see for example:
  #
  #   https://github.com/capistrano/rvm
  #   https://github.com/capistrano/rbenv
  #   https://github.com/capistrano/chruby
  #   https://github.com/capistrano/bundler
  #   https://github.com/capistrano/rails
  #   https://github.com/capistrano/passenger
  #
  # require 'capistrano/rvm'
  # require 'capistrano/rbenv'
  # require 'capistrano/chruby'
  require 'capistrano/bundler'
  require 'capistrano/rails/assets'
  require 'capistrano/rails/migrations'
  require 'capistrano/passenger'
  
  # Load custom tasks from `lib/capistrano/tasks` if you have any defined
  Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }
  </code></pre>
  
  <p>Thank you!</p>