I am using an asset host (AWS Cloudfront) for my Rails application:
# config/environments/production.rb
config.asset_host = "xxxxxxxxxxx.cloudfront.net"
During my deployment on my CI service I precompile assets:
bundle exec rake assets:precompile
And then push those generated assets to the S3 bucket that serves as the origin of the Cloudfront distribution.
Note: I don't include the precompiled assets in my final docker image that is eventually deployed.
Now when I start the server and try to access it - I receive the error:
application.css is not present in the asset pipeline
I know that there are multiple questions on Stackoverflow with this specific error message. But I tried everything e.g. like setting config.assets.compile = true/false
but the only thing that made it work was including the precompiled assets in the build (final docker image).
So now I am asking myself: Do I have to always include the assets locally although I am using an asset host?!
the way asset pipeline
resolve asset path that it'll look up the fingerprinting
of the asset file first (which be generated by the rake task precompile
) then map to asset_host
(if any), if there's no fingerprinting
map to the asset then it'll throw exception, it does not check on your asset_host
.
if you don't include the precompiled assets in your docker image, your rails app in docker container can't find asset files since there's no fingerprinting
be generated in that container.
so yes, you have to.
however, you can bypass the asset pipeline
by add a forward slash before the asset path or add skip_pipeline: true
, in your case, you already generate the fingerprinting and push those files to your asset host so you can bypass ,for example the application.css
, like this stylesheet_link_tag '/application-{fingerprinting}.css'
, but obviously it's not the good choice since you need to do this for all files.