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 <