Adds an optional cloud/paid mode behind a BILLING_ENABLED flag. With the flag off the app is byte-identical to today's self-hosted BYOK build (regression-zero). Backend (cloud/ package, only imported when BILLING_ENABLED): - Auth: magic link (Resend) + Google OAuth (authlib) + JWT sessions - Stripe: hosted Checkout with 3-day card trial, Customer Portal, idempotent order-safe webhooks; 3 plans (Starter/Creator/Pro) resolved by lookup_key - Postgres + SQLAlchemy async; atomic minute metering (reserve/commit/release, plan->topup FIFO, restart-safe) with sweeper - Managed keys: Gemini + Upload-Post server-side for entitled users; paid-only (BYOK core header ignored on hosted); Upload-Post white-label per-user profiles - Metering wired into /api/process (probe->reserve->402, priority queue) and thumbnail image generation (3 min/batch) - yt-dlp residential PROXY_URL support + 720p cap for hosted YouTube downloads Frontend: - AuthContext, LoginModal, PricingSection (3-day trial), AccountPage, UsageMeter, TopUpModal, TrialGate/AdvancedBanner - Paid-only UI: hide BYOK core inputs, trial prompts per tool - Included (Clip Generator, YouTube Studio) vs BYOK (AI Shorts/dubbing: fal.ai + ElevenLabs) clearly separated; ThumbnailStudio + SaaShortsTab managed-aware - Landing: free-self-host vs paid-hosted messaging Verified end-to-end against real Postgres + Stripe test mode.
67 lines
1.9 KiB
Docker
67 lines
1.9 KiB
Docker
# Multi-stage build for smaller final image
|
|
FROM python:3.11-slim AS builder
|
|
|
|
WORKDIR /app
|
|
|
|
# Install build dependencies
|
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
build-essential \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
# Copy and install Python dependencies
|
|
# Copy and install Python dependencies
|
|
COPY requirements.txt requirements-billing.txt ./
|
|
RUN python -m venv /opt/venv
|
|
ENV PATH="/opt/venv/bin:$PATH"
|
|
RUN pip install --upgrade pip
|
|
RUN pip install --no-cache-dir -r requirements.txt
|
|
# Cloud (paid mode) deps: installed always so one image serves both modes; they
|
|
# are only imported when BILLING_ENABLED is set. Harmless/unused in self-host.
|
|
RUN pip install --no-cache-dir -r requirements-billing.txt
|
|
|
|
# Final stage
|
|
FROM python:3.11-slim
|
|
|
|
WORKDIR /app
|
|
|
|
# Install FFmpeg, OpenCV dependencies, and Node.js (for yt-dlp JS challenges)
|
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
ffmpeg \
|
|
libgl1 \
|
|
libglib2.0-0 \
|
|
libsm6 \
|
|
libxext6 \
|
|
libxrender1 \
|
|
nodejs \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
# Copy virtual env from builder
|
|
COPY --from=builder /opt/venv /opt/venv
|
|
ENV PATH="/opt/venv/bin:$PATH"
|
|
ENV PYTHONUNBUFFERED=1
|
|
|
|
# Always upgrade yt-dlp to latest (YouTube bot-detection changes frequently)
|
|
RUN pip install --upgrade --no-cache-dir yt-dlp
|
|
|
|
# Copy application code
|
|
COPY . .
|
|
|
|
# Create a non-root user (Moved up)
|
|
RUN groupadd -r appuser && useradd -r -g appuser -d /app -s /sbin/nologin appuser
|
|
|
|
# Create directories including Ultralytics cache config
|
|
RUN mkdir -p /app/uploads /app/output /tmp/Ultralytics
|
|
# Fix permissions: /app for code/uploads, /tmp/Ultralytics for AI cache
|
|
RUN chown -R appuser:appuser /app /tmp/Ultralytics
|
|
|
|
# Switch to non-root user
|
|
USER appuser
|
|
|
|
# Pre-download YOLO model on build (now running as appuser)
|
|
RUN python -c "from ultralytics import YOLO; YOLO('yolov8n.pt')"
|
|
|
|
# Expose FastAPI port
|
|
EXPOSE 8000
|
|
|
|
# Run FastAPI app
|
|
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8000"]
|