-
Notifications
You must be signed in to change notification settings - Fork 6
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
Replace pdm
to uv
for faster dependency management
#347
Conversation
…l usage of pdm with uv
WORKDIR /project | ||
|
||
# Install uv | ||
COPY --from=ghcr.io/astral-sh/uv:0.5.2 /uv /bin/uv |
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.
Does this definitely work? I'm sure you tested it and I just didn't realise this syntax was possible 😅
But I thought that --from
and external source never used to be an option!
That's why I used this pattern:
FROM ghcr.io/astral-sh/uv:0.5.2 as uv-image
...
COPY --from=uv-image /uv /bin/uv
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.
Nice! Thus must have been added in a recent docker version
https://docs.docker.com/build/building/multi-stage/#use-an-external-image-as-a-stage
# Install dependencies and project into the local packages directory | ||
RUN pdm install --check --prod --no-editable | ||
# Sync the project again using uv, ensuring all project dependencies are installed | ||
RUN --mount=type=cache,target=/root/.cache/uv \ |
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.
What's the reason for the double sync
?
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.
What's the reason for the double
sync
?
RUN --mount=type=cache,target=/root/.cache/uv \
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
--mount=type=bind,source=uv.lock,target=uv.lock \
uv sync --frozen --no-install-project
# Sync the project again using uv, ensuring all project dependencies are installed
RUN --mount=type=cache,target=/root/.cache/uv \
uv sync
I found, the first uv sync with --no-install-project caches dependencies, while the second installs the project after copying the code. This speeds up builds. Details: [link].
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.
Love the idea!
But the code is not copied in between the two run commands, meaning this extra step doesn't really do anything 😆
(You could probably remove the second sync with no consequence)
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.
Nice change! 🎉
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.
Test out removing that extra sync stage to see if it's needed, otherwise all good 👍
Replaced
pdm
withuv
for faster dependency management.uv
is written in Rust, making it much faster for locking dependencies and managing Python versions.Changes:
pdm
usage touv
.uv
compatibility.Bonus:
Pre-commit hook ensures lockfile updates automatically.
Reference:
Inspired by [fmtm PR #1891](hotosm/fmtm#1891).
@spwoodcock @nrjadkry @nischalstha9 , I've updated the project to use
uv
as the package manager. Could you please review the changes.