# Build stage FROM node:20-alpine AS builder # Install build dependencies for native modules RUN apk add --no-cache python3 make g++ py3-pip # Install pnpm RUN corepack enable && corepack prepare pnpm@9.12.3 --activate WORKDIR /app # Copy package files COPY package.json pnpm-lock.yaml ./ # Install dependencies (allow lockfile updates since we added @ai-sdk/openai) RUN pnpm install --no-frozen-lockfile # Copy application code COPY . . # Build the Next.js application without database migration # The migration will run at startup if POSTGRES_URL is set RUN pnpm exec next build # Production stage FROM node:20-alpine AS runner # Install pnpm RUN corepack enable && corepack prepare pnpm@9.12.3 --activate # Use the existing node user (UID 1000) which is already in the image WORKDIR /app # Copy built application from builder stage COPY --from=builder --chown=node:node /app/.next/standalone ./ COPY --from=builder --chown=node:node /app/.next/static ./.next/static # Create empty public directory since we removed images RUN mkdir -p ./public && chown node:node ./public # Copy package.json for reference COPY --from=builder --chown=node:node /app/package.json ./ # Switch to node user (UID 1000, required by Hugging Face) USER node # Expose port 7860 (Hugging Face Spaces requirement) EXPOSE 7860 # Set environment variables for Hugging Face Spaces ENV PORT=7860 ENV HOSTNAME="0.0.0.0" ENV NODE_ENV=production ENV AUTH_TRUST_HOST=true ENV NEXTAUTH_URL=https://seriousmountain-vercel-demo.hf.space # Start the application CMD ["node", "server.js"]