AssetSync / asset_sync

Synchronises Assets between Rails and S3
1.89k stars 346 forks source link

No such middleware to insert before: ActionDispatch::Static #221

Open abatko opened 11 years ago

abatko commented 11 years ago

I have a barebones Rails app (with just a blank root/home page).

As far as I know I have configured the app correctly for asset_sync:

Additionally, I tested that all this works locally:

-bash> RAILS_ENV=staging bundle exec rake assets:precompile
/Users/abatko/.rvm/rubies/ruby-1.9.3-p448/bin/ruby /Users/abatko/.rvm/gems/ruby-1.9.3-p448@global/bin/rake assets:precompile:all RAILS_ENV=staging RAILS_GROUPS=assets
AssetSync: using default configuration from built-in initializer
AssetSync: using default configuration from built-in initializer
AssetSync: Syncing.
Using: Directory Search of /Volumes/wd500gb/Users/abatko/Dev/Hello/hello/public/assets
Uploading: assets/application-1350ddecbcfa8f141098f698b5cc8bd4.css
Uploading: assets/application-1350ddecbcfa8f141098f698b5cc8bd4.css.gz
Uploading: assets/application-f59fba384c15ea7bcc32aafc1043ae78.js
Uploading: assets/application-f59fba384c15ea7bcc32aafc1043ae78.js.gz
Uploading: assets/jquery.min-348aa0e74773e2cf14a075e8936d8be8.map
Uploading: assets/rails-74ff64462ea2ef17574efab2800f2ed9.png
Uploading: assets/application.css
Uploading: assets/application.js
Uploading: assets/jquery.min.map
Uploading: assets/rails.png
AssetSync: Done.

Following this test, I delete the assets folder on both S3 and in my local public folder.

When I push to Heroku, I get this failure:

-bash> git push staging master
...
-----> Writing config/database.yml to read from DATABASE_URL
-----> Preparing app for Rails asset pipeline
       Running: rake assets:precompile
       rake aborted!
       No such middleware to insert before: ActionDispatch::Static
       /tmp/build_1v0f5oqlna8n9/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.13/lib/action_dispatch/middleware/stack.rb:120:in `assert_index'
       /tmp/build_1v0f5oqlna8n9/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.13/lib/action_dispatch/middleware/stack.rb:83:in `insert'
       /tmp/build_1v0f5oqlna8n9/vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/configuration.rb:38:in `block in merge_into'
       /tmp/build_1v0f5oqlna8n9/vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/configuration.rb:37:in `each'
       /tmp/build_1v0f5oqlna8n9/vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/configuration.rb:37:in `merge_into'
       /tmp/build_1v0f5oqlna8n9/vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/engine.rb:469:in `app'
       /tmp/build_1v0f5oqlna8n9/vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/application/finisher.rb:31:in `block in <module:Finisher>'
       /tmp/build_1v0f5oqlna8n9/vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/initializable.rb:30:in `instance_exec'
       /tmp/build_1v0f5oqlna8n9/vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/initializable.rb:30:in `run'
       /tmp/build_1v0f5oqlna8n9/vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/initializable.rb:55:in `block in run_initializers'
       /tmp/build_1v0f5oqlna8n9/vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/initializable.rb:54:in `each'
       /tmp/build_1v0f5oqlna8n9/vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/initializable.rb:54:in `run_initializers'
       /tmp/build_1v0f5oqlna8n9/vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/application.rb:136:in `initialize!'
       /tmp/build_1v0f5oqlna8n9/vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/railtie/configurable.rb:30:in `method_missing'
       /tmp/build_1v0f5oqlna8n9/config/environment.rb:9:in `<top (required)>'
       /tmp/build_1v0f5oqlna8n9/vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/application.rb:103:in `require'
       /tmp/build_1v0f5oqlna8n9/vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/application.rb:103:in `require_environment!'
       /tmp/build_1v0f5oqlna8n9/vendor/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/application.rb:297:in `block (2 levels) in initialize_tasks'
       /tmp/build_1v0f5oqlna8n9/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.13/lib/sprockets/assets.rake:93:in `block (2 levels) in <top (required)>'
       /tmp/build_1v0f5oqlna8n9/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.13/lib/sprockets/assets.rake:60:in `block (3 levels) in <top (required)>'
       /tmp/build_1v0f5oqlna8n9/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.13/lib/sprockets/assets.rake:23:in `invoke_or_reboot_rake_task'
       /tmp/build_1v0f5oqlna8n9/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.13/lib/sprockets/assets.rake:29:in `block (2 levels) in <top (required)>'
       Tasks: TOP => environment
       (See full trace by running task with --trace)
       AssetSync: using default configuration from built-in initializer
       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
-----> 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: 31.2MB
-----> Launching... done, v31

Whereas when I set config.serve_static_assets = true in staging.rb the push succeeds (and assets are uploaded as expected):

-bash> git push staging master
...
-----> Writing config/database.yml to read from DATABASE_URL
-----> Preparing app for Rails asset pipeline
       Running: rake assets:precompile
       AssetSync: using default configuration from built-in initializer
       AssetSync: using default configuration from built-in initializer
       AssetSync: Syncing.
       Using: Directory Search of /tmp/build_389b1gem3asdx/public/assets
       Uploading: assets/application-37ef150c142a979883d04c9b7bc8f406.css.gz
       Uploading: assets/jquery.min.map
       Uploading: assets/application-a228a1ab4c032130f2a959069a131d0f.js
       Uploading: assets/application.js
       Uploading: assets/application.css.gz
       Uploading: assets/application.css
       Uploading: assets/application-37ef150c142a979883d04c9b7bc8f406.css
       Uploading: assets/rails-12bb8809901c53b5ade4ecdcb7071f04.png
       Uploading: assets/jquery.min-7830d6497a1cb35cc8ef23eb129c7820.map
       Uploading: assets/application.js.gz
       Uploading: assets/manifest.yml
       Uploading: assets/application-a228a1ab4c032130f2a959069a131d0f.js.gz
       Uploading: assets/rails.png
       AssetSync: Done.
       Asset precompilation completed (38.40s)
-----> 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: 31.6MB
-----> Launching... done, v32

Any idea what may be wrong?

davidjrice commented 11 years ago

This is a Heroku problem. When you don't have serve static assets set, heroku installs a plugin to do that. Regardless of your asset host I believe.

With your app then being a stripped down app the middleware stack is not what heroku is expecting. Causing the error.

One thing would be to upgrade to rails 4. As vendor/plugins is deprecated, heroku doesn't install the plugin.

abatko commented 11 years ago

A friend of mine, working on a different app, but with a similar setup (ruby 1.9.3, rails 3.2.13, asset_sync 1.0.0, no local public/assets directory) has config.serve_static_assets = false and uploads work without fail. How can that be?

jclay commented 10 years ago

The same issue just appeared for me recently on rails-4.0.1. Any insight on what was causing this?

glennfu commented 10 years ago

I'm getting this on Rails 4.0.4 today.

ryana commented 10 years ago

For people that are reporting failures that others cannot reproduce, do you have heroku-deflater in your Gemfile? Removing it got rid of the error for me.

abatko commented 10 years ago

No heroku-deflater in my projects.

cmloegcmluin commented 9 years ago

I believe heroku-deflater caused this problem, but even after removing it from my Gemfile, the issue persists.

rfroetscher commented 9 years ago

Make sure you have gem 'rails_12factor', group: :production. That solved the problem for me.