FROM node:20-alpine

RUN apk add --no-cache libc6-compat openssl

RUN npm install -g pnpm@9

WORKDIR /app

COPY package.json pnpm-lock.yaml ./

# Skip Puppeteer Chrome download in Docker builds
ENV PUPPETEER_SKIP_DOWNLOAD=1

RUN pnpm install --frozen-lockfile

COPY . .

RUN pnpm prisma generate

ENV NEXT_TELEMETRY_DISABLED=1
ENV NODE_OPTIONS="--max-old-space-size=1024"
RUN pnpm run build

EXPOSE 3000

ENV PORT=3000

CMD ["pnpm", "start"]
