# Use Python 3.13 slim image FROM python:3.13-slim # Set working directory WORKDIR /app # Install system dependencies # Note: LibreOffice is excluded from the base image to reduce size (~500MB) # It can be installed on-demand via the Admin Panel → System Dependencies RUN apt-get update && apt-get install -y \ poppler-utils \ ffmpeg \ libmagic1 \ sudo \ fonts-noto-color-emoji \ && rm -rf /var/lib/apt/lists/* # Copy requirements first for better caching COPY requirements.txt . # Install Python dependencies RUN pip install --no-cache-dir -r requirements.txt # Copy application code COPY . . # Copy and set permissions for entrypoint script COPY docker-entrypoint.sh /docker-entrypoint.sh RUN chmod +x /docker-entrypoint.sh # Create directories for uploads and database RUN mkdir -p app/static/uploads instance # Set environment variables ENV FLASK_APP=app.app:create_app ENV PYTHONUNBUFFERED=1 ENV FLASK_ENV=production # Expose port EXPOSE 5000 # Create a non-root user and grant sudo access for dependency installation RUN useradd -m -u 1000 appuser && \ chown -R appuser:appuser /app /docker-entrypoint.sh && \ echo "Defaults:appuser !requiretty, !use_pty" >> /etc/sudoers && \ echo "appuser ALL=(ALL) NOPASSWD: /usr/bin/apt-get" >> /etc/sudoers && \ echo "appuser ALL=(ALL) NOPASSWD: /app/install_libreoffice.sh" >> /etc/sudoers && \ echo "appuser ALL=(ALL) NOPASSWD: /app/install_emoji_fonts.sh" >> /etc/sudoers && \ chmod +x /app/install_libreoffice.sh /app/install_emoji_fonts.sh USER appuser # Health check HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \ CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:5000/').read()" || exit 1 # Run the application via entrypoint ENTRYPOINT ["/docker-entrypoint.sh"]