Skip to content

Commit 34cba36

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 add .gitignore.j2 templates so generated projects don't ignore uv.lock, and remove uv.lock from existing .gitignore files that were blocking it.
1 parent 89097c0 commit 34cba36

File tree

17 files changed

+285
-66
lines changed

17 files changed

+285
-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/commands/init.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ def create_project_structure(
7575
# Create root files
7676
root_templates = {
7777
".dockerignore.j2": ".dockerignore",
78+
".gitignore.j2": ".gitignore",
7879
"manifest.yaml.j2": "manifest.yaml",
7980
"README.md.j2": "README.md",
8081
"environments.yaml.j2": "environments.yaml",
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
__pycache__/
2+
*.py[cod]
3+
*$py.class
4+
*.so
5+
.Python
6+
build/
7+
dist/
8+
*.egg-info/
9+
*.egg
10+
11+
.venv
12+
.env
13+
.env.local
14+
15+
.idea/
16+
.vscode/
17+
*.swp
18+
*.swo
19+
20+
.DS_Store
21+
22+
.pytest_cache/
23+
.coverage
24+
htmlcov/
25+
26+
.ipynb_checkpoints/

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
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
__pycache__/
2+
*.py[cod]
3+
*$py.class
4+
*.so
5+
.Python
6+
build/
7+
dist/
8+
*.egg-info/
9+
*.egg
10+
11+
.venv
12+
.env
13+
.env.local
14+
15+
.idea/
16+
.vscode/
17+
*.swp
18+
*.swo
19+
20+
.DS_Store
21+
22+
.pytest_cache/
23+
.coverage
24+
htmlcov/
25+
26+
.ipynb_checkpoints/

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
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
__pycache__/
2+
*.py[cod]
3+
*$py.class
4+
*.so
5+
.Python
6+
build/
7+
dist/
8+
*.egg-info/
9+
*.egg
10+
11+
.venv
12+
.env
13+
.env.local
14+
15+
.idea/
16+
.vscode/
17+
*.swp
18+
*.swo
19+
20+
.DS_Store
21+
22+
.pytest_cache/
23+
.coverage
24+
htmlcov/
25+
26+
.ipynb_checkpoints/

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
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
__pycache__/
2+
*.py[cod]
3+
*$py.class
4+
*.so
5+
.Python
6+
build/
7+
dist/
8+
*.egg-info/
9+
*.egg
10+
11+
.venv
12+
.env
13+
.env.local
14+
15+
.idea/
16+
.vscode/
17+
*.swp
18+
*.swo
19+
20+
.DS_Store
21+
22+
.pytest_cache/
23+
.coverage
24+
htmlcov/
25+
26+
.ipynb_checkpoints/

0 commit comments

Comments
 (0)