From 382ac50369c115e40aa6f1e562e772f4e0ee6a46 Mon Sep 17 00:00:00 2001 From: vanderheijden86 Date: Fri, 17 May 2024 23:34:40 +0200 Subject: [PATCH] feat: static file plugin upload & curl plugin via github resources --- args.json | 6 +-- src/node_launcher.star | 68 +++++++++++++++++++++----------- src/package_io/input_parser.star | 3 ++ 3 files changed, 50 insertions(+), 27 deletions(-) diff --git a/args.json b/args.json index 27f0122..f744768 100644 --- a/args.json +++ b/args.json @@ -14,7 +14,7 @@ "min_memory": 0, "vm_name": "testNet", "chain_name": "testChain", - "custom_subnet_vm_path": "/uploaded_plugins/subnet-evm", - "custom_subnet_vm_url": "", - "subnet_genesis_json": "/static_files/genesis.json", + "custom_subnet_vm_path": "", + "custom_subnet_vm_url": "https://github.com/ava-labs/subnet-evm/releases/download/v0.6.4/subnet-evm_0.6.4_linux_amd64.tar.gz", + "subnet_genesis_json": "/static_files/genesis.json", } diff --git a/src/node_launcher.star b/src/node_launcher.star index 3c7b0d6..8c9ebd3 100644 --- a/src/node_launcher.star +++ b/src/node_launcher.star @@ -56,20 +56,31 @@ def launch(plan, genesis, image, node_count, ephemeral_ports, min_cpu, min_memor log_files_cmds = ["touch /tmp/{0}".format(log_file) for log_file in log_files] log_file_cmd = " && ".join(log_files_cmds) - subnet_evm_plugin = plan.upload_files( - "../static_files/subnet-evm") + if custom_subnet_vm_path: + subnet_evm_plugin = plan.upload_files(custom_subnet_vm_path) + # take only dir from custom_subnet_vm_path + plan.print("subnet_evm_plugin: {0}".format(custom_subnet_vm_path)) + # Extract the directory part of the path + last_slash_index = custom_subnet_vm_path.rfind('/') + subnet_evm_plugin_dir = custom_subnet_vm_path[:last_slash_index] + plan.print("subnet_evm_plugin_dir: {0}".format(subnet_evm_plugin_dir)) + node_files = { + "/tmp/data": genesis, + subnet_evm_plugin_dir: subnet_evm_plugin + } + elif custom_subnet_vm_url: + node_files = { + "/tmp/data": genesis + } node_service_config = ServiceConfig( - image = image, - ports = { - "rpc": PortSpec(number = RPC_PORT_NUM, transport_protocol = "TCP", wait = None), - "staking": PortSpec(number = STAKING_PORT_NUM, transport_protocol = "TCP", wait = None) + image=image, + ports={ + "rpc": PortSpec(number=RPC_PORT_NUM, transport_protocol="TCP", wait=None), + "staking": PortSpec(number=STAKING_PORT_NUM, transport_protocol="TCP", wait=None) }, entrypoint=["/bin/sh", "-c", log_file_cmd + " && cd /tmp && tail -F *.log"], - files={ - "/tmp/data": genesis, - "/uploaded_plugins/": subnet_evm_plugin, - }, + files=node_files, public_ports=public_ports, min_cpu=min_cpu, min_memory=min_memory, @@ -100,9 +111,7 @@ def launch(plan, genesis, image, node_count, ephemeral_ports, min_cpu, min_memor if custom_subnet_vm_path: cp(plan, node_name, custom_subnet_vm_path, ABS_PLUGIN_DIRPATH + vmId) elif custom_subnet_vm_url: - download_to_path(plan, custom_subnet_vm_url, ABS_PLUGIN_DIRPATH + vmId) - else: - copy_over_default_plugin(plan, node_name, vmId) + download_to_path_and_untar(plan, node_name, custom_subnet_vm_url, ABS_PLUGIN_DIRPATH + vmId) plan.exec( service_name=node_name, @@ -171,38 +180,49 @@ def wait_for_health(plan, node_name): ) -def copy_over_default_plugin(plan, node_name, vmId): - filename_response = plan.exec( +def cp(plan, node_name, src, dest): + plan.exec( service_name=node_name, recipe=ExecRecipe( - command=["/bin/sh", "-c", "ls {0} | tr -d '\n'".format(ABS_PLUGIN_DIRPATH)] + command=["cp", src, dest] ) ) - default_plugin_name = filename_response["output"] - cp(plan, node_name, ABS_PLUGIN_DIRPATH + default_plugin_name, ABS_PLUGIN_DIRPATH + vmId) -def cp(plan, node_name, src, dest): +def download_to_path_and_untar(plan, node_name, url, dest): + # Install curl plan.exec( service_name=node_name, recipe=ExecRecipe( - command=["cp", src, dest] + command=["/bin/sh", "-c", + "apt update --allow-insecure-repositories && apt-get install curl -y --allow-unauthenticated"] ) ) + # Download the file + download_path = "/static_files/subnet_vm.tar.gz" + plan.print("Downloading {0} to {1}".format(url, download_path)) + plan.exec( + service_name=node_name, + recipe=ExecRecipe( + command=["/bin/sh", "-c", "mkdir -p /static_files/ && curl -L {0} -o {1}".format(url, download_path)] + ) + ) -def download_to_path(plan, node_name, url, dest): + # Untar the downloaded file + plan.print("Untaring {0}".format(download_path)) plan.exec( service_name=node_name, recipe=ExecRecipe( - command=["/bin/sh", "-c", - "apt update --allow-insecure-repositories && apt-get install curl -y --allow-unauthenticated"] + command=["/bin/sh", "-c", "mkdir -p /avalanchego/build/plugins && tar -zxvf {0} -C /static_files/".format(download_path)] ) ) + # Move the extracted binary to the destination + plan.print("Moving extracted binary to {0}".format(dest)) plan.exec( service_name=node_name, recipe=ExecRecipe( - command=["/bin/sh", "-c", "curl {0} -o {1}".format(url, dest)] + command=["/bin/sh", "-c", "mv /static_files/subnet-evm {0}".format(dest)] ) ) \ No newline at end of file diff --git a/src/package_io/input_parser.star b/src/package_io/input_parser.star index d5f895d..60f67b3 100644 --- a/src/package_io/input_parser.star +++ b/src/package_io/input_parser.star @@ -8,6 +8,9 @@ def parse_input(input_args): if result["node_count"] < 2: fail("node_count must be at least 2") result["num_validators"] = result.get("num_validators", result["node_count"]) + # if both custom_subnet_vm_path and custom_subnet_vm_url are provided, throw error + if result["custom_subnet_vm_path"] and result["custom_subnet_vm_url"]: + fail("Only one of custom_subnet_vm_path and custom_subnet_vm_url can be provided") return result