@@ -34,15 +34,14 @@ def start_command(port: int | None, detached: bool = False, skip_build: bool = F
3434 else :
3535 return _handle_existing_container (repo_config , container , force )
3636
37- codegen_version = version ("codegen" )
38- rich .print (f"[bold green]Codegen version:[/bold green] { codegen_version } " )
39- codegen_root = Path (__file__ ).parent .parent .parent .parent .parent .parent
4037 if port is None :
4138 port = get_free_port ()
4239
4340 try :
4441 if not skip_build :
45- _build_docker_image (codegen_root )
42+ codegen_root = Path (__file__ ).parent .parent .parent .parent .parent .parent
43+ codegen_version = version ("codegen" )
44+ _build_docker_image (codegen_root = codegen_root , codegen_version = codegen_version )
4645 _run_docker_container (repo_config , port , detached )
4746 rich .print (Panel (f"[green]Server started successfully![/green]\n Access the server at: [bold]http://{ _default_host } :{ port } [/bold]" , box = ROUNDED , title = "Codegen Server" ))
4847 # TODO: memory snapshot here
@@ -51,7 +50,7 @@ def start_command(port: int | None, detached: bool = False, skip_build: bool = F
5150 raise click .Abort ()
5251
5352
54- def _handle_existing_container (repo_config : RepoConfig , container : DockerContainer , force : bool ) -> None :
53+ def _handle_existing_container (repo_config : RepoConfig , container : DockerContainer ) -> None :
5554 if container .is_running ():
5655 rich .print (
5756 Panel (
@@ -70,34 +69,48 @@ def _handle_existing_container(repo_config: RepoConfig, container: DockerContain
7069 click .Abort ()
7170
7271
73- def _build_docker_image (codegen_root : Path ) -> None :
74- platform = _get_platform ()
75- dockerfile_path = Path (__file__ ).parent / "Dockerfile-runner"
72+ def _build_docker_image (codegen_root : Path , codegen_version : str ) -> None :
73+ build_type = _get_build_type (codegen_version )
7674 build_cmd = [
7775 "docker" ,
7876 "buildx" ,
7977 "build" ,
8078 "--platform" ,
81- platform ,
79+ _get_platform () ,
8280 "-f" ,
83- str (dockerfile_path ),
81+ str (Path ( __file__ ). parent / "Dockerfile" ),
8482 "-t" ,
8583 "codegen-runner" ,
84+ "--build-arg" ,
85+ f"CODEGEN_VERSION={ codegen_version } " ,
86+ "--build-arg" ,
87+ f"BUILD_TYPE={ build_type } " ,
8688 "--load" ,
87- str (codegen_root ),
8889 ]
90+
91+ # Only add the context path if we're doing a local build
92+ if build_type == "dev" :
93+ build_cmd .append (str (codegen_root ))
94+ else :
95+ build_cmd .append ("." ) # Minimal context when installing from PyPI
96+
8997 rich .print (
9098 Panel (
9199 f"{ str .join (' ' , build_cmd )} " ,
92100 box = ROUNDED ,
93- title = "Running Build Command" ,
101+ title = f "Running Build Command ( { build_type } ) " ,
94102 style = "blue" ,
95103 padding = (1 , 1 ),
96104 )
97105 )
98106 subprocess .run (build_cmd , check = True )
99107
100108
109+ def _get_build_type (version : str ) -> str :
110+ """Get the build type based on the version string."""
111+ return "dev" if "dev" in version or "+" in version else "release"
112+
113+
101114def _get_platform () -> str :
102115 machine = py_platform .machine ().lower ()
103116 if machine in ("x86_64" , "amd64" ):
0 commit comments