Node.js with ruby on rails
I am upgrading an existing Heroku project in order to migrate it to railway.
The existing project uses Bootstrap, which has a dependency on jQuery.
jQuery in rails requires a JavaScript compiler, and I've been using node.js in my existing projects, but the docker image for rails doesn't appear to include it, or any way to make this work, which means that building fails at the "compiling assets" stage, meaning that deployment fails.
I created a new rails project from scratch, with new versions of ruby and rails, to try to see if it was a dependency on an older version of rails, but that didn't help (the new project works fine on my local computer)
Tl;Dr can I convince my rails docker image to include node.js for JavaScript compilation?
Jon
11 Replies
you can use NIXPACKS_PKGS env variable to include nodejs dependency
https://nixpacks.com/docs/configuration/environment
Environment | Nixpacks
App source + Nix packages + Docker = Image
@Dhananjay Any advice on the packages to add, or am I better off picking the "NIXPACKS_APT_PKGS" and picking packages I know from there?
I thing just adding nodejs package should do the job , you should try it yourself and see if that works
NIXPACKS_PKGS=nodejs
in the dashboard
Ta
That appears to have worked. Now I just have to fix my other errors :-D
Is Node.js only required in your project just for compiling assets?
I believe so. I don't believe it's used for anything else after asset compilation
Is your app shipped as a Docker container?
@msrumon I made one based on the default rails postgres application. I believe it's a docker container
My project is now working on the new system, although I gutted the version of ruby and rails, and rebuilt based on the database and apps folders, but upgrading versions is generally a good security consideration.
If so, why not utilize it?
@msrumon ta. I couldn't find anything like that, but was probably looking in the wrong direction. I might keep the
NIXPACKS_PKGS
environment variable as it's very easy to leave in place, and still allows me to share my git repo with users not requiring railway/docker (although no one has shown interest so far)
Jon