FROM node:20-alpine AS builder WORKDIR /app # Copy package files COPY server/package.json server/tsconfig.json ./server/ COPY client/package.json client/tsconfig.json client/vite.config.ts client/tailwind.config.js client/postcss.config.js client/index.html ./client/ COPY client/tsconfig.node.json ./client/ # Install build dependencies for better-sqlite3 compilation, then install dependencies RUN apk add --no-cache python3 make g++ && \ cd server && npm install --no-audit --no-fund --loglevel=error RUN cd client && npm install --no-audit --no-fund --loglevel=error # Copy source code COPY server/src ./server/src COPY client/src ./client/src COPY client/public ./client/public COPY shared ./shared # Build server RUN cd server && npm run build # Build client RUN cd client && npm run build # Production stage FROM node:20-alpine WORKDIR /app # Install only production dependencies for server COPY server/package.json ./server/ # Build tools are needed here too because npm install compiles better-sqlite3 from scratch again RUN apk add --no-cache python3 make g++ && \ cd server && npm install --omit=dev --no-audit --no-fund --loglevel=error && \ apk del python3 make g++ # Copy built artifacts COPY --from=builder /app/server/dist ./server/dist COPY --from=builder /app/client/dist ./client/dist # Configure port for Hugging Face Spaces (expects 7860) ENV PORT=7860 # Create persistent data directory (HF Spaces mounts storage at /data) RUN mkdir -p /data # Expose port EXPOSE 7860 # Health check HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \ CMD wget --no-verbose --tries=1 --spider http://localhost:7860/ || exit 1 # Start server with pre-startup database cleanup COPY start.sh /app/start.sh RUN chmod +x /app/start.sh CMD ["sh", "/app/start.sh"]