rkihacker commited on
Commit
e85766b
·
verified ·
1 Parent(s): 4ca437f

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +33 -13
Dockerfile CHANGED
@@ -1,21 +1,41 @@
1
- # Use an official Python runtime as a parent image
2
- FROM python:3.9-slim
 
3
 
4
- # Set the working directory in the container
5
  WORKDIR /app
6
 
7
- # Copy the dependencies file to the working directory
8
- COPY requirements.txt .
 
9
 
10
- # Install any needed packages specified in requirements.txt
11
- RUN pip install --no-cache-dir -r requirements.txt
 
12
 
13
- # Copy the rest of the application's code to the working directory
14
- COPY main.py .
 
 
15
 
16
- # Expose the port the app runs on
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  EXPOSE 8000
18
 
19
- # Run the application with Uvicorn
20
- # The host 0.0.0.0 makes the server accessible from outside the container
21
- CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
 
1
+ # --- Stage 1: Build Stage ---
2
+ # Use a full Python image to build our dependencies.
3
+ FROM python:3.11-slim as builder
4
 
5
+ # Set the working directory.
6
  WORKDIR /app
7
 
8
+ # Install poetry for dependency management.
9
+ # Using poetry is a best practice for managing dependencies.
10
+ RUN pip install poetry
11
 
12
+ # Copy only the files needed for dependency installation.
13
+ # This leverages Docker's layer caching.
14
+ COPY pyproject.toml poetry.lock ./
15
 
16
+ # Install dependencies.
17
+ # --no-root: Don't install the project itself, only the dependencies.
18
+ # --no-dev: Exclude development dependencies.
19
+ RUN poetry install --no-root --no-dev
20
 
21
+ # --- Stage 2: Runtime Stage ---
22
+ # Use a slim Python image for the final container.
23
+ FROM python:3.11-slim
24
+
25
+ # Set the working directory.
26
+ WORKDIR /app
27
+
28
+ # Copy the installed dependencies from the builder stage.
29
+ COPY --from=builder /app/.venv /.venv
30
+
31
+ # Set the PATH to include the virtual environment's bin directory.
32
+ ENV PATH="/app/.venv/bin:$PATH"
33
+
34
+ # Copy the application code.
35
+ COPY . .
36
+
37
+ # Expose the port Gunicorn will run on.
38
  EXPOSE 8000
39
 
40
+ # The command to run the application using Gunicorn.
41
+ CMD ["gunicorn", "-c", "gunicorn_config.py", "main:app"]