R
Railway•2w ago
cody

Errors with Dockerfile

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.
Solution:
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
Jump to solution
14 Replies
Percy
Percy•2w ago
Project ID: f8f1d4b6-1530-4b65-a444-67b8c86c5fca
cody
cody•2w ago
f8f1d4b6-1530-4b65-a444-67b8c86c5fca
cody
cody•2w ago
In deployment I get this error
No description
cody
cody•2w 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"]
# 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"]
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
Brody
Brody•2w ago
first off, simplify that dockerfile, no multi layers
cody
cody•2w ago
I mean I can try but this took me about an hour to construct 🥲 I'll just do all the steps in one directory then
Brody
Brody•2w ago
and you'll likely come back to it soon enough, but it's too complex for your first try use only a single FROM in the whole dockerfile
cody
cody•2w ago
alright the official bun guide was telling me to use multiple to keep things organized so i followed their instructions Actually, I somehow got everything to work with just a bit of searching around
Brody
Brody•2w 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 what was the issue?
Solution
cody
cody•2w 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
cody
cody•2w ago
I'm now sitting at a comfortable 108 mb of ram usage, which is good enough for me 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 I just had to change the start command though, so all is good
Brody
Brody•2w ago
are you gonna also follow buns recommendations on deploying to production? https://bun.sh/docs/bundler/executables#deploying-to-production
cody
cody•2w ago
I tried, but the exe crashes since there's 3rd party things that I use which bun can't compile to an exe I'm fine with how it is rn. The ram usage has decreased a lot
Brody
Brody•2w ago
sounds good!