# syntax=docker/dockerfile:1.7
ARG NODE_VERSION=22-alpine

FROM node:${NODE_VERSION} AS base
RUN apk add --no-cache libc6-compat
RUN corepack enable && corepack prepare pnpm@10.13.1 --activate
WORKDIR /app

FROM base AS deps
COPY pnpm-workspace.yaml pnpm-lock.yaml* package.json .npmrc ./
COPY turbo.json tsconfig.base.json ./
COPY apps/recall-web/package.json apps/recall-web/
COPY packages/shared-types/package.json packages/shared-types/
COPY packages/shared-utils/package.json packages/shared-utils/
RUN pnpm install --frozen-lockfile=false

FROM deps AS dev
COPY . .
WORKDIR /app/apps/recall-web
EXPOSE 3000
CMD ["pnpm", "dev"]

FROM deps AS build
COPY . .
WORKDIR /app/apps/recall-web
RUN pnpm build

FROM node:${NODE_VERSION} AS prod
RUN apk add --no-cache libc6-compat
WORKDIR /app
ENV NODE_ENV=production
COPY --from=build /app/apps/recall-web/.next/standalone ./
COPY --from=build /app/apps/recall-web/.next/static ./apps/recall-web/.next/static
COPY --from=build /app/apps/recall-web/public ./apps/recall-web/public
EXPOSE 3000
CMD ["node", "apps/recall-web/server.js"]
