File size: 2,700 Bytes
c3383a4
 
 
 
 
 
 
a0851ba
c3383a4
 
 
 
 
 
f84e081
 
c3383a4
 
 
 
 
 
 
 
 
 
 
 
 
8ea0f9c
c3383a4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a0851ba
 
 
c3383a4
a0851ba
89bfc09
a2994eb
 
c3383a4
 
 
a0851ba
c3383a4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a0851ba
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# Dockerfile for Safe Driving Assistant
# This container sets up a fully functional, headless-capable runtime environment
# for the AI Safe Driving Assistant. It includes all necessary C/C++ build
# dependencies for compiling dlib, PortAudio bindings (PyAudio), and sound/video
# codecs, along with Xvfb (Virtual Framebuffer) to prevent OpenCV GUI crashes.

# Use official lightweight Python base image
FROM python:3.11-slim

# Set environment variables to optimize Python performance and docker execution
ENV PYTHONUNBUFFERED=1 \
    PYTHONDONTWRITEBYTECODE=1 \
    DEBIAN_FRONTEND=noninteractive \
    PULSE_SERVER=unix:/tmp/pulseaudio.socket \
    FLASK_HOST=0.0.0.0 \
    SDL_AUDIODRIVER=dummy
# Set the working directory inside the container
WORKDIR /app

# Install system dependencies (build tools, audio, video, espeak, git, Xvfb)
RUN apt-get update && apt-get install -y --no-install-recommends \
    build-essential \
    cmake \
    g++ \
    git \
    gfortran \
    pkg-config \
    libopenblas-dev \
    liblapack-dev \
    libgl1 \
    libglib2.0-0 \
    libsm6 \
    libxext6 \
    libxrender-dev \
    libx11-dev \
    portaudio19-dev \
    libasound2-dev \
    alsa-utils \
    pulseaudio \
    libsdl2-dev \
    libsdl2-image-dev \
    libsdl2-mixer-dev \
    libsdl2-ttf-dev \
    libsndfile1 \
    espeak \
    libespeak-dev \
    xvfb \
    x11-apps \
    && rm -rf /var/lib/apt/lists/*

# Upgrade pip and wheel, but pin setuptools to prevent breaking face_recognition_models
RUN pip install --no-cache-dir --upgrade pip wheel && \
    pip install --no-cache-dir "setuptools<80.0.0"

# Install custom face recognition repositories
RUN pip install "face_recognition @ git+https://github.com/lovnishverma/face_recognition.git"
RUN pip install git+https://github.com/ageitgey/face_recognition_models

# Copy requirements.txt first to leverage Docker's build cache
COPY requirements.txt .

# Install dependencies (dlib, pyaudio, and scipy compilation can take a while)
RUN pip install --no-cache-dir -r requirements.txt

# Copy the rest of the application files
COPY . .

# Expose Flask web HUD port (5000 by default in main.py)
EXPOSE 5000

# Create an entrypoint script to automatically spin up Xvfb and start the application
RUN echo '#!/bin/bash\n\
if [ -z "$DISPLAY" ]; then\n\
    echo "[Docker-Entrypoint] No DISPLAY detected. Starting Virtual Framebuffer (Xvfb)..."\n\
    Xvfb :99 -screen 0 640x480x24 &\n\
    export DISPLAY=:99\n\
    sleep 1\n\
fi\n\
echo "[Docker-Entrypoint] Starting Safe Driving Assistant..."\n\
exec python main.py\n\
' > /app/entrypoint.sh && chmod +x /app/entrypoint.sh

# Use the virtual display entrypoint script
ENTRYPOINT ["/app/entrypoint.sh"]