aeye4safety-backend / Dockerfile
Nishath2025's picture
Fix SSL library compatibility and improve Google Vision API setup
03cd24b
FROM python:3.9-slim
# Set working directory
WORKDIR /app
# Set environment variables for headless OpenCV before installing anything
ENV OPENCV_IO_ENABLE_OPENEXR=1
ENV QT_QPA_PLATFORM=offscreen
ENV DISPLAY=""
# Install minimal system dependencies
RUN apt-get update && apt-get install -y \
gcc \
g++ \
libffi-dev \
libssl-dev \
libglib2.0-0 \
wget \
python3-dev \
libgl1-mesa-dev \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*
# Copy requirements first for better caching
COPY requirements.txt .
# Install Python dependencies with NumPy version constraint
RUN pip install --no-cache-dir "numpy<2.0.0,>=1.24.3"
RUN pip install --no-cache-dir -r requirements.txt
# Remove conflicting OpenCV packages and ensure only headless version with compatible NumPy
RUN pip uninstall -y opencv-python opencv-contrib-python || true
RUN pip install --force-reinstall opencv-python-headless==4.8.0.76
# Copy the application code
COPY . .
# Set Google Cloud credentials path
ENV GOOGLE_APPLICATION_CREDENTIALS=/app/src/ocr/api_key/studied-temple-465613-g5-286bc260a5b5.json
# Make startup script executable
RUN chmod +x startup.sh
# Test OpenCV installation
RUN python test_opencv.py
# Test Google Vision API credentials (non-blocking)
RUN python test_google_vision.py || echo "Google Vision API test completed with warnings"
# Create necessary directories with proper permissions
RUN mkdir -p uploads instance logs && chmod 755 uploads instance logs
# Set proper ownership and permissions for the app directory
RUN chown -R 1000:1000 /app && chmod -R 755 /app
# Set environment variables
ENV FLASK_APP=main.py
ENV FLASK_ENV=production
ENV PYTHONPATH=/app
ENV PORT=7860
# Expose port 7860 (required by Hugging Face Spaces)
EXPOSE 7860
# Run the application using startup script
CMD ["./startup.sh"]