build: optimize Docker image and switch to production server

- Add --no-install-recommends flag to apt-get to reduce image size
- Add ca-certificates package for secure HTTPS connections
- Clean pip cache after installing dependencies (rm -rf /root/.cache/pip)
- Replace Flask development server with Gunicorn for production deployment
- Configure Gunicorn with 4 workers, 120s timeout, and access/error logging
- Binding to 0.0.0.0:5001 for container networking
This commit is contained in:
2026-01-17 13:47:09 -05:00
parent f6edf62082
commit 954cd87a20

View File

@@ -1,7 +1,7 @@
FROM python:3.11-slim FROM python:3.11-slim
# Install system dependencies for Pillow and Tesseract # Install system dependencies for Pillow and Tesseract
RUN apt-get update && apt-get install -y \ RUN apt-get update && apt-get install -y --no-install-recommends \
tesseract-ocr \ tesseract-ocr \
libtesseract-dev \ libtesseract-dev \
libfreetype6-dev \ libfreetype6-dev \
@@ -18,7 +18,7 @@ RUN apt-get update && apt-get install -y \
wget \ wget \
unzip \ unzip \
git \ git \
&& fc-cache -f -v \ ca-certificates \
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
# Download and install select Google Fonts from GitHub # Download and install select Google Fonts from GitHub
@@ -60,8 +60,9 @@ WORKDIR /app
# Copy requirements first for better caching # Copy requirements first for better caching
COPY requirements.txt . COPY requirements.txt .
# Install Python dependencies # Install Python dependencies and clear cache
RUN pip install --no-cache-dir -r requirements.txt RUN pip install --no-cache-dir -r requirements.txt && \
rm -rf /root/.cache/pip
# Copy application files # Copy application files
COPY app.py . COPY app.py .
@@ -76,5 +77,5 @@ EXPOSE 5001
# Set environment variables # Set environment variables
ENV PYTHONUNBUFFERED=1 ENV PYTHONUNBUFFERED=1
# Run the application # Run the application with Gunicorn
CMD ["python", "app.py"] CMD ["gunicorn", "--bind", "0.0.0.0:5001", "--workers", "4", "--timeout", "120", "--access-logfile", "-", "--error-logfile", "-", "app:app"]