R
Railwayโ€ข2y ago
luna

NixPacks are huge

Moved from #๐ŸŽญ๏ฝœshow-off-your-stuff
66 Replies
Percy
Percyโ€ข2y ago
Project ID: N/A
luna
lunaOPโ€ข2y ago
FROM node:18-alpine as builder

WORKDIR /app

# Install required packages
COPY package*.json /app/
RUN npm install

# Copy source files
COPY src /app/src
COPY tsconfig.json squirrelly.js /app/
COPY patches /app/patches
COPY prisma /app/prisma

# Generate Prisma Client
RUN npx prisma generate

# Build application
RUN npm run build

# ==== Final Image
FROM node:18-alpine as final
USER node:node
WORKDIR /app

# Copying build output
COPY --from=builder --chown=node:node /app/squirrelly.js ./
COPY --from=builder --chown=node:node /app/package*.json ./
COPY --from=builder --chown=node:node /app/prisma prisma
COPY --from=builder --chown=node:node /app/node_modules/.prisma node_modules/.prisma
COPY --from=builder --chown=node:node /app/dist dist

# Install only the production dependencies
RUN npm install --production

CMD npm start
FROM node:18-alpine as builder

WORKDIR /app

# Install required packages
COPY package*.json /app/
RUN npm install

# Copy source files
COPY src /app/src
COPY tsconfig.json squirrelly.js /app/
COPY patches /app/patches
COPY prisma /app/prisma

# Generate Prisma Client
RUN npx prisma generate

# Build application
RUN npm run build

# ==== Final Image
FROM node:18-alpine as final
USER node:node
WORKDIR /app

# Copying build output
COPY --from=builder --chown=node:node /app/squirrelly.js ./
COPY --from=builder --chown=node:node /app/package*.json ./
COPY --from=builder --chown=node:node /app/prisma prisma
COPY --from=builder --chown=node:node /app/node_modules/.prisma node_modules/.prisma
COPY --from=builder --chown=node:node /app/dist dist

# Install only the production dependencies
RUN npm install --production

CMD npm start
Percy
Percyโ€ข2y ago
You might find these helpful: - Friend banned? - dhfidsfghbjdgbfd - Cannot access projects
โš ๏ธ experimental feature
luna
lunaOPโ€ข2y ago
My old build was 400MB it's now 100MB.
milo
miloโ€ข2y ago
cheers so if it is okay can u go to ur last deployment using nixpacks and send the table at the toop of the build logs?
luna
lunaOPโ€ข2y ago
==============
Using Nixpacks
==============
context: 38896407f0d7d63901693309885bef41

โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ• Nixpacks v1.4.2 โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•—
โ•‘ setup โ”‚ nodejs-18_x, npm-8_x, openssl โ•‘
โ•‘โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•‘
โ•‘ install โ”‚ npm ci โ•‘
โ•‘โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•‘
โ•‘ build โ”‚ npm run build โ•‘
โ•‘โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•‘
โ•‘ start โ”‚ npm run start โ•‘
โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
==============
Using Nixpacks
==============
context: 38896407f0d7d63901693309885bef41

โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ• Nixpacks v1.4.2 โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•—
โ•‘ setup โ”‚ nodejs-18_x, npm-8_x, openssl โ•‘
โ•‘โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•‘
โ•‘ install โ”‚ npm ci โ•‘
โ•‘โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•‘
โ•‘ build โ”‚ npm run build โ•‘
โ•‘โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•‘
โ•‘ start โ”‚ npm run start โ•‘
โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
That?
milo
miloโ€ข2y ago
yup cheers do you need openssl?
luna
lunaOPโ€ข2y ago
I was forcing v18 since I needed fetch.
milo
miloโ€ข2y ago
you dont install it in ur dockerfile
luna
lunaOPโ€ข2y ago
dont think so. Im using alpine and i didnt add ssl myself.
milo
miloโ€ข2y ago
maybe alpine does some funny stuff
luna
lunaOPโ€ข2y ago
nah you need to usually add it yourself. all the images at work have alpine + openssl installed so i know it's for sure missing by default
milo
miloโ€ข2y ago
can u send ur like prisma file prisma schema
luna
lunaOPโ€ข2y ago
milo
miloโ€ข2y ago
ahhh thank you
milo
miloโ€ข2y ago
gonna work on making this better hopefulkly
luna
lunaOPโ€ข2y ago
the only unconventional thing im doing is using tsup to bundle all the deps inline, but that's no different to using esbuild, webpack, etc. plus the savings just from using 2 images is huge, the second(final) only gets the production deps.
milo
miloโ€ข2y ago
problem is with nixpacks, we have to copy over all deps as we dont know which is which like, if a prod app needs a dev dep to start or something
luna
lunaOPโ€ข2y ago
yeah, we also use this at work to easily remove things from node_modules like markdown files and such people forget to remove from the deps before publishing. https://www.npmjs.com/package/node-prune We saw 50% reduction in some of our node_modules from that alone. if a prod app needs a dep to start it's a dep not a devDep, idk why people confuse those.
milo
miloโ€ข2y ago
well people are idiots lol
luna
lunaOPโ€ข2y ago
my main point is it's not really an issue if people use them how they're meant to be used.
milo
miloโ€ข2y ago
you kinda unfortunately have to expect it
luna
lunaOPโ€ข2y ago
true ๐Ÿ˜ฆ
milo
miloโ€ข2y ago
GitHub
Alpine Images ยท railwayapp/nixpacks ยท Discussion #825
Alpine Linux is a distribution of Linux that is secure and small. I think we should use it over Ubuntu/Debian whenever possible, which is basically when a plan doesn't require any apt packa...
jackson
jacksonโ€ข2y ago
alpine has openssl v3 by default now, but yeah could install v1 compat
milo
miloโ€ข2y ago
what do u think about the issue i sent
luna
lunaOPโ€ข2y ago
the more ya know.
jackson
jacksonโ€ข2y ago
would likely cause a TON of issues but could shrink image size a bit
milo
miloโ€ข2y ago
how so? ๐Ÿค”
jackson
jacksonโ€ข2y ago
switching package managers from apt to apk, different system dependencies, stuff like that
milo
miloโ€ข2y ago
i said if the plan didnt have any apt packjages
jackson
jacksonโ€ข2y ago
would likely cause some hidden issues in people's projects, stuff like "libmonkey.so.c not found"
milo
miloโ€ข2y ago
we could use alpine images
jackson
jacksonโ€ข2y ago
ah
milo
miloโ€ข2y ago
monkey!?!
jackson
jacksonโ€ข2y ago
wtfbowl
milo
miloโ€ข2y ago
:lipbite wait it's not what it looks like
jackson
jacksonโ€ข2y ago
well yeah if it's a bone stock js project then alpine 18 is probably the move
luna
lunaOPโ€ข2y ago
what about using debian slim?
jackson
jacksonโ€ข2y ago
that's what i use on several projects could get neb's opinion
milo
miloโ€ข2y ago
Neber
luna
lunaOPโ€ข2y ago
debian slim would be at least a move in the right direction. Plus add multi-step builds and that'd shave a lot of space.
milo
miloโ€ข2y ago
we already do multi stage
luna
lunaOPโ€ข2y ago
I mean.. you do but you dont take advantage of it though. Looking at my logs it creates with the build step, then does everything in stage-0. Kinda defeating the whole purpose of multi-step.
milo
miloโ€ข2y ago
wait what that sounds broken
luna
lunaOPโ€ข2y ago
#1 [internal] load build definition from Dockerfile
#1 sha256:ea2e532503e902eb9b4c6ecdb02da98a3c4960e97586847a9260ed07e9b61489

#1 transferring dockerfile: 2.23kB done
#1 DONE 0.0s

#2 [internal] load .dockerignore
#2 sha256:c380b620781affc5f699a98d101c2adc247f7f07baa5ddc7c7c755cbe850391d
#2 transferring context: 2B done
#2 DONE 0.0s

#3 [internal] load metadata for ghcr.io/railwayapp/nixpacks:ubuntu-1677542600
#3 sha256:35ba3c4c9c27e2c10ffc5e2ba3111bff1e2ed2b0ed00afdfc6e6aea781c437e3

#3 DONE 16.9s

#1 [internal] load build definition from Dockerfile
#1 sha256:ea2e532503e902eb9b4c6ecdb02da98a3c4960e97586847a9260ed07e9b61489

#1 transferring dockerfile: 2.23kB done
#1 DONE 0.0s

#2 [internal] load .dockerignore
#2 sha256:c380b620781affc5f699a98d101c2adc247f7f07baa5ddc7c7c755cbe850391d
#2 transferring context: 2B done
#2 DONE 0.0s

#3 [internal] load metadata for ghcr.io/railwayapp/nixpacks:ubuntu-1677542600
#3 sha256:35ba3c4c9c27e2c10ffc5e2ba3111bff1e2ed2b0ed00afdfc6e6aea781c437e3

#3 DONE 16.9s

That's build step.
milo
miloโ€ข2y ago
something got brokeyn
luna
lunaOPโ€ข2y ago
and then after that stage-0 nothing after stage-0
#4 [stage-0 1/10]
#13 [stage-0 9/10]
#4 [stage-0 1/10]
#13 [stage-0 9/10]
Brody
Brodyโ€ข2y ago
I too have noticed this, I thought I was just tripping though
milo
miloโ€ข2y ago
well thats definetly broken i blame Brody (he uses go)
luna
lunaOPโ€ข2y ago
so maybe you dont need to change anything but just fix this lol
Brody
Brodyโ€ข2y ago
Fair
milo
miloโ€ข2y ago
lo
Brody
Brodyโ€ข2y ago
I think railway likes shipping 400mb images
milo
miloโ€ข2y ago
lmof
nebula
nebulaโ€ข2y ago
hi yeah nixpacks are massive
milo
miloโ€ข2y ago
NEB
nebula
nebulaโ€ข2y ago
im gonna be diving in sometime this week
milo
miloโ€ข2y ago
nebnebnebn neb something bad is happening
nebula
nebulaโ€ข2y ago
what
milo
miloโ€ข2y ago
<#1083064733122441286>
jr
jrโ€ข2y ago
Keep in mind that with the layer cache on the registry, the things that we need to upload and pull are often much lower than this Often source changes to node projects result in about 30mb changes Only for specific languages
Brody
Brodyโ€ข2y ago
Oh yeah I know, I'm just joking around
jr
jrโ€ข2y ago
We used to use debian slim but moved to Ubuntu since Debian was being annoying with a few packages. Mainly openssl (still used 1). This image size is very comparable though
milo
miloโ€ข2y ago
Oh
Want results from more Discord servers?
Add your server