预编译资产失败Heroku Rails

时间:2018-12-18 20:07:29

标签: ruby-on-rails heroku

我以前能够成功部署到Heroku,但是,在安装了carrierwave-aws gem之后,出现标题中列出的错误。我查看了日志并看到错误:

remote:        Running: rake assets:precompile
remote:        rake aborted!
remote:        KeyError: key not found: "S3_BUCKET_NAME"

当我运行Rails控制台并运行ENV.fetch('S3_BUCKET_NAME')时,它会显示存储桶。我确实安装了dotenv-rails gem,但不确定如何修复Heroku遇到的错误。 aws凭证位于添加到我的gitignore中的.env文件中,并且carrierwave.rb正在以与在Rails控制台中尝试的相同方式来获取凭证。任何帮助将不胜感激!

我尝试按照此处here的建议将:config.assets.initialize_on_precompile = false放入我的application.rb文件,但这只是为“无法编译ruby应用程序”提供了另一个错误

如果需要,这里是完整的服务器日志:

remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Ruby app detected
remote: -----> Compiling Ruby/Rails
remote: -----> Using Ruby version: ruby-2.5.1
remote: -----> Installing dependencies using bundler 1.15.2
remote:        Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin -j4 --deployment
remote:        Warning: the running version of Bundler (1.15.2) is older than the version that created the lockfile (1.17.1). We suggest you upgrade to the latest version of Bundler by running `gem install bundler`.
remote:        Fetching gem metadata from https://rubygems.org/.............
remote:        Fetching version metadata from https://rubygems.org/..
remote:        Fetching dependency metadata from https://rubygems.org/.
remote:        Using rake 12.3.2
remote:        Using concurrent-ruby 1.1.3
remote:        Using minitest 5.11.3
remote:        Using thread_safe 0.3.6
remote:        Using builder 3.2.3
remote:        Using erubi 1.7.1
remote:        Using mini_portile2 2.3.0
remote:        Using crass 1.0.4
remote:        Using rack 2.0.6
remote:        Using nio4r 2.3.1
remote:        Using websocket-extensions 0.1.3
remote:        Using mini_mime 1.0.1
remote:        Using arel 9.0.0
remote:        Using mimemagic 0.3.2
remote:        Using execjs 2.7.0
remote:        Fetching aws-eventstream 1.0.1
remote:        Fetching aws-partitions 1.125.0
remote:        Fetching aws-sigv4 1.0.3
remote:        Installing aws-eventstream 1.0.1
remote:        Installing aws-sigv4 1.0.3
remote:        Installing aws-partitions 1.125.0
remote:        Fetching jmespath 1.4.0
remote:        Using bcrypt 3.1.12
remote:        Using msgpack 1.2.4
remote:        Using popper_js 1.14.5
remote:        Using rb-fsevent 0.10.3
remote:        Using ffi 1.9.25
remote:        Using bundler 1.15.2
remote:        Fetching mime-types-data 3.2018.0812
remote:        Installing jmespath 1.4.0
remote:        Installing mime-types-data 3.2018.0812
remote:        Using coderay 1.1.2
remote:        Using coffee-script-source 1.12.2
remote:        Using method_source 0.9.2
remote:        Using thor 0.20.3
remote:        Using orm_adapter 0.5.0
remote:        Fetching dotenv 2.5.0
remote:        Installing dotenv 2.5.0
remote:        Using multi_json 1.13.1
remote:        Fetching mini_magick 4.9.2
remote:        Using ostruct 0.1.0
remote:        Using pg 1.1.3
remote:        Using puma 3.12.0
remote:        Using tilt 2.0.9
remote:        Using sohel_view_tool 0.1.0
remote:        Using turbolinks-source 5.2.0
remote:        Using tzinfo 1.2.5
remote:        Using nokogiri 1.8.5
remote:        Using websocket-driver 0.7.0
remote:        Using mail 2.7.1
remote:        Using i18n 1.1.1
remote:        Using rack-test 1.1.0
remote:        Using warden 1.2.8
remote:        Using sprockets 3.7.2
remote:        Using marcel 0.3.3
remote:        Using autoprefixer-rails 9.4.2
remote:        Using uglifier 4.1.20
remote:        Using bootsnap 1.3.2
remote:        Using rb-inotify 0.9.10
remote:        Installing mini_magick 4.9.2
remote:        Using coffee-script 2.4.1
remote:        Using pry 0.12.2
remote:        Fetching aws-sdk-core 3.44.0
remote:        Fetching mime-types 3.2.2
remote:        Installing mime-types 3.2.2
remote:        Installing aws-sdk-core 3.44.0
remote:        Using turbolinks 5.2.0
remote:        Using loofah 2.2.3
remote:        Using activesupport 5.2.2
remote:        Using sass-listen 4.0.0
remote:        Using rails-html-sanitizer 1.0.4
remote:        Using rails-dom-testing 2.0.3
remote:        Using globalid 0.4.1
remote:        Using activemodel 5.2.2
remote:        Using jbuilder 2.8.0
remote:        Using sass 3.7.2
remote:        Using activejob 5.2.2
remote:        Using activerecord 5.2.2
remote:        Fetching carrierwave 1.2.3
remote:        Using actionview 5.2.2
remote:        Using friendly_id 5.2.4
remote:        Using petergate 2.0.1
remote:        Using bootstrap 4.1.3
remote:        Using actionpack 5.2.2
remote:        Using actioncable 5.2.2
remote:        Using actionmailer 5.2.2
remote:        Using activestorage 5.2.2
remote:        Using railties 5.2.2
remote:        Using sprockets-rails 3.2.1
remote:        Using coffee-rails 4.2.2
remote:        Using responders 2.4.0
remote:        Fetching dotenv-rails 2.5.0
remote:        Installing carrierwave 1.2.3
remote:        Installing dotenv-rails 2.5.0
remote:        Using jquery-rails 4.3.3
remote:        Using jquery-ui-rails 5.0.5
remote:        Using rails 5.2.2
remote:        Using sass-rails 5.0.7
remote:        Using devise 4.5.0
remote:        Fetching aws-sdk-kms 1.13.0
remote:        Installing aws-sdk-kms 1.13.0
remote:        Fetching aws-sdk-s3 1.30.0
remote:        Installing aws-sdk-s3 1.30.0
remote:        Fetching carrierwave-aws 1.3.0
remote:        Installing carrierwave-aws 1.3.0
remote:        Bundle complete! 28 Gemfile dependencies, 91 gems now installed.
remote:        Gems in the groups development and test were not installed.
remote:        Bundled gems are installed into ./vendor/bundle.
remote:        Bundle completed (5.98s)
remote:        Cleaning up the bundler cache.
remote:        Warning: the running version of Bundler (1.15.2) is older than the version that created the lockfile (1.17.1). We suggest you upgrade to the latest version of Bundler by running `gem install bundler`.
remote:        The latest bundler is 2.0.0.pre.2, but you are currently running 1.15.2.
remote:        To update, run `gem install bundler --pre`
remote: -----> Installing node-v8.10.0-linux-x64
remote: -----> Detecting rake tasks
remote: -----> Preparing app for Rails asset pipeline
remote:        Running: rake assets:precompile
remote:        rake aborted!
remote:        KeyError: key not found: "S3_BUCKET_NAME"
remote:        /tmp/build_bed53da6969ae50aa98632527d1504c6/config/initializers/carrierwave.rb:3:in `fetch'
remote:        /tmp/build_bed53da6969ae50aa98632527d1504c6/config/initializers/carrierwave.rb:3:in `block in <main>'
remote:        /tmp/build_bed53da6969ae50aa98632527d1504c6/vendor/bundle/ruby/2.5.0/gems/carrierwave-1.2.3/lib/carrierwave/uploader/configuration.rb:161:in `configure'
remote:        /tmp/build_bed53da6969ae50aa98632527d1504c6/vendor/bundle/ruby/2.5.0/gems/carrierwave-1.2.3/lib/carrierwave.rb:14:in `configure'
remote:        /tmp/build_bed53da6969ae50aa98632527d1504c6/config/initializers/carrierwave.rb:1:in `<main>'
remote:        /tmp/build_bed53da6969ae50aa98632527d1504c6/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:50:in `load'
remote:        /tmp/build_bed53da6969ae50aa98632527d1504c6/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:50:in `load'
remote:        /tmp/build_bed53da6969ae50aa98632527d1504c6/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:285:in `block in load'
remote:        /tmp/build_bed53da6969ae50aa98632527d1504c6/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:257:in `load_dependency'
remote:        /tmp/build_bed53da6969ae50aa98632527d1504c6/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:285:in `load'
remote:        /tmp/build_bed53da6969ae50aa98632527d1504c6/vendor/bundle/ruby/2.5.0/gems/railties-5.2.2/lib/rails/engine.rb:657:in `block in load_config_initializer'
remote:        /tmp/build_bed53da6969ae50aa98632527d1504c6/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.2/lib/active_support/notifications.rb:170:in `instrument'
remote:        /tmp/build_bed53da6969ae50aa98632527d1504c6/vendor/bundle/ruby/2.5.0/gems/railties-5.2.2/lib/rails/engine.rb:656:in `load_config_initializer'
remote:        /tmp/build_bed53da6969ae50aa98632527d1504c6/vendor/bundle/ruby/2.5.0/gems/railties-5.2.2/lib/rails/engine.rb:614:in `block (2 levels) in <class:Engine>'
remote:        /tmp/build_bed53da6969ae50aa98632527d1504c6/vendor/bundle/ruby/2.5.0/gems/railties-5.2.2/lib/rails/engine.rb:613:in `each'
remote:        /tmp/build_bed53da6969ae50aa98632527d1504c6/vendor/bundle/ruby/2.5.0/gems/railties-5.2.2/lib/rails/engine.rb:613:in `block in <class:Engine>'
remote:        /tmp/build_bed53da6969ae50aa98632527d1504c6/vendor/bundle/ruby/2.5.0/gems/railties-5.2.2/lib/rails/initializable.rb:32:in `instance_exec'
remote:        /tmp/build_bed53da6969ae50aa98632527d1504c6/vendor/bundle/ruby/2.5.0/gems/railties-5.2.2/lib/rails/initializable.rb:32:in `run'
remote:        /tmp/build_bed53da6969ae50aa98632527d1504c6/vendor/bundle/ruby/2.5.0/gems/railties-5.2.2/lib/rails/initializable.rb:61:in `block in run_initializers'
remote:        /tmp/build_bed53da6969ae50aa98632527d1504c6/vendor/bundle/ruby/2.5.0/gems/railties-5.2.2/lib/rails/initializable.rb:50:in `each'
remote:        /tmp/build_bed53da6969ae50aa98632527d1504c6/vendor/bundle/ruby/2.5.0/gems/railties-5.2.2/lib/rails/initializable.rb:50:in `tsort_each_child'
remote:        /tmp/build_bed53da6969ae50aa98632527d1504c6/vendor/bundle/ruby/2.5.0/gems/railties-5.2.2/lib/rails/initializable.rb:60:in `run_initializers'
remote:        /tmp/build_bed53da6969ae50aa98632527d1504c6/vendor/bundle/ruby/2.5.0/gems/railties-5.2.2/lib/rails/application.rb:361:in `initialize!'
remote:        /tmp/build_bed53da6969ae50aa98632527d1504c6/config/environment.rb:5:in `<main>'
remote:        /tmp/build_bed53da6969ae50aa98632527d1504c6/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require'
remote:        /tmp/build_bed53da6969ae50aa98632527d1504c6/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `block in require_with_bootsnap_lfi'
remote:        /tmp/build_bed53da6969ae50aa98632527d1504c6/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/loaded_features_index.rb:65:in `register'
remote:        /tmp/build_bed53da6969ae50aa98632527d1504c6/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:20:in `require_with_bootsnap_lfi'
remote:        /tmp/build_bed53da6969ae50aa98632527d1504c6/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:29:in `require'
remote:        /tmp/build_bed53da6969ae50aa98632527d1504c6/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:291:in `block in require'
remote:        /tmp/build_bed53da6969ae50aa98632527d1504c6/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:257:in `load_dependency'
remote:        /tmp/build_bed53da6969ae50aa98632527d1504c6/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:291:in `require'
remote:        /tmp/build_bed53da6969ae50aa98632527d1504c6/vendor/bundle/ruby/2.5.0/gems/railties-5.2.2/lib/rails/application.rb:337:in `require_environment!'
remote:        /tmp/build_bed53da6969ae50aa98632527d1504c6/vendor/bundle/ruby/2.5.0/gems/railties-5.2.2/lib/rails/application.rb:520:in `block in run_tasks_blocks'
remote:        /tmp/build_bed53da6969ae50aa98632527d1504c6/vendor/bundle/ruby/2.5.0/gems/sprockets-rails-3.2.1/lib/sprockets/rails/task.rb:62:in `block (2 levels) in define'
remote:        /tmp/build_bed53da6969ae50aa98632527d1504c6/vendor/bundle/ruby/2.5.0/gems/rake-12.3.2/exe/rake:27:in `<top (required)>'
remote:        Tasks: TOP => environment
remote:        (See full trace by running task with --trace)
remote:
remote:  !
remote:  !     Precompiling assets failed.
remote:  !
remote:  !     Push rejected, failed to compile Ruby app.
remote:
remote:  !     Push failed
remote: Verifying deploy...
remote:
remote: !   Push rejected to sohel-p-portfolio.
remote:
To https://git.heroku.com/sohel-p-portfolio.git

heroku记录最后一行:

2018-12-18T19:49:24.000000+00:00 app[api]: Build failed -- check your build logs

1 个答案:

答案 0 :(得分:1)

您可以使用...在Heroku上手动设置env变量。

$ heroku config:set S3_BUCKET_NAME=yourbucketname