Heroku在预编译资产时中断。 “rake aborted!无法连接到'127.0.0.1上的MySQL服务器'(111)”

时间:2013-08-18 01:31:44

标签: ruby-on-rails ruby-on-rails-3 heroku rake

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

  1. 我补充道 config.assets.initialize_on_precompile = false 到我的application.rb文件。

  2. 它也在我的环境/ staging.rb& production.rb文件。

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

  4. 我有一个临时环境,我可以推得很好,不明白发生了什么

    我在下面添加了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)
    

1 个答案:

答案 0 :(得分:3)

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

您需要通过Heroku实验室功能

为您的应用程序提供对环境变量的访问权限
heroku labs:enable user-env-compile -a myapp

您可以在https://devcenter.heroku.com/articles/labs-user-env-compile

了解详情