Update Dockerfile
Browse files- Dockerfile +33 -13
Dockerfile
CHANGED
|
@@ -1,21 +1,41 @@
|
|
| 1 |
-
#
|
| 2 |
-
|
|
|
|
| 3 |
|
| 4 |
-
# Set the working directory
|
| 5 |
WORKDIR /app
|
| 6 |
|
| 7 |
-
#
|
| 8 |
-
|
|
|
|
| 9 |
|
| 10 |
-
#
|
| 11 |
-
|
|
|
|
| 12 |
|
| 13 |
-
#
|
| 14 |
-
|
|
|
|
|
|
|
| 15 |
|
| 16 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
EXPOSE 8000
|
| 18 |
|
| 19 |
-
#
|
| 20 |
-
|
| 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"]
|
|
|