Niansuh commited on
Commit
de85a22
·
verified ·
1 Parent(s): c4443d1

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +17 -7
Dockerfile CHANGED
@@ -1,26 +1,36 @@
1
- # Use an official Python runtime as a parent image
2
- FROM python:3.10-slim
3
 
4
  # Install system dependencies
5
  RUN apt-get update && apt-get install -y --no-install-recommends \
6
  build-essential \
7
  && rm -rf /var/lib/apt/lists/*
8
 
9
- # Set environment variables
10
- ENV PYTHONDONTWRITEBYTECODE=1
11
- ENV PYTHONUNBUFFERED=1
12
 
13
  # Set the working directory in the container
14
  WORKDIR /app
15
 
16
- # Copy the requirements file first
17
  COPY requirements.txt /app/
18
 
19
  # Install dependencies
20
  RUN pip install --no-cache-dir --upgrade pip
21
  RUN pip install --no-cache-dir -r requirements.txt
22
 
23
- # Copy the current directory contents into the container
 
 
 
 
 
 
 
 
 
 
 
24
  COPY . /app
25
 
26
  # Expose the port that the FastAPI app runs on
 
1
+ # Stage 1: Build
2
+ FROM python:3.10-slim AS builder
3
 
4
  # Install system dependencies
5
  RUN apt-get update && apt-get install -y --no-install-recommends \
6
  build-essential \
7
  && rm -rf /var/lib/apt/lists/*
8
 
9
+ # Set environment variables for user installation
10
+ ENV PATH=/root/.local/bin:$PATH
 
11
 
12
  # Set the working directory in the container
13
  WORKDIR /app
14
 
15
+ # Copy the requirements file first for caching
16
  COPY requirements.txt /app/
17
 
18
  # Install dependencies
19
  RUN pip install --no-cache-dir --upgrade pip
20
  RUN pip install --no-cache-dir -r requirements.txt
21
 
22
+ # Stage 2: Production
23
+ FROM python:3.10-slim
24
+
25
+ # Set environment variables for user installation
26
+ ENV PATH=/root/.local/bin:$PATH
27
+ ENV PYTHONUNBUFFERED=1
28
+
29
+ # Set the working directory in the container
30
+ WORKDIR /app
31
+
32
+ # Copy only the necessary files from the builder stage
33
+ COPY --from=builder /root/.local /root/.local
34
  COPY . /app
35
 
36
  # Expose the port that the FastAPI app runs on