File size: 2,849 Bytes
34c82c0
8686886
 
34c82c0
8686886
 
 
34c82c0
756b6e8
8f5efe7
756b6e8
 
 
8686886
34c82c0
8686886
 
34c82c0
 
756b6e8
 
 
8686886
34c82c0
 
 
 
 
8686886
 
34c82c0
 
8686886
 
 
34c82c0
8686886
 
756b6e8
 
 
 
8f5efe7
34c82c0
 
 
4b7639b
34c82c0
756b6e8
34c82c0
 
 
 
 
4b7639b
 
 
8686886
34c82c0
8686886
4ad9785
34c82c0
 
4ad9785
34c82c0
756b6e8
34c82c0
756b6e8
34c82c0
756b6e8
34c82c0
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# 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.