From 954cd87a2058a703ceccbd02b754e877ec231e7c Mon Sep 17 00:00:00 2001 From: Seth Van Niekerk Date: Sat, 17 Jan 2026 13:47:09 -0500 Subject: [PATCH] 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 --- Dockerfile | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index 106f838..ad093e5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ FROM python:3.11-slim # 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 \ libtesseract-dev \ libfreetype6-dev \ @@ -18,7 +18,7 @@ RUN apt-get update && apt-get install -y \ wget \ unzip \ git \ - && fc-cache -f -v \ + ca-certificates \ && rm -rf /var/lib/apt/lists/* # Download and install select Google Fonts from GitHub @@ -60,8 +60,9 @@ WORKDIR /app # Copy requirements first for better caching COPY requirements.txt . -# Install Python dependencies -RUN pip install --no-cache-dir -r requirements.txt +# Install Python dependencies and clear cache +RUN pip install --no-cache-dir -r requirements.txt && \ + rm -rf /root/.cache/pip # Copy application files COPY app.py . @@ -76,5 +77,5 @@ EXPOSE 5001 # Set environment variables ENV PYTHONUNBUFFERED=1 -# Run the application -CMD ["python", "app.py"] +# Run the application with Gunicorn +CMD ["gunicorn", "--bind", "0.0.0.0:5001", "--workers", "4", "--timeout", "120", "--access-logfile", "-", "--error-logfile", "-", "app:app"]