From c4df844da6901ddce9e6149edd3263a063430493 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=AD=C3=B0ir=20Valberg=20Gu=C3=B0mundsson?= Date: Thu, 26 Dec 2024 00:03:26 +0100 Subject: [PATCH] Move to uv - it is the hot new thing. --- .dockerignore | 5 +- Dockerfile | 73 ++- Justfile | 19 + Makefile | 29 -- README.md | 33 +- docker-compose.yml | 2 +- entrypoint.sh | 2 - pyproject.toml | 41 +- src/project/settings.py | 8 +- uv.lock | 954 ++++++++++++++++++++++++++++++++++++++++ 10 files changed, 1033 insertions(+), 133 deletions(-) create mode 100644 Justfile delete mode 100644 Makefile create mode 100644 uv.lock diff --git a/.dockerignore b/.dockerignore index ad9d537..6aa09a8 100644 --- a/.dockerignore +++ b/.dockerignore @@ -3,8 +3,7 @@ */.* !src/ -!requirements.txt -!requirements/ -!entrypoint.sh !pyproject.toml +!uv.lock +!entrypoint.sh !README.md diff --git a/Dockerfile b/Dockerfile index 920c448..9b252cf 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,52 +1,45 @@ -FROM python:3.12-slim-bookworm +FROM ghcr.io/astral-sh/uv:python3.12-alpine + +# - Silence uv complaining about not being able to use hard links, +# - tell uv to byte-compile packages for faster application startups, +# - prevent uv from accidentally downloading isolated Python builds, +# - pick a Python, +# - and finally declare `/app` as the target for `uv sync`. +ENV UV_LINK_MODE=copy \ + UV_COMPILE_BYTECODE=1 \ + UV_PYTHON_DOWNLOADS=never \ + UV_PYTHON=python3.12 \ + UV_PROJECT_ENVIRONMENT=/venv -# PYTHONFAULTHANDLER: Propagate tracebacks from all threads. -# PYTHONUNBUFFERED: Write terminal output straight to docker (to not confuse Docker Compose). -# PYTHONDONTWRITEBYTECODE: Dont write *pyc files at all, making it possible for a 100% read-only container. -# PIP_NO_CACHE_DIR: Disable PIP cache, we don't need pip's cache after building the image. -# PIP_DISABLE_PIP_VERSION_CHECK: Build the image with the available pip, do not check for updates (faster!) -# PIP_DEFAULT_TIMEOUT: Allow for longer timeouts. -ENV PYTHONFAULTHANDLER=1 \ - PYTHONUNBUFFERED=1 \ - PYTHONDONTWRITEBYTECODE=1 \ - PIP_NO_CACHE_DIR=1 \ - PIP_DISABLE_PIP_VERSION_CHECK=on \ - PIP_DEFAULT_TIMEOUT=100 ARG BUILD ENV BUILD=${BUILD} -ARG REQUIREMENTS_FILE=requirements.txt +ARG DJANGO_ENV=production WORKDIR /app -RUN groupadd -g 1000 www && useradd -u 1000 -ms /bin/bash -g www www +RUN --mount=type=cache,target=/root/.cache/uv \ + --mount=type=bind,source=uv.lock,target=uv.lock \ + --mount=type=bind,source=pyproject.toml,target=pyproject.toml <