bump version + finish UV article
All checks were successful
Build Blog Docker Image / build docker (push) Successful in 1m6s

This commit is contained in:
2024-02-29 23:01:32 +01:00
parent a4e31c49c7
commit a5e23468a3
11 changed files with 78 additions and 44 deletions

View File

@ -2,7 +2,7 @@
title: "Authelia : a selfhosted SSO"
date: 2022-04-10
slug: "authelia-selfhosted-sso"
tags: ["authentication", "docker", "sso", "tools"]
tags: ["authentication", "docker", "SSO", "tools"]
type: "security"
---

View File

@ -2,7 +2,7 @@
title: "How to host multiple services on one public IP ?"
date: 2022-02-28
slug: "how-to-host-multiple-services-on-one-public-ip"
tags: ["ddns", "docker", "network", "reverse proxy"]
tags: ["DDNS", "docker", "network", "reverse proxy"]
type: "infrastructure"
---

View File

@ -2,7 +2,7 @@
title: "Migrate from Ghost to Hugo"
date: 2024-02-24
slug: "migrate-from-ghost-to-hugo"
tags: ["ci/cd", "docker", "git", "hugo"]
tags: ["CI/CD", "docker", "git", "hugo"]
type: "programming"
---

View File

@ -1,17 +1,33 @@
---
title: "UV the new python package installer written in Rust"
date: 2024-02-23
draft: true
date: 2024-02-25
slug: "uv-the-new-python-package-installer-written-in-rust"
tags: ["ci/cd", "docker", "python", "tools"]
tags: ["CI/CD", "docker", "python", "tools"]
type: "programming"
---
## Overview
[UV](https://astral.sh/blog/uv) is Team Astral's new tool. It's written in Rust and aims to replace `pip` and `pip-tools`, all with extreme speed.
After the publication of [Ruff](https://astral.sh/ruff), the team continues with the aim of creating a "Cargo for Python" with this new publication.
UV can be installed in several ways (with pip or standalone) and is compatible with Linux, Windows and macOS. I installed it with the following command:
```bash
pip install uv
```
To use it, simply use the `uv` prefix and then one of the following commands:
```bash
# Basic command like install, uninstall, freeze, sync, compile
uv pip
# Create a VENV
uv venv
# Clean cache or show cache directory
uv cache
```
## UV benchmark
Let's compare UV and VENV/PIP to see how this new solution performs: according to the creators, UV should be around 80x faster than `python -m venv` and 7x faster than `virtualenv`.
Let's compare UV and VENV/PIP to see how this new solution performs. According to the creators, UV should be around 80x faster than `python -m venv` and 7x faster than `virtualenv`.
After creating virtual environments with these different tools, I was able to obtain the following results:
@ -76,8 +92,7 @@ options: {
For packet insertion I find that UV is ~5x faster than pip and ~33x faster then `pip` with the UV cache.
## Docker image for CI/CD
UV
Now let's try to integrate it into our CIs. To do this, I'll create a modified python image that I'll then use in my various workflows.
```dockerfile
FROM python:3.11-slim
@ -91,6 +106,9 @@ ENV VIRTUAL_ENV /.venv
ENV PATH /.venv/bin:$PATH
```
The Dockerfile is quite simple, I base it on a python 3.11 image, upgrade pip, then install UV. I then create a venv with UV, and activate it. Finally, I install the packets I need for my workflows.
Finally, I set the environment variables `VIRTUAL_ENV` and `PATH`. This allows me to be directly in the venv when using the image. I then build the image and check that it works correctly:
```bash
debian@debian:~/dev/images$ docker build -t uv_python .
[...]
@ -109,6 +127,9 @@ Type "help", "copyright", "credits" or "license" for more information.
>>>
```
After building and testing the image with a docker run, I can confirm that the image works correctly and is usable in my various CIs.
In addition to this image, we can set the cache for UV in Workflow. For Gitlab, I use the following configuration:
```yml
[...]
variables:
@ -120,3 +141,16 @@ cache:
- $CI_PROJECT_DIR/.cache/uv
[...]
```
After a few, I've noticed that the cache can be useful in some situations (especially if you have a very good machine) but can also slow down the CI in others. In some situations, UV is faster than Gitlab's cache compression/decompression. In particular, I've seen it slow down runners using HDDs.
I suggest you test with and without to see which is faster.
## Conclusion
UV is a very promising tool, in line with what Team Astral has to offer. In my opinion, it can already be deployed in production, and therefore saves a great amont of time, especially for repeat installations (e.g. CI). The speed of this tool even calls into question some current time-saving options, such as the CI cache.
It's worth noting that, despite the objective of being a "drop-in replacement for pip", it currently lacks features that could be blocking in certain situations:
- No --trusted-host option ([#1339](https://github.com/astral-sh/uv/issues/1339))
- No installation without venv ([#1374](https://github.com/astral-sh/uv/issues/1374))
- etc.