diff --git a/main.star b/main.star index 851bc47..8e2df70 100644 --- a/main.star +++ b/main.star @@ -17,6 +17,7 @@ def run(plan, args): dict: Service details containing information about relay chains, parachains, and Prometheus. """ plan.upload_files(src = "./parachain/static_files/configs", name = "configs") + plan.upload_files(src = "./parachain/static_files/javascript", name = "javascript") prometheus_template = read_file("./package_io/static_files/prometheus.yml.tmpl") service_details = {"relaychains": {}, "parachains": {}, "prometheus": ""} @@ -32,7 +33,7 @@ def run(plan, args): service_details["relaychains"] = relay_node_detals final_parachain_detail = [] for paras in args["para"]: - parachain_details={} + parachain_details = {} parachain_details["service_name"] = "parachain_service_" + paras["name"] parachain_details["parachain_name"] = paras["name"] parachain_info = parachain.run_testnet_mainnet(plan, paras, args) @@ -40,12 +41,14 @@ def run(plan, args): final_parachain_detail.append(parachain_details) service_details["parachains"] = final_parachain_detail + #run prometheus , if it returs some endpoint then grafana will up prometheus_address = promethues.launch_prometheus(plan, args, service_details, prometheus_template) - service_details["prometheus"] = prometheus_address - grafana.launch_grafana(plan, grafana) + if prometheus_address.startswith("http://"): + service_details["prometheus"] = prometheus_address + grafana.launch_grafana(plan, grafana) #run the polkadot js App explorer if args["explorer"] == True: - service_details["explorer"] = explorer.run_pokadot_js_app(plan, "wss://127.0.0.1:9944") + service_details["explorer"] = explorer.run_pokadot_js_app(plan, "ws://127.0.0.1:9944") - return service_details \ No newline at end of file + return service_details diff --git a/package_io/promethues.star b/package_io/promethues.star index 0815f23..f09e0e6 100644 --- a/package_io/promethues.star +++ b/package_io/promethues.star @@ -27,6 +27,10 @@ def launch_prometheus( args, service_details, ) + + if len(template_data["MetricsJobs"]) == 0: + return "No Prometheus is available" + template_and_data = shared_utils.new_template_and_data( config_template, template_data, @@ -89,21 +93,21 @@ def new_config_template_data(plan, args, service_details): scrape_interval = "5s", ), ) - + for parachain in args["para"]: for node in parachain["nodes"]: if node["prometheus"] == True: - for para_chain in service_details["parachains"]: + for para_chain in service_details["parachains"]: for para_chain_node in para_chain["nodes"]: service_name = para_chain_node["node_details"].name - string = "{}-{}-{}".format(parachain["name"],node["name"],args["chain-type"]) + string = "{}-{}-{}".format(parachain["name"], node["name"], args["chain-type"]) if string == service_name: ip = para_chain_node["node_details"].ip_address port_number = para_chain_node["node_details"].ports["metrics"].number endpoint = "{0}:{1}".format(ip, port_number) metrics_jobs.append( new_metrics_job( - job_name = "parachain_{}_service_{}".format(parachain["name"],node["name"]), + job_name = "parachain_{}_service_{}".format(parachain["name"], node["name"]), endpoint = endpoint, scrape_interval = "5s", ), diff --git a/parachain/build-spec.star b/parachain/build-spec.star index 1a2c68e..46f5473 100644 --- a/parachain/build-spec.star +++ b/parachain/build-spec.star @@ -7,26 +7,26 @@ def create_parachain_build_spec_with_para_id(plan, image, binary, chain_name, ch "-c", "{0} build-spec --chain={1} --disable-default-bootnode > /tmp/{2}.json".format(binary, chain_base, chain_name), ]) - build_spec.create_edit_and_build_spec(plan, constant.PLAIN_BUILD_SPEC, image, chain_name, command, build_file = None) + build_spec.create_edit_and_build_spec(plan, chain_name + "plain", image, chain_name, command, build_file = None) command = ExecRecipe(command = [ "/bin/sh", "-c", "sed -e 's/\"parachainId\": *[0-9]\\+/\"parachainId\": {0}/' -e 's/\"para_id\": [0-9]*,/\"para_id\": {0},/' -e 's/\"paraId\": [0-9]*,/\"paraId\": {0},/' /build/{1}.json > /tmp/{1}.json".format(para_id, chain_name), ]) - build_spec.create_edit_and_build_spec(plan, constant.EDIT_BUILD_SPEC, constant.CURL_JQ_IMAGE, chain_name, command, constant.PLAIN_BUILD_SPEC) - raw_service = create_raw_build_spec_genisis_state_genisis_wasm(plan, binary, image, chain_name, constant.EDIT_BUILD_SPEC) + build_spec.create_edit_and_build_spec(plan, chain_name + "edit", constant.CURL_JQ_IMAGE, chain_name, command, chain_name + "plain") + raw_service = create_raw_build_spec_genisis_state_genisis_wasm(plan, binary, image, chain_name, chain_name + "edit") return raw_service def create_raw_build_spec_genisis_state_genisis_wasm(plan, binary, image, chain_name, build_file): - raw_service = build_spec.create_service_for_build_spec(plan, constant.RAW_BUILD_SPEC, image, build_file) + raw_service = build_spec.create_service_for_build_spec(plan, chain_name + "raw", image, build_file) command = ExecRecipe(command = [ "/bin/sh", "-c", "{0} build-spec --chain=/build/{1}.json --raw --disable-default-bootnode > /tmp/{1}-raw.json".format(binary, chain_name), ]) - result = plan.exec(service_name = constant.RAW_BUILD_SPEC, recipe = command) + result = plan.exec(service_name = chain_name + "raw", recipe = command) plan.verify(result["code"], "==", 0) command = ExecRecipe(command = [ @@ -34,7 +34,7 @@ def create_raw_build_spec_genisis_state_genisis_wasm(plan, binary, image, chain_ "-c", "{0} export-genesis-wasm --chain=/tmp/{1}-raw.json > /tmp/{1}-genesis-wasm".format(binary, chain_name), ]) - result = plan.exec(service_name = constant.RAW_BUILD_SPEC, recipe = command) + result = plan.exec(service_name = chain_name + "raw", recipe = command) plan.verify(result["code"], "==", 0) command = ExecRecipe(command = [ @@ -42,7 +42,7 @@ def create_raw_build_spec_genisis_state_genisis_wasm(plan, binary, image, chain_ "-c", "{0} export-genesis-state --chain=/tmp/{1}-raw.json > /tmp/{1}-genesis-state".format(binary, chain_name), ]) - result = plan.exec(service_name = constant.RAW_BUILD_SPEC, recipe = command) + result = plan.exec(service_name = chain_name + "raw", recipe = command) plan.verify(result["code"], "==", 0) # command = ExecRecipe(command = [ @@ -50,9 +50,9 @@ def create_raw_build_spec_genisis_state_genisis_wasm(plan, binary, image, chain_ # "-c", # "cp /build/{0}.json /tmp/{0}.json".format(chain_name), # ]) - # plan.exec(service_name = constant.RAW_BUILD_SPEC, recipe = command) + # plan.exec(service_name = chain_name+"raw", recipe = command) - plan.store_service_files(service_name = constant.RAW_BUILD_SPEC, src = "/tmp/*", name = constant.RAW_BUILD_SPEC) - plan.stop_service(constant.RAW_BUILD_SPEC) + plan.store_service_files(service_name = chain_name + "raw", src = "/tmp/*", name = chain_name + "raw") + plan.stop_service(chain_name + "raw") return raw_service diff --git a/parachain/parachain.star b/parachain/parachain.star index 41eb6f3..f5ec8bd 100644 --- a/parachain/parachain.star +++ b/parachain/parachain.star @@ -164,7 +164,7 @@ def run_testnet_mainnet(plan, parachain, args): ] parachain_info = {parachain["name"]: {}} - if parachain == "altair" or "centrifuge": + if parachain["name"] == "altair" or parachain["name"] == "centrifuge": common_command = common_command + ["--database=auto"] if parachain["name"] == "subzero" and args["chain-type"] == "mainnet": diff --git a/parachain/register-para-id.star b/parachain/register-para-id.star index 187a503..44b1928 100644 --- a/parachain/register-para-id.star +++ b/parachain/register-para-id.star @@ -2,7 +2,6 @@ build_spec = import_module("../package_io/build-spec.star") constant = import_module("../package_io/constant.star") def register_para_id(plan, alice_ip): - plan.upload_files(src = "./static_files/javascript", name = "javascript") test = build_spec.create_service_for_build_spec(plan, constant.PARA_SLOT_REGISTER_SERVICE_NAME, constant.NODE_IMAGE, "javascript") result = plan.exec(service_name = test.name, recipe = ExecRecipe(command = ["/bin/sh", "-c", "cd /build && npm i "])) plan.verify(result["code"], "==", 0) @@ -15,12 +14,12 @@ def register_para_id(plan, alice_ip): def onboard_genesis_state_and_wasm(plan, para_id, chain_name, alice_ip): service = plan.add_service( - name = "upload-genesis-file", + name = "upload-{}-genesis-file".format(chain_name), config = ServiceConfig( image = constant.NODE_IMAGE, files = { "/app": "configs", - "/build": constant.RAW_BUILD_SPEC, + "/build": chain_name + "raw", "/javascript": "javascript", }, entrypoint = ["/bin/sh"], diff --git a/relaychain/relay-chain.star b/relaychain/relay-chain.star index 4c00584..77793fa 100644 --- a/relaychain/relay-chain.star +++ b/relaychain/relay-chain.star @@ -11,8 +11,8 @@ def start_relay_chain(plan, args): """ name = args["chain-type"] chain = args["relaychain"]["name"] - final_details=[] - + final_details = [] + prometheus = 9615 for relay_node in args["relaychain"]["nodes"]: port = relay_node["port"] @@ -40,7 +40,6 @@ def start_relay_chain(plan, args): return final_details - def start_test_main_net_relay_nodes(plan, args): """ Starts testnet/mainnet relay nodes based on the provided arguments. @@ -66,7 +65,6 @@ def start_test_main_net_relay_nodes(plan, args): return relay_node_details - def spawn_multiple_relay(plan, count): """ Spawns multiple local relay chain nodes. @@ -81,7 +79,6 @@ def spawn_multiple_relay(plan, count): port = port + count start_relay_chain_local(plan, node_list[i], port) - def start_relay_chains_local(plan, args): """ Starts local relay chain nodes based on the provided arguments. @@ -102,15 +99,14 @@ def start_relay_chains_local(plan, args): prometheus_port = 9615 for node in relay_nodes: relay_detail = {} - service_details = start_relay_chain_local(plan, node["name"], node["port"], prometheus_port) + service_details = start_relay_chain_local(plan, args, node["name"], node["port"], prometheus_port) relay_detail["service_details"] = service_details relay_detail["service_name"] = service_details.name final_details.append(relay_detail) prometheus_port = prometheus_port + 1 return final_details - -def start_relay_chain_local(plan, name, port, prometheus_port): +def start_relay_chain_local(plan, args, name, port, prometheus_port): """ Starts a local relay chain node based on the provided arguments. @@ -125,7 +121,7 @@ def start_relay_chain_local(plan, name, port, prometheus_port): """ exec_command = ["bin/sh", "-c", "polkadot --base-path=/data --chain=/app/raw-polkadot.json --validator --rpc-external --rpc-cors=all --name=alice --{0} --rpc-methods=unsafe --execution=wasm --prometheus-external".format(name)] service_details = plan.add_service( - name = "polkadot-{0}".format(name), + name = "{0}-{1}".format(args["relaychain"]["name"], name), config = ServiceConfig( image = "parity/polkadot:latest", files = {