|
| 1 | +# Multi-stage Dockerfile for scenesmith. |
| 2 | +# Single-container setup: all servers (geometry generation, retrieval, blender, |
| 3 | +# etc.) are auto-managed by the pipeline inside the container. |
| 4 | + |
| 5 | +# ============================================================================= |
| 6 | +# Stage 1: Base system with Python 3.11 and system dependencies. |
| 7 | +# ============================================================================= |
| 8 | +FROM nvidia/cuda:12.4.0-devel-ubuntu22.04 AS base |
| 9 | + |
| 10 | +ENV DEBIAN_FRONTEND=noninteractive |
| 11 | + |
| 12 | +# Install Python 3.11 via deadsnakes PPA and system packages. |
| 13 | +RUN apt-get update && apt-get install -y --no-install-recommends \ |
| 14 | + software-properties-common \ |
| 15 | + && add-apt-repository ppa:deadsnakes/ppa \ |
| 16 | + && apt-get update && apt-get install -y --no-install-recommends \ |
| 17 | + python3.11 \ |
| 18 | + python3.11-dev \ |
| 19 | + python3.11-venv \ |
| 20 | + python3.11-distutils \ |
| 21 | + libpython3.11-dev \ |
| 22 | + git \ |
| 23 | + git-lfs \ |
| 24 | + wget \ |
| 25 | + unzip \ |
| 26 | + bubblewrap \ |
| 27 | + cmake \ |
| 28 | + build-essential \ |
| 29 | + # X11/EGL libs for headless Blender rendering. |
| 30 | + libgl1 \ |
| 31 | + libegl1 \ |
| 32 | + libxrender1 \ |
| 33 | + libxkbcommon0 \ |
| 34 | + libsm6 \ |
| 35 | + libxext6 \ |
| 36 | + libxi6 \ |
| 37 | + libxxf86vm1 \ |
| 38 | + libglib2.0-0 \ |
| 39 | + && rm -rf /var/lib/apt/lists/* |
| 40 | + |
| 41 | +# Set Python 3.11 as default. |
| 42 | +RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.11 1 \ |
| 43 | + && update-alternatives --install /usr/bin/python python /usr/bin/python3.11 1 |
| 44 | + |
| 45 | +# Install uv package manager. |
| 46 | +COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /usr/local/bin/ |
| 47 | + |
| 48 | +# Set environment variables. |
| 49 | +ENV CUDA_HOME=/usr/local/cuda-12.4 |
| 50 | +ENV PATH="${CUDA_HOME}/bin:${PATH}" |
| 51 | +ENV LD_LIBRARY_PATH="${CUDA_HOME}/lib64:${LD_LIBRARY_PATH}" |
| 52 | +ENV NVIDIA_VISIBLE_DEVICES=all |
| 53 | +ENV NVIDIA_DRIVER_CAPABILITIES=compute,utility,graphics |
| 54 | + |
| 55 | +WORKDIR /app |
| 56 | + |
| 57 | +# ============================================================================= |
| 58 | +# Stage 2: Python dependencies. |
| 59 | +# ============================================================================= |
| 60 | +FROM base AS deps |
| 61 | + |
| 62 | +COPY pyproject.toml uv.lock .python-version README.md ./ |
| 63 | +RUN uv sync --frozen --no-dev |
| 64 | + |
| 65 | +# ============================================================================= |
| 66 | +# Stage 3: SAM3D backend (optional but included in image). |
| 67 | +# ============================================================================= |
| 68 | +FROM deps AS sam3d |
| 69 | + |
| 70 | +COPY scripts/install_sam3d_docker.sh scripts/install_sam3d_docker.sh |
| 71 | + |
| 72 | +# Disable uv project config to avoid hitting the Blender PyPI index |
| 73 | +# (from pyproject.toml) which rate-limits during Docker builds. |
| 74 | +# Set TORCH_CUDA_ARCH_LIST since no GPU is available during build. |
| 75 | +# Covers Ampere (A100, A10), Ada Lovelace (L40S, RTX 4090), Hopper (H100). |
| 76 | +RUN UV_NO_CONFIG=1 TORCH_CUDA_ARCH_LIST="8.0;8.6;8.9;9.0" \ |
| 77 | + bash scripts/install_sam3d_docker.sh |
| 78 | + |
| 79 | +# ============================================================================= |
| 80 | +# Stage 4: Application code. |
| 81 | +# ============================================================================= |
| 82 | +FROM sam3d AS app |
| 83 | + |
| 84 | +# Copy full repo source. |
| 85 | +COPY . . |
| 86 | + |
| 87 | +# Remove stale bytecode from earlier stages (SAM3D install imports |
| 88 | +# scenesmith, creating .pyc that would shadow updated .py files). |
| 89 | +RUN find /app/scenesmith -name "__pycache__" -type d -exec rm -rf {} + 2>/dev/null; true |
| 90 | + |
| 91 | +# Activate the virtual environment by prepending it to PATH. |
| 92 | +ENV VIRTUAL_ENV=/app/.venv |
| 93 | +ENV PATH="${VIRTUAL_ENV}/bin:${PATH}" |
| 94 | +ENV PYTHONPATH=/app |
| 95 | +ENV PYTHONUNBUFFERED=1 |
| 96 | + |
| 97 | +# Default command: print usage help. |
| 98 | +CMD ["python", "-c", \ |
| 99 | + "print('scenesmith Docker container\\n')\n\ |
| 100 | +print('Usage examples:\\n')\n\ |
| 101 | +print(' # Smoke test')\n\ |
| 102 | +print(' docker run --gpus all scenesmith python -c \"import torch; print(torch.cuda.is_available()); import scenesmith\"\\n')\n\ |
| 103 | +print(' # Run unit tests')\n\ |
| 104 | +print(' docker run --gpus all scenesmith pytest tests/unit/ -x\\n')\n\ |
| 105 | +print(' # Run scene generation (requires data volumes and API keys)')\n\ |
| 106 | +print(' docker compose up\\n')\n\ |
| 107 | +print('See README.md for full documentation.')"] |
0 commit comments