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

前端 未结 6 873
半阙折子戏
半阙折子戏 2020-12-24 14:47

When I start

cap production deploy

it fails like this:

DEBUG [4ee8fa7a] Command: cd /home/deploy/myapp/releases/         


        
相关标签:
6条回答
  • 2020-12-24 14:54

    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.

    0 讨论(0)
  • 2020-12-24 15:04

    Based on Marc's answer which definitely seems to be the right one,

    you can workaround this until it is fixed upstream by adding this to your config/deploy.rb in the "namespace :deploy" block:

      desc 'Provision env before assets:precompile'
      task :fix_bug_env do
        set :rails_env, (fetch(:rails_env) || fetch(:stage))
      end
    
      before "deploy:assets:precompile", "deploy:fix_bug_env"
    

    This will force loading the env and provisionning RAILS_ENV before assets:precompile is called.

    0 讨论(0)
  • 2020-12-24 15:07

    What happens if you add a file:

    deploy/production.rb
    

    With this line:

    set :stage, :production
    
    0 讨论(0)
  • 2020-12-24 15:14

    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

    0 讨论(0)
  • 2020-12-24 15:14

    If you're using passenger, you need to add

    rails_env production;
    

    in the in web server's (eg: nginx) .conf where you've specified values for passenger_ruby and passenger_root.

    0 讨论(0)
  • 2020-12-24 15:20

    Seems to be a bug in capistrano-rails.

    There is a task (rails.rake) that sets the environment either from rails_env or stage:

    namespace :deploy do
      before :starting, :set_rails_env do
        set :rails_env, (fetch(:rails_env) || fetch(:stage))
      end
    end
    

    But this task isn't called before i.e. assets:precompile. So this:

    namespace :assets do
      task :precompile do
        on roles :web do
          within release_path do
            with rails_env: fetch(:rails_env) do
              execute :rake, "assets:precompile"
            end
          end
        end
      end
    end
    

    fails because rails_env is nil if it isn't set explicitly.

    If I have the time to dig a little deeper I'll file a bug report.

    0 讨论(0)
提交回复
热议问题