R
Railway3y ago
jad

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
Dhananjay
Dhananjay3y ago
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
jad
jadOP3y ago
@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?
Dhananjay
Dhananjay3y ago
I thing just adding nodejs package should do the job , you should try it yourself and see if that works
Dhananjay
Dhananjay3y ago
NIXPACKS_PKGS=nodejs in the dashboard
jad
jadOP3y ago
Ta That appears to have worked. Now I just have to fix my other errors :⁠-⁠D
Rumon
Rumon3y ago
Is Node.js only required in your project just for compiling assets?
jad
jadOP3y ago
I believe so. I don't believe it's used for anything else after asset compilation
Rumon
Rumon3y ago
Is your app shipped as a Docker container?
jad
jadOP3y ago
@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.
Rumon
Rumon3y ago
If so, why not utilize it?
FROM node:lts-alpine AS assets
ENV NODE_ENV development
WORKDIR /tmp/app # any path of your choice, just make sure it doesn't collide with system files
COPY package*.json ./
RUN npm install
COPY . . # you can also copy specific files for compiling assets as well
RUN npm run build # change it according to your need

FROM ruby:alpine
# ... i don't know anything about ruby, so can't progress beyond
FROM node:lts-alpine AS assets
ENV NODE_ENV development
WORKDIR /tmp/app # any path of your choice, just make sure it doesn't collide with system files
COPY package*.json ./
RUN npm install
COPY . . # you can also copy specific files for compiling assets as well
RUN npm run build # change it according to your need

FROM ruby:alpine
# ... i don't know anything about ruby, so can't progress beyond
jad
jadOP3y ago
@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
Want results from more Discord servers?
Add your server