-
Notifications
You must be signed in to change notification settings - Fork 410
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
Introduce uv for Python dependencies management #148
base: main
Are you sure you want to change the base?
Conversation
* Multistage build to avoid shipping uv and getting a lightweight image * Based on uv official example: https://github.com/astral-sh/uv-docker-example/blob/main/multistage.Dockerfile
Hi David, I wanted to start a new django project this weekend, and found your PR and thought I'd base my project on Lithium, using your work because I ❤️ However I found a problem when I follow the instructions in your README after I configured PostgreSQL as per the instructions and when I run
I managed to work around it by installing libpq in the Docker container, like so: --- a/Dockerfile
+++ b/Dockerfile
@@ -13,7 +13,7 @@ RUN --mount=type=cache,target=/root/.cache/uv \
# Then, use a final image without uv
FROM python:3.12-slim-bookworm
+RUN apt-get update && apt-get install -y libpq-dev |
Ah yes you're right @mbeijen , thanks! Your added line is correct, but not at the right place: it must be inserted before |
There you go @mbeijen . It took me a bit more time than expected as I tried making |
# Then, use a final image without uv | ||
FROM python:3.12-slim-bookworm |
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.
Any reason to not include uv
in our final image? It seems useful.
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.
Two reasons yes:
- I think it's a best practice in most cases to avoid getting build tools in production. Your production code doesn't need it:
- Dependencies have already been resolved and installed (that's the build step)
- There is no multiple-Python or multiple-venv shenanigans within the container
- The official guide for using
uv
withDocker
provided a ready-to-go multistageDockerfile
, so it seems not only they agree with1.
, but also they make it trivial to implement.
Some figures:
python:3.12-slim-bookworm
is 124MBghcr.io/astral-sh/uv:python3.12-bookworm-slim
is 157MB
@jefftriplett do you think there are use cases for having uv
in the container?
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.
It's all trade-offs, and I think that's fine.
It might be something to re-think (maybe add a production layer) once we merge requirements.in
into pyproject.toml
. That makes having dev requirements easier. (after this PR merges)
I kind of view these projects as more dx/dev-friendly so being inside compose should expose uv so we can run uv lock
or uv add {package}
but I'm honestly still new to the Lithium.
All good and thank you for the explanation.
|
Closes #141
The main benefits of uv for this project are:
pyproject.toml