def upload(ctx, user, func, host=None, s3=False, ibm=False, subdir=None, py=False, ts=False, prebuilt=False): host, port = _get_host_port(host, None) if py: func_file = join(PROJ_ROOT, "func", user, "{}.py".format(func)) url = "http://{}:{}/p/{}/{}".format(host, port, user, func) curl_file(url, func_file) elif ts: func_file = join(PROJ_ROOT, "typescript", "build", "{}.wasm".format(func)) url = "http://{}:{}/f/ts/{}".format(host, port, func) curl_file(url, func_file) else: base_dir = WASM_DIR if prebuilt else FUNC_BUILD_DIR if subdir: func_file = join(base_dir, user, subdir, "{}.wasm".format(func)) elif prebuilt: func_file = join(base_dir, user, func, "function.wasm") else: func_file = join(base_dir, user, "{}.wasm".format(func)) if s3: print("Uploading {}/{} to S3".format(user, func)) s3_key = _get_s3_key(user, func) upload_file_to_s3(func_file, RUNTIME_S3_BUCKET, s3_key) if ibm: print("Uploading {}/{} to IBM cloud storage".format(user, func)) ibm_key = _get_s3_key(user, func) upload_file_to_ibm(func_file, RUNTIME_S3_BUCKET, ibm_key) else: url = "http://{}:{}/f/{}/{}".format(host, port, user, func) curl_file(url, func_file)
def _upload_function(user, func, port=None, host=None, s3=False, ibm=False, py=False, ts=False, file=None, local_copy=False): host, port = get_upload_host_port(host, port) if py and local_copy: storage_dir = join(FAASM_SHARED_STORAGE_ROOT, "pyfuncs", user, func) shared_dir = join(FAASM_SHARED_ROOT, "pyfuncs", user, func) if exists(shared_dir): rmtree(shared_dir) if not exists(storage_dir): makedirs(storage_dir) src_file = join(FUNC_DIR, user, "{}.py".format(func)) dest_file = join(storage_dir, "function.py") copy(src_file, dest_file) elif py: func_file = join(PROJ_ROOT, "func", user, "{}.py".format(func)) url = "http://{}:{}/p/{}/{}".format(host, port, user, func) curl_file(url, func_file) elif ts: func_file = join(PROJ_ROOT, "typescript", "build", "{}.wasm".format(func)) url = "http://{}:{}/f/ts/{}".format(host, port, func) curl_file(url, func_file) else: if file: func_file = file else: func_file = join(WASM_DIR, user, func, "function.wasm") if s3: print("Uploading {}/{} to S3".format(user, func)) s3_key = _get_s3_key(user, func) upload_file_to_s3(func_file, RUNTIME_S3_BUCKET, s3_key) if ibm: print("Uploading {}/{} to IBM cloud storage".format(user, func)) ibm_key = _get_s3_key(user, func) upload_file_to_ibm(func_file, RUNTIME_S3_BUCKET, ibm_key) else: url = "http://{}:{}/f/{}/{}".format(host, port, user, func) curl_file(url, func_file)