# Use Node.js 18 Alpine for a lightweight image FROM node:18-alpine AS base # Install dependencies only when needed FROM base AS deps RUN apk add --no-cache libc6-compat WORKDIR /app # Copy package files COPY package.json package-lock.json ./ RUN npm ci # Rebuild the source code only when needed FROM base AS builder WORKDIR /app COPY --from=deps /app/node_modules ./node_modules COPY . . # Build Next.js application RUN npm run build # Production image, copy all the files and run next FROM base AS runner WORKDIR /app ENV NODE_ENV=production ENV PORT=7860 ENV HOSTNAME="0.0.0.0" # Use the existing node user (UID 1000) which matches HF Spaces requirement # Copy necessary files from builder COPY --from=builder --chown=node:node /app/public ./public COPY --from=builder --chown=node:node /app/.next/standalone ./ COPY --from=builder --chown=node:node /app/.next/static ./.next/static # Switch to the node user (UID 1000) USER node # Expose the port the app runs on EXPOSE 7860 # Start the application CMD ["node", "server.js"]