@@ -34,15 +34,14 @@ def start_command(port: int | None, detached: bool = False, skip_build: bool = F
34
34
else :
35
35
return _handle_existing_container (repo_config , container , force )
36
36
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
40
37
if port is None :
41
38
port = get_free_port ()
42
39
43
40
try :
44
41
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 )
46
45
_run_docker_container (repo_config , port , detached )
47
46
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" ))
48
47
# TODO: memory snapshot here
@@ -51,7 +50,7 @@ def start_command(port: int | None, detached: bool = False, skip_build: bool = F
51
50
raise click .Abort ()
52
51
53
52
54
- def _handle_existing_container (repo_config : RepoConfig , container : DockerContainer , force : bool ) -> None :
53
+ def _handle_existing_container (repo_config : RepoConfig , container : DockerContainer ) -> None :
55
54
if container .is_running ():
56
55
rich .print (
57
56
Panel (
@@ -70,34 +69,48 @@ def _handle_existing_container(repo_config: RepoConfig, container: DockerContain
70
69
click .Abort ()
71
70
72
71
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 )
76
74
build_cmd = [
77
75
"docker" ,
78
76
"buildx" ,
79
77
"build" ,
80
78
"--platform" ,
81
- platform ,
79
+ _get_platform () ,
82
80
"-f" ,
83
- str (dockerfile_path ),
81
+ str (Path ( __file__ ). parent / "Dockerfile" ),
84
82
"-t" ,
85
83
"codegen-runner" ,
84
+ "--build-arg" ,
85
+ f"CODEGEN_VERSION={ codegen_version } " ,
86
+ "--build-arg" ,
87
+ f"BUILD_TYPE={ build_type } " ,
86
88
"--load" ,
87
- str (codegen_root ),
88
89
]
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
+
89
97
rich .print (
90
98
Panel (
91
99
f"{ str .join (' ' , build_cmd )} " ,
92
100
box = ROUNDED ,
93
- title = "Running Build Command" ,
101
+ title = f "Running Build Command ( { build_type } ) " ,
94
102
style = "blue" ,
95
103
padding = (1 , 1 ),
96
104
)
97
105
)
98
106
subprocess .run (build_cmd , check = True )
99
107
100
108
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
+
101
114
def _get_platform () -> str :
102
115
machine = py_platform .machine ().lower ()
103
116
if machine in ("x86_64" , "amd64" ):
0 commit comments