1

当使用 cleardb mysql db 推送到 heroku 时,heroku 在预编译资产时会中断。

  1. 我已将 config.assets.initialize_on_precompile = false 添加到我的 application.rb 文件中。

  2. 它也在我的 environment/staging.rb 和 production.rb 文件中。

  3. 我已将 cleardb url 添加到 DATABSE_URL 配置变量作为 mysql2 url。

我有一个暂存环境,我可以很好地推动,不明白发生了什么

我在下面添加了heroku输出:

   Your bundle is complete! It was installed into ./vendor/bundle
   Cleaning up the bundler cache.
-----> Writing config/database.yml to read from DATABASE_URL
-----> Preparing app for Rails asset pipeline
   Running: rake assets:precompile
   rake aborted!
   Can't connect to MySQL server on '127.0.0.1' (111)


    /tmp/build_ure0m4wsxy41/vendor/bundle/ruby/1.9.1/gems/mysql20.3.13/lib/mysql2/client.rb:58:    in `connect'
       /tmp/build_ure0m4wsxy41/vendor/bundle/ruby/1.9.1/gems/mysql2-0.3.13/lib/mysql2/client.rb:58:in `initialize'
       /tmp/build_ure0m4wsxy41/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.9/lib/active_record/connection_adapters/mysql2_adapter.rb:16:in `new'
       /tmp/build_ure0m4wsxy41/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.9/lib/active_record/connection_adapters/mysql2_adapter.rb:16:in `mysql2_connection'
       /tmp/build_ure0m4wsxy41/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/connection_pool.rb:315:in `new_connection'
       /tmp/build_ure0m4wsxy41/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/connection_pool.rb:325:in `checkout_new_connection'
       /tmp/build_ure0m4wsxy41/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/connection_pool.rb:247:in `block(2 levels) in checkout'
       /tmp/build_ure0m4wsxy41/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/connection_pool.rb:242:in `loop'
       /tmp/build_ure0m4wsxy41/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/connection_pool.rb:242:in `block
in checkout'
       /tmp/build_ure0m4wsxy41/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.9/
lib/active_record/connection_adapters/abstract/connection_pool.rb:239:in `checko
ut'
       /tmp/build_ure0m4wsxy41/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.9/
lib/active_record/connection_adapters/abstract/connection_pool.rb:102:in `block
in connection'
       /tmp/build_ure0m4wsxy41/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.9/
lib/active_record/connection_adapters/abstract/connection_pool.rb:101:in `connec
tion'
       /tmp/build_ure0m4wsxy41/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.9/
lib/active_record/connection_adapters/abstract/connection_pool.rb:410:in `retrie
ve_connection'
       /tmp/build_ure0m4wsxy41/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.9/
lib/active_record/connection_adapters/abstract/connection_specification.rb:171:i
n `retrieve_connection'
       /tmp/build_ure0m4wsxy41/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.9/
lib/active_record/connection_adapters/abstract/connection_specification.rb:145:i
n `connection'
       /tmp/build_ure0m4wsxy41/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.9/
lib/active_record/model_schema.rb:308:in `clear_cache!'
       /tmp/build_ure0m4wsxy41/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.9/
lib/active_record/railtie.rb:97:in `block (2 levels) in <class:Railtie>'
       /tmp/build_ure0m4wsxy41/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.9
/lib/active_support/callbacks.rb:418:in `_run__2258599545640707426__prepare__376
3978473180365505__callbacks'
       /tmp/build_ure0m4wsxy41/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.9
/lib/active_support/callbacks.rb:405:in `__run_callback'
       /tmp/build_ure0m4wsxy41/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.9
/lib/active_support/callbacks.rb:385:in `_run_prepare_callbacks'
       /tmp/build_ure0m4wsxy41/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.9
/lib/active_support/callbacks.rb:81:in `run_callbacks'
       /tmp/build_ure0m4wsxy41/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.9/li
b/action_dispatch/middleware/reloader.rb:74:in `prepare!'
       /tmp/build_ure0m4wsxy41/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.9/li
b/action_dispatch/middleware/reloader.rb:48:in `prepare!'
       /tmp/build_ure0m4wsxy41/vendor/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/
rails/application/finisher.rb:47:in `block in <module:Finisher>'
       /tmp/build_ure0m4wsxy41/vendor/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/
rails/initializable.rb:30:in `instance_exec'
       /tmp/build_ure0m4wsxy41/vendor/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/
rails/initializable.rb:30:in `run'
       /tmp/build_ure0m4wsxy41/vendor/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/
rails/initializable.rb:55:in `block in run_initializers'
       /tmp/build_ure0m4wsxy41/vendor/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/
rails/initializable.rb:54:in `each'
       /tmp/build_ure0m4wsxy41/vendor/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/
rails/initializable.rb:54:in `run_initializers'
       /tmp/build_ure0m4wsxy41/vendor/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/
rails/application.rb:136:in `initialize!'
       /tmp/build_ure0m4wsxy41/vendor/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/
rails/railtie/configurable.rb:30:in `method_missing'
       /tmp/build_ure0m4wsxy41/config/environment.rb:8:in `<top (required)>'
       /tmp/build_ure0m4wsxy41/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.9
/lib/active_support/dependencies.rb:251:in `require'
       /tmp/build_ure0m4wsxy41/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.9
/lib/active_support/dependencies.rb:251:in `block in require'
       /tmp/build_ure0m4wsxy41/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.9
/lib/active_support/dependencies.rb:236:in `load_dependency'
       /tmp/build_ure0m4wsxy41/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.9
/lib/active_support/dependencies.rb:251:in `require'
       /tmp/build_ure0m4wsxy41/vendor/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/
rails/application.rb:103:in `require_environment!'
       /tmp/build_ure0m4wsxy41/vendor/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/
rails/application.rb:297:in `block (2 levels) in initialize_tasks'
       /tmp/build_ure0m4wsxy41/vendor/bundle/ruby/1.9.1/gems/rake-10.0.4/lib/rak
e/task.rb:246:in `call'
       /tmp/build_ure0m4wsxy41/vendor/bundle/ruby/1.9.1/gems/rake-10.0.4/lib/rak
e/task.rb:246:in `block in execute'
       /tmp/build_ure0m4wsxy41/vendor/bundle/ruby/1.9.1/gems/rake-10.0.4/lib/rak
e/task.rb:241:in `each'
       /tmp/build_ure0m4wsxy41/vendor/bundle/ruby/1.9.1/gems/rake-10.0.4/lib/rak
e/task.rb:241:in `execute'
       /tmp/build_ure0m4wsxy41/vendor/bundle/ruby/1.9.1/gems/rake-10.0.4/lib/rak
e/task.rb:184:in `block in invoke_with_call_chain'
       /tmp/build_ure0m4wsxy41/vendor/bundle/ruby/1.9.1/gems/rake-10.0.4/lib/rak
e/task.rb:177:in `invoke_with_call_chain'
       /tmp/build_ure0m4wsxy41/vendor/bundle/ruby/1.9.1/gems/rake-10.0.4/lib/rak
e/task.rb:170:in `invoke'
       /tmp/build_ure0m4wsxy41/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.9/li
b/sprockets/assets.rake:93:in `block (2 levels) in <top (required)>'
       /tmp/build_ure0m4wsxy41/vendor/bundle/ruby/1.9.1/gems/rake-10.0.4/lib/rak
e/task.rb:246:in `call'
       /tmp/build_ure0m4wsxy41/vendor/bundle/ruby/1.9.1/gems/rake-10.0.4/lib/rak
e/task.rb:246:in `block in execute'
       /tmp/build_ure0m4wsxy41/vendor/bundle/ruby/1.9.1/gems/rake-10.0.4/lib/rak
e/task.rb:241:in `each'
       /tmp/build_ure0m4wsxy41/vendor/bundle/ruby/1.9.1/gems/rake-10.0.4/lib/rak
e/task.rb:241:in `execute'
       /tmp/build_ure0m4wsxy41/vendor/bundle/ruby/1.9.1/gems/rake-10.0.4/lib/rak
e/task.rb:184:in `block in invoke_with_call_chain'
       /tmp/build_ure0m4wsxy41/vendor/bundle/ruby/1.9.1/gems/rake-10.0.4/lib/rak
e/task.rb:177:in `invoke_with_call_chain'
       /tmp/build_ure0m4wsxy41/vendor/bundle/ruby/1.9.1/gems/rake-10.0.4/lib/rak
e/task.rb:205:in `block in invoke_prerequisites'
       /tmp/build_ure0m4wsxy41/vendor/bundle/ruby/1.9.1/gems/rake-10.0.4/lib/rak
e/task.rb:203:in `each'
       /tmp/build_ure0m4wsxy41/vendor/bundle/ruby/1.9.1/gems/rake-10.0.4/lib/rak
e/task.rb:203:in `invoke_prerequisites'
       /tmp/build_ure0m4wsxy41/vendor/bundle/ruby/1.9.1/gems/rake-10.0.4/lib/rak
e/task.rb:183:in `block in invoke_with_call_chain'
       /tmp/build_ure0m4wsxy41/vendor/bundle/ruby/1.9.1/gems/rake-10.0.4/lib/rak
e/task.rb:177:in `invoke_with_call_chain'
       /tmp/build_ure0m4wsxy41/vendor/bundle/ruby/1.9.1/gems/rake-10.0.4/lib/rak
e/task.rb:170:in `invoke'
       /tmp/build_ure0m4wsxy41/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.9/li
b/sprockets/assets.rake:60:in `block (3 levels) in <top (required)>'
       /tmp/build_ure0m4wsxy41/vendor/bundle/ruby/1.9.1/gems/rake-10.0.4/lib/rak
e/task.rb:246:in `call'
       /tmp/build_ure0m4wsxy41/vendor/bundle/ruby/1.9.1/gems/rake-10.0.4/lib/rak
e/task.rb:246:in `block in execute'
       /tmp/build_ure0m4wsxy41/vendor/bundle/ruby/1.9.1/gems/rake-10.0.4/lib/rak
e/task.rb:241:in `each'
       /tmp/build_ure0m4wsxy41/vendor/bundle/ruby/1.9.1/gems/rake-10.0.4/lib/rak
e/task.rb:241:in `execute'
       /tmp/build_ure0m4wsxy41/vendor/bundle/ruby/1.9.1/gems/rake-10.0.4/lib/rak
e/task.rb:184:in `block in invoke_with_call_chain'
       /tmp/build_ure0m4wsxy41/vendor/bundle/ruby/1.9.1/gems/rake-10.0.4/lib/rak
e/task.rb:177:in `invoke_with_call_chain'
       /tmp/build_ure0m4wsxy41/vendor/bundle/ruby/1.9.1/gems/rake-10.0.4/lib/rak
e/task.rb:170:in `invoke'
       /tmp/build_ure0m4wsxy41/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.9/li
b/sprockets/assets.rake:23:in `invoke_or_reboot_rake_task'
       /tmp/build_ure0m4wsxy41/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.9/li
b/sprockets/assets.rake:29:in `block (2 levels) in <top (required)>'
       /tmp/build_ure0m4wsxy41/vendor/bundle/ruby/1.9.1/gems/rake-10.0.4/lib/rak
e/task.rb:246:in `call'
       /tmp/build_ure0m4wsxy41/vendor/bundle/ruby/1.9.1/gems/rake-10.0.4/lib/rak
e/task.rb:246:in `block in execute'
       /tmp/build_ure0m4wsxy41/vendor/bundle/ruby/1.9.1/gems/rake-10.0.4/lib/rak
e/task.rb:241:in `each'
       /tmp/build_ure0m4wsxy41/vendor/bundle/ruby/1.9.1/gems/rake-10.0.4/lib/rak
e/task.rb:241:in `execute'
       /tmp/build_ure0m4wsxy41/vendor/bundle/ruby/1.9.1/gems/rake-10.0.4/lib/rak
e/task.rb:184:in `block in invoke_with_call_chain'
       /tmp/build_ure0m4wsxy41/vendor/bundle/ruby/1.9.1/gems/rake-10.0.4/lib/rak
e/task.rb:177:in `invoke_with_call_chain'
       /tmp/build_ure0m4wsxy41/vendor/bundle/ruby/1.9.1/gems/rake-10.0.4/lib/rak
e/task.rb:170:in `invoke'
       /tmp/build_ure0m4wsxy41/vendor/bundle/ruby/1.9.1/gems/rake-10.0.4/lib/rak
e/application.rb:143:in `invoke_task'
       /tmp/build_ure0m4wsxy41/vendor/bundle/ruby/1.9.1/gems/rake-10.0.4/lib/rak
e/application.rb:101:in `block (2 levels) in top_level'
       /tmp/build_ure0m4wsxy41/vendor/bundle/ruby/1.9.1/gems/rake-10.0.4/lib/rak
e/application.rb:101:in `each'
       /tmp/build_ure0m4wsxy41/vendor/bundle/ruby/1.9.1/gems/rake-10.0.4/lib/rak
e/application.rb:101:in `block in top_level'
       /tmp/build_ure0m4wsxy41/vendor/bundle/ruby/1.9.1/gems/rake-10.0.4/lib/rak
e/application.rb:110:in `run_with_threads'
       /tmp/build_ure0m4wsxy41/vendor/bundle/ruby/1.9.1/gems/rake-10.0.4/lib/rak
e/application.rb:95:in `top_level'
       /tmp/build_ure0m4wsxy41/vendor/bundle/ruby/1.9.1/gems/rake-10.0.4/lib/rak
e/application.rb:73:in `block in run'
       /tmp/build_ure0m4wsxy41/vendor/bundle/ruby/1.9.1/gems/rake-10.0.4/lib/rak
e/application.rb:160:in `standard_exception_handling'
       /tmp/build_ure0m4wsxy41/vendor/bundle/ruby/1.9.1/gems/rake-10.0.4/lib/rak
e/application.rb:70:in `run'
       Tasks: TOP => environment
       (See full trace by running task with --trace)
       Precompiling assets failed, enabling runtime asset compilation
       Injecting rails31_enable_runtime_asset_compilation
       Please see this article for troubleshooting help:
       http://devcenter.heroku.com/articles/rails31_heroku_cedar#troubleshooting

-----> WARNINGS:
       Removing `Gemfile.lock` because it was generated on Windows.
       Bundler will do a full resolve so native gems are handled properly.
       This may result in unexpected gem versions being used in your app.
-----> Rails plugin injection
       Injecting rails_log_stdout
       Injecting rails3_serve_static_assets
-----> Discovering process types
       Procfile declares types      -> web
       Default types for Ruby/Rails -> console, rake, worker

-----> Compiled slug size: 59.8MB
-----> Launching... done, v17
-----> Deploy hooks scheduled, check output in your logs
       http://acadmx-staging-two.herokuapp.com deployed to Heroku

To git@heroku.com:acadmx-staging-two.git
   e0d337d..1f9808f  production -> master
Andrew@ANDREW-T520 ~/Documents/Projects/Acadmx/src/acadmx_web (production)
4

1 回答 1

3

如果您的应用程序在启动阶段初始化(Rails 在某些情况下会这样做)与数据库的连接,那么您在生产环境中编译资产时会遇到此问题。

您需要通过 Heroku 实验室功能让您的应用程序访问环境变量

heroku labs:enable user-env-compile -a myapp

您可以在https://devcenter.heroku.com/articles/labs-user-env-compile阅读更多相关信息

于 2013-08-18T07:15:41.650 回答