R
Railway10mo ago
luci1

node_modules

I'm trying to deploy using my build script. The build script consist in install normally the packages (including the development packages), but after, I need to remove the node_modules file to install only the production package's, but I got the error about .cache folder #12 1.527 rm: cannot remove 'node_modules/.cache': Device or resource busy Someone knows a way to reinstall the node_modules only for production? The current build command:
tsup ./src && rm -rf node_modules src && yarn install --prod
tsup ./src && rm -rf node_modules src && yarn install --prod
The "tsup" will convert my TypeScript project to JavaScript project at dist folder, so I don't need the src folder anymore.
Solution:
its works with some changes ```docker FROM node:18.17.1-alpine3.18 AS base FROM base AS build...
Jump to solution
45 Replies
Percy
Percy10mo ago
Project ID: N/A
Brody
Brody10mo ago
you should not be installing the node modules in the build command but first, is node_modules in your .gitignore?
luci1
luci110mo ago
of course i'm trying to reinstall the node_modules to reduce the project size
Brody
Brody10mo ago
does the initial build with tsup need dev dependencies?
luci1
luci110mo ago
the tsup is a dev dependencie, I don't need tsup to run the project, just for convert typescript to javascript during the build command
Brody
Brody10mo ago
isnt there a trim command that will remove dev deps? tsup ./src && yarn trim --dev
luci1
luci110mo ago
i'll try, one moment
Brody
Brody10mo ago
dont know if thats a thing, but you get the idea no no, i just made that up you need to check for the actual flag and syntax
luci1
luci110mo ago
does command works for yarn v1 (classic)?
Brody
Brody10mo ago
again, i dont know it was a pseudo command
luci1
luci110mo ago
did not work Yasuo
Brody
Brody10mo ago
bruh ^
luci1
luci110mo ago
i tryed to run tsup ./src && rm -rf src && yarn install --prod but my build time got a lot more seconds
Brody
Brody10mo ago
^
luci1
luci110mo ago
sure do you know if pnpm can do it?
Brody
Brody10mo ago
npm can
luci1
luci110mo ago
with prune?
Brody
Brody10mo ago
npm prune --production
luci1
luci110mo ago
pnpm too
Brody
Brody10mo ago
honestly just use npm, ive never seen much of a benefit with yarn or pnpm
luci1
luci110mo ago
nothing new, #12 2.315 up to date, audited 349 packages in 962ms, the correct is under of 300 packages running the following script:
tsup ./src && rm -rf src && npm prune --omit=dev
tsup ./src && rm -rf src && npm prune --omit=dev
but keeps uploading 235.4MB project_id: 56101361-0f25-4fa0-acf1-9524a7ab9a3d
Brody
Brody10mo ago
I mean, is 235 such a big deal? but for real, what you're trying to do would best be achieved in a multistage dockerfile
luci1
luci110mo ago
yes, i'm think this too
luci1
luci110mo ago
always was 200+ MB
luci1
luci110mo ago
i'll read the docs for the moment to implements dockerfile
Brody
Brody10mo ago
just have a Dockerfile in your project and railway will build with a dockerfile, but railway doesn't have any docs on how to write a dockerfile, since there are already so many great resources on that
luci1
luci110mo ago
do you know a documentation to create a Dockerfile? i just know how to use docker compose i have never used dockerfile before
Brody
Brody10mo ago
not off the top of my head, I'm sure you can find plenty of resources on Google though
luci1
luci110mo ago
ok, i'll search Ziggs is a good size? or i can reduce more? my project is very small
luci1
luci110mo ago
only theses javascript files (and the prisma orm), and probably is not more than 100mb
luci1
luci110mo ago
or... maybe the prisma is the large size?
Brody
Brody10mo ago
what node image are you using?
luci1
luci110mo ago
alpine
Brody
Brody10mo ago
let's see the dockerfile
luci1
luci110mo ago
hmm... i'm working around the dockerfile, because it's not copying my dist (generated by yarn build) folder probably because its in .gitignore file
Brody
Brody10mo ago
send the file anyway also, have you said what kind of app this is yet? apologies if you have
luci1
luci110mo ago
a common fastify/express backend app
luci1
luci110mo ago
Brody
Brody10mo ago
uh yeah that's not gonna work I'd rewrite that for you, but unfortunately I'm not at my computer right now
luci1
luci110mo ago
no problems bro Yasuo i'm close too
Brody
Brody10mo ago
lol not really tbh you are using CMD instead of RUN hey @luci give this a shot, but without seeing your code, i cant promise it will work
FROM node:18.17.1-alpine3.18 AS base

FROM base AS build

ENV NPM_CONFIG_UPDATE_NOTIFIER false
ENV NPM_CONFIG_FUND false

WORKDIR /app

COPY package.json yarn.lock ./

RUN yarn install

RUN yarn build

RUN npm prune --production

FROM base AS run

WORKDIR /app

COPY --from=build /app/node_modules/ ./
COPY --from=build /app/dist/ ./
COPY --from=build /app/package.json ./

CMD yarn start
FROM node:18.17.1-alpine3.18 AS base

FROM base AS build

ENV NPM_CONFIG_UPDATE_NOTIFIER false
ENV NPM_CONFIG_FUND false

WORKDIR /app

COPY package.json yarn.lock ./

RUN yarn install

RUN yarn build

RUN npm prune --production

FROM base AS run

WORKDIR /app

COPY --from=build /app/node_modules/ ./
COPY --from=build /app/dist/ ./
COPY --from=build /app/package.json ./

CMD yarn start
Solution
luci1
luci110mo ago
its works with some changes
FROM node:18.17.1-alpine3.18 AS base

FROM base AS build

ENV NPM_CONFIG_UPDATE_NOTIFIER false
ENV NPM_CONFIG_FUND false

WORKDIR /app

COPY package.json yarn.lock ./
COPY prisma ./prisma/

RUN yarn install

COPY src ./src

RUN yarn build

RUN npm prune --omit=dev

FROM base AS run

WORKDIR /app

COPY --from=build /app/node_modules/ ./node_modules
COPY --from=build /app/dist/ ./dist
COPY --from=build /app/package.json ./

CMD yarn start
FROM node:18.17.1-alpine3.18 AS base

FROM base AS build

ENV NPM_CONFIG_UPDATE_NOTIFIER false
ENV NPM_CONFIG_FUND false

WORKDIR /app

COPY package.json yarn.lock ./
COPY prisma ./prisma/

RUN yarn install

COPY src ./src

RUN yarn build

RUN npm prune --omit=dev

FROM base AS run

WORKDIR /app

COPY --from=build /app/node_modules/ ./node_modules
COPY --from=build /app/dist/ ./dist
COPY --from=build /app/package.json ./

CMD yarn start
With a total size of 157.3MB
Brody
Brody10mo ago
awesome, glad I could help
luci1
luci110mo ago
thanks bro Fizz
Brody
Brody10mo ago
no problem!