Skip to content

Commit e46d22a

Browse files
committed
feat: Modified dockerfiles to use uv instead of pip
1 parent aef310b commit e46d22a

File tree

3 files changed

+59
-6
lines changed

3 files changed

+59
-6
lines changed

config/Dockerfile.api

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,42 @@
1-
FROM python:3.12-slim
1+
# 1. Use a "builder" stage to install dependencies
2+
FROM python:3.12-slim AS builder
3+
4+
# Copy the uv binary from the official distroless image
5+
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
26

37
WORKDIR /app
48

9+
# Create a virtual environment
10+
RUN uv venv
11+
12+
# Copy dependency definitions
513
COPY pyproject.toml uv.lock ./
6-
RUN pip install uv && \
7-
uv sync --system --no-cache --frozen-lock
814

15+
# Install dependencies into the virtual environment, excluding the project itself.
16+
RUN . .venv/bin/activate && uv sync --locked --no-install-project
17+
18+
# Copy the application source code
919
COPY src/ ./src/
20+
21+
# Install the project itself into the venv.
22+
# Since dependencies are already installed, this step is very fast.
23+
RUN . .venv/bin/activate && uv pip install .
24+
25+
# 2. Use a clean "final" stage for the runtime environment
26+
FROM python:3.12-slim
27+
28+
WORKDIR /app
29+
30+
# Copy the virtual environment with all dependencies from the builder stage
31+
COPY --from=builder /app/.venv ./.venv
32+
33+
# Copy other necessary assets
1034
COPY models/model.joblib ./models/
1135
COPY data/data.csv ./data/
1236

37+
# Activate the virtual environment by adding it to the PATH
38+
ENV PATH="/app/.venv/bin:$PATH"
39+
1340
EXPOSE 5000
1441

1542
CMD ["python", "-m", "gunicorn", "--bind", "0.0.0.0:5000", "src.app:app"]

config/Dockerfile.streamlit

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,38 @@
1-
FROM python:3.12-slim
1+
# 1. Use a "builder" stage to install dependencies
2+
FROM python:3.12-slim AS builder
3+
4+
# Copy the uv binary from the official distroless image
5+
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
26

37
WORKDIR /app
48

9+
# Create a virtual environment
10+
RUN uv venv
11+
12+
# Copy dependency definitions
513
COPY pyproject.toml uv.lock ./
6-
RUN pip install uv && \
7-
uv sync --system --no-cache --frozen-lock
814

15+
# Install dependencies into the virtual environment, excluding the project itself.
16+
RUN . .venv/bin/activate && uv sync --locked --no-install-project
17+
18+
# Copy the application source code
919
COPY src/ ./src/
1020

21+
# Install the project itself into the venv.
22+
# Since dependencies are already installed, this step is very fast.
23+
RUN . .venv/bin/activate && uv pip install .
24+
25+
# 2. Use a clean "final" stage for the runtime environment
26+
FROM python:3.12-slim
27+
28+
WORKDIR /app
29+
30+
# Copy the virtual environment with all dependencies from the builder stage
31+
COPY --from=builder /app/.venv ./.venv
32+
33+
# Activate the virtual environment by adding it to the PATH
34+
ENV PATH="/app/.venv/bin:$PATH"
35+
1136
EXPOSE 8501
1237

1338
CMD ["streamlit", "run", "src/streamlit_app.py", "--server.port=8501", "--server.address=0.0.0.0"]

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ readme = "README.md"
66
requires-python = ">=3.12"
77
dependencies = [
88
"flask>=3.1.2",
9+
"gunicorn>=22.0.0",
910
"joblib>=1.5.2",
1011
"pandas>=2.3.3",
1112
"pytest>=8.4.2",

0 commit comments

Comments
 (0)