FROM node:22-alpine AS builder

RUN npm install -g pnpm

WORKDIR /app
COPY package*.json pnpm-lock.yaml ./
RUN pnpm install --frozen-lockfile
COPY . .

ARG API_BASE
ENV API_BASE=$API_BASE

RUN pnpm run build

FROM node:22-alpine
RUN npm install -g pnpm
WORKDIR /app
COPY package.json pnpm-lock.yaml ./
RUN pnpm install --frozen-lockfile --prod
COPY --from=builder /app/.next ./.next
COPY --from=builder /app/public ./public
COPY --from=builder /app/next.config.ts ./

ARG API_BASE
ENV API_BASE=$API_BASE

EXPOSE 3000
CMD ["pnpm", "start"]