# === STAGE 1: Build & Dependencies === FROM node:22 AS builder WORKDIR /app # Install pnpm and enable corepack RUN corepack enable && corepack prepare pnpm@latest --activate # Copy the lockfile and package.json to leverage caching COPY package.json pnpm-lock.yaml ./ # Use a cache mount to persist the pnpm store across builds. # The 'pnpm install' command will use this persistent cache. RUN --mount=type=cache,target=/root/.local/share/pnpm/store/v3 \ pnpm install --frozen-lockfile # Copy the rest of the application files COPY . . # Use a second cache mount for the Vinxi build artifacts. # This tells Docker to mount a persistent cache directory to a build-cache location. # The `pnpm run build` command will now use this cache for incremental builds. # We'll assume a `.vinxi` or `.cache` directory for this example. RUN --mount=type=cache,target=/app/.vinxi \ pnpm run build # === STAGE 2: Production Final Image === FROM node:22-alpine WORKDIR /app # Enable corepack and install only production dependencies RUN corepack enable && corepack prepare pnpm@latest --activate COPY package.json pnpm-lock.yaml ./ # This install can also use the cache mount to avoid re-downloading RUN --mount=type=cache,target=/root/.local/share/pnpm/store/v3 \ pnpm install --frozen-lockfile --prod # Copy the compiled assets and lockfile from the builder stage COPY --from=builder /app/.output ./.output COPY --from=builder /app/package.json ./package.json EXPOSE 3000 CMD ["pnpm", "start"]