assets:precompile not compiling CSS assets

This is probably not a Fly issue; but on the odd chance that this is related to static files/nginx or some like setting like that, I’m posting here. Also want to note that when I build and run the same exact Dockerfile locally, I don’t get this issue.

I suddenly started having this problem in my production box where most of the css assets are compiled, except for the 3 assets I tell dartsass to build, application.css and two others here:

config/initializers/dartsass.rb

# config/initializers/dartsass.rb
Rails.application.config.dartsass.builds = {
  "application.scss" => "application.css",
  "mailer.scss" => "mailer.css",
  "active_admin.scss" => "active_admin.css"
}

Immediately after deploying, public/assets only has the scss files and the .manifest.json also does not reference the .css files (because they don’t exist in public/assets:

root@3d8d9296ce7948:/rails# cat public/assets/.manifest.json 
{"active_admin.js":"active_admin-9383b93bd6d1d9fa0a36586f11fbb66bf00abbe8.js","application.scss":"application-7596f0d55dbc14bbba8357ba2519b6a92c1ba3e5.scss","active_admin.scss":"active_admin-b3484b0fe9d5b655c7bfabf44d4844d3f578e38c.scss","base/sizes.scss":"base/

root@3d8d9296ce7948:/rails# ls public/assets/ | grep application
application-7596f0d55dbc14bbba8357ba2519b6a92c1ba3e5.scss
application-8c437f3aabfc2ca3fdda87f69e6041a7e3c5f5e3.js

After I run assets:precompile again on the box, the assets are generated:

root@3d8d9296ce7948:/rails# bin/rails assets:precompile
I, [2024-02-24T22:12:30.174296 #329]  INFO -- : Writing application-23b791d200e0a4700af4b77c5bd2aea477b5575c.css
I, [2024-02-24T22:12:30.205423 #329]  INFO -- : Writing active_admin-9d8f9c30e6ef1f119225b74cf213f50721c80914.css
I, [2024-02-24T22:12:30.205963 #329]  INFO -- : Writing mailer-0e34617c354ffe5379b296cf599c202195eab754.css
root@3d8d9296ce7948:/rails# ls public/assets/ | grep application
application-23b791d200e0a4700af4b77c5bd2aea477b5575c.css

root@3d8d9296ce7948:/rails# cat public/assets/.manifest.json 
{"application.css":"application-23b791d200e0a4700af4b77c5bd2aea477b5575c.css","active_admin.css":"active_admin-9d8f9c30e6ef1f119225b74cf213f50721c80914.css","mailer.css":"mailer-0e34617c354ffe5379b296cf599c202195eab754.css"

The thing is, I am already doing assets:precompile in my Dockerfile and copying the output to the final image:

FROM ... as build

# Precompiling assets for production without requiring secret RAILS_MASTER_KEY
RUN SECRET_KEY_BASE=DUMMY ./bin/rails assets:precompile

...

COPY --from=build /rails /rails

Not sure why this started happening, as I haven’t updated much of anything. Appreciate any ideas.

gem versions:
rails (7.0.7.2)
propshaft (0.8.0)
dartsass-rails (0.5.0)

I don’t know what’s causing this. The only difference between assets:precompile at build time and after deploy should be access to secrets.

What I do in cases like these is run:

fly console --dockerfile Dockerfile -C bash

In this way, I can quickly test the effects of changes to the Dockerfile without having to worry about whether the server can start or having to ssh in.

Okay this was extremely unexpected.

After reading cssbundling-rails’ (which I don’t use in my project) documentation, I found this: GitHub - rails/cssbundling-rails: Bundle and process CSS in Rails with Tailwind, PostCSS, and Sass via Node.js.

You must have app/assets/builds available. Add the directory with a .gitkeep file, and you’ll ensure it’s available in production.

And that was it – the assets were digested correctly.

This is a bit perplexing because in the Fly production VM, I could find the assets compiled by dartsass-rails in that same exact folder (app/assets/builds/*.css), so I knew the folder existed; but the digested application-7577900c40f86606a5c6acaa00076c57a63f48a6.css etc were not in public/assets, so I also knew propshaft was not finding anything in app/assets/builds. There must be a dir creation order issue somewhere between dartsass-rails and propshaft.

Anyway, someone ought to add that warning to propshaft’s documentation I guess.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.