Changed app.py: • process_pft_pdf() now uses the uploaded file stream directly instead of copying the PDF into bytes. • Output now uses SpooledTemporaryFile, so larger generated PDFs spill to disk instead of staying fully in RAM. • Explicitly closes PdfReader objects after writing. • Removed @app.teardown_request gc.collect(), which was running too early and could break send_file. • Added response.call_on_close() cleanup so the generated PDF stream is closed only after Flask/Werkzeug finishes sending it. Changed Dockerfile: • Added Gunicorn --max-requests 50 --max-requests-jitter 10 as a production guardrail against PDF-library or allocator memory growth.
19 lines
536 B
Docker
19 lines
536 B
Docker
# Use an official Python runtime as a parent image
|
|
FROM python:3.11-slim
|
|
|
|
# Set the working directory in the container
|
|
WORKDIR /app
|
|
|
|
# Copy the requirements file and install dependencies
|
|
COPY requirements.txt .
|
|
RUN pip install --no-cache-dir -r requirements.txt
|
|
|
|
# Copy the rest of the application code
|
|
COPY . .
|
|
|
|
# Expose the port the app runs on
|
|
EXPOSE 5000
|
|
|
|
# Command to run the application using Gunicorn (production ready)
|
|
CMD ["gunicorn", "--bind", "0.0.0.0:5000", "--max-requests", "50", "--max-requests-jitter", "10", "app:app"]
|