# ============================================================================= # Dockerfile.gpu — CUDA-accelerated build for DeepGuard AI # # This variant uses NVIDIA's CUDA 12.1 runtime image so PyTorch can run # on the GPU, making model inference 5-10× faster than CPU. # # Prerequisites: # - NVIDIA GPU with driver >= 525.60.13 (Linux) / 528.33 (Windows WSL2) # - NVIDIA Container Toolkit: https://docs.nvidia.com/datacenter/cloud-native/container-toolkit # # Build: # docker build -f Dockerfile.gpu -t deepguard:gpu . # # Run: # docker run --gpus all -p 8501:8501 deepguard:gpu # # With docker-compose (add to your docker-compose.yml): # services: # streamlit: # image: deepguard:gpu # deploy: # resources: # reservations: # devices: # - driver: nvidia # count: all # capabilities: [gpu] # ============================================================================= # ── Stage 1: System deps ─────────────────────────────────────────────────── FROM nvidia/cuda:12.1.1-runtime-ubuntu22.04 AS base # Install system packages needed by OpenCV, MediaPipe, and PyTorch RUN apt-get update && apt-get install -y --no-install-recommends \ python3.11 \ python3-pip \ python3-dev \ libgl1-mesa-glx \ libglib2.0-0 \ libsm6 \ libxext6 \ libxrender-dev \ libgomp1 \ libgles2-mesa \ libegl1 \ libomp-dev \ && rm -rf /var/lib/apt/lists/* # Symlink python3 → python for compatibility RUN ln -sf /usr/bin/python3.11 /usr/bin/python # ── Stage 2: Python deps ──────────────────────────────────────────────────── FROM base AS deps WORKDIR /app COPY requirements.txt ./ # Install PyTorch with CUDA 12.x support first (separate line for layer caching) RUN pip install --no-cache-dir --upgrade pip RUN pip install --no-cache-dir torch torchvision --index-url https://download.pytorch.org/whl/cu121 # Then the rest of the dependencies RUN pip install --no-cache-dir \ streamlit>=1.30 \ opencv-python>=4.8 \ pillow>=10.0 \ numpy>=1.24 \ transformers>=4.36 \ mediapipe>=0.10.9 \ huggingface-hub>=0.20 \ fastapi>=0.100.0 \ uvicorn[standard]>=0.23.0 \ python-multipart>=0.0.6 \ celery>=5.3.0 \ redis>=5.0.0 \ slowapi>=0.1.9 \ pytest>=8.0.0 \ gunicorn>=21.2.0 # ── Stage 3: Runtime ─────────────────────────────────────────────────────── FROM deps AS runtime WORKDIR /app COPY . . RUN mkdir -p static/scans logs # ── Ports ────────────────────────────────────────────────────────────────── EXPOSE 8501 EXPOSE 8000 # ── Environment ──────────────────────────────────────────────────────────── ENV STREAMLIT_SERVER_PORT=8501 ENV STREAMLIT_SERVER_ADDRESS=0.0.0.0 ENV STREAMLIT_SERVER_HEADLESS=true ENV DF_LOG_LEVEL=INFO ENV CUDA_VISIBLE_DEVICES=all # ── Default: Streamlit UI ────────────────────────────────────────────────── CMD ["streamlit", "run", "app.py", \ "--server.port=8501", \ "--server.address=0.0.0.0", \ "--server.headless=true"] # ── Health check ────────────────────────────────────────────────────────── HEALTHCHECK --interval=30s --timeout=10s --start-period=120s --retries=3 \ CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8501/_stcore/health')" || exit 1