44)
55from faasmctl .util .docker import in_docker
66from requests import put
7+ from subprocess import run
78
89
910def upload_wasm (user , func , wasm_file , ini_file = None ):
@@ -13,11 +14,38 @@ def upload_wasm(user, func, wasm_file, ini_file=None):
1314 if not ini_file :
1415 ini_file = get_faasm_ini_file ()
1516
17+ # Work out if WASM file is a host path, or a path in a container
18+ wasm_in_ctr = wasm_file .rfind (":" ) != - 1
19+ if wasm_in_ctr :
20+ tmp_ctr_name = "wasm-ctr"
21+
22+ def stop_ctr ():
23+ run (f"docker rm -f { tmp_ctr_name } " , shell = True , capture_output = True )
24+
25+ ctr_image = wasm_file [: wasm_file .rfind (":" )]
26+ in_ctr_path = wasm_file [wasm_file .rfind (":" ) + 1 :]
27+ docker_cmd = "docker run -d --name {} {} bash" .format (tmp_ctr_name , ctr_image )
28+ run (docker_cmd , shell = True , capture_output = True )
29+
30+ tmp_wasm_file = "/tmp/wasm-ctr-func.wasm"
31+ docker_cmd = "docker cp {}:{} {}" .format (
32+ tmp_ctr_name , in_ctr_path , tmp_wasm_file
33+ )
34+ try :
35+ run (docker_cmd , shell = True , capture_output = True )
36+ except Exception as e :
37+ print ("Caught exception copying: {}" .format (e ))
38+
39+ stop_ctr ()
40+
41+ wasm_file = tmp_wasm_file
42+
1643 host , port = get_faasm_upload_host_port (ini_file , in_docker ())
1744 url = "http://{}:{}/f/{}/{}" .format (host , port , user , func )
1845
1946 response = put (url , data = open (wasm_file , "rb" ))
20- print ("Response ({}): {}" .format (response .status_code , response .text ))
47+ if response .status_code != 200 :
48+ raise RuntimeError (f"Error uploading WASM: { response .text } " )
2149
2250
2351def upload_python (func , python_file , ini_file = None ):
0 commit comments