FROM oven/bun:latest AS base

FROM base AS deps

WORKDIR /app

COPY package.json bun.lock ./

COPY src/prisma ./src/prisma

RUN bun install --frozen-lockfile

FROM base AS builder

RUN apt-get update -y && apt-get install -y openssl

WORKDIR /app

COPY --from=deps /app/node_modules ./node_modules

COPY . .

RUN bun run build

FROM builder AS production

WORKDIR /app

ENV NODE_ENV=production

ENV TZ="Europe/Madrid"

ENV NEXT_TELEMETRY_DISABLED=1

COPY --from=builder /app/public ./public

COPY --from=builder /app/.next/server ./
COPY --from=builder /app/.next/static ./.next/static

EXPOSE ${PORT}

CMD ["bun", "run", "start"]