# Step 1: Builder image FROM node:20-alpine AS builder RUN apk add --no-cache libc6-compat curl WORKDIR /app RUN corepack enable pnpm # Step 2: Install dependencies # Copy manifest files specifically for better layer caching COPY pnpm-lock.yaml pnpm-workspace.yaml package.json .npmrc ./ # Copy all package.json files COPY packages/*/package.json ./packages/ # Note: globbing subdirectories for package.json might require more specific COPY commands # if the structure is deep, but for our flat packages/* it works or needs manual listing. # Since we have many packages, copying them individually or as a block is better. # Use a secret for NPM_TOKEN and a standardized cache mount RUN --mount=type=cache,id=pnpm,target=/pnpm/store \ --mount=type=secret,id=NPM_TOKEN \ export NPM_TOKEN=$(cat /run/secrets/NPM_TOKEN) && \ pnpm config set store-dir /pnpm/store && \ pnpm i --frozen-lockfile # Step 3: Build shared packages COPY . . RUN pnpm --filter "./packages/*" -r build