# ── Stage 1: Install dependencies ───────────────────────────────────────────── FROM node:20-slim AS deps WORKDIR /app COPY frontend/package*.json ./ RUN npm ci # ── Stage 2: Build Next.js ───────────────────────────────────────────────────── FROM node:20-slim AS builder WORKDIR /app COPY --from=deps /app/node_modules ./node_modules COPY frontend/ . # Bake the backend HuggingFace Space URL at build time. # NEXT_PUBLIC_* vars are embedded into the JS bundle during `next build`, # so they must be set here — not at container start. ARG NEXT_PUBLIC_API_URL=https://trojan0x-caretrace-backend.hf.space ENV NEXT_PUBLIC_API_URL=$NEXT_PUBLIC_API_URL RUN npm run build # ── Stage 3: Lean production runner ─────────────────────────────────────────── FROM node:20-slim AS runner WORKDIR /app ENV NODE_ENV=production # HuggingFace Spaces requires port 7860 ENV PORT=7860 ENV HOSTNAME=0.0.0.0 # Copy only the standalone output — no node_modules needed COPY --from=builder /app/.next/standalone ./ COPY --from=builder /app/.next/static ./.next/static COPY --from=builder /app/public ./public EXPOSE 7860 CMD ["node", "server.js"]