Skip to content

Commit

Permalink
Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
FlyingFathead committed Oct 10, 2024
1 parent 19e926e commit d5959b2
Show file tree
Hide file tree
Showing 7 changed files with 898 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .catgitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
README.md
CUDA_SETUP.md
LICENSE
yolo_detections/**
old/
old/**
28 changes: 28 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Python cache files
__pycache__
*.pyc
*.pyo
*.pyd

# Git repository
.git
.gitignore

# Docker files
Dockerfile
docker-compose.yml

# Exclude large files and directories not needed for the build
node_modules
*.log
*.zip
*.tar
*.gz

# Any other directories or files you don't need in the build context
data/
tests/
docs/
examples/
logs/
yolo_detections/
63 changes: 63 additions & 0 deletions .github/workflows/build-and-push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Build and Push YOLOv8 Docker Image

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

env:
REGISTRY: ghcr.io
IMAGE_NAME: flyingfathead/dvr-yolov8-detection

jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
# Step 1: Checkout the repository
- name: Checkout repository
uses: actions/checkout@v4

# Step 2: Log in to GitHub Container Registry
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

# Step 3: Set up Docker Buildx
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

# Step 4: Cache Docker layers
- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
# Step 5: Build and push Docker image
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new

# Step 6: Update cache
- name: Update cache
if: success()
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ detection_clips/**
yolo_detections/
yolo_detections/**
logs/
logs/**
logs/**
93 changes: 93 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# Use NVIDIA CUDA base image with Ubuntu 22.04
FROM nvidia/cuda:12.4.0-base-ubuntu22.04

# Set environment variables
ENV DEBIAN_FRONTEND=noninteractive
ENV LANG=C.UTF-8

# Install system dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
cmake \
git \
wget \
unzip \
pkg-config \
libjpeg-dev \
libpng-dev \
libtiff-dev \
libavcodec-dev \
libavformat-dev \
libswscale-dev \
libv4l-dev \
libxvidcore-dev \
libx264-dev \
libgtk-3-dev \
libatlas-base-dev \
gfortran \
libgl1 \
python3-dev \
python3-pip \
&& rm -rf /var/lib/apt/lists/*

# Upgrade pip for Python 3.12
RUN python3 -m pip install --upgrade pip

# Install Python dependencies
RUN python3 -m pip install numpy

# Define OpenCV version
ENV OPENCV_VERSION=4.10.0

# Create a directory for OpenCV
WORKDIR /opt/opencv_build

# Download OpenCV and OpenCV_contrib
RUN wget -O opencv.zip https://github.com/opencv/opencv/archive/${OPENCV_VERSION}.zip && \
wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/${OPENCV_VERSION}.zip && \
unzip opencv.zip && \
unzip opencv_contrib.zip && \
mv opencv-${OPENCV_VERSION} opencv && \
mv opencv_contrib-${OPENCV_VERSION} opencv_contrib

# Create build directory
WORKDIR /opt/opencv_build/opencv/build

# Configure OpenCV with CUDA
RUN cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D OPENCV_EXTRA_MODULES_PATH=/opt/opencv_build/opencv_contrib/modules \
-D WITH_CUDA=ON \
-D ENABLE_FAST_MATH=1 \
-D CUDA_FAST_MATH=1 \
-D WITH_CUBLAS=1 \
-D OPENCV_ENABLE_NONFREE=ON \
-D BUILD_EXAMPLES=OFF \
..

# Build OpenCV
RUN make -j$(nproc) && make install && ldconfig

# Verify OpenCV installation
RUN echo "=============================================================="
RUN echo "If OpenCV compilation was successful, it should show up below:"
RUN echo "=============================================================="
RUN python3 -c "import cv2; print(cv2.__version__)"
RUN python3 -c "import cv2; print(cv2.cuda.getCudaEnabledDeviceCount())"
RUN echo "=============================================================="

# Install YOLOv8 and other Python dependencies
RUN pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu124
RUN pip install -r requirements.txt

# Create a working directory for the application
WORKDIR /app

# Copy your application code into the container
COPY . /app

# Expose any necessary ports (if applicable)
# Example: EXPOSE 8000

# Define the entrypoint or command
CMD ["python3", "yolov8_live_rtmp_stream_detection.py"]
Loading

0 comments on commit d5959b2

Please sign in to comment.