rkihacker commited on
Commit
9214547
·
verified ·
1 Parent(s): 686e475

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +18 -5
Dockerfile CHANGED
@@ -1,13 +1,17 @@
1
  # --- Stage 1: Build Dependencies ---
2
  FROM python:3.9-slim as builder
3
 
 
 
 
 
4
  # Set working directory
5
  WORKDIR /app
6
 
7
- # Install uvloop first as it's a build dependency for some packages
8
- RUN pip install --no-cache-dir uvloop
9
 
10
- # Copy requirements and install them
11
  COPY requirements.txt .
12
  RUN pip install --no-cache-dir -r requirements.txt
13
 
@@ -18,16 +22,24 @@ FROM python:3.9-slim
18
  # Set the working directory
19
  WORKDIR /app
20
 
 
 
 
 
21
  # Create a non-root user and group for security
22
- RUN addgroup --system app && adduser --system --group app
 
23
 
24
- # Copy installed packages from the builder stage
 
25
  COPY --from=builder /usr/local/lib/python3.9/site-packages /usr/local/lib/python3.9/site-packages
 
26
 
27
  # Copy the application code
28
  COPY . .
29
 
30
  # Change ownership of the app directory to the non-root user
 
31
  RUN chown -R app:app /app
32
 
33
  # Switch to the non-root user
@@ -37,4 +49,5 @@ USER app
37
  EXPOSE 8000
38
 
39
  # Run the application using Gunicorn
 
40
  CMD ["gunicorn", "-c", "gunicorn_conf.py", "main:app"]
 
1
  # --- Stage 1: Build Dependencies ---
2
  FROM python:3.9-slim as builder
3
 
4
+ # Set environment variables to prevent writing .pyc files and for unbuffered output
5
+ ENV PYTHONDONTWRITEBYTECODE 1
6
+ ENV PYTHONUNBUFFERED 1
7
+
8
  # Set working directory
9
  WORKDIR /app
10
 
11
+ # Install uvloop and gunicorn first as they are core dependencies
12
+ RUN pip install --no-cache-dir uvloop gunicorn
13
 
14
+ # Copy requirements and install the rest of the packages
15
  COPY requirements.txt .
16
  RUN pip install --no-cache-dir -r requirements.txt
17
 
 
22
  # Set the working directory
23
  WORKDIR /app
24
 
25
+ # Set same environment variables for consistency
26
+ ENV PYTHONDONTWRITEBYTECODE 1
27
+ ENV PYTHONUNBUFFERED 1
28
+
29
  # Create a non-root user and group for security
30
+ # This is a more robust way to create a user with a home directory
31
+ RUN addgroup --system app && adduser --system --ingroup app --shell /bin/sh --home /app app
32
 
33
+ # Copy installed packages AND binaries from the builder stage
34
+ # This is the CRUCIAL FIX: copying /usr/local/bin where gunicorn lives
35
  COPY --from=builder /usr/local/lib/python3.9/site-packages /usr/local/lib/python3.9/site-packages
36
+ COPY --from=builder /usr/local/bin /usr/local/bin
37
 
38
  # Copy the application code
39
  COPY . .
40
 
41
  # Change ownership of the app directory to the non-root user
42
+ # This ensures the user can read the files
43
  RUN chown -R app:app /app
44
 
45
  # Switch to the non-root user
 
49
  EXPOSE 8000
50
 
51
  # Run the application using Gunicorn
52
+ # The command is now guaranteed to be in the PATH
53
  CMD ["gunicorn", "-c", "gunicorn_conf.py", "main:app"]