nixpacks icon indicating copy to clipboard operation
nixpacks copied to clipboard

Rails assets not loading with Nixpacks

Open saurabhbhatia opened this issue 2 years ago • 4 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Describe the bug

I tried to deploy a Rails app on Railway using the default compilation method - Nixpacks. The app is a vanilla rails app, with minimal config. All the secret keys are check into the repo as encrypted credentials. Following are the only env vars apart from Rails defaults

NIXPACKS_BUILD_CMD
bundle exec rake assets:precompile && bundle exec rails db:migrate
NIXPACKS_START_CMD
bundle exec rails s -b 0.0.0.0

With nixpacks, my build step works fine but fails to load any of the assets as shown in the screenshots below. Heroku buildpack works just fine. The issue happens even when I remove the above env vars.

Screen Shot 2022-09-13 at 7 17 46 pm Screen Shot 2022-09-13 at 7 18 21 pm Screen Shot 2022-09-13 at 7 18 26 pm

To reproduce

Steps to reproduce the bug:

  1. Deploy a rails app with standalone tailwind CSS - rails new testapp --css tailwind.
  2. Set up some basic styles.
  3. Push to trailway.
  4. Navigate to the railway url.

Expected behavior

The styles must load like so, when nixpacks are selected -

Screen Shot 2022-09-13 at 7 31 02 pm

Environment

  • Rails 7
  • Latest Nixpacks ( default )

saurabhbhatia avatar Sep 13 '22 09:09 saurabhbhatia

Can you please provide an example repo. I am seeing build errors on a new rails app generated with that command (outside of nixpacks and railway).

coffee-cup avatar Sep 13 '22 15:09 coffee-cup

@coffee-cup this is the repo i'm trying to deploy - https://github.com/safewlabs/comix-mono. That's odd because i don't get any build errors while deploying.

saurabhbhatia avatar Sep 13 '22 23:09 saurabhbhatia

It uses a standalone version of Tailwindcss - https://github.com/rails/tailwindcss-rails / https://tailwindcss.com/blog/standalone-cli

saurabhbhatia avatar Sep 14 '22 00:09 saurabhbhatia

I'm seeing the same behavior in my repo.

Additional info:

  1. Nixpacks builder + RAILS_ENV variable not set = assets pipeline works
  2. Nixpacks builder + RAILS_ENV=production variable = assets do not load
  3. Heroku builder + RAILS_ENV=production variable = assets pipeline works

This is currently deployed to: https://web-production-61e7.up.railway.app/

As of October 12 @ 11:30p PST, I've switched back to the failing scenario above (Nixpacks builder + RAILS_ENV=production variable, assets do not load). Hopefully the logs linked to that deployment are helpful to diagnose.

Is there anything else I can do to help investigate?

DreadPirateShawn avatar Oct 13 '22 06:10 DreadPirateShawn

When I compare the deployment logs, searching for "rake assets", I notice one difference that may be directly relevant:

Heroku builder + RAILS_ENV=production variable = assets pipeline works

Running: rake assets:precompile
Running: rake assets:clean

Nixpacks builder + RAILS_ENV=production variable = assets do not load

║ build      │ bundle exec rake assets:precompile                              ║
#20 [stage-0 16/18] RUN  bundle exec rake assets:precompile

It appears that the Nixbuilds are missing the "rake assets:clean" invocation.

Not sure if there are other meaningful distinctions too -- I focused on the word "assets" in my comparison, but there may be other subtleties.

DreadPirateShawn avatar Oct 13 '22 06:10 DreadPirateShawn

@coffee-cup fyi ^ there's an additional repro now, if that helps.

DreadPirateShawn avatar Oct 27 '22 05:10 DreadPirateShawn

I split my issue to a separate ticket (https://github.com/railwayapp/nixpacks/issues/672) and will delete my previous comments, to keep this original issue cleaner.

DreadPirateShawn avatar Nov 11 '22 18:11 DreadPirateShawn