Skip to content

Commit

Permalink
feat: static file plugin upload & curl plugin via github resources
Browse files Browse the repository at this point in the history
  • Loading branch information
vanderheijden86 committed May 19, 2024
1 parent 419de32 commit ebbba29
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 27 deletions.
6 changes: 3 additions & 3 deletions args.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}
68 changes: 44 additions & 24 deletions src/node_launcher.star
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)]
)
)
3 changes: 3 additions & 0 deletions src/package_io/input_parser.star
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down

0 comments on commit ebbba29

Please sign in to comment.