Search code examples
ruby-on-railskamalpropshaft

Kamal deploy can't find application.css


In my Kamal v2 / Propshaft deployed application (Rails 8.0.0) the CSS assets are being compiled (SCSS -> CSS), and pushed to the Kamal container on the remote server, but Rails cannot find them. I'm using Propshaft and no node or other JS tools.

Error log from kamal logs

2024-11-17T17:26:45.976357325Z Information for cause: Propshaft::MissingAssetError (The asset 'application.css' was not found in the load path.):
2024-11-17T17:26:45.976363158Z [d1968adc-03c5-4e53-b2d2-42e19b1b1bc9]
2024-11-17T17:26:45.976368411Z [d1968adc-03c5-4e53-b2d2-42e19b1b1bc9] app/views/layouts/public.html.erb:6

app/views/layouts/public.html.erb

<%= stylesheet_link_tag "application", "data-turbo-track": "reload" %>
<%= javascript_include_tag "application", "data-turbo-track": "reload", defer: true %>

In the container, the compiled CSS file exists and the contents look OK. (accessed with kamal app exec -i bash)

rails@63cc5d2195a1:/rails/app/assets/builds$ ls
application.css

Gemfile (partial)

gem "dartsass-rails"
gem "importmap-rails"
gem "propshaft"

config/environments/production.rb

config.public_file_server.headers = { "cache-control" => "public, max-age=#{1.year.to_i}" }
config.public_file_server.enabled = true

config/deploy.yml

# Bridge fingerprinted assets, like JS and CSS, between versions to avoid
# hitting 404 on in-flight requests. Combines all files from new and old
# version inside the asset_path.
asset_path: /rails/public/assets

Any ideas on how to connect the dots?


Solution

  • Make sure you have app/assets/builds/.keep file pushed into repo. When app starts - Propshaft add this directory to load path and then registers for filesystem notifications if new files are added into it. However, if it doesn't exist - of course it cannot registers for notifications so it doesn't add this dir to load path.