@@ -319,31 +319,65 @@ def _update_function_code(
319319 f"Start to update VeFaaS function { function_name } with path { path } ."
320320 )
321321
322- # Upload and mount code using extracted method
323- self ._upload_and_mount_code (function_id , path )
322+ import shutil
323+ from pathlib import Path
324+ from cookiecutter .main import cookiecutter
325+ import veadk .integrations .ve_faas as vefaas
326+ from veadk .version import VERSION
327+
328+ user_proj_path = Path (path ).resolve ()
329+ template_dir = Path (vefaas .__file__ ).parent / "template"
330+ tmp_dir_name = f"{ user_proj_path .name } _update_{ formatted_timestamp ()} "
331+
332+ settings = {
333+ "local_dir_name" : tmp_dir_name .replace ("-" , "_" ),
334+ "app_name" : user_proj_path .name .replace ("-" , "_" ),
335+ "veadk_version" : VERSION ,
336+ }
324337
325- # Use update_function client method to apply changes
326- self .client .update_function (
327- volcenginesdkvefaas .UpdateFunctionRequest (
328- id = function_id ,
329- request_timeout = 1800 , # Keep same timeout as deploy
330- )
338+ cookiecutter (
339+ template = str (template_dir ),
340+ output_dir = "/tmp" ,
341+ no_input = True ,
342+ extra_context = settings ,
331343 )
332344
333- logger .info (f"Function updated successfully: { function_id } " )
334-
335- logger .info (f"VeFaaS function { function_name } with ID { function_id } updated." )
336-
337- # Release the application to apply changes
338- url = self ._release_application (app_id )
339-
340- logger .info (f"VeFaaS application { application_name } with ID { app_id } released." )
345+ tmp_path = Path ("/tmp" ) / tmp_dir_name
346+ try :
347+ agent_dir = tmp_path / "src" / user_proj_path .name .replace ("-" , "_" )
348+ if agent_dir .exists ():
349+ shutil .rmtree (agent_dir )
350+ agent_dir .mkdir (parents = True , exist_ok = True )
351+ shutil .copytree (user_proj_path , agent_dir , dirs_exist_ok = True )
352+ user_requirements = user_proj_path / "requirements.txt"
353+
354+ if user_requirements .exists ():
355+ logger .debug ("Using user-provided requirements.txt" )
356+ shutil .copy (user_requirements , tmp_path / "src" / "requirements.txt" )
357+ else :
358+ logger .warning ("No requirements.txt found, using template default" )
341359
342- logger .info (
343- f"VeFaaS application { application_name } with ID { app_id } updated on { url } ."
344- )
360+ self ._upload_and_mount_code (function_id , str (tmp_path / "src" ))
361+ self .client .update_function (
362+ volcenginesdkvefaas .UpdateFunctionRequest (
363+ id = function_id ,
364+ request_timeout = 1800 , # Keep same timeout as deploy
365+ )
366+ )
367+ logger .info (
368+ f"VeFaaS function { function_name } with ID { function_id } updated."
369+ )
370+ url = self ._release_application (app_id )
371+ logger .info (
372+ f"VeFaaS application { application_name } with ID { app_id } released."
373+ )
374+ logger .info (f"VeFaaS application { application_name } updated on { url } ." )
375+ return url , app_id , function_id
345376
346- return url , app_id , function_id
377+ finally :
378+ if tmp_path .exists ():
379+ shutil .rmtree (tmp_path )
380+ logger .debug (f"Cleaned up temporary directory: { tmp_path } " )
347381
348382 def get_application_details (self , app_id : str = None , app_name : str = None ):
349383 if not app_id and not app_name :
0 commit comments