Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't deploy with Kamal after install esbuild #208

Closed
sbleon opened this issue Jan 21, 2025 · 3 comments
Closed

Can't deploy with Kamal after install esbuild #208

sbleon opened this issue Jan 21, 2025 · 3 comments

Comments

@sbleon
Copy link

sbleon commented Jan 21, 2025

After installing this gem and using it to install esbuild, the build stage of the Dockerfile doesn't have the tools needed to precompile assets. Here's the error I got:

 [build 6/6] RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile
 1.342 bin/rails aborted!
 1.342 jsbundling-rails: Command install failed, ensure yarn is installed
 1.370 
 1.370 Tasks: TOP => assets:precompile => javascript:build => javascript:install
 1.370 (See full trace by running task with --trace)
 ERROR: process "/bin/sh -c SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile" did not complete successfully: exit code: 1

I was able to resolve this issue by adding the following to the build stage of the Kamal-generated Dockerfile after the apt-get install build-essential step.

RUN curl -fsSL https://deb.nodesource.com/setup_20.x -o nodesource_setup.sh && \
    bash nodesource_setup.sh
RUN apt-get install -y nodejs
RUN npm install --global yarn

I don't know if this is something that is generalizable, or if it is needed for all of the various bundlers. But, I suspect that other folks will run into this error and might not have the Docker knowledge needed to fix it.

@dhh
Copy link
Member

dhh commented Mar 9, 2025

Not a lot we can do about that. If you generate a new Rails 8 app and you say you want esbuild, that is configured for you. But otherwise this is something you have to do by yourself. Possible we could add something to an FAQ though. Feel free to explore that!

@dhh dhh closed this as completed Mar 9, 2025
@sbleon
Copy link
Author

sbleon commented Mar 10, 2025

Thanks, @dhh. I think adding a note to the FAQ would go a long way. Would it be totally crazy to have the javascript:install rake task check for the presence of Kamal and have it output a message like the following?

Kamal detected. See the FAQ for deployment config instructions.
https://github.com/rails/jsbundling-rails?tab=readme-ov-file#faq

@dhh
Copy link
Member

dhh commented Mar 10, 2025

Happy to consider a PR! All depends on how invasive it feels etc.

sbleon added a commit to sbleon/jsbundling-rails that referenced this issue Mar 10, 2025
This should help devs who added the gem to a Rails app after initially generating the app.

Background is at rails#208
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants