| # Multi-stage build for uvify HuggingFace app | |
| FROM node:20-slim AS frontend-builder | |
| # Set working directory for frontend build | |
| WORKDIR /app | |
| # Copy package files | |
| COPY package*.json ./ | |
| # Install Node.js dependencies | |
| RUN npm ci | |
| # Copy frontend source code | |
| COPY src/ ./src/ | |
| COPY public/ ./public/ | |
| COPY index.html ./ | |
| COPY vite.config.ts ./ | |
| COPY tsconfig*.json ./ | |
| COPY tailwind.config.js ./ | |
| COPY postcss.config.js ./ | |
| COPY eslint.config.js ./ | |
| # Build the frontend for production | |
| RUN npm run build | |
| # Production stage | |
| FROM python:3.10-slim | |
| # Create a non-root user | |
| RUN useradd --create-home --shell /bin/bash user | |
| # Set working directory | |
| WORKDIR /app | |
| # Install system dependencies and uv | |
| RUN apt-get update && apt-get install -y \ | |
| curl \ | |
| git \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # Install uv for fast Python package management | |
| RUN pip install uv | |
| # Copy frontend build from previous stage | |
| COPY --chown=user --from=frontend-builder /app/dist ./static | |
| # Copy Python backend files | |
| COPY --chown=user server.py ./ | |
| COPY --chown=user requirements.txt ./ | |
| # Install Python dependencies using uv | |
| RUN uv pip install --system -r requirements.txt | |
| # Change ownership of the app directory to user | |
| RUN chown -R user:user /app | |
| # Switch to non-root user | |
| USER user | |
| # Expose port 7860 (HuggingFace default) | |
| EXPOSE 7860 | |
| # Set environment variables | |
| ENV PORT=7860 | |
| ENV PYTHONPATH=/app | |
| # Health check | |
| HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \ | |
| CMD curl -f http://localhost:7860/docs || exit 1 | |
| # Run the production server | |
| CMD ["python", "server.py"] |