python-detector-worker/Dockerfile.base
2025-09-25 22:25:27 +07:00

61 lines
No EOL
2.1 KiB
Text

# Base image with all ML dependencies and NVIDIA Video Codec SDK
FROM pytorch/pytorch:2.8.0-cuda12.6-cudnn9-runtime
# Install system dependencies including GStreamer with NVDEC support
RUN apt update && apt install -y \
libgl1 \
libglib2.0-0 \
libgtk-3-0 \
libgomp1 \
# GStreamer base
libgstreamer1.0-0 \
libgstreamer-plugins-base1.0-0 \
libgstreamer-plugins-bad1.0-0 \
gstreamer1.0-tools \
gstreamer1.0-plugins-base \
gstreamer1.0-plugins-good \
gstreamer1.0-plugins-bad \
gstreamer1.0-plugins-ugly \
gstreamer1.0-libav \
# GStreamer Python bindings
python3-gst-1.0 \
# NVIDIA specific GStreamer plugins for hardware acceleration
gstreamer1.0-vaapi \
# FFmpeg with hardware acceleration support
ffmpeg \
libavcodec-extra \
libavformat58 \
libswscale5 \
# TurboJPEG for fast JPEG encoding
libturbojpeg0-dev \
&& rm -rf /var/lib/apt/lists/*
# Install NVIDIA DeepStream (includes hardware accelerated GStreamer plugins)
# This provides nvv4l2decoder, nvvideoconvert, etc.
RUN apt update && apt install -y \
wget \
software-properties-common \
&& wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/cuda-keyring_1.0-1_all.deb \
&& dpkg -i cuda-keyring_1.0-1_all.deb \
&& apt update \
&& apt install -y libnvidia-decode-535 \
&& rm -rf /var/lib/apt/lists/* cuda-keyring_1.0-1_all.deb
# Set environment variables for hardware acceleration
ENV OPENCV_FFMPEG_CAPTURE_OPTIONS="video_codec;h264_cuvid"
ENV GST_PLUGIN_PATH="/usr/lib/x86_64-linux-gnu/gstreamer-1.0"
ENV LD_LIBRARY_PATH="/usr/local/cuda/lib64:${LD_LIBRARY_PATH}"
# Copy and install base requirements (ML dependencies that rarely change)
COPY requirements.base.txt .
RUN pip install --no-cache-dir -r requirements.base.txt
# Set working directory
WORKDIR /app
# Create images directory for bind mount
RUN mkdir -p /app/images && \
chmod 755 /app/images
# This base image will be reused for all worker builds
CMD ["python3", "-m", "fastapi", "run", "--host", "0.0.0.0", "--port", "8000"]