# HF Custom VNC - Dockerfile for Hugging Face Spaces # Optimized for minimal size and fast startup # Build stage FROM node:18-alpine AS builder WORKDIR /app # Copy package files COPY package*.json ./ # Install dependencies (npm install for fresh projects without lock file) RUN npm install # Copy source code COPY . . # Build Next.js application RUN npm run build # Production stage FROM node:18-alpine AS runner WORKDIR /app # Create non-root user RUN addgroup --system --gid 1001 nodejs RUN adduser --system --uid 1001 nextjs # Set environment variables ENV NODE_ENV=production ENV PORT=7860 # Copy standalone output COPY --from=builder /app/.next/standalone ./ COPY --from=builder /app/.next/static ./.next/static COPY --from=builder /app/public ./public # Copy startup script COPY --from=builder /app/scripts/start-hf.sh /app/start-hf.sh RUN chmod +x /app/start-hf.sh # Install Xvfb and tools for virtual display RUN apk add --no-cache \ xvfb \ xdotool \ dbus \ ttf-freefont \ && rm -rf /var/cache/apk/* # Set ownership RUN chown -R nextjs:nodejs /app # Switch to non-root user USER nextjs # Expose port EXPOSE 7860 # Health check HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ CMD wget --no-verbose --tries=1 --spider http://localhost:7860/ || exit 1 # Start the application CMD ["/app/start-hf.sh"]