From 2b4af796a5f9c1bf4913a503c14e176e27f68d3e Mon Sep 17 00:00:00 2001 From: Niklas Rosenstein Date: Sat, 7 Sep 2024 12:25:26 +0000 Subject: [PATCH 1/3] Fix Docker integration docs for intermediate layers --- docs/guides/integration/docker.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/guides/integration/docker.md b/docs/guides/integration/docker.md index b78f21507a54..4ba8d69572bb 100644 --- a/docs/guides/integration/docker.md +++ b/docs/guides/integration/docker.md @@ -347,6 +347,8 @@ ADD . /app # Sync the project RUN --mount=type=cache,target=/root/.cache/uv \ + --mount=type=bind,source=uv.lock,target=uv.lock \ + --mount=type=bind,source=pyproject.toml,target=pyproject.toml \ uv sync --frozen ``` From 9a9dbe1cb851d459f6afa28aa32305de08ea752a Mon Sep 17 00:00:00 2001 From: Niklas Rosenstein Date: Sat, 7 Sep 2024 12:29:06 +0000 Subject: [PATCH 2/3] Update docker.md --- docs/guides/integration/docker.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/guides/integration/docker.md b/docs/guides/integration/docker.md index 4ba8d69572bb..3f228230e341 100644 --- a/docs/guides/integration/docker.md +++ b/docs/guides/integration/docker.md @@ -362,6 +362,11 @@ _contents_ are not copied into the image until the final `uv sync` command. If you want to remove specific packages from the sync, use `--no-install-package `. +!!! note README file + + If your `pyproject.toml` references a README file with the `project.readme` key, you will + also need to mount it for the `uv sync --frozen` command (the layer that installs your project). + ### Using uv temporarily If uv isn't needed in the final image, the binary can be mounted in each invocation: From ea61ed1c4308a942e5773ca9ebf8adc1b3c8b7db Mon Sep 17 00:00:00 2001 From: Niklas Rosenstein Date: Sat, 7 Sep 2024 12:39:10 +0000 Subject: [PATCH 3/3] Update docker.md --- docs/guides/integration/docker.md | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/docs/guides/integration/docker.md b/docs/guides/integration/docker.md index 3f228230e341..025721dc9117 100644 --- a/docs/guides/integration/docker.md +++ b/docs/guides/integration/docker.md @@ -340,7 +340,7 @@ WORKDIR /app RUN --mount=type=cache,target=/root/.cache/uv \ --mount=type=bind,source=uv.lock,target=uv.lock \ --mount=type=bind,source=pyproject.toml,target=pyproject.toml \ - uv sync --frozen --no-install-project + uv sync --frozen --no-install-project --link-mode=copy --compile-bytecode # Copy the project into the image ADD . /app @@ -349,11 +349,22 @@ ADD . /app RUN --mount=type=cache,target=/root/.cache/uv \ --mount=type=bind,source=uv.lock,target=uv.lock \ --mount=type=bind,source=pyproject.toml,target=pyproject.toml \ - uv sync --frozen + --mount=type=bind,source=README.md,target=README.md \ + uv sync --frozen --link-mode=copy --compile-bytecode ``` -Note that the `pyproject.toml` is required to identify the project root and name, but the project -_contents_ are not copied into the image until the final `uv sync` command. +!!! note Explanation + + * The `pyproject.toml` is required to identify the project root and name, but the project + _contents_ are not copied into the image until the final `uv sync` command. + * The `README.md` is required if your `pyproject.toml` references it in the `project.readme` + key. Update this if your configuration references a different file (or remove it if your + `pyproject.toml` references no readme). + * Uv by default hardlinks files from the cache directory into the virtual environment. The + cache directory here is only mounted at build time, which Uv will detect and fall back to + copy the files, but issue a warning. Hence, we tell Uv explicitly to copy files instead of + linking them with `--link-mode=copy`. + * Adding `--compile-bytecode` improves the startup performance of your project. !!! tip @@ -362,11 +373,6 @@ _contents_ are not copied into the image until the final `uv sync` command. If you want to remove specific packages from the sync, use `--no-install-package `. -!!! note README file - - If your `pyproject.toml` references a README file with the `project.readme` key, you will - also need to mount it for the `uv sync --frozen` command (the layer that installs your project). - ### Using uv temporarily If uv isn't needed in the final image, the binary can be mounted in each invocation: