All checks were successful
Build Worker Base and Application Images / check-base-changes (push) Successful in 8s
Build Worker Base and Application Images / build-base (push) Successful in 7m22s
Build Worker Base and Application Images / build-docker (push) Successful in 4m45s
Build Worker Base and Application Images / deploy-stack (push) Successful in 44s
97 lines
No EOL
3.4 KiB
Text
97 lines
No EOL
3.4 KiB
Text
# Base image with complete ML and hardware acceleration stack
|
|
FROM pytorch/pytorch:2.8.0-cuda12.6-cudnn9-runtime
|
|
|
|
# Install build dependencies and system libraries
|
|
RUN apt-get update && apt-get install -y \
|
|
# Build tools
|
|
build-essential \
|
|
cmake \
|
|
git \
|
|
pkg-config \
|
|
wget \
|
|
unzip \
|
|
yasm \
|
|
nasm \
|
|
# System libraries
|
|
libgl1-mesa-glx \
|
|
libglib2.0-0 \
|
|
libgomp1 \
|
|
# Core media libraries (essential ones only)
|
|
libjpeg-dev \
|
|
libpng-dev \
|
|
libx264-dev \
|
|
libx265-dev \
|
|
libvpx-dev \
|
|
libmp3lame-dev \
|
|
libv4l-dev \
|
|
# FFmpeg development libraries for OpenCV integration
|
|
libavcodec-dev \
|
|
libavformat-dev \
|
|
libavutil-dev \
|
|
libavdevice-dev \
|
|
libavfilter-dev \
|
|
libswscale-dev \
|
|
libswresample-dev \
|
|
# TurboJPEG for fast JPEG encoding
|
|
libturbojpeg0-dev \
|
|
# Python development
|
|
python3-dev \
|
|
python3-numpy \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
# Install prebuilt FFmpeg with CUDA support
|
|
# Ensure CUDA paths are available
|
|
ENV PATH="/usr/local/cuda/bin:${PATH}"
|
|
ENV LD_LIBRARY_PATH="/usr/local/cuda/lib64:${LD_LIBRARY_PATH}"
|
|
|
|
# Install NVIDIA Video Codec SDK headers first
|
|
RUN cd /tmp && \
|
|
wget https://github.com/FFmpeg/nv-codec-headers/archive/refs/tags/n12.1.14.0.zip && \
|
|
unzip n12.1.14.0.zip && \
|
|
cd nv-codec-headers-n12.1.14.0 && \
|
|
make install && \
|
|
rm -rf /tmp/*
|
|
|
|
# Download and install prebuilt FFmpeg with CUDA support
|
|
RUN cd /tmp && \
|
|
echo "Installing prebuilt FFmpeg with CUDA support..." && \
|
|
wget https://github.com/BtbN/FFmpeg-Builds/releases/download/latest/ffmpeg-master-latest-linux64-gpl.tar.xz && \
|
|
tar -xf ffmpeg-master-latest-linux64-gpl.tar.xz && \
|
|
cd ffmpeg-master-latest-linux64-gpl && \
|
|
# Copy binaries to system paths
|
|
cp bin/* /usr/local/bin/ && \
|
|
ldconfig && \
|
|
# Verify CUVID decoders are available
|
|
echo "=== Verifying FFmpeg CUVID Support ===" && \
|
|
(ffmpeg -hide_banner -decoders 2>/dev/null | grep cuvid || echo "No CUVID decoders found") && \
|
|
echo "=== Verifying FFmpeg NVENC Support ===" && \
|
|
(ffmpeg -hide_banner -encoders 2>/dev/null | grep nvenc || echo "No NVENC encoders found") && \
|
|
cd / && rm -rf /tmp/*
|
|
|
|
# Set environment variables for maximum hardware acceleration
|
|
ENV LD_LIBRARY_PATH="/usr/local/cuda/lib64:/usr/local/lib:${LD_LIBRARY_PATH}"
|
|
ENV PKG_CONFIG_PATH="/usr/local/lib/pkgconfig:${PKG_CONFIG_PATH}"
|
|
ENV PYTHONPATH="/usr/local/lib/python3.10/dist-packages:${PYTHONPATH}"
|
|
|
|
# Optimized environment variables for hardware acceleration
|
|
ENV OPENCV_FFMPEG_CAPTURE_OPTIONS="rtsp_transport;tcp|hwaccel;cuda|hwaccel_device;0|video_codec;h264_cuvid|hwaccel_output_format;cuda"
|
|
ENV OPENCV_FFMPEG_WRITER_OPTIONS="video_codec;h264_nvenc|preset;fast|tune;zerolatency|gpu;0"
|
|
ENV CUDA_VISIBLE_DEVICES=0
|
|
ENV NVIDIA_VISIBLE_DEVICES=all
|
|
ENV NVIDIA_DRIVER_CAPABILITIES=compute,video,utility
|
|
|
|
# Copy and install base requirements (exclude opencv-python since we built from source)
|
|
COPY requirements.base.txt .
|
|
RUN grep -v opencv-python requirements.base.txt > requirements.tmp && \
|
|
mv requirements.tmp requirements.base.txt && \
|
|
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"] |