File size: 1,152 Bytes
e85766b
 
 
686e475
e85766b
686e475
 
e85766b
 
 
6576a32
e85766b
 
 
686e475
e85766b
 
 
 
686e475
e85766b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6576a32
aa258f7
e85766b
 
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
# --- Stage 1: Build Stage ---
# Use a full Python image to build our dependencies.
FROM python:3.11-slim as builder

# Set the working directory.
WORKDIR /app

# Install poetry for dependency management.
# Using poetry is a best practice for managing dependencies.
RUN pip install poetry

# Copy only the files needed for dependency installation.
# This leverages Docker's layer caching.
COPY pyproject.toml poetry.lock ./

# Install dependencies.
# --no-root: Don't install the project itself, only the dependencies.
# --no-dev: Exclude development dependencies.
RUN poetry install --no-root --no-dev

# --- Stage 2: Runtime Stage ---
# Use a slim Python image for the final container.
FROM python:3.11-slim

# Set the working directory.
WORKDIR /app

# Copy the installed dependencies from the builder stage.
COPY --from=builder /app/.venv /.venv

# Set the PATH to include the virtual environment's bin directory.
ENV PATH="/app/.venv/bin:$PATH"

# Copy the application code.
COPY . .

# Expose the port Gunicorn will run on.
EXPOSE 8000

# The command to run the application using Gunicorn.
CMD ["gunicorn", "-c", "gunicorn_config.py", "main:app"]