# ---- Builder Stage ----
FROM --platform=linux/amd64 node:22-alpine AS builder

WORKDIR /app
RUN corepack enable && corepack prepare yarn@4.4.0 --activate
COPY package.json yarn.lock .yarnrc.yml ./
RUN yarn install
COPY . .
RUN npx babel . --out-dir dist --copy-files

# ---- Runtime Stage ----
FROM --platform=linux/amd64 node:22-alpine AS runtime

WORKDIR /app
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/.env ./

# Set env
ENV NODE_ENV=production
EXPOSE 8000

CMD ["node", "dist/index.js"]