FROM node:20-slim AS base
RUN corepack enable
COPY . /app
WORKDIR /app

FROM base AS prod-deps
RUN pnpm install --prod --frozen-lockfile

FROM base AS build

ARG OPENAI_API_KEY=${OPENAI_API_KEY}
ARG DREAM_API_KEY=${DREAM_API_KEY}

ARG S3_ENDPOINT_URL=${S3_ENDPOINT_URL}
ARG S3_BUCKET_NAME=${S3_BUCKET_NAME}
ARG S3_ACCESS_KEY=${S3_ACCESS_KEY}
ARG S3_SECRET_ACCESS_KEY=${S3_SECRET_ACCESS_KEY}
ARG POCKETBASE_URL=${POCKETBASE_URL}

RUN pnpm install --frozen-lockfile
RUN pnpm run build

FROM base
COPY --from=prod-deps /app/node_modules /app/node_modules
COPY --from=build /app/build /app/build
EXPOSE 3000
CMD [ "node", "build" ]
