# ================================================
FROM oven/bun AS build

WORKDIR /app

# Cache packages installation
COPY package.json package.json
COPY bun.lock bun.lock

RUN bun install

COPY ./src ./src

ENV NODE_ENV=production

RUN bun build \
	--compile \
	--minify-whitespace \
	--minify-syntax \
	--outfile server \
	src/index.ts

# ================================================
FROM debian:12

RUN apt-get update && \
    apt-get install -y libstdc++6 && \
    apt-get clean

WORKDIR /app

COPY --from=build /app/server server
COPY --from=build /app/node_modules node_modules

ENV NODE_ENV=production

CMD ["./server"]

EXPOSE 3000
