Spaces:
Sleeping
Sleeping
| # 1. Base image | |
| FROM python:3.9-slim | |
| # 2. Prevent __pycache__, buffer logs | |
| ENV PYTHONDONTWRITEBYTECODE=1 | |
| ENV PYTHONUNBUFFERED=1 | |
| # 3. Define where uploads go and where the database file will live | |
| # Both should be in a writable location like /tmp | |
| ENV UPLOAD_DIR=/tmp/uploads | |
| # Define the database URL. With instance_path=/tmp in app.py, | |
| # 'sqlite:///patients.db' will resolve to /tmp/patients.db | |
| ENV DATABASE_URL=sqlite:///patients.db | |
| # 4. Set working dir | |
| WORKDIR /app | |
| # 5. System deps | |
| # Install build-essential (for compiling packages), zlib1g-dev and libjpeg-dev | |
| # (often needed by reportlab for image/compression support). | |
| # libsqlite3-dev might be needed for some advanced sqlite features or drivers, | |
| # uncomment if you hit db issues, but usually not required for basic sqlite3. | |
| RUN apt-get update \ | |
| && apt-get install -y --no-install-recommends \ | |
| build-essential \ | |
| zlib1g-dev \ | |
| libjpeg-dev \ | |
| # libsqlite3-dev \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # 6. Python deps | |
| # Make sure your requirements.txt includes Flask-SQLAlchemy | |
| COPY requirements.txt . | |
| RUN pip install --no-cache-dir -r requirements.txt | |
| # 7. Copy app code | |
| COPY . . | |
| # 8. Pre-create the uploads directory in /tmp | |
| # The Flask instance path (/tmp) will be created by Flask itself when needed | |
| # within the writable /tmp directory. | |
| RUN mkdir -p "${UPLOAD_DIR}/pdfs" | |
| # 9. Entrypoint: Ensure runtime directories exist, then launch gunicorn | |
| # The database file and tables will be created automatically by db.create_all() | |
| # when the Flask app context is first used (which Gunicorn does on boot). | |
| RUN printf '#!/bin/sh\n\ | |
| # Ensure the upload directory exists at runtime (redundant but safe for /tmp) | |
| # Flask instance_path=/tmp is handled by app.py and directory creation within /tmp\n\ | |
| mkdir -p "${UPLOAD_DIR}/pdfs"\n\ | |
| \n\ | |
| # Execute Gunicorn to run the Flask app\n\ | |
| # Pass environment variables explicitly or rely on Docker --env flags\n\ | |
| # It\'s better to pass sensitive vars like API keys/Twilio via --env flags when running docker\n\ | |
| exec gunicorn --workers 4 --bind 0.0.0.0:7860 app:app\n' \ | |
| > /entrypoint.sh \ | |
| && chmod +x /entrypoint.sh | |
| # 10. Expose the port Gunicorn is binding to | |
| EXPOSE 7860 | |
| # 11. Set the entrypoint | |
| ENTRYPOINT ["/entrypoint.sh"] | |
| # Important note for production persistence with SQLite: | |
| # The patients.db file and uploaded PDFs will be created inside the container\'s /tmp directory. | |
| # To persist this data between container runs or updates, you MUST mount a Docker Volume | |
| # to the /tmp directory when you run the container. | |
| # | |
| # Example using docker run: | |
| # docker run -d -p 7860:7860 -v my_tmp_volume:/tmp -e GENAI_API_KEY="your_key" -e TWILIO_ACCOUNT_SID="..." your_image_name | |
| # | |
| # For production deployments with orchestration (Docker Compose, Kubernetes), | |
| # define volumes and environment variables in their configuration files. |