Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Capistrano 3, Rails 4, database configuration does not specify adapter

When I start

cap production deploy

it fails like this:

DEBUG [4ee8fa7a] Command: cd /home/deploy/myapp/releases/releases/20131025212110 && (RVM_BIN_PATH=~/.rvm/bin RAILS_ENV= ~/.rvm/bin/myapp_rake assets:precompile )
DEBUG [4ee8fa7a]        rake aborted!
DEBUG [4ee8fa7a]        database configuration does not specify adapter

You can see that "RAILS_ENV=" is actually empty and I'm wondering why that might be happening? I assume that this is the reason for the latter error that I don't have a database configuration.

The deploy.rb file is below:

set :application, 'myapp'
set :repo_url, '[email protected]:developer/myapp.git'
set :branch, :master
set :deploy_to, '/home/deploy/myapp/releases'
set :scm, :git
set :devpath, "/home/deploy/myapp_development"
set :user, "deploy"
set :use_sudo, false
set :default_env, { rvm_bin_path: '~/.rvm/bin' }

set :keep_releases, 5

namespace :deploy do
  desc 'Restart application'
  task :restart do
    on roles(:app), in: :sequence, wait: 5 do
      # Your restart mechanism here, for example:
      within release_path do
        execute " bundle exec thin restart -O -C config/thin/production.yml"
      end
    end
  end

  after :restart, :clear_cache do
    on roles(:web), in: :groups, limit: 3, wait: 10 do
      within release_path do

      end
    end
  end

  after :finishing, 'deploy:cleanup'
end

Database.yml:

production:
  adapter: mysql2
  encoding: utf8
  database: myapp_production
  pool: 5
  username: user
  password: pass
  host: localhost

development:
  adapter: mysql2
  encoding: utf8
  database: myapp_development
  pool: 5
  username: user
  password: pass
  host: localhost

The issue is resolved if I add

set :rails_env, "production"

to my deploy.rb, but this looks like hardcoding to me and I'm sure there's a nicer solution.

like image 642
Kazmin Avatar asked Oct 25 '13 21:10

Kazmin


2 Answers

Edit: Per this pull request, it's now fixed in version 1.1.0 of capistrano-rails.

Per this Github issue, another fix is to edit your Capfile. Comment out these two lines

#require 'capistrano/rails/assets'
#require 'capistrano/rails/migrations'

and put this line in

require 'capistrano/rails'

which will correctly set your RAILS_ENV variable.

like image 53
Waynn Lue Avatar answered Nov 18 '22 23:11

Waynn Lue


Using Cap 3 and capistrano_rails on rails 4 I was getting the same error; in the environment file(s) being deployed, I set

set :stage, :production
set :rails_env, 'production' # even though doc says only need to do this if it's different

Doc here: https://github.com/capistrano/rails

like image 13
Tom Harrison Avatar answered Nov 18 '22 23:11

Tom Harrison