1313DOCKER_TEMPLATE = """# Sandbox base image
1414FROM zenmldocker/zenml-sandbox:latest
1515
16+ # Install uv from official distroless image
17+ COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
18+
19+ # Set uv environment variables for optimization
20+ ENV UV_SYSTEM_PYTHON=1
21+ ENV UV_COMPILE_BYTECODE=1
22+
1623# Project metadata
1724LABEL project_name="{name}"
1825LABEL project_version="0.1.0"
@@ -103,23 +110,21 @@ def parse_pyproject(project_dir: Path) -> list[str]:
103110 return []
104111
105112
106- def get_dependencies (project_dir : Path , use_uv : bool ) -> str :
113+ def get_dependencies (project_dir : Path ) -> tuple [ str , list [ str ]] :
107114 """Aggregate dependencies from requirements or pyproject and format the install block.
108115
109116 Includes a warning if no dependencies are found.
110117 """
111118 deps = parse_requirements (project_dir ) or parse_pyproject (project_dir )
112119 if not deps :
113120 print (f"Warning: no dependencies found in { project_dir } " )
114- return "# No dependencies found"
121+ return "# No dependencies found" , []
115122 # build install commands
116123 lines = []
117- lines .append ("# Install dependencies" )
118- if use_uv :
119- lines .append ("RUN pip install uv" )
120- lines .append ("RUN uv pip install --system \\ " )
121- else :
122- lines .append ("RUN pip install --no-cache-dir \\ " )
124+ lines .append ("# Install dependencies with uv and cache optimization" )
125+ lines .append ("RUN --mount=type=cache,target=/root/.cache/uv \\ " )
126+ lines .append (" uv pip install --system \\ " )
127+
123128 lines += [f' "{ d } " \\ ' for d in deps [:- 1 ]] + [f' "{ deps [- 1 ]} "' ]
124129 return "\n " .join (lines ), deps
125130
@@ -190,7 +195,6 @@ def gen_env_block(
190195def generate_dockerfile (
191196 project_path : str ,
192197 output_dir : str | None = None ,
193- use_uv : bool = True ,
194198) -> bool :
195199 """Create Dockerfile.sandbox using the template, dependencies, and environment setup.
196200
@@ -201,7 +205,7 @@ def generate_dockerfile(
201205 print (f"Error: { out } not found" )
202206 return False
203207 name = Path (project_path ).name
204- deps_block , installed_deps = get_dependencies (out , use_uv )
208+ deps_block , installed_deps = get_dependencies (out )
205209 keys = find_env_keys (out )
206210 env_block = gen_env_block (out , keys , installed_deps )
207211 content = DOCKER_TEMPLATE .format (
@@ -228,11 +232,7 @@ def main() -> None:
228232 help = "Use uv for dependency installation (default: True)" ,
229233 )
230234 args = parser .parse_args ()
231- sys .exit (
232- 0
233- if generate_dockerfile (args .project , args .output_dir , args .use_uv )
234- else 1
235- )
235+ sys .exit (0 if generate_dockerfile (args .project , args .output_dir ) else 1 )
236236
237237
238238if __name__ == "__main__" :
0 commit comments