Skip to content

Commit 7b811c0

Browse files
committed
Use uv sync --locked in Dockerfile templates per official uv Docker guidance
Replace `uv pip install --system` with `uv sync --locked` in all 7 Dockerfile-uv.j2 templates. This uses the uv.lock file for reproducible builds, adds two-stage dependency installation for layer caching, BuildKit cache mounts, UV_COMPILE_BYTECODE for faster startup, and virtualenv PATH. Also remove uv.lock from existing .gitignore files that were blocking it.
1 parent 89097c0 commit 7b811c0

File tree

9 files changed

+102
-66
lines changed

9 files changed

+102
-66
lines changed

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,5 @@ Brewfile.lock.json
1616

1717
.DS_Store
1818

19-
examples/**/uv.lock
20-
2119
# Claude workspace directories
2220
.claude-workspace/

examples/demos/procurement_agent/.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,3 @@ htmlcov/
6060

6161
# UV
6262
.venv/
63-
uv.lock

src/agentex/lib/cli/templates/default-langgraph/Dockerfile-uv.j2

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,27 @@ RUN apt-get update && apt-get install -y \
2020
&& apt-get clean \
2121
&& rm -rf /var/lib/apt/lists/**
2222

23-
RUN uv pip install --system --upgrade pip setuptools wheel
24-
23+
ENV UV_COMPILE_BYTECODE=1
24+
ENV UV_LINK_MODE=copy
2525
ENV UV_HTTP_TIMEOUT=1000
2626

27-
# Copy just the pyproject.toml file to optimize caching
28-
COPY {{ project_path_from_build_root }}/pyproject.toml /app/{{ project_path_from_build_root }}/pyproject.toml
29-
3027
WORKDIR /app/{{ project_path_from_build_root }}
3128

32-
# Install the required Python packages using uv
33-
RUN uv pip install --system .
29+
# Copy dependency files for layer caching
30+
COPY {{ project_path_from_build_root }}/pyproject.toml {{ project_path_from_build_root }}/uv.lock ./
31+
32+
# Install dependencies (without project itself, for layer caching)
33+
RUN --mount=type=cache,target=/root/.cache/uv \
34+
uv sync --locked --no-install-project --no-dev
3435

3536
# Copy the project code
36-
COPY {{ project_path_from_build_root }}/project /app/{{ project_path_from_build_root }}/project
37+
COPY {{ project_path_from_build_root }}/project ./project
38+
39+
# Install the project
40+
RUN --mount=type=cache,target=/root/.cache/uv \
41+
uv sync --locked --no-dev
3742

38-
# Set environment variables
43+
ENV PATH="/app/{{ project_path_from_build_root }}/.venv/bin:$PATH"
3944
ENV PYTHONPATH=/app
4045

4146
# Run the agent using uvicorn

src/agentex/lib/cli/templates/default/Dockerfile-uv.j2

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,27 @@ RUN apt-get update && apt-get install -y \
2020
&& apt-get clean \
2121
&& rm -rf /var/lib/apt/lists/**
2222

23-
RUN uv pip install --system --upgrade pip setuptools wheel
24-
23+
ENV UV_COMPILE_BYTECODE=1
24+
ENV UV_LINK_MODE=copy
2525
ENV UV_HTTP_TIMEOUT=1000
2626

27-
# Copy just the pyproject.toml file to optimize caching
28-
COPY {{ project_path_from_build_root }}/pyproject.toml /app/{{ project_path_from_build_root }}/pyproject.toml
29-
3027
WORKDIR /app/{{ project_path_from_build_root }}
3128

32-
# Install the required Python packages using uv
33-
RUN uv pip install --system .
29+
# Copy dependency files for layer caching
30+
COPY {{ project_path_from_build_root }}/pyproject.toml {{ project_path_from_build_root }}/uv.lock ./
31+
32+
# Install dependencies (without project itself, for layer caching)
33+
RUN --mount=type=cache,target=/root/.cache/uv \
34+
uv sync --locked --no-install-project --no-dev
3435

3536
# Copy the project code
36-
COPY {{ project_path_from_build_root }}/project /app/{{ project_path_from_build_root }}/project
37+
COPY {{ project_path_from_build_root }}/project ./project
38+
39+
# Install the project
40+
RUN --mount=type=cache,target=/root/.cache/uv \
41+
uv sync --locked --no-dev
3742

38-
# Set environment variables
43+
ENV PATH="/app/{{ project_path_from_build_root }}/.venv/bin:$PATH"
3944
ENV PYTHONPATH=/app
4045

4146
# Run the agent using uvicorn

src/agentex/lib/cli/templates/sync-langgraph/Dockerfile-uv.j2

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,27 @@ RUN apt-get update && apt-get install -y \
2020
&& apt-get clean \
2121
&& rm -rf /var/lib/apt/lists/**
2222

23-
RUN uv pip install --system --upgrade pip setuptools wheel
24-
23+
ENV UV_COMPILE_BYTECODE=1
24+
ENV UV_LINK_MODE=copy
2525
ENV UV_HTTP_TIMEOUT=1000
2626

27-
# Copy just the pyproject.toml file to optimize caching
28-
COPY {{ project_path_from_build_root }}/pyproject.toml /app/{{ project_path_from_build_root }}/pyproject.toml
29-
3027
WORKDIR /app/{{ project_path_from_build_root }}
3128

32-
# Install the required Python packages using uv
33-
RUN uv pip install --system .
29+
# Copy dependency files for layer caching
30+
COPY {{ project_path_from_build_root }}/pyproject.toml {{ project_path_from_build_root }}/uv.lock ./
31+
32+
# Install dependencies (without project itself, for layer caching)
33+
RUN --mount=type=cache,target=/root/.cache/uv \
34+
uv sync --locked --no-install-project --no-dev
3435

3536
# Copy the project code
36-
COPY {{ project_path_from_build_root }}/project /app/{{ project_path_from_build_root }}/project
37+
COPY {{ project_path_from_build_root }}/project ./project
38+
39+
# Install the project
40+
RUN --mount=type=cache,target=/root/.cache/uv \
41+
uv sync --locked --no-dev
3742

38-
# Set environment variables
43+
ENV PATH="/app/{{ project_path_from_build_root }}/.venv/bin:$PATH"
3944
ENV PYTHONPATH=/app
4045

4146
# Run the agent using uvicorn

src/agentex/lib/cli/templates/sync-openai-agents/Dockerfile-uv.j2

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,27 @@ RUN apt-get update && apt-get install -y \
2020
&& apt-get clean \
2121
&& rm -rf /var/lib/apt/lists/**
2222

23-
RUN uv pip install --system --upgrade pip setuptools wheel
24-
23+
ENV UV_COMPILE_BYTECODE=1
24+
ENV UV_LINK_MODE=copy
2525
ENV UV_HTTP_TIMEOUT=1000
2626

27-
# Copy just the pyproject.toml file to optimize caching
28-
COPY {{ project_path_from_build_root }}/pyproject.toml /app/{{ project_path_from_build_root }}/pyproject.toml
29-
3027
WORKDIR /app/{{ project_path_from_build_root }}
3128

32-
# Install the required Python packages using uv
33-
RUN uv pip install --system .
29+
# Copy dependency files for layer caching
30+
COPY {{ project_path_from_build_root }}/pyproject.toml {{ project_path_from_build_root }}/uv.lock ./
31+
32+
# Install dependencies (without project itself, for layer caching)
33+
RUN --mount=type=cache,target=/root/.cache/uv \
34+
uv sync --locked --no-install-project --no-dev
3435

3536
# Copy the project code
36-
COPY {{ project_path_from_build_root }}/project /app/{{ project_path_from_build_root }}/project
37+
COPY {{ project_path_from_build_root }}/project ./project
38+
39+
# Install the project
40+
RUN --mount=type=cache,target=/root/.cache/uv \
41+
uv sync --locked --no-dev
3742

38-
# Set environment variables
43+
ENV PATH="/app/{{ project_path_from_build_root }}/.venv/bin:$PATH"
3944
ENV PYTHONPATH=/app
4045

4146
# Run the agent using uvicorn

src/agentex/lib/cli/templates/sync/Dockerfile-uv.j2

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,27 @@ RUN apt-get update && apt-get install -y \
2020
&& apt-get clean \
2121
&& rm -rf /var/lib/apt/lists/**
2222

23-
RUN uv pip install --system --upgrade pip setuptools wheel
24-
23+
ENV UV_COMPILE_BYTECODE=1
24+
ENV UV_LINK_MODE=copy
2525
ENV UV_HTTP_TIMEOUT=1000
2626

27-
# Copy just the pyproject.toml file to optimize caching
28-
COPY {{ project_path_from_build_root }}/pyproject.toml /app/{{ project_path_from_build_root }}/pyproject.toml
29-
3027
WORKDIR /app/{{ project_path_from_build_root }}
3128

32-
# Install the required Python packages using uv
33-
RUN uv pip install --system .
29+
# Copy dependency files for layer caching
30+
COPY {{ project_path_from_build_root }}/pyproject.toml {{ project_path_from_build_root }}/uv.lock ./
31+
32+
# Install dependencies (without project itself, for layer caching)
33+
RUN --mount=type=cache,target=/root/.cache/uv \
34+
uv sync --locked --no-install-project --no-dev
3435

3536
# Copy the project code
36-
COPY {{ project_path_from_build_root }}/project /app/{{ project_path_from_build_root }}/project
37+
COPY {{ project_path_from_build_root }}/project ./project
38+
39+
# Install the project
40+
RUN --mount=type=cache,target=/root/.cache/uv \
41+
uv sync --locked --no-dev
3742

38-
# Set environment variables
43+
ENV PATH="/app/{{ project_path_from_build_root }}/.venv/bin:$PATH"
3944
ENV PYTHONPATH=/app
4045

4146
# Run the agent using uvicorn

src/agentex/lib/cli/templates/temporal-openai-agents/Dockerfile-uv.j2

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,30 @@ RUN curl -L https://github.com/temporalio/tctl/releases/download/v1.18.1/tctl_1.
2626
chmod +x /usr/local/bin/tctl && \
2727
rm /tmp/tctl.tar.gz
2828

29-
RUN uv pip install --system --upgrade pip setuptools wheel
30-
29+
ENV UV_COMPILE_BYTECODE=1
30+
ENV UV_LINK_MODE=copy
3131
ENV UV_HTTP_TIMEOUT=1000
3232

33-
# Copy just the pyproject.toml file to optimize caching
34-
COPY {{ project_path_from_build_root }}/pyproject.toml /app/{{ project_path_from_build_root }}/pyproject.toml
35-
3633
WORKDIR /app/{{ project_path_from_build_root }}
3734

38-
# Install the required Python packages using uv
39-
RUN uv pip install --system .
35+
# Copy dependency files for layer caching
36+
COPY {{ project_path_from_build_root }}/pyproject.toml {{ project_path_from_build_root }}/uv.lock ./
37+
38+
# Install dependencies (without project itself, for layer caching)
39+
RUN --mount=type=cache,target=/root/.cache/uv \
40+
uv sync --locked --no-install-project --no-dev
4041

4142
# Copy the project code
42-
COPY {{ project_path_from_build_root }}/project /app/{{ project_path_from_build_root }}/project
43+
COPY {{ project_path_from_build_root }}/project ./project
44+
45+
# Install the project
46+
RUN --mount=type=cache,target=/root/.cache/uv \
47+
uv sync --locked --no-dev
48+
49+
ENV PATH="/app/{{ project_path_from_build_root }}/.venv/bin:$PATH"
4350

4451
# Run the ACP server using uvicorn
4552
CMD ["uvicorn", "project.acp:acp", "--host", "0.0.0.0", "--port", "8000"]
4653

4754
# When we deploy the worker, we will replace the CMD with the following
48-
# CMD ["python", "-m", "run_worker"]
55+
# CMD ["python", "-m", "run_worker"]

src/agentex/lib/cli/templates/temporal/Dockerfile-uv.j2

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,30 @@ RUN curl -L https://github.com/temporalio/tctl/releases/download/v1.18.1/tctl_1.
2626
chmod +x /usr/local/bin/tctl && \
2727
rm /tmp/tctl.tar.gz
2828

29-
RUN uv pip install --system --upgrade pip setuptools wheel
30-
29+
ENV UV_COMPILE_BYTECODE=1
30+
ENV UV_LINK_MODE=copy
3131
ENV UV_HTTP_TIMEOUT=1000
3232

33-
# Copy just the pyproject.toml file to optimize caching
34-
COPY {{ project_path_from_build_root }}/pyproject.toml /app/{{ project_path_from_build_root }}/pyproject.toml
35-
3633
WORKDIR /app/{{ project_path_from_build_root }}
3734

38-
# Install the required Python packages using uv
39-
RUN uv pip install --system .
35+
# Copy dependency files for layer caching
36+
COPY {{ project_path_from_build_root }}/pyproject.toml {{ project_path_from_build_root }}/uv.lock ./
37+
38+
# Install dependencies (without project itself, for layer caching)
39+
RUN --mount=type=cache,target=/root/.cache/uv \
40+
uv sync --locked --no-install-project --no-dev
4041

4142
# Copy the project code
42-
COPY {{ project_path_from_build_root }}/project /app/{{ project_path_from_build_root }}/project
43+
COPY {{ project_path_from_build_root }}/project ./project
44+
45+
# Install the project
46+
RUN --mount=type=cache,target=/root/.cache/uv \
47+
uv sync --locked --no-dev
48+
49+
ENV PATH="/app/{{ project_path_from_build_root }}/.venv/bin:$PATH"
4350

4451
# Run the ACP server using uvicorn
4552
CMD ["uvicorn", "project.acp:acp", "--host", "0.0.0.0", "--port", "8000"]
4653

4754
# When we deploy the worker, we will replace the CMD with the following
48-
# CMD ["python", "-m", "run_worker"]
55+
# CMD ["python", "-m", "run_worker"]

0 commit comments

Comments
 (0)