Ruby on rails Carrierwave/Fog未看到Heroku环境变量

Ruby on rails Carrierwave/Fog未看到Heroku环境变量,ruby-on-rails,ruby,heroku,carrierwave,fog,Ruby On Rails,Ruby,Heroku,Carrierwave,Fog,我正在从Ruby 1.9.3/Rails 3.2.14升级到Ruby 2.2.0/Rails 4.2.1,一切都可以在我的开发系统上运行。当推到Heroku时,我得到ArgumentError:缺少必需的参数:aws\u access\u key\id、aws\u secret\u access\u key,但是这些环境变量已设置 ~/documents/coding$ heroku config -a vupgrade === vupgrade Config Vars .... AWS_ACC

我正在从Ruby 1.9.3/Rails 3.2.14升级到Ruby 2.2.0/Rails 4.2.1,一切都可以在我的开发系统上运行。当推到Heroku时,我得到
ArgumentError:缺少必需的参数:aws\u access\u key\id、aws\u secret\u access\u key
,但是这些环境变量已设置

~/documents/coding$ heroku config -a vupgrade
=== vupgrade Config Vars
....
AWS_ACCESS_KEY_ID:            ...XYZ...
AWS_SECRET_ACCESS_KEY:        ...XYZ...
....
分叉我的暂存系统后,推送的(更完整的)输出如下:

~/documents/coding$ git push upgrade upgrade:master
Fetching repository, done.
Counting objects: 9950, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (5166/5166), done.
Writing objects: 100% (9950/9950), 82.90 MiB | 748.00 KiB/s, done.
Total 9950 (delta 7130), reused 6420 (delta 4535)

-----> Fetching custom git buildpack... done
-----> Ruby app detected
-----> Compiling Ruby/Rails
-----> Using Ruby version: ruby-2.2.0
-----> Installing gsl
-----> Installing dependencies using 1.5.2
       Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin -j4 --deployment
       Fetching source index from https://rubygems.org/
       Fetching https://ccd14907bc3e94a7f9e2366ad113d7c89b88eeb2:x-oauth-basic@github.com/rvizza/rb-gsl.git
       Fetching git://github.com/bearded-nemesis/heroku-rglpk.git
       Fetching https://ccd14907bc3e94a7f9e2366ad113d7c89b88eeb2:x-oauth-basic@github.com/rvizza/joule.git
       Fetching https://ccd14907bc3e94a7f9e2366ad113d7c89b88eeb2:x-oauth-basic@github.com/rvizza/ride_parser.git
       Fetching https://ccd14907bc3e94a7f9e2366ad113d7c89b88eeb2:x-oauth-basic@github.com/rvizza/top_efforts.git
       Fetching https://ccd14907bc3e94a7f9e2366ad113d7c89b88eeb2:x-oauth-basic@github.com/rvizza/RubyPeaks.git
       Using rake (10.4.2)
       Installing CFPropertyList (2.3.0)
       Installing i18n (0.7.0)
       Installing thread_safe (0.3.5)
       Installing minitest (5.5.1)
       Installing builder (3.2.2)
       Installing mini_portile (0.6.2)
       Installing mime-types (1.25.1)
       Installing erubis (2.7.0)
       Installing arel (6.0.0)
       Installing encryptor (1.3.0)
       Installing rack (1.6.0)
       Installing execjs (2.3.0)
       Installing cancancan (1.10.1)
       Installing sass (3.4.13)
       Installing coffee-script-source (1.9.1)
       Installing thor (0.19.1)
       Installing daemons (1.1.9)
       Installing orm_adapter (0.5.0)
       Installing excon (0.44.4)
       Installing fastercsv (1.5.5)
       Installing formatador (0.2.5)
       Installing net-ssh (2.9.2)
       Installing multi_json (1.11.0)
       Installing bcrypt (3.1.10)
       Installing inflecto (0.0.2)
       Installing ipaddress (0.8.0)
       Installing json (1.8.2)
       Installing hike (1.2.3)
       Installing multi_xml (0.5.5)
       Installing systemu (2.6.4)
       Installing netrc (0.10.3)
       Installing narray (0.6.1.1)
       Installing nori (2.4.0)
       Using heroku-rglpk (0.2.1) from git://github.com/bearded-nemesis/heroku-rglpk.git (at master)
       Using bundler (1.5.2)
       Installing newrelic_rpm (3.10.0.279)
       Installing rails_serve_static_assets (0.0.4)
       Installing rails_stdout_logging (0.0.3)
       Installing tilt (1.4.1)
       Installing rolify (4.0.0)
       Installing eventmachine (1.0.5)
       Installing session (3.2.0)
       Using ride_parser (0.0.2) from https://ccd14907bc3e94a7f9e2366ad113d7c89b88eeb2:x-oauth-basic@github.com/rvizza/ride_parser.git (at master)
       Using trainingpeaks (0.0.0) from https://ccd14907bc3e94a7f9e2366ad113d7c89b88eeb2:x-oauth-basic@github.com/rvizza/RubyPeaks.git (at master)
       Using top_efforts (0.0.2) from https://ccd14907bc3e94a7f9e2366ad113d7c89b88eeb2:x-oauth-basic@github.com/rvizza/top_efforts.git (at master)
       Installing unf_ext (0.0.6)
       Installing switch_user (0.9.5)
       Installing will_paginate (3.0.7)
       Installing gyoku (1.2.2)
       Installing fission (0.5.0)
       Installing mail (2.6.3)
       Installing attr_encrypted (1.3.3)
       Installing pg (0.18.1)
       Installing rack-test (0.6.3)
       Installing httpi (2.3.0)
       Installing coffee-script (2.3.0)
       Installing figaro (1.1.0)
       Installing warden (1.2.3)
       Installing net-scp (1.2.1)
       Installing heroku-api (0.3.18)
       Installing tzinfo (1.2.2)
       Installing autoprefixer-rails (5.1.7)
       Installing macaddr (1.7.1)
       Installing fog-json (1.0.0)
       Installing rest-client (1.7.3)
       Installing rails_12factor (0.0.3)
       Installing sprockets (2.12.3)
       Installing thin (1.5.1)
       Installing rush (0.6.8)
       Installing unf (0.1.4)
       Installing will_paginate-bootstrap (1.0.1)
       Installing fog-core (1.29.0)
       Installing activesupport (4.2.1)
       Installing tzinfo-data (1.2015.1)
       Installing bootstrap-sass (3.3.3)
       Installing uuid (2.3.7)
       Installing stripe (1.20.1)
       Installing fog-brightbox (0.7.1)
       Installing fog-sakuracloud (1.0.0)
       Installing fog-serverlove (0.1.1)
       Installing fog-softlayer (0.4.1)
       Installing fog-storm_on_demand (0.1.0)
       Installing nokogiri (1.6.6.2)
       Installing fog-vmfusion (0.0.1)
       Installing rails-deprecated_sanitizer (1.0.3)
       Installing globalid (0.3.3)
       Installing activemodel (4.2.1)
       Installing delayed_job (4.0.6)
       Installing stripe_event (1.5.0)
       Installing loofah (2.0.1)
       Installing akami (1.2.2)
       Installing fog-xml (0.1.1)
       Using joule (1.0.4) from https://ccd14907bc3e94a7f9e2366ad113d7c89b88eeb2:x-oauth-basic@github.com/rvizza/joule.git (at master)
       Installing httparty (0.13.3)
       Installing rails-dom-testing (1.0.6)
       Installing wasabi (3.3.0)
       Installing carrierwave (0.10.0)
       Installing activerecord (4.2.1)
       Installing rails-html-sanitizer (1.0.2)
       Installing fog-atmos (0.1.0)
       Installing fog-ecloud (0.0.2)
       Installing fog-profitbricks (0.0.1)
       Installing fog-radosgw (0.0.3)
       Installing fog-aws (0.1.1)
       Installing fog-riakcs (0.1.0)
       Installing fog-terremark (0.0.4)
       Installing fog-voxel (0.0.2)
       Installing savon (2.8.1)
       Installing delayed_job_active_record (4.0.3)
       Installing actionview (4.2.1)
       Installing strava-api-v3 (0.1.0)
       Installing actionpack (4.2.1)
       Installing railties (4.2.1)
       Installing sprockets-rails (2.2.4)
       Installing simple_form (3.1.0.rc2)
       Installing coffee-rails (4.1.0)
       Installing responders (2.1.0)
       Installing jquery-fileupload-rails (0.4.4)
       Installing fog (1.28.0)
       Installing jquery-rails (4.0.3)
       Installing devise (3.4.1)
       Using gsl (1.14.7) from https://ccd14907bc3e94a7f9e2366ad113d7c89b88eeb2:x-oauth-basic@github.com/rvizza/rb-gsl.git (at master)
       Installing activejob (4.2.1)
       Installing actionmailer (4.2.1)
       Installing rails (4.2.1)
       Installing workless (1.2.3)
       Installing spinjs-rails (1.4)
       Your bundle is complete!
       Gems in the groups development and test were not installed.
       It was installed into ./vendor/bundle
       Post-install message from httparty:
       When you HTTParty, you must party hard!
       Bundle completed (465.41s)
       Cleaning up the bundler cache.
       Removing  (extensions)
-----> Writing config/database.yml to read from DATABASE_URL
-----> Preparing app for Rails asset pipeline
       Running: rake assets:precompile
       rake aborted!
       ArgumentError: Missing required arguments: aws_access_key_id, aws_secret_access_key
       /tmp/build_b9f857cd429cef497f20b494b19ece85/vendor/bundle/ruby/2.2.0/gems/fog-core-1.29.0/lib/fog/core/service.rb:244:in `validate_options'
       /tmp/build_b9f857cd429cef497f20b494b19ece85/vendor/bundle/ruby/2.2.0/gems/fog-core-1.29.0/lib/fog/core/service.rb:268:in `handle_settings'
       /tmp/build_b9f857cd429cef497f20b494b19ece85/vendor/bundle/ruby/2.2.0/gems/fog-core-1.29.0/lib/fog/core/service.rb:98:in `new'
       /tmp/build_b9f857cd429cef497f20b494b19ece85/vendor/bundle/ruby/2.2.0/gems/fog-core-1.29.0/lib/fog/storage.rb:25:in `new'
       /tmp/build_b9f857cd429cef497f20b494b19ece85/vendor/bundle/ruby/2.2.0/gems/carrierwave-0.10.0/lib/carrierwave/uploader/configuration.rb:83:in `eager_load_fog'
       /tmp/build_b9f857cd429cef497f20b494b19ece85/vendor/bundle/ruby/2.2.0/gems/carrierwave-0.10.0/lib/carrierwave/uploader/configuration.rb:96:in `fog_credentials='
       /tmp/build_b9f857cd429cef497f20b494b19ece85/config/initializers/carrierwave.rb:2:in `block in <top (required)>'
       /tmp/build_b9f857cd429cef497f20b494b19ece85/vendor/bundle/ruby/2.2.0/gems/carrierwave-0.10.0/lib/carrierwave/uploader/configuration.rb:118:in `configure'
       /tmp/build_b9f857cd429cef497f20b494b19ece85/vendor/bundle/ruby/2.2.0/gems/carrierwave-0.10.0/lib/carrierwave.rb:14:in `configure'
       /tmp/build_b9f857cd429cef497f20b494b19ece85/config/initializers/carrierwave.rb:1:in `<top (required)>'
       /tmp/build_b9f857cd429cef497f20b494b19ece85/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:268:in `load'
       /tmp/build_b9f857cd429cef497f20b494b19ece85/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:268:in `block in load'
       /tmp/build_b9f857cd429cef497f20b494b19ece85/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:240:in `load_dependency'
       /tmp/build_b9f857cd429cef497f20b494b19ece85/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:268:in `load'
       /tmp/build_b9f857cd429cef497f20b494b19ece85/vendor/bundle/ruby/2.2.0/gems/railties-4.2.1/lib/rails/engine.rb:652:in `block in load_config_initializer'
       /tmp/build_b9f857cd429cef497f20b494b19ece85/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.1/lib/active_support/notifications.rb:166:in `instrument'
       /tmp/build_b9f857cd429cef497f20b494b19ece85/vendor/bundle/ruby/2.2.0/gems/railties-4.2.1/lib/rails/engine.rb:651:in `load_config_initializer'
       /tmp/build_b9f857cd429cef497f20b494b19ece85/vendor/bundle/ruby/2.2.0/gems/railties-4.2.1/lib/rails/engine.rb:616:in `block (2 levels) in <class:Engine>'
       /tmp/build_b9f857cd429cef497f20b494b19ece85/vendor/bundle/ruby/2.2.0/gems/railties-4.2.1/lib/rails/engine.rb:615:in `each'
       /tmp/build_b9f857cd429cef497f20b494b19ece85/vendor/bundle/ruby/2.2.0/gems/railties-4.2.1/lib/rails/engine.rb:615:in `block in <class:Engine>'
       /tmp/build_b9f857cd429cef497f20b494b19ece85/vendor/bundle/ruby/2.2.0/gems/railties-4.2.1/lib/rails/initializable.rb:30:in `instance_exec'
       /tmp/build_b9f857cd429cef497f20b494b19ece85/vendor/bundle/ruby/2.2.0/gems/railties-4.2.1/lib/rails/initializable.rb:30:in `run'
       /tmp/build_b9f857cd429cef497f20b494b19ece85/vendor/bundle/ruby/2.2.0/gems/railties-4.2.1/lib/rails/initializable.rb:55:in `block in run_initializers'
       /tmp/build_b9f857cd429cef497f20b494b19ece85/vendor/bundle/ruby/2.2.0/gems/railties-4.2.1/lib/rails/initializable.rb:44:in `each'
       /tmp/build_b9f857cd429cef497f20b494b19ece85/vendor/bundle/ruby/2.2.0/gems/railties-4.2.1/lib/rails/initializable.rb:44:in `tsort_each_child'
       /tmp/build_b9f857cd429cef497f20b494b19ece85/vendor/bundle/ruby/2.2.0/gems/railties-4.2.1/lib/rails/initializable.rb:54:in `run_initializers'
       /tmp/build_b9f857cd429cef497f20b494b19ece85/vendor/bundle/ruby/2.2.0/gems/railties-4.2.1/lib/rails/application.rb:352:in `initialize!'
       /tmp/build_b9f857cd429cef497f20b494b19ece85/vendor/bundle/ruby/2.2.0/gems/railties-4.2.1/lib/rails/railtie.rb:194:in `public_send'
       /tmp/build_b9f857cd429cef497f20b494b19ece85/vendor/bundle/ruby/2.2.0/gems/railties-4.2.1/lib/rails/railtie.rb:194:in `method_missing'
       /tmp/build_b9f857cd429cef497f20b494b19ece85/config/environment.rb:5:in `<top (required)>'
       /tmp/build_b9f857cd429cef497f20b494b19ece85/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:in `require'
       /tmp/build_b9f857cd429cef497f20b494b19ece85/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:in `block in require'
       /tmp/build_b9f857cd429cef497f20b494b19ece85/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:240:in `load_dependency'
       /tmp/build_b9f857cd429cef497f20b494b19ece85/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:in `require'
       /tmp/build_b9f857cd429cef497f20b494b19ece85/vendor/bundle/ruby/2.2.0/gems/railties-4.2.1/lib/rails/application.rb:328:in `require_environment!'
       /tmp/build_b9f857cd429cef497f20b494b19ece85/vendor/bundle/ruby/2.2.0/gems/railties-4.2.1/lib/rails/application.rb:457:in `block in run_tasks_blocks'
       /tmp/build_b9f857cd429cef497f20b494b19ece85/vendor/bundle/ruby/2.2.0/gems/sprockets-rails-2.2.4/lib/sprockets/rails/task.rb:64:in `block (2 levels) in define'
       Tasks: TOP => environment
       (See full trace by running task with --trace)
 !
 !     Precompiling assets failed.
 !

 !     Push rejected, failed to compile Ruby app

To git@heroku.com:vupgrade.git
 ! [remote rejected] upgrade -> master (pre-receive hook declined)
error: failed to push some refs to 'git@heroku.com:vupgrade.git'
CarrierWave.configure do |config|
  config.fog_credentials = {
    :provider              => 'AWS',
    :aws_access_key_id     => ENV['AWS_ACCESS_KEY_ID'],
    :aws_secret_access_key => ENV['AWS_SECRET_ACCESS_KEY'],
    :region                => ENV['AWS_REGION']
  }

  if Rails.env.production? || Rails.env.staging?
    config.storage = :fog
  else
    config.storage = :file
    config.enable_processing = false
    config.root = "#{Rails.root}/tmp"
  end

  config.cache_dir = "#{Rails.root}/tmp/uploads"
  config.fog_directory = ENV['AWS_BUCKET_NAME']
end
unless ENV['AWS_ACCESS_KEY_ID'].blank?
  CarrierWave.configure do |config|
    config.fog_credentials = {
    ....
    }
  end
end
谢谢,
Robert

既然您使用的是CarrierWaveUpload gem,那么您应该在初始值设定项中使用它

示例:
/config/initializers/carrierwave.rb

CarrierWave.configure do |config|
  config.fog_credentials = {
    provider:              'AWS',                        # required
    aws_access_key_id:     ENV['AWS_ACCESS_KEY_ID'],                        
    aws_secret_access_key: ENV['AWS_SECRET_KEY_ID']
    #Other options ommited
  }
您可以在此处看到所需的所有参数:


首先,请注意,我使用的是自定义构建包,这可能是其中一些问题的原因。当我第一次遇到上面的问题时,我并不认为这是相关的,但是我研究得越多,我就越觉得它是相关的……主要是因为我无法想象其他人已经用我在下面概述的相同的笨拙的修复方法克服了这些问题。作为警告,关于答案

从Rails 4中删除了
config.assets.initialize\on\u precompile=false
,所有初始化程序显然都在预编译期间运行。如果它们包含环境引用,那么您就有问题了,因为在Heroku资产预编译期间,这些环境值不存在。此外,在预编译期间,Desive将尝试连接到数据库,但数据库也不可用

我选择通过有条件地运行包含ENV引用的初始值设定项来修复这些问题,如下所示:

~/documents/coding$ git push upgrade upgrade:master
Fetching repository, done.
Counting objects: 9950, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (5166/5166), done.
Writing objects: 100% (9950/9950), 82.90 MiB | 748.00 KiB/s, done.
Total 9950 (delta 7130), reused 6420 (delta 4535)

-----> Fetching custom git buildpack... done
-----> Ruby app detected
-----> Compiling Ruby/Rails
-----> Using Ruby version: ruby-2.2.0
-----> Installing gsl
-----> Installing dependencies using 1.5.2
       Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin -j4 --deployment
       Fetching source index from https://rubygems.org/
       Fetching https://ccd14907bc3e94a7f9e2366ad113d7c89b88eeb2:x-oauth-basic@github.com/rvizza/rb-gsl.git
       Fetching git://github.com/bearded-nemesis/heroku-rglpk.git
       Fetching https://ccd14907bc3e94a7f9e2366ad113d7c89b88eeb2:x-oauth-basic@github.com/rvizza/joule.git
       Fetching https://ccd14907bc3e94a7f9e2366ad113d7c89b88eeb2:x-oauth-basic@github.com/rvizza/ride_parser.git
       Fetching https://ccd14907bc3e94a7f9e2366ad113d7c89b88eeb2:x-oauth-basic@github.com/rvizza/top_efforts.git
       Fetching https://ccd14907bc3e94a7f9e2366ad113d7c89b88eeb2:x-oauth-basic@github.com/rvizza/RubyPeaks.git
       Using rake (10.4.2)
       Installing CFPropertyList (2.3.0)
       Installing i18n (0.7.0)
       Installing thread_safe (0.3.5)
       Installing minitest (5.5.1)
       Installing builder (3.2.2)
       Installing mini_portile (0.6.2)
       Installing mime-types (1.25.1)
       Installing erubis (2.7.0)
       Installing arel (6.0.0)
       Installing encryptor (1.3.0)
       Installing rack (1.6.0)
       Installing execjs (2.3.0)
       Installing cancancan (1.10.1)
       Installing sass (3.4.13)
       Installing coffee-script-source (1.9.1)
       Installing thor (0.19.1)
       Installing daemons (1.1.9)
       Installing orm_adapter (0.5.0)
       Installing excon (0.44.4)
       Installing fastercsv (1.5.5)
       Installing formatador (0.2.5)
       Installing net-ssh (2.9.2)
       Installing multi_json (1.11.0)
       Installing bcrypt (3.1.10)
       Installing inflecto (0.0.2)
       Installing ipaddress (0.8.0)
       Installing json (1.8.2)
       Installing hike (1.2.3)
       Installing multi_xml (0.5.5)
       Installing systemu (2.6.4)
       Installing netrc (0.10.3)
       Installing narray (0.6.1.1)
       Installing nori (2.4.0)
       Using heroku-rglpk (0.2.1) from git://github.com/bearded-nemesis/heroku-rglpk.git (at master)
       Using bundler (1.5.2)
       Installing newrelic_rpm (3.10.0.279)
       Installing rails_serve_static_assets (0.0.4)
       Installing rails_stdout_logging (0.0.3)
       Installing tilt (1.4.1)
       Installing rolify (4.0.0)
       Installing eventmachine (1.0.5)
       Installing session (3.2.0)
       Using ride_parser (0.0.2) from https://ccd14907bc3e94a7f9e2366ad113d7c89b88eeb2:x-oauth-basic@github.com/rvizza/ride_parser.git (at master)
       Using trainingpeaks (0.0.0) from https://ccd14907bc3e94a7f9e2366ad113d7c89b88eeb2:x-oauth-basic@github.com/rvizza/RubyPeaks.git (at master)
       Using top_efforts (0.0.2) from https://ccd14907bc3e94a7f9e2366ad113d7c89b88eeb2:x-oauth-basic@github.com/rvizza/top_efforts.git (at master)
       Installing unf_ext (0.0.6)
       Installing switch_user (0.9.5)
       Installing will_paginate (3.0.7)
       Installing gyoku (1.2.2)
       Installing fission (0.5.0)
       Installing mail (2.6.3)
       Installing attr_encrypted (1.3.3)
       Installing pg (0.18.1)
       Installing rack-test (0.6.3)
       Installing httpi (2.3.0)
       Installing coffee-script (2.3.0)
       Installing figaro (1.1.0)
       Installing warden (1.2.3)
       Installing net-scp (1.2.1)
       Installing heroku-api (0.3.18)
       Installing tzinfo (1.2.2)
       Installing autoprefixer-rails (5.1.7)
       Installing macaddr (1.7.1)
       Installing fog-json (1.0.0)
       Installing rest-client (1.7.3)
       Installing rails_12factor (0.0.3)
       Installing sprockets (2.12.3)
       Installing thin (1.5.1)
       Installing rush (0.6.8)
       Installing unf (0.1.4)
       Installing will_paginate-bootstrap (1.0.1)
       Installing fog-core (1.29.0)
       Installing activesupport (4.2.1)
       Installing tzinfo-data (1.2015.1)
       Installing bootstrap-sass (3.3.3)
       Installing uuid (2.3.7)
       Installing stripe (1.20.1)
       Installing fog-brightbox (0.7.1)
       Installing fog-sakuracloud (1.0.0)
       Installing fog-serverlove (0.1.1)
       Installing fog-softlayer (0.4.1)
       Installing fog-storm_on_demand (0.1.0)
       Installing nokogiri (1.6.6.2)
       Installing fog-vmfusion (0.0.1)
       Installing rails-deprecated_sanitizer (1.0.3)
       Installing globalid (0.3.3)
       Installing activemodel (4.2.1)
       Installing delayed_job (4.0.6)
       Installing stripe_event (1.5.0)
       Installing loofah (2.0.1)
       Installing akami (1.2.2)
       Installing fog-xml (0.1.1)
       Using joule (1.0.4) from https://ccd14907bc3e94a7f9e2366ad113d7c89b88eeb2:x-oauth-basic@github.com/rvizza/joule.git (at master)
       Installing httparty (0.13.3)
       Installing rails-dom-testing (1.0.6)
       Installing wasabi (3.3.0)
       Installing carrierwave (0.10.0)
       Installing activerecord (4.2.1)
       Installing rails-html-sanitizer (1.0.2)
       Installing fog-atmos (0.1.0)
       Installing fog-ecloud (0.0.2)
       Installing fog-profitbricks (0.0.1)
       Installing fog-radosgw (0.0.3)
       Installing fog-aws (0.1.1)
       Installing fog-riakcs (0.1.0)
       Installing fog-terremark (0.0.4)
       Installing fog-voxel (0.0.2)
       Installing savon (2.8.1)
       Installing delayed_job_active_record (4.0.3)
       Installing actionview (4.2.1)
       Installing strava-api-v3 (0.1.0)
       Installing actionpack (4.2.1)
       Installing railties (4.2.1)
       Installing sprockets-rails (2.2.4)
       Installing simple_form (3.1.0.rc2)
       Installing coffee-rails (4.1.0)
       Installing responders (2.1.0)
       Installing jquery-fileupload-rails (0.4.4)
       Installing fog (1.28.0)
       Installing jquery-rails (4.0.3)
       Installing devise (3.4.1)
       Using gsl (1.14.7) from https://ccd14907bc3e94a7f9e2366ad113d7c89b88eeb2:x-oauth-basic@github.com/rvizza/rb-gsl.git (at master)
       Installing activejob (4.2.1)
       Installing actionmailer (4.2.1)
       Installing rails (4.2.1)
       Installing workless (1.2.3)
       Installing spinjs-rails (1.4)
       Your bundle is complete!
       Gems in the groups development and test were not installed.
       It was installed into ./vendor/bundle
       Post-install message from httparty:
       When you HTTParty, you must party hard!
       Bundle completed (465.41s)
       Cleaning up the bundler cache.
       Removing  (extensions)
-----> Writing config/database.yml to read from DATABASE_URL
-----> Preparing app for Rails asset pipeline
       Running: rake assets:precompile
       rake aborted!
       ArgumentError: Missing required arguments: aws_access_key_id, aws_secret_access_key
       /tmp/build_b9f857cd429cef497f20b494b19ece85/vendor/bundle/ruby/2.2.0/gems/fog-core-1.29.0/lib/fog/core/service.rb:244:in `validate_options'
       /tmp/build_b9f857cd429cef497f20b494b19ece85/vendor/bundle/ruby/2.2.0/gems/fog-core-1.29.0/lib/fog/core/service.rb:268:in `handle_settings'
       /tmp/build_b9f857cd429cef497f20b494b19ece85/vendor/bundle/ruby/2.2.0/gems/fog-core-1.29.0/lib/fog/core/service.rb:98:in `new'
       /tmp/build_b9f857cd429cef497f20b494b19ece85/vendor/bundle/ruby/2.2.0/gems/fog-core-1.29.0/lib/fog/storage.rb:25:in `new'
       /tmp/build_b9f857cd429cef497f20b494b19ece85/vendor/bundle/ruby/2.2.0/gems/carrierwave-0.10.0/lib/carrierwave/uploader/configuration.rb:83:in `eager_load_fog'
       /tmp/build_b9f857cd429cef497f20b494b19ece85/vendor/bundle/ruby/2.2.0/gems/carrierwave-0.10.0/lib/carrierwave/uploader/configuration.rb:96:in `fog_credentials='
       /tmp/build_b9f857cd429cef497f20b494b19ece85/config/initializers/carrierwave.rb:2:in `block in <top (required)>'
       /tmp/build_b9f857cd429cef497f20b494b19ece85/vendor/bundle/ruby/2.2.0/gems/carrierwave-0.10.0/lib/carrierwave/uploader/configuration.rb:118:in `configure'
       /tmp/build_b9f857cd429cef497f20b494b19ece85/vendor/bundle/ruby/2.2.0/gems/carrierwave-0.10.0/lib/carrierwave.rb:14:in `configure'
       /tmp/build_b9f857cd429cef497f20b494b19ece85/config/initializers/carrierwave.rb:1:in `<top (required)>'
       /tmp/build_b9f857cd429cef497f20b494b19ece85/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:268:in `load'
       /tmp/build_b9f857cd429cef497f20b494b19ece85/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:268:in `block in load'
       /tmp/build_b9f857cd429cef497f20b494b19ece85/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:240:in `load_dependency'
       /tmp/build_b9f857cd429cef497f20b494b19ece85/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:268:in `load'
       /tmp/build_b9f857cd429cef497f20b494b19ece85/vendor/bundle/ruby/2.2.0/gems/railties-4.2.1/lib/rails/engine.rb:652:in `block in load_config_initializer'
       /tmp/build_b9f857cd429cef497f20b494b19ece85/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.1/lib/active_support/notifications.rb:166:in `instrument'
       /tmp/build_b9f857cd429cef497f20b494b19ece85/vendor/bundle/ruby/2.2.0/gems/railties-4.2.1/lib/rails/engine.rb:651:in `load_config_initializer'
       /tmp/build_b9f857cd429cef497f20b494b19ece85/vendor/bundle/ruby/2.2.0/gems/railties-4.2.1/lib/rails/engine.rb:616:in `block (2 levels) in <class:Engine>'
       /tmp/build_b9f857cd429cef497f20b494b19ece85/vendor/bundle/ruby/2.2.0/gems/railties-4.2.1/lib/rails/engine.rb:615:in `each'
       /tmp/build_b9f857cd429cef497f20b494b19ece85/vendor/bundle/ruby/2.2.0/gems/railties-4.2.1/lib/rails/engine.rb:615:in `block in <class:Engine>'
       /tmp/build_b9f857cd429cef497f20b494b19ece85/vendor/bundle/ruby/2.2.0/gems/railties-4.2.1/lib/rails/initializable.rb:30:in `instance_exec'
       /tmp/build_b9f857cd429cef497f20b494b19ece85/vendor/bundle/ruby/2.2.0/gems/railties-4.2.1/lib/rails/initializable.rb:30:in `run'
       /tmp/build_b9f857cd429cef497f20b494b19ece85/vendor/bundle/ruby/2.2.0/gems/railties-4.2.1/lib/rails/initializable.rb:55:in `block in run_initializers'
       /tmp/build_b9f857cd429cef497f20b494b19ece85/vendor/bundle/ruby/2.2.0/gems/railties-4.2.1/lib/rails/initializable.rb:44:in `each'
       /tmp/build_b9f857cd429cef497f20b494b19ece85/vendor/bundle/ruby/2.2.0/gems/railties-4.2.1/lib/rails/initializable.rb:44:in `tsort_each_child'
       /tmp/build_b9f857cd429cef497f20b494b19ece85/vendor/bundle/ruby/2.2.0/gems/railties-4.2.1/lib/rails/initializable.rb:54:in `run_initializers'
       /tmp/build_b9f857cd429cef497f20b494b19ece85/vendor/bundle/ruby/2.2.0/gems/railties-4.2.1/lib/rails/application.rb:352:in `initialize!'
       /tmp/build_b9f857cd429cef497f20b494b19ece85/vendor/bundle/ruby/2.2.0/gems/railties-4.2.1/lib/rails/railtie.rb:194:in `public_send'
       /tmp/build_b9f857cd429cef497f20b494b19ece85/vendor/bundle/ruby/2.2.0/gems/railties-4.2.1/lib/rails/railtie.rb:194:in `method_missing'
       /tmp/build_b9f857cd429cef497f20b494b19ece85/config/environment.rb:5:in `<top (required)>'
       /tmp/build_b9f857cd429cef497f20b494b19ece85/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:in `require'
       /tmp/build_b9f857cd429cef497f20b494b19ece85/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:in `block in require'
       /tmp/build_b9f857cd429cef497f20b494b19ece85/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:240:in `load_dependency'
       /tmp/build_b9f857cd429cef497f20b494b19ece85/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:in `require'
       /tmp/build_b9f857cd429cef497f20b494b19ece85/vendor/bundle/ruby/2.2.0/gems/railties-4.2.1/lib/rails/application.rb:328:in `require_environment!'
       /tmp/build_b9f857cd429cef497f20b494b19ece85/vendor/bundle/ruby/2.2.0/gems/railties-4.2.1/lib/rails/application.rb:457:in `block in run_tasks_blocks'
       /tmp/build_b9f857cd429cef497f20b494b19ece85/vendor/bundle/ruby/2.2.0/gems/sprockets-rails-2.2.4/lib/sprockets/rails/task.rb:64:in `block (2 levels) in define'
       Tasks: TOP => environment
       (See full trace by running task with --trace)
 !
 !     Precompiling assets failed.
 !

 !     Push rejected, failed to compile Ruby app

To git@heroku.com:vupgrade.git
 ! [remote rejected] upgrade -> master (pre-receive hook declined)
error: failed to push some refs to 'git@heroku.com:vupgrade.git'
CarrierWave.configure do |config|
  config.fog_credentials = {
    :provider              => 'AWS',
    :aws_access_key_id     => ENV['AWS_ACCESS_KEY_ID'],
    :aws_secret_access_key => ENV['AWS_SECRET_ACCESS_KEY'],
    :region                => ENV['AWS_REGION']
  }

  if Rails.env.production? || Rails.env.staging?
    config.storage = :fog
  else
    config.storage = :file
    config.enable_processing = false
    config.root = "#{Rails.root}/tmp"
  end

  config.cache_dir = "#{Rails.root}/tmp/uploads"
  config.fog_directory = ENV['AWS_BUCKET_NAME']
end
unless ENV['AWS_ACCESS_KEY_ID'].blank?
  CarrierWave.configure do |config|
    config.fog_credentials = {
    ....
    }
  end
end
虽然我并不热衷于这个想法,但我也决定在本地预编译我的资产,并将它们提交给源代码控制。这似乎可以防止Heroku在服务器上预编译资产,从而解决问题


感谢@geemus和@joao的帮助。

您可以按照以下说明在Heroku中设置环境变量:


这些将在Rails代码中以
ENV['my\u environment\u variable\u name']
的形式访问,其中
my\u environment\u variable\u name
是您在Heroku仪表板中输入的环境变量的名称。

我在Ubuntu 20.04中处理Rails 6应用程序时遇到了同样的问题

当我尝试将图像上载到DigitalOcean Spaces(与AWS S3 Bucket相同)时,我得到错误:

ArgumentError:缺少必需的参数:aws\u访问\u密钥\u id、aws\u机密\u访问\u密钥

以下是我如何修复它的方法

我的环境变量已在我的
.env
文件中正确设置

问题是我有另一个
.env
文件,它是
.env.template
,它的
aws\u access\u key\u id
aws\u secret\u access\u key
的值不正确

我所要做的就是删除这个文件。这次Rails应用程序能够从
.env
文件中选择环境变量的值

就这些


我希望这有帮助

很抱歉@joao,我忘了提到我有carrierwave初始值设定项,只是用它的内容更新了我的问题。抱歉@RobertVizza。我不知道该怎么帮你。我以前从未和heroku env vars有过问题。如果在登台环境中运行ruby控制台,您能看到这些变量吗<代码>heroku运行rails控制台谢谢@joao。我确实尝试过heroku run rails console,但是当carrierwave初始值设定项运行时,我得到了与上面相同的错误。如果你愿意,你应该可以只执行heroku run irb,它不会加载你的应用程序,但它会给你irb,你可以用它查看ENV(与heroku run bash相同)。谢谢@geemus。当我使用
heroku run irb
检查ENV时,从我的carrierwave初始值设定项设置的两个ENV变量存在。我想知道,与设置ENV时相比,调用初始值设定项时是否存在排序问题…?您能分享更多stacktrace吗?我认为,这可能有助于提供更多的背景,说明问题可能在哪里。谢谢当然可以,geemus。我只包括了整个痕迹。谢谢你看。我仍然对这件事感到困惑。谢谢,我现在还不清楚……奇怪。我认为这不应该是heroku的时间问题(env应该在前面)。您是否调用或更改
Carrierwave.configure
其他任何位置?也就是说,这个配置可能在某个地方被覆盖了?单独来看,它看起来不错,您也可以尝试在初始值设定项的顶部添加一些
put
语句,这将为您提供有关ENV中的值的即时信息。