UV and Distroless - #644
Conversation
e769b6e to
9734ee2
Compare
6c31cd5 to
4992b6c
Compare
dfb2a4d to
ab1bd8c
Compare
amanning9
left a comment
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
Remove this change before merge.
| # - reopened | ||
| # branches: | ||
| # - master | ||
| pull_request: #TODO: This change should not make it into the final PR. |
There was a problem hiding this comment.
Remove this change before merge.
| @@ -1,47 +0,0 @@ | |||
| anyio==4.14.2 | |||
There was a problem hiding this comment.
The version locking which used to be contained in requirements.txt is now contained in the uv.lock file.
| @@ -1,40 +0,0 @@ | |||
| [metadata] | |||
There was a problem hiding this comment.
Package info is now moved to pyproject.toml, as per PEP621
| @@ -0,0 +1 @@ | |||
| 3.12 | |||
There was a problem hiding this comment.
This file locks the python version used for development and deployment.
| ### INSTALL PINNED PYTHON ### | ||
| # https://docs.astral.sh/uv/guides/install-python/ | ||
| COPY .python-version /app-source | ||
| RUN uv python install \ |
There was a problem hiding this comment.
Using uv to install python ensures that we can always get python security patches quickly and easily.
| ### INSTALL PROJECT INTO VENV ### | ||
| # uv sync --active makes uv (re)create the currently | ||
| # active venv and install into it. | ||
| ENV VIRTUAL_ENV /app |
There was a problem hiding this comment.
Installing the project into a venv makes it easy to wholesale copy it to the final image.
| ########################### | ||
| ### COMPILE FINAL IMAGE ### | ||
| ########################### | ||
| FROM gcr.io/distroless/cc-debian13:$FINAL_IMAGE_TAG AS final |
There was a problem hiding this comment.
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.
| 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 |
There was a problem hiding this comment.
In an ideal world all these config files would probably be in a more sane/easy-to-find place.
| @@ -0,0 +1,4 @@ | |||
| ui | |||
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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
UV: https://docs.astral.sh/uv/
I suggest we use UV for the python packaging, I think the main advantages of this are:
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/