Skip to content

UV and Distroless - #644

Open
amanning9 wants to merge 5 commits into
actions-devfrom
demo-uv
Open

UV and Distroless#644
amanning9 wants to merge 5 commits into
actions-devfrom
demo-uv

Conversation

@amanning9

@amanning9 amanning9 commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

UV: https://docs.astral.sh/uv/
I suggest we use UV for the python packaging, I think the main advantages of this are:

  • Installing packages is at least 10x faster than pip.
    • Much faster buils and installs.
  • uv manages a lockfile (uv.lock) which replaces the requirements.txt file:
    • Packages are securely locked by hash instead of just version number.
    • When you add a new package, it resolves and pins all the dependencies automatially for all supported python versions.
    • Dependabot will update this lockfile.
  • It takes away any effort in managing a local development environment.
    • Manages the virtual environment for you.
    • You always get the versions in the lockfile in your venv.
  • Able to manage the python install too.

Distroless: https://github.com/GoogleContainerTools/distroless/
The main advantage of distroless is a completely minimal image, so a very much reduced attack surface compared to a ubuntu image.
I think the main disadvantage/thing to note there is that final images will likely become harded to debug, since they contain no shell.
However, there are ways of working around this: https://edu.chainguard.dev/chainguard/chainguard-images/troubleshooting/debugging-distroless-images/

@amanning9
amanning9 force-pushed the demo-uv branch 4 times, most recently from e769b6e to 9734ee2 Compare July 23, 2026 12:03
@amanning9
amanning9 changed the base branch from master to actions-dev July 23, 2026 14:45
@amanning9
amanning9 force-pushed the demo-uv branch 3 times, most recently from 6c31cd5 to 4992b6c Compare July 23, 2026 14:58
@amanning9 amanning9 changed the title UV and Distroless [Draft] UV and Distroless Jul 23, 2026
@amanning9
amanning9 marked this pull request as ready for review July 23, 2026 15:06
@amanning9
amanning9 requested a review from a team as a code owner July 23, 2026 15:06
Comment thread pyproject.toml
Comment thread pyproject.toml Outdated
@amanning9
amanning9 force-pushed the demo-uv branch 5 times, most recently from dfb2a4d to ab1bd8c Compare July 29, 2026 14:53

@amanning9 amanning9 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Explanatory inline comments!


- name: Build and push image
uses: azimuth-cloud/github-actions/docker-multiarch-build-push@master
uses: azimuth-cloud/github-actions/docker-multiarch-build-push@demo-uv #TODO: DO NOT MERGE THIS. For testing only.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this change before merge.

# - reopened
# branches:
# - master
pull_request: #TODO: This change should not make it into the final PR.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this change before merge.

Comment thread api/requirements.txt
@@ -1,47 +0,0 @@
anyio==4.14.2

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The version locking which used to be contained in requirements.txt is now contained in the uv.lock file.

Comment thread api/setup.cfg
@@ -1,40 +0,0 @@
[metadata]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Package info is now moved to pyproject.toml, as per PEP621

Comment thread .python-version
@@ -0,0 +1 @@
3.12

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file locks the python version used for development and deployment.

Comment thread api/Dockerfile
### INSTALL PINNED PYTHON ###
# https://docs.astral.sh/uv/guides/install-python/
COPY .python-version /app-source
RUN uv python install \

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using uv to install python ensures that we can always get python security patches quickly and easily.

Comment thread api/Dockerfile Outdated
### INSTALL PROJECT INTO VENV ###
# uv sync --active makes uv (re)create the currently
# active venv and install into it.
ENV VIRTUAL_ENV /app

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Installing the project into a venv makes it easy to wholesale copy it to the final image.

Comment thread api/Dockerfile
###########################
### COMPILE FINAL IMAGE ###
###########################
FROM gcr.io/distroless/cc-debian13:$FINAL_IMAGE_TAG AS final

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tag is only a build arg to allow easily using the debug version in dev.
Note that the non-debug version doesn't even have a shell.

Comment thread api/Dockerfile
ENV SSL_CERT_FILE /etc/ssl/certs/ca-certificates.crt
ENV REQUESTS_CA_BUNDLE /etc/ssl/certs/ca-certificates.crt
### INSTALL CONFIG ###
COPY ./api/etc/gunicorn /etc/gunicorn

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In an ideal world all these config files would probably be in a more sane/easy-to-find place.

@@ -0,0 +1,4 @@
ui

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Build context was changed to the whole repo to make sure the uv.lock file was included, but when building the api we don't need this stuff to be sent to the docker daemon.

irt-shpc
irt-shpc previously approved these changes Jul 30, 2026

@irt-shpc irt-shpc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. It differs a tiny bit from the pyhelm3 changes I made (I ripped out tox cos it wasn't doing anything and use black for formatting and ruff for check) but they are not really important unless someone decides we have to be absolutely in lock step across the estate

@amanning9 amanning9 changed the title [Draft] UV and Distroless UV and Distroless Aug 5, 2026
@amanning9
amanning9 changed the base branch from actions-dev to master August 5, 2026 13:15
@amanning9
amanning9 dismissed irt-shpc’s stale review August 5, 2026 13:15

The base branch was changed.

@amanning9
amanning9 changed the base branch from master to actions-dev August 5, 2026 13:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants