2 years ago
I'm trying to go back to compiled typescript code to reduce bun's memory usage. I've constructed my dockerfile and everything works fine up until the point it has to actually run the code. Could someone that has knowledge on docker assist me, as I'm a complete idiot in this.
23 Replies
2 years ago
f8f1d4b6-1530-4b65-a444-67b8c86c5fca
2 years ago
In deployment I get this error

2 years ago
And the dockerfile is as follows:
# Base image
FROM oven/bun:latest as base
WORKDIR /gato
# Install dependencies (including dev dependencies)
FROM base AS install
COPY package.json bun.lockb ./
RUN bun install --frozen-lockfile
# Build the project
FROM base AS build
COPY --from=install /gato/node_modules ./node_modules
COPY . .
RUN bun run db:generate
RUN bun run build
# Prepare the final image
FROM base AS release
WORKDIR /gato
COPY --from=install /gato/node_modules ./node_modules
COPY --from=build /gato/dist ./dist
ENV NODE_ENV=production
USER bun
ENTRYPOINT ["bun", "run", "dist/index.js"]2 years ago
Just for a bit of context, the reason I have to use my own dockerfile is because of a previous issue with prisma and openssl, which wouldn't load the required engines
2 years ago
first off, simplify that dockerfile, no multi layers
2 years ago
I mean I can try but this took me about an hour to construct 🥲
2 years ago
I'll just do all the steps in one directory then
2 years ago
and you'll likely come back to it soon enough, but it's too complex for your first try
2 years ago
use only a single FROM in the whole dockerfile
2 years ago
alright
2 years ago
the official bun guide was telling me to use multiple to keep things organized so i followed their instructions
2 years ago
Actually, I somehow got everything to work with just a bit of searching around
2 years ago
and that's absolutely the way you want to do things, but it's just a little more complex, so its best to start off simple first
2 years ago
what was the issue?
2 years ago
I wasn't copying the files properly from directory to directory, that's what I understood. A friend also helped simplify the file to only 2 stages and gave me a little guidance on how docker and it's image system works
2 years ago
I'm now sitting at a comfortable 108 mb of ram usage, which is good enough for me
2 years ago
Tho I had to bring my old deploy.js script back to life since the built in one (in client functions) broke due to the image setup
2 years ago
I just had to change the start command though, so all is good
2 years ago
are you gonna also follow buns recommendations on deploying to production?
2 years ago
2 years ago
I tried, but the exe crashes since there's 3rd party things that I use which bun can't compile to an exe
2 years ago
I'm fine with how it is rn. The ram usage has decreased a lot
2 years ago
sounds good!