# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license

# Builds ultralytics/ultralytics:latest-arm64 image on DockerHub https://hub.docker.com/r/ultralytics/ultralytics
# Image is aarch64-compatible for Apple M1, M2, M3, Raspberry Pi and other ARM architectures

FROM python:3.13-slim-trixie

# Set environment variables (suppress PyTorch NNPACK warnings)
ENV PYTHONUNBUFFERED=1 \
    PIP_NO_CACHE_DIR=1 \
    PIP_BREAK_SYSTEM_PACKAGES=1 \
    UV_BREAK_SYSTEM_PACKAGES=1 \
    TORCH_CPP_LOG_LEVEL=ERROR

# Downloads to user config dir
ADD https://github.com/ultralytics/assets/releases/download/v0.0.0/Arial.ttf \
    https://github.com/ultralytics/assets/releases/download/v0.0.0/Arial.Unicode.ttf \
    /root/.config/Ultralytics/

# Install linux packages
# TensorFlow on aarch64 may require pkg-config and libhdf5-dev if h5py builds from source.
RUN apt-get update && \
    apt-get install -y --no-install-recommends \
    git zip unzip wget curl htop gcc && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

# Create working directory
WORKDIR /ultralytics

# Copy contents and configure dependencies
COPY . .
RUN sed -i'' -e 's/"opencv-python/"opencv-python-headless/' pyproject.toml
ADD https://github.com/ultralytics/assets/releases/download/v8.4.0/yolo26n.pt .

# Install pip packages and remove build files
RUN python3 -m pip install uv && \
    uv pip install --system --no-cache -e ".[export]" --extra-index-url https://download.pytorch.org/whl/cpu --index-strategy unsafe-best-match && \
    # Remove extra build files
    rm -rf /root/.config/Ultralytics/persistent_cache.json \
    /usr/local/lib/python3.13/site-packages/torch/test /usr/local/lib/python3.13/site-packages/torch/bin/test_*

# Usage --------------------------------------------------------------------------------------------------------------

# Production builds: https://github.com/ultralytics/ultralytics/blob/main/.github/workflows/docker.yml
# Example (build): t=ultralytics/ultralytics:latest-arm64 && docker build --platform linux/arm64 -f docker/Dockerfile-arm64 -t $t .
# Example (push): docker push $t
# Example (pull): t=ultralytics/ultralytics:latest-arm64 && docker pull $t
# Example (run): docker run -it --ipc=host $t
# Example (run-with-volume): docker run -it --ipc=host -v "$PWD/shared/datasets:/datasets" $t
