| # Multi-stage build for Clipon | |
| # Stage 1: Build React frontend | |
| FROM node:20-alpine AS frontend-builder | |
| WORKDIR /frontend | |
| # Copy frontend source | |
| COPY frontend/ . | |
| # Install dependencies with npm install (no lockfile required) and build | |
| RUN npm install && npm run build | |
| # Stage 2: Python runtime | |
| FROM python:3.11-slim | |
| WORKDIR /app | |
| # Install system dependencies | |
| RUN apt-get update && apt-get install -y \ | |
| ffmpeg \ | |
| curl \ | |
| git \ | |
| build-essential \ | |
| libsndfile1 \ | |
| libsndfile1-dev \ | |
| espeak-ng \ | |
| fonts-dejavu-core \ | |
| fonts-liberation \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # Copy Python requirements | |
| COPY requirements.txt . | |
| # Install Python dependencies (yt-dlp pinned to latest for YouTube compatibility) | |
| RUN pip install --no-cache-dir -r requirements.txt && \ | |
| pip install --no-cache-dir --upgrade yt-dlp | |
| # Copy built frontend from Stage 1 | |
| COPY --from=frontend-builder /frontend/dist ./frontend/dist | |
| # Copy application source code | |
| COPY app.py . | |
| COPY config.py . | |
| COPY models/ ./models/ | |
| COPY services/ ./services/ | |
| # Create non-root user | |
| RUN useradd -m -u 1000 appuser && \ | |
| chown -R appuser:appuser /app && \ | |
| mkdir -p /tmp/clipcraft/clips /tmp/clipcraft/uploads /tmp/clipcraft/output \ | |
| /tmp/makereels_uploads /tmp/makereels_outputs && \ | |
| chown -R appuser:appuser /tmp/clipcraft /tmp/makereels_uploads /tmp/makereels_outputs | |
| USER appuser | |
| # Expose port | |
| EXPOSE 7860 | |
| # Health check | |
| HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ | |
| CMD curl -f http://localhost:7860/health || exit 1 | |
| # Start application | |
| CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "1"] | |