Skip to content

Commit 71db37c

Browse files
fix(template): keep the uv cache off /tmp during image builds
Co-Authored-By: mish@e2b.dev <mish@e2b.dev>
1 parent 6e8e94a commit 71db37c

2 files changed

Lines changed: 19 additions & 10 deletions

File tree

‎template/charts/pyproject.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ module-name = ["e2b_charts"]
2323
module-root = ""
2424

2525
[build-system]
26-
requires = ["uv_build>=0.10.0,<0.11.0"]
26+
requires = ["uv_build>=0.13.4,<0.14.0"]
2727
build-backend = "uv_build"
2828

2929
[tool.ruff.lint]

‎template/template.py‎

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
from e2b import ReadyCmd, Template, wait_for_url
22

33

4-
# `--no-editable` builds `charts` (via uv's built-in `uv_build` backend) instead
4+
# The cache lives on the image disk, not /tmp (which `--no-cache` would use and
5+
# which is too small for the kernel packages), and is removed in the same step.
6+
# `--no-editable` builds `charts` with uv's built-in `uv_build` backend instead
57
# of linking the copied sources.
6-
UV_SYNC_FLAGS = (
7-
"--locked --no-dev --no-editable --compile-bytecode --no-cache"
8-
" --no-python-downloads"
9-
)
8+
UV_CACHE_DIR = "/root/.cache/uv"
9+
10+
11+
def uv_sync(project: str, flags: str = "") -> str:
12+
return (
13+
f"UV_CACHE_DIR={UV_CACHE_DIR} uv sync --project {project} --locked --no-dev"
14+
f" --no-editable --compile-bytecode --no-python-downloads{flags}"
15+
f" && rm -rf {UV_CACHE_DIR}"
16+
)
1017

1118

1219
def make_template(
@@ -62,9 +69,11 @@ def make_template(
6269
.copy(["pyproject.toml", "uv.lock"], ".python-env/")
6370
.copy("charts", ".python-env/charts")
6471
.run_cmd(
65-
"UV_PROJECT_ENVIRONMENT=/usr/local uv sync --project .python-env"
66-
f" {UV_SYNC_FLAGS} --inexact"
67-
+ (" --group bash" if "bash" in enabled_kernels else "")
72+
"UV_PROJECT_ENVIRONMENT=/usr/local "
73+
+ uv_sync(
74+
".python-env",
75+
" --inexact" + (" --group bash" if "bash" in enabled_kernels else ""),
76+
)
6877
)
6978
)
7079

@@ -110,7 +119,7 @@ def make_template(
110119
template = (
111120
template
112121
# Create server virtual environment
113-
.copy("server", ".server").run_cmd(f"uv sync --project .server {UV_SYNC_FLAGS}")
122+
.copy("server", ".server").run_cmd(uv_sync(".server"))
114123
)
115124

116125
# Copy configuration files

0 commit comments

Comments
 (0)