Skip to content

Commit fa76174

Browse files
authored
Use UV_NO_DEV in the examples (#73)
1 parent 5748835 commit fa76174

4 files changed

Lines changed: 21 additions & 7 deletions

File tree

Dockerfile

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,23 @@ ENV UV_COMPILE_BYTECODE=1
1414
# Copy from the cache instead of linking since it's a mounted volume
1515
ENV UV_LINK_MODE=copy
1616

17+
# Omit development dependencies
18+
ENV UV_NO_DEV=1
19+
1720
# Ensure installed tools can be executed out of the box
1821
ENV UV_TOOL_BIN_DIR=/usr/local/bin
1922

2023
# Install the project's dependencies using the lockfile and settings
2124
RUN --mount=type=cache,target=/root/.cache/uv \
2225
--mount=type=bind,source=uv.lock,target=uv.lock \
2326
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
24-
uv sync --locked --no-install-project --no-dev
27+
uv sync --locked --no-install-project
2528

2629
# Then, add the rest of the project source code and install it
2730
# Installing separately from its dependencies allows optimal layer caching
2831
COPY . /app
2932
RUN --mount=type=cache,target=/root/.cache/uv \
30-
uv sync --locked --no-dev
33+
uv sync --locked
3134

3235
# Place executables in the environment at the front of the path
3336
ENV PATH="/app/.venv/bin:$PATH"
@@ -39,7 +42,8 @@ ENTRYPOINT []
3942
USER nonroot
4043

4144
# Run the FastAPI application by default
45+
# Uses `uv run` to sync dependencies on startup, respecting UV_NO_DEV
4246
# Uses `fastapi dev` to enable hot-reloading when the `watch` sync occurs
4347
# Uses `--host 0.0.0.0` to allow access from outside the container
4448
# Note in production, you should use `fastapi run` instead
45-
CMD ["fastapi", "dev", "--host", "0.0.0.0", "src/uv_docker_example"]
49+
CMD ["uv", "run", "fastapi", "dev", "--host", "0.0.0.0", "src/uv_docker_example"]

compose.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ services:
77
ports:
88
- "8000:8000"
99

10+
# Include development dependencies when working locally
11+
environment:
12+
- UV_NO_DEV=0
13+
1014
develop:
1115
# Create a `watch` configuration to update the app
1216
# https://docs.docker.com/compose/file-watch/#compose-watch-versus-bind-mounts

multistage.Dockerfile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim AS builder
66
ENV UV_COMPILE_BYTECODE=1 UV_LINK_MODE=copy
77

8+
# Omit development dependencies
9+
ENV UV_NO_DEV=1
10+
811
# Disable Python downloads, because we want to use the system interpreter
912
# across both images. If using a managed Python version, it needs to be
1013
# copied from the build image into the final image; see `standalone.Dockerfile`
@@ -15,10 +18,10 @@ WORKDIR /app
1518
RUN --mount=type=cache,target=/root/.cache/uv \
1619
--mount=type=bind,source=uv.lock,target=uv.lock \
1720
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
18-
uv sync --locked --no-install-project --no-dev
21+
uv sync --locked --no-install-project
1922
COPY . /app
2023
RUN --mount=type=cache,target=/root/.cache/uv \
21-
uv sync --locked --no-dev
24+
uv sync --locked
2225

2326

2427
# Then, use a final image without uv

standalone.Dockerfile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
FROM ghcr.io/astral-sh/uv:bookworm-slim AS builder
55
ENV UV_COMPILE_BYTECODE=1 UV_LINK_MODE=copy
66

7+
# Omit development dependencies
8+
ENV UV_NO_DEV=1
9+
710
# Configure the Python directory so it is consistent
811
ENV UV_PYTHON_INSTALL_DIR=/python
912

@@ -17,10 +20,10 @@ WORKDIR /app
1720
RUN --mount=type=cache,target=/root/.cache/uv \
1821
--mount=type=bind,source=uv.lock,target=uv.lock \
1922
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
20-
uv sync --locked --no-install-project --no-dev
23+
uv sync --locked --no-install-project
2124
COPY . /app
2225
RUN --mount=type=cache,target=/root/.cache/uv \
23-
uv sync --locked --no-dev
26+
uv sync --locked
2427

2528
# Then, use a final image without uv
2629
FROM debian:bookworm-slim

0 commit comments

Comments
 (0)