From ac5ab2f973509c6761e783cafc5677b63c89dd40 Mon Sep 17 00:00:00 2001 From: Tom Cobb Date: Tue, 28 Oct 2025 09:50:50 +0000 Subject: [PATCH] Change uv caching approach Now control uv cache location with enviroment variables --- .devcontainer.json | 17 ++++++++++------- Dockerfile | 6 ------ README.md | 2 ++ 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/.devcontainer.json b/.devcontainer.json index 7b5f8ec..d2446cb 100644 --- a/.devcontainer.json +++ b/.devcontainer.json @@ -6,10 +6,13 @@ }, "remoteEnv": { // Allow X11 apps to run inside the container - "DISPLAY": "${localEnv:DISPLAY}" + "DISPLAY": "${localEnv:DISPLAY}", + // Put things that allow it in the persistent cache + "UV_CACHE_DIR": "/cache/uv", + "UV_PYTHON_CACHE_DIR": "/cache/uv-python" }, - // Create the config folder for the user modifiable terminal-config and the uv cache - "initializeCommand": "mkdir -p ${localEnv:HOME}/.config/terminal-config ${localEnv:HOME}/.cache/uv", + // Create the config folder for the user modifiable terminal-config + "initializeCommand": "mkdir -p ${localEnv:HOME}/.config/terminal-config", "runArgs": [ // Allow the container to access the host X11 display and EPICS CA "--net=host", @@ -23,11 +26,11 @@ "target": "/user-terminal-config", "type": "bind" }, - // Keep a persistent cross container cache for uv + // Keep a persistent cross container cache { - "source": "${localEnv:HOME}/.cache/uv", - "target": "/root/.cache/uv", - "type": "bind" + "source": "devcontainer-shared-cache", + "target": "/cache", + "type": "volume" } ], // Mount the parent as /workspaces so we can pip install peers as editable diff --git a/Dockerfile b/Dockerfile index 5c2bb97..724e14a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -46,9 +46,3 @@ RUN /root/terminal-config/ensure-user-terminal-config.sh && \ # Install uv using the official image # See https://docs.astral.sh/uv/guides/integration/docker/#installing-uv COPY --from=ghcr.io/astral-sh/uv:0.9 /uv /uvx /bin/ - -# We recommend mounting in a cache for uv, so silence warnings about it being on a different volume -# and cache python interpreter downloads in the same directory -# https://docs.astral.sh/uv/guides/integration/docker/#caching -ENV UV_LINK_MODE=copy -ENV UV_PYTHON_CACHE_DIR=/root/.cache/uv/python diff --git a/README.md b/README.md index eb0e59b..2d45867 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,8 @@ History is also stored in this directory, in `.bash_eternal_history` and `.zsh_e See [this repo's `.devcontainer.json`](./.devcontainer.json) for an example on how to use as a devcontainer. Or clone this repo, open in vscode and click "reopen in container" +If you are considering using this for a pure python project devcontainer, consider using https://github.com/DiamondLightSource/python-copier-template + ## How to use in the build stage of a Dockerfile If you are using this during the build stage of a Dockerfile, then you should select the upstream `ubuntu` container for the runtime.