rajkhanke commited on
Commit
756b6e8
·
verified ·
1 Parent(s): 34c82c0

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +15 -33
Dockerfile CHANGED
@@ -1,5 +1,4 @@
1
  # 1. Base image
2
- # Using a more specific Python version is good practice
3
  FROM python:3.9-slim
4
 
5
  # 2. Prevent __pycache__, buffer logs
@@ -7,28 +6,25 @@ ENV PYTHONDONTWRITEBYTECODE=1
7
  ENV PYTHONUNBUFFERED=1
8
 
9
  # 3. Define where uploads go and where the database file will live
10
- # Use /tmp for directories the non-root user needs to write to.
11
  ENV UPLOAD_DIR=/tmp/uploads
12
- # Specify the absolute path for the database file in /tmp
13
- ENV DATABASE_URL=sqlite:////tmp/patients.db
14
- # Also explicitly tell Flask where the instance path is, resolving the PermissionError
15
- ENV FLASK_INSTANCE_PATH=/tmp
16
 
17
  # 4. Set working dir
18
  WORKDIR /app
19
 
20
  # 5. System deps
21
  # Install build-essential (for compiling packages), zlib1g-dev and libjpeg-dev
22
- # (often needed by reportlab for image/compression support), and any other
23
- # libs required by your specific python packages (check their docs).
24
- # Add libpq-dev if you were using PostgreSQL later.
25
- # Add libsqlite3-dev if encountering issues with the sqlite driver (usually not needed for basic usage).
26
  RUN apt-get update \
27
  && apt-get install -y --no-install-recommends \
28
  build-essential \
29
  zlib1g-dev \
30
  libjpeg-dev \
31
- # Potentially add libsqlite3-dev if you encounter driver issues:
32
  # libsqlite3-dev \
33
  && rm -rf /var/lib/apt/lists/*
34
 
@@ -38,24 +34,20 @@ COPY requirements.txt .
38
  RUN pip install --no-cache-dir -r requirements.txt
39
 
40
  # 7. Copy app code
41
- # This includes app.py, index.html, doctor_dashboard.html, etc.
42
  COPY . .
43
 
44
- # 8. Pre-create the uploads directory and the database parent directory in /tmp
45
- # /tmp itself usually exists and is writable, but explicit creation is safer.
46
- # Also explicitly create the Flask instance path directory.
47
- RUN mkdir -p "${UPLOAD_DIR}/pdfs" "${FLASK_INSTANCE_PATH}"
48
 
49
  # 9. Entrypoint: Ensure runtime directories exist, then launch gunicorn
50
  # The database file and tables will be created automatically by db.create_all()
51
  # when the Flask app context is first used (which Gunicorn does on boot).
52
  RUN printf '#!/bin/sh\n\
53
  # Ensure the upload directory exists at runtime (redundant but safe for /tmp)
 
54
  mkdir -p "${UPLOAD_DIR}/pdfs"\n\
55
- # Ensure the Flask instance path exists (redundant but safe for /tmp)
56
- mkdir -p "${FLASK_INSTANCE_PATH}"\n\
57
- # Ensure the database file\'s parent directory exists (redundant for /tmp)
58
- # mkdir -p "$(dirname "${DATABASE_URL#sqlite:////}")"\n\
59
  \n\
60
  # Execute Gunicorn to run the Flask app\n\
61
  # Pass environment variables explicitly or rely on Docker --env flags\n\
@@ -71,22 +63,12 @@ EXPOSE 7860
71
  ENTRYPOINT ["/entrypoint.sh"]
72
 
73
  # Important note for production persistence with SQLite:
74
- # The patients.db file will be created inside the container\'s /tmp directory.
75
  # To persist this data between container runs or updates, you MUST mount a Docker Volume
76
- # to the directory where the database file is located (in this case, /tmp).
77
- # NOTE: Mounting /tmp is a common pattern but means EVERYTHING in /tmp is persisted.
78
- # A safer approach for SQLite persistence is often to use a dedicated volume just
79
- # for the database file's directory, e.g., placing it in a custom directory like /data
80
- # instead of /tmp, and mounting a volume to /data.
81
  #
82
- # Example using docker run (mounting /tmp for persistence - includes DB and Uploads):
83
  # docker run -d -p 7860:7860 -v my_tmp_volume:/tmp -e GENAI_API_KEY="your_key" -e TWILIO_ACCOUNT_SID="..." your_image_name
84
  #
85
- # Example using docker run (more secure: create a custom data dir in the Dockerfile and mount a volume there)
86
- # Dockerfile addition: RUN mkdir /data && chown youruser:yourgroup /data (if using a specific user)
87
- # Flask config change: ENV DATABASE_URL=sqlite:////data/patients.db
88
- # Docker run command: docker run -d -p 7860:7860 -v my_db_volume:/data ... your_image_name
89
- # (For this specific Dockerfile, mounting /tmp is the easiest fix.)
90
- #
91
  # For production deployments with orchestration (Docker Compose, Kubernetes),
92
  # define volumes and environment variables in their configuration files.
 
1
  # 1. Base image
 
2
  FROM python:3.9-slim
3
 
4
  # 2. Prevent __pycache__, buffer logs
 
6
  ENV PYTHONUNBUFFERED=1
7
 
8
  # 3. Define where uploads go and where the database file will live
9
+ # Both should be in a writable location like /tmp
10
  ENV UPLOAD_DIR=/tmp/uploads
11
+ # Define the database URL. With instance_path=/tmp in app.py,
12
+ # 'sqlite:///patients.db' will resolve to /tmp/patients.db
13
+ ENV DATABASE_URL=sqlite:///patients.db
 
14
 
15
  # 4. Set working dir
16
  WORKDIR /app
17
 
18
  # 5. System deps
19
  # Install build-essential (for compiling packages), zlib1g-dev and libjpeg-dev
20
+ # (often needed by reportlab for image/compression support).
21
+ # libsqlite3-dev might be needed for some advanced sqlite features or drivers,
22
+ # uncomment if you hit db issues, but usually not required for basic sqlite3.
 
23
  RUN apt-get update \
24
  && apt-get install -y --no-install-recommends \
25
  build-essential \
26
  zlib1g-dev \
27
  libjpeg-dev \
 
28
  # libsqlite3-dev \
29
  && rm -rf /var/lib/apt/lists/*
30
 
 
34
  RUN pip install --no-cache-dir -r requirements.txt
35
 
36
  # 7. Copy app code
 
37
  COPY . .
38
 
39
+ # 8. Pre-create the uploads directory in /tmp
40
+ # The Flask instance path (/tmp) will be created by Flask itself when needed
41
+ # within the writable /tmp directory.
42
+ RUN mkdir -p "${UPLOAD_DIR}/pdfs"
43
 
44
  # 9. Entrypoint: Ensure runtime directories exist, then launch gunicorn
45
  # The database file and tables will be created automatically by db.create_all()
46
  # when the Flask app context is first used (which Gunicorn does on boot).
47
  RUN printf '#!/bin/sh\n\
48
  # Ensure the upload directory exists at runtime (redundant but safe for /tmp)
49
+ # Flask instance_path=/tmp is handled by app.py and directory creation within /tmp\n\
50
  mkdir -p "${UPLOAD_DIR}/pdfs"\n\
 
 
 
 
51
  \n\
52
  # Execute Gunicorn to run the Flask app\n\
53
  # Pass environment variables explicitly or rely on Docker --env flags\n\
 
63
  ENTRYPOINT ["/entrypoint.sh"]
64
 
65
  # Important note for production persistence with SQLite:
66
+ # The patients.db file and uploaded PDFs will be created inside the container\'s /tmp directory.
67
  # To persist this data between container runs or updates, you MUST mount a Docker Volume
68
+ # to the /tmp directory when you run the container.
 
 
 
 
69
  #
70
+ # Example using docker run:
71
  # docker run -d -p 7860:7860 -v my_tmp_volume:/tmp -e GENAI_API_KEY="your_key" -e TWILIO_ACCOUNT_SID="..." your_image_name
72
  #
 
 
 
 
 
 
73
  # For production deployments with orchestration (Docker Compose, Kubernetes),
74
  # define volumes and environment variables in their configuration files.