-
Notifications
You must be signed in to change notification settings - Fork 899
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Docker integration docs for intermediate layers #7166
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -340,18 +340,31 @@ 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 | ||
|
||
# Sync the project | ||
RUN --mount=type=cache,target=/root/.cache/uv \ | ||
uv sync --frozen | ||
--mount=type=bind,source=uv.lock,target=uv.lock \ | ||
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \ | ||
Comment on lines
+350
to
+351
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wouldn't these be added by the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh my, I blame tunnel vision. 🤦 In my case I added only the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The source directory needs to stick around because we don't support non-editable installs of workspace members during syncs yet (#5792). Maybe it'd be best to address your case in the documentation by adding a case to the optimization examples for copying the src directory instead of the full project directory? |
||
--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 | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I have a preference for setting an environment variable for this as in astral-sh/uv-docker-example#16
I think we cover bytecode compilation in a separate example though https://docs.astral.sh/uv/guides/integration/docker/#compiling-bytecode
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that bytecode compilation shouldn't be included in this example, as it is already covered afterwards
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair point, although I feel obliged to point out that it also talks about caching later but uses a cache mount in this example already. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I missed that when someone added the bind mounts to the example in #6921 — we should probably drop that from here too for clarity.