NitinBot002 commited on
Commit
b70573c
·
verified ·
1 Parent(s): ec3f33f

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +15 -42
Dockerfile CHANGED
@@ -1,48 +1,21 @@
1
- # ---- Stage 1: The Builder ----
2
- # This stage installs dependencies and compiles the Python code into bytecode.
3
- FROM python:3.11.4-slim as builder
4
 
5
- WORKDIR /usr/src/app
 
6
 
7
- # Copy and install dependencies
8
- COPY requirements.txt ./
9
- RUN pip install -q --no-cache-dir -r requirements.txt
10
 
11
- # Copy the application source code
12
- COPY . .
13
-
14
- # Compile all .py files. The -b flag creates legacy .pyc files.
15
- RUN python -m compileall -b -f .
16
-
17
-
18
- # --- Stage 2: The Final Production Image ---
19
- # This stage takes only the compiled code and necessary assets.
20
- FROM python:3.11.4-slim
21
-
22
- WORKDIR /usr/src/app
23
 
24
- # Copy the compiled .pyc files and other assets from the builder stage
25
- COPY --from=builder /usr/src/app/*.pyc .
26
- COPY --from=builder /usr/src/app/templates ./templates
27
- COPY --from=builder /usr/src/app/requirements.txt .
28
-
29
- # --- THIS IS THE KEY FIX FOR THE PATH ERROR ---
30
- # Install dependencies as the ROOT user first.
31
- # This ensures executables like 'gunicorn' are installed in a system-wide
32
- # directory (e.g., /usr/local/bin) that is in the default $PATH.
33
- RUN pip install -q --no-cache-dir -r requirements.txt
34
-
35
- # Now, create the non-root user for running the application
36
- RUN useradd --create-home appuser
37
-
38
- # Change the ownership of the entire app directory to our new user.
39
- # This allows the app to write files like client_secrets.json and token.json.
40
- RUN chown -R appuser:appuser /usr/src/app
41
 
42
- # Switch to the non-root user for running the application.
43
- # This is the final security step before execution.
44
- USER appuser
45
 
46
- # The command to run the application.
47
- # Gunicorn is now in the $PATH, and the 'appuser' has permission to run it.
48
- CMD ["gunicorn", "app:app", "--bind", "0.0.0.0:7860"]
 
1
+ # Use the official Python 3.9 slim image as the base
2
+ FROM python:3.9-slim
 
3
 
4
+ # Set the working directory inside the container
5
+ WORKDIR /app
6
 
7
+ # Copy the requirements file first to leverage Docker cache
8
+ COPY requirements.txt requirements.txt
 
9
 
10
+ # Install the Python dependencies
11
+ RUN pip install --no-cache-dir -r requirements.txt
 
 
 
 
 
 
 
 
 
 
12
 
13
+ # Copy the rest of the application code
14
+ COPY . .
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
 
16
+ # Expose the port the app runs on (defined by the PORT environment variable or 5000)
17
+ EXPOSE 5000
 
18
 
19
+ # Define the command to run the application
20
+ # Run the application using Gunicorn
21
+ CMD ["gunicorn", "--bind", "0.0.0.0:5000", "app:app"]