@@ -138,38 +138,64 @@ def _prepare_staging_directory(
138138 else :
139139 shutil .copy2 (item , dest )
140140
141+ # Ensure Dockerfile is at repository root (required by Hugging Face)
142+ dockerfile_server_path = staging_dir / "server" / "Dockerfile"
143+ dockerfile_root_path = staging_dir / "Dockerfile"
144+ dockerfile_path : Path | None = None
145+
146+ if dockerfile_server_path .exists ():
147+ if dockerfile_root_path .exists ():
148+ dockerfile_root_path .unlink ()
149+ dockerfile_server_path .rename (dockerfile_root_path )
150+ console .print (
151+ "[bold cyan]Moved Dockerfile to repository root for deployment[/bold cyan]"
152+ )
153+ dockerfile_path = dockerfile_root_path
154+ elif dockerfile_root_path .exists ():
155+ dockerfile_path = dockerfile_root_path
156+
141157 # Modify Dockerfile to optionally enable web interface and update base image
142- dockerfile_path = staging_dir / "server" / "Dockerfile"
143- if dockerfile_path .exists ():
158+ if dockerfile_path and dockerfile_path .exists ():
144159 dockerfile_content = dockerfile_path .read_text ()
145160 lines = dockerfile_content .split ("\n " )
146161 new_lines = []
147162 cmd_found = False
148163 base_image_updated = False
149164 web_interface_env_exists = "ENABLE_WEB_INTERFACE" in dockerfile_content
165+ last_instruction = None
150166
151167 for line in lines :
168+ stripped = line .strip ()
169+ token = stripped .split (maxsplit = 1 )[0 ] if stripped else ""
170+ current_instruction = token .upper ()
171+
172+ is_healthcheck_continuation = last_instruction == "HEALTHCHECK"
173+
152174 # Update base image if specified
153- if base_image and line .strip ().startswith ("FROM" ) and not base_image_updated :
154- # Replace the FROM line with new base image
175+ if base_image and stripped .startswith ("FROM" ) and not base_image_updated :
155176 new_lines .append (f"FROM { base_image } " )
156177 base_image_updated = True
178+ last_instruction = "FROM"
157179 continue
158180
159- # Add ENABLE_WEB_INTERFACE before CMD if requested
160- if line .strip ().startswith ("CMD" ) and not cmd_found and not web_interface_env_exists :
161- # Add ENV line before CMD
162- if enable_interface :
163- new_lines .append ("ENV ENABLE_WEB_INTERFACE=true" )
181+ if (
182+ stripped .startswith ("CMD" )
183+ and not cmd_found
184+ and not web_interface_env_exists
185+ and enable_interface
186+ and not is_healthcheck_continuation
187+ ):
188+ new_lines .append ("ENV ENABLE_WEB_INTERFACE=true" )
164189 cmd_found = True
165190
166191 new_lines .append (line )
167192
168- # Add ENABLE_WEB_INTERFACE if CMD not found and not already present
193+ if current_instruction :
194+ last_instruction = current_instruction
195+
169196 if not cmd_found and not web_interface_env_exists and enable_interface :
170197 new_lines .append ("ENV ENABLE_WEB_INTERFACE=true" )
171198
172- # If base image was specified but FROM line wasn't found, add it at the beginning
173199 if base_image and not base_image_updated :
174200 new_lines .insert (0 , f"FROM { base_image } " )
175201
0 commit comments