- 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
82 lines
4.6 KiB
Docker
82 lines
4.6 KiB
Docker
FROM python:3.11-slim
|
|
|
|
# Install system dependencies for Pillow and Tesseract
|
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
tesseract-ocr \
|
|
libtesseract-dev \
|
|
libfreetype6-dev \
|
|
libjpeg-dev \
|
|
libpng-dev \
|
|
fonts-dejavu \
|
|
fonts-dejavu-core \
|
|
fonts-dejavu-extra \
|
|
fonts-liberation \
|
|
fonts-liberation2 \
|
|
fonts-noto \
|
|
fonts-freefont-ttf \
|
|
fontconfig \
|
|
wget \
|
|
unzip \
|
|
git \
|
|
ca-certificates \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
# Download and install select Google Fonts from GitHub
|
|
RUN mkdir -p /usr/share/fonts/truetype/google-fonts && \
|
|
cd /tmp && \
|
|
# Roboto from official release\
|
|
wget -q https://github.com/google/roboto/releases/download/v2.138/roboto-unhinted.zip && \
|
|
unzip -q roboto-unhinted.zip -d roboto && \
|
|
find roboto -name "*.ttf" -path "*/Roboto-Bold.ttf" -exec cp {} /usr/share/fonts/truetype/google-fonts/ \; && \
|
|
find roboto -name "*.ttf" -path "*/Roboto-Regular.ttf" -exec cp {} /usr/share/fonts/truetype/google-fonts/ \; && \
|
|
find roboto -name "*.ttf" -path "*/Roboto-Black.ttf" -exec cp {} /usr/share/fonts/truetype/google-fonts/ \; && \
|
|
# Clone Google Fonts repo for other fonts (shallow clone)\
|
|
git clone --depth 1 --filter=blob:none --sparse https://github.com/google/fonts.git && \
|
|
cd fonts && \
|
|
git sparse-checkout set ofl/opensans ofl/montserrat ofl/oswald ofl/raleway ofl/lato ofl/poppins ofl/anton ofl/bebasneue ofl/ptsans ofl/nunito && \
|
|
# Copy specific font files\
|
|
find ofl/opensans -name "OpenSans-Bold.ttf" -o -name "OpenSans-Regular.ttf" -o -name "OpenSans-ExtraBold.ttf" | xargs -I {} cp {} /usr/share/fonts/truetype/google-fonts/ 2>/dev/null || true && \
|
|
find ofl/opensans -name "OpenSans*\[wght\].ttf" -exec cp {} /usr/share/fonts/truetype/google-fonts/OpenSans-Variable.ttf \; 2>/dev/null || true && \
|
|
find ofl/montserrat -name "Montserrat-Bold.ttf" -o -name "Montserrat-Regular.ttf" -o -name "Montserrat-Black.ttf" | xargs -I {} cp {} /usr/share/fonts/truetype/google-fonts/ 2>/dev/null || true && \
|
|
find ofl/montserrat -name "Montserrat*\[wght\].ttf" -exec cp {} /usr/share/fonts/truetype/google-fonts/Montserrat-Variable.ttf \; 2>/dev/null || true && \
|
|
find ofl/oswald -name "Oswald-Bold.ttf" -o -name "Oswald-Regular.ttf" | xargs -I {} cp {} /usr/share/fonts/truetype/google-fonts/ 2>/dev/null || true && \
|
|
find ofl/oswald -name "Oswald*\[wght\].ttf" -exec cp {} /usr/share/fonts/truetype/google-fonts/Oswald-Variable.ttf \; 2>/dev/null || true && \
|
|
find ofl/raleway -name "Raleway-Bold.ttf" -o -name "Raleway-Regular.ttf" -o -name "Raleway-Black.ttf" | xargs -I {} cp {} /usr/share/fonts/truetype/google-fonts/ 2>/dev/null || true && \
|
|
find ofl/raleway -name "Raleway*\[wght\].ttf" -exec cp {} /usr/share/fonts/truetype/google-fonts/Raleway-Variable.ttf \; 2>/dev/null || true && \
|
|
find ofl/lato -name "Lato-Bold.ttf" -o -name "Lato-Regular.ttf" -o -name "Lato-Black.ttf" | xargs -I {} cp {} /usr/share/fonts/truetype/google-fonts/ 2>/dev/null || true && \
|
|
find ofl/poppins -name "Poppins-Bold.ttf" -o -name "Poppins-Regular.ttf" -o -name "Poppins-Black.ttf" | xargs -I {} cp {} /usr/share/fonts/truetype/google-fonts/ 2>/dev/null || true && \
|
|
find ofl/anton -name "Anton-Regular.ttf" | xargs -I {} cp {} /usr/share/fonts/truetype/google-fonts/ 2>/dev/null || true && \
|
|
find ofl/bebasneue -name "BebasNeue-Regular.ttf" | xargs -I {} cp {} /usr/share/fonts/truetype/google-fonts/ 2>/dev/null || true && \
|
|
find ofl/ptsans -name "PTSans-Bold.ttf" -o -name "PTSans-Regular.ttf" | xargs -I {} cp {} /usr/share/fonts/truetype/google-fonts/ 2>/dev/null || true && \
|
|
find ofl/nunito -name "Nunito-Bold.ttf" -o -name "Nunito-Regular.ttf" -o -name "Nunito-Black.ttf" | xargs -I {} cp {} /usr/share/fonts/truetype/google-fonts/ 2>/dev/null || true && \
|
|
find ofl/nunito -name "Nunito*\[wght\].ttf" -exec cp {} /usr/share/fonts/truetype/google-fonts/Nunito-Variable.ttf \; 2>/dev/null || true && \
|
|
# Clean up\
|
|
cd /tmp && rm -rf fonts roboto *.zip && \
|
|
fc-cache -f -v
|
|
|
|
# Set working directory
|
|
WORKDIR /app
|
|
|
|
# Copy requirements first for better caching
|
|
COPY 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 .
|
|
COPY templates/ templates/
|
|
|
|
# Create uploads directory
|
|
RUN mkdir -p uploads
|
|
|
|
# Expose port
|
|
EXPOSE 5001
|
|
|
|
# Set environment variables
|
|
ENV PYTHONUNBUFFERED=1
|
|
|
|
# Run the application with Gunicorn
|
|
CMD ["gunicorn", "--bind", "0.0.0.0:5001", "--workers", "4", "--timeout", "120", "--access-logfile", "-", "--error-logfile", "-", "app:app"]
|