From 3d34cc8cd1440b8f2a97d5578c067e917800fe84 Mon Sep 17 00:00:00 2001 From: A-Harby Date: Mon, 20 May 2024 20:52:46 +0300 Subject: [PATCH 1/8] add the scripts for the applications (peertube, mattermost, funkwhale, casperlabs) --- .../scripts/applications/casberlabs.ts | 142 +++++++++++++++++ .../scripts/applications/funkwhale.ts | 145 +++++++++++++++++ .../scripts/applications/mattermost.ts | 150 ++++++++++++++++++ .../scripts/applications/peertube.ts | 144 +++++++++++++++++ 4 files changed, 581 insertions(+) create mode 100644 packages/grid_client/scripts/applications/casberlabs.ts create mode 100644 packages/grid_client/scripts/applications/funkwhale.ts create mode 100644 packages/grid_client/scripts/applications/mattermost.ts create mode 100644 packages/grid_client/scripts/applications/peertube.ts diff --git a/packages/grid_client/scripts/applications/casberlabs.ts b/packages/grid_client/scripts/applications/casberlabs.ts new file mode 100644 index 0000000000..d2ac562424 --- /dev/null +++ b/packages/grid_client/scripts/applications/casberlabs.ts @@ -0,0 +1,142 @@ +import { FilterOptions, GatewayNameModel, MachinesModel } from "../../src"; +import { config, getClient } from "../client_loader"; +import { log } from "../utils"; + +async function pingNodes(client, nodes) { + for (const node of nodes) { + try { + await client.zos.pingNode({ nodeId: node.nodeId }); + return node.nodeId; + } catch (error) { + console.log("node " + node.nodeId + " is not responding, trying different node."); + } + } + throw new Error("No avaiable nodes"); +} + +async function deploy(client, vms) { + const res = await client.machines.deploy(vms); + log("================= Deploying VM ================="); + log(res); + log("================= Deploying VM ================="); +} + +async function deployGW(client, gw) { + const res = await client.gateway.deploy_name(gw); + log("================= Deploying name gateway ================="); + log(res); + log("================= Deploying name gateway ================="); +} + +async function getDeployment(client, vms) { + const res = await client.machines.getObj(vms); + log("================= Getting deployment information ================="); + log(res); + log("================= Getting deployment information ================="); + return res; +} + +async function getDeploymentGW(client, gw) { + const res = await client.gateway.getObj(gw); + log("================= Getting deployment information ================="); + log(res); + log("================= Getting deployment information ================="); + return res; +} + +async function cancel(client, vms, gw) { + const resvm = await client.machines.delete(vms); + const resgw = await client.gateway.delete_name(gw); + log("================= Canceling the deployment ================="); + log(resvm); + log(resgw); + log("================= Canceling the deployment ================="); +} + +async function main() { + const name = "newcasperlabs"; + const grid3 = await getClient(`casperlabs/${name}`); + const subdomain = "cl" + grid3.twinId + name; + + //VMNode Selection + const vmQueryOptions: FilterOptions = { + cru: 2, + mru: 4, + sru: 50, + availableFor: grid3.twinId, + farmId: 1, + }; + //GatewayNode Selection + const gatewayQueryOptions: FilterOptions = { + gateway: true, + availableFor: grid3.twinId, + }; + const gatewayNode = (await grid3.capacity.filterNodes(gatewayQueryOptions))[0]; + + const vms: MachinesModel = { + name, + network: { + name: "wedtest", + ip_range: "10.249.0.0/16", + }, + machines: [ + { + name: "casperlabs", + node_id: +(await pingNodes(grid3, await grid3.capacity.filterNodes(vmQueryOptions))), + disks: [ + { + name: "wedDisk", + size: 50, + mountpoint: "/data", + }, + ], + planetary: true, + public_ip: false, + public_ip6: false, + mycelium: false, + cpu: 2, + memory: 1024 * 4, + rootfs_size: 0, + flist: "https://hub.grid.tf/tf-official-apps/casperlabs-latest.flist", + entrypoint: "/sbin/zinit init", + env: { + SSH_KEY: config.ssh_key, + CASPERLABS_HOSTNAME: subdomain + "." + gatewayNode.publicConfig.domain, + }, + }, + ], + metadata: "", + description: "test deploying CasberLabs via ts grid3 client", + }; + + //Deploy VMs + await deploy(grid3, vms); + + //Get the deployment + const result = await getDeployment(grid3, name); + + //Name Gateway Model + const gw: GatewayNameModel = { + name: subdomain, + node_id: gatewayNode.nodeId, + tls_passthrough: false, + backends: ["http://[" + result[0].planetary + "]:80"], + }; + + //Deploy gateway + await deployGW(grid3, gw); + + //Get the deployment + const gatewayResult = await getDeploymentGW(grid3, gw.name); + + //Get the site link + const domain = "https://" + gatewayResult[0].domain; + log(domain); + + //Uncomment the line below to cancel the deployment + // await cancel(grid3, { name }, { name: subdomain }); + + await grid3.disconnect(); +} + +main(); diff --git a/packages/grid_client/scripts/applications/funkwhale.ts b/packages/grid_client/scripts/applications/funkwhale.ts new file mode 100644 index 0000000000..8b41a893c7 --- /dev/null +++ b/packages/grid_client/scripts/applications/funkwhale.ts @@ -0,0 +1,145 @@ +import { FilterOptions, GatewayNameModel, MachinesModel } from "../../src"; +import { config, getClient } from "../client_loader"; +import { log } from "../utils"; + +async function pingNodes(client, nodes) { + for (const node of nodes) { + try { + await client.zos.pingNode({ nodeId: node.nodeId }); + return node.nodeId; + } catch (error) { + console.log("node " + node.nodeId + " is not responding, trying different node."); + } + } + throw new Error("No avaiable nodes"); +} + +async function deploy(client, vms) { + const res = await client.machines.deploy(vms); + log("================= Deploying VM ================="); + log(res); + log("================= Deploying VM ================="); +} + +async function deployGW(client, gw) { + const res = await client.gateway.deploy_name(gw); + log("================= Deploying name gateway ================="); + log(res); + log("================= Deploying name gateway ================="); +} + +async function getDeployment(client, vms) { + const res = await client.machines.getObj(vms); + log("================= Getting deployment information ================="); + log(res); + log("================= Getting deployment information ================="); + return res; +} + +async function getDeploymentGW(client, gw) { + const res = await client.gateway.getObj(gw); + log("================= Getting deployment information ================="); + log(res); + log("================= Getting deployment information ================="); + return res; +} + +async function cancel(client, vms, gw) { + const resvm = await client.machines.delete(vms); + const resgw = await client.gateway.delete_name(gw); + log("================= Canceling the deployment ================="); + log(resvm); + log(resgw); + log("================= Canceling the deployment ================="); +} + +async function main() { + const name = "newfunkwhale"; + const grid3 = await getClient(`funkwhale/${name}`); + const subdomain = "fw" + grid3.twinId + name; + + //VMNode Selection + const vmQueryOptions: FilterOptions = { + cru: 1, + mru: 2, + sru: 50, + availableFor: grid3.twinId, + farmId: 1, + }; + //GatewayNode Selection + const gatewayQueryOptions: FilterOptions = { + gateway: true, + availableFor: grid3.twinId, + }; + const gatewayNode = (await grid3.capacity.filterNodes(gatewayQueryOptions))[0]; + + const vms: MachinesModel = { + name, + network: { + name: "wedtest", + ip_range: "10.249.0.0/16", + }, + machines: [ + { + name: "funkwhale", + node_id: +(await pingNodes(grid3, await grid3.capacity.filterNodes(vmQueryOptions))), + disks: [ + { + name: "wedDisk", + size: 50, + mountpoint: "/data", + }, + ], + planetary: true, + public_ip: false, + public_ip6: false, + mycelium: false, + cpu: 1, + memory: 1024 * 2, + rootfs_size: 0, + flist: "https://hub.grid.tf/tf-official-apps/funkwhale-dec21.flist", + entrypoint: "/init.sh", + env: { + SSH_KEY: config.ssh_key, + FUNKWHALE_HOSTNAME: subdomain + "." + gatewayNode.publicConfig.domain, + DJANGO_SUPERUSER_EMAIL: "admin123@funk.whale", // edit me + DJANGO_SUPERUSER_USERNAME: "admin123", // edit me + DJANGO_SUPERUSER_PASSWORD: "admin123", // edit me + }, + }, + ], + metadata: "", + description: "test deploying FunkWhale via ts grid3 client", + }; + + //Deploy VMs + await deploy(grid3, vms); + + //Get the deployment + const result = await getDeployment(grid3, name); + + //Name Gateway Model + const gw: GatewayNameModel = { + name: subdomain, + node_id: gatewayNode.nodeId, + tls_passthrough: false, + backends: ["http://[" + result[0].planetary + "]:80"], + }; + + //Deploy gateway + await deployGW(grid3, gw); + + //Get the deployment + const gatewayResult = await getDeploymentGW(grid3, gw.name); + + //Get the site link + const domain = "https://" + gatewayResult[0].domain; + log(domain); + + //Uncomment the line below to cancel the deployment + // await cancel(grid3, { name }, { name: subdomain }); + + await grid3.disconnect(); +} + +main(); diff --git a/packages/grid_client/scripts/applications/mattermost.ts b/packages/grid_client/scripts/applications/mattermost.ts new file mode 100644 index 0000000000..3fe51abc59 --- /dev/null +++ b/packages/grid_client/scripts/applications/mattermost.ts @@ -0,0 +1,150 @@ +import { FilterOptions, GatewayNameModel, MachinesModel } from "../../src"; +import { config, getClient } from "../client_loader"; +import { log } from "../utils"; + +async function pingNodes(client, nodes) { + for (const node of nodes) { + try { + await client.zos.pingNode({ nodeId: node.nodeId }); + return node.nodeId; + } catch (error) { + console.log("node " + node.nodeId + " is not responding, trying different node."); + } + } + throw new Error("No avaiable nodes"); +} + +async function deploy(client, vms) { + const res = await client.machines.deploy(vms); + log("================= Deploying VM ================="); + log(res); + log("================= Deploying VM ================="); +} + +async function deployGW(client, gw) { + const res = await client.gateway.deploy_name(gw); + log("================= Deploying name gateway ================="); + log(res); + log("================= Deploying name gateway ================="); +} + +async function getDeployment(client, vms) { + const res = await client.machines.getObj(vms); + log("================= Getting deployment information ================="); + log(res); + log("================= Getting deployment information ================="); + return res; +} + +async function getDeploymentGW(client, gw) { + const res = await client.gateway.getObj(gw); + log("================= Getting deployment information ================="); + log(res); + log("================= Getting deployment information ================="); + return res; +} + +async function cancel(client, vms, gw) { + const resvm = await client.machines.delete(vms); + const resgw = await client.gateway.delete_name(gw); + log("================= Canceling the deployment ================="); + log(resvm); + log(resgw); + log("================= Canceling the deployment ================="); +} + +async function main() { + const name = "newmattermost"; + const grid3 = await getClient(`mattermost/${name}`); + const subdomain = "mm" + grid3.twinId + name; + + //VMNode Selection + const vmQueryOptions: FilterOptions = { + cru: 1, + mru: 2, + sru: 50, + availableFor: grid3.twinId, + farmId: 1, + }; + //GatewayNode Selection + const gatewayQueryOptions: FilterOptions = { + gateway: true, + availableFor: grid3.twinId, + }; + const gatewayNode = (await grid3.capacity.filterNodes(gatewayQueryOptions))[0]; + + const vms: MachinesModel = { + name, + network: { + name: "wedtest", + ip_range: "10.249.0.0/16", + }, + machines: [ + { + name: "mattermost", + node_id: +(await pingNodes(grid3, await grid3.capacity.filterNodes(vmQueryOptions))), + disks: [ + { + name: "wedDisk", + size: 50, + mountpoint: "/var/lib/docker", + }, + ], + planetary: true, + public_ip: false, + public_ip6: false, + mycelium: false, + cpu: 1, + memory: 1024 * 2, + rootfs_size: 0, + flist: "https://hub.grid.tf/tf-official-apps/mattermost-latest.flist", + entrypoint: "/sbin/zinit init", + env: { + SSH_KEY: config.ssh_key, + MATTERMOST_DOMAIN: subdomain + "." + gatewayNode.publicConfig.domain, + SITE_URL: "https://" + subdomain + "." + gatewayNode.publicConfig.domain, + DJANGO_SUPERUSER_EMAIL: "admin123@matter.most", // edit me + DB_PASSWORD: "admin123", // edit me + // Optional + // SMTPUsername: "username", + // SMTPPassword: "password", + // SMTPServer: "hostname", + // SMTPPort: "port", + }, + }, + ], + metadata: "", + description: "test deploying MatterMost via ts grid3 client", + }; + + //Deploy VMs + await deploy(grid3, vms); + + //Get the deployment + const result = await getDeployment(grid3, name); + + //Name Gateway Model + const gw: GatewayNameModel = { + name: subdomain, + node_id: gatewayNode.nodeId, + tls_passthrough: false, + backends: ["http://[" + result[0].planetary + "]:8000"], + }; + + //Deploy gateway + await deployGW(grid3, gw); + + //Get the deployment + const gatewayResult = await getDeploymentGW(grid3, gw.name); + + //Get the site link + const domain = "https://" + gatewayResult[0].domain; + log(domain); + + //Uncomment the line below to cancel the deployment + // await cancel(grid3, { name }, { name: subdomain }); + + await grid3.disconnect(); +} + +main(); diff --git a/packages/grid_client/scripts/applications/peertube.ts b/packages/grid_client/scripts/applications/peertube.ts new file mode 100644 index 0000000000..7b1161de00 --- /dev/null +++ b/packages/grid_client/scripts/applications/peertube.ts @@ -0,0 +1,144 @@ +import { FilterOptions, GatewayNameModel, MachinesModel } from "../../src"; +import { config, getClient } from "../client_loader"; +import { log } from "../utils"; + +async function pingNodes(client, nodes) { + for (const node of nodes) { + try { + await client.zos.pingNode({ nodeId: node.nodeId }); + return node.nodeId; + } catch (error) { + console.log("node " + node.nodeId + " is not responding, trying different node."); + } + } + throw new Error("No avaiable nodes"); +} + +async function deploy(client, vms) { + const res = await client.machines.deploy(vms); + log("================= Deploying VM ================="); + log(res); + log("================= Deploying VM ================="); +} + +async function deployGW(client, gw) { + const res = await client.gateway.deploy_name(gw); + log("================= Deploying name gateway ================="); + log(res); + log("================= Deploying name gateway ================="); +} + +async function getDeployment(client, vms) { + const res = await client.machines.getObj(vms); + log("================= Getting deployment information ================="); + log(res); + log("================= Getting deployment information ================="); + return res; +} + +async function getDeploymentGW(client, gw) { + const res = await client.gateway.getObj(gw); + log("================= Getting deployment information ================="); + log(res); + log("================= Getting deployment information ================="); + return res; +} + +async function cancel(client, vms, gw) { + const resvm = await client.machines.delete(vms); + const resgw = await client.gateway.delete_name(gw); + log("================= Canceling the deployment ================="); + log(resvm); + log(resgw); + log("================= Canceling the deployment ================="); +} + +async function main() { + const name = "newpeertube"; + const grid3 = await getClient(`peertube/${name}`); + const subdomain = "pt" + grid3.twinId + name; + + //VMNode Selection + const vmQueryOptions: FilterOptions = { + cru: 1, + mru: 2, + sru: 50, + availableFor: grid3.twinId, + farmId: 1, + }; + //GatewayNode Selection + const gatewayQueryOptions: FilterOptions = { + gateway: true, + availableFor: grid3.twinId, + }; + const gatewayNode = (await grid3.capacity.filterNodes(gatewayQueryOptions))[0]; + + const vms: MachinesModel = { + name, + network: { + name: "wedtest", + ip_range: "10.249.0.0/16", + }, + machines: [ + { + name: "peertube", + node_id: +(await pingNodes(grid3, await grid3.capacity.filterNodes(vmQueryOptions))), + disks: [ + { + name: "wedDisk", + size: 50, + mountpoint: "/data", + }, + ], + planetary: true, + public_ip: false, + public_ip6: false, + mycelium: false, + cpu: 1, + memory: 1024 * 2, + rootfs_size: 0, + flist: "https://hub.grid.tf/tf-official-apps/peertube-v3.1.1.flist", + entrypoint: "/sbin/zinit init", + env: { + SSH_KEY: config.ssh_key, + PEERTUBE_WEBSERVER_HOSTNAME: subdomain + "." + gatewayNode.publicConfig.domain, + PEERTUBE_ADMIN_EMAIL: "admin123@peer.tube", // edit me + PT_INITIAL_ROOT_PASSWORD: "admin123", // edit me + }, + }, + ], + metadata: "", + description: "test deploying PeerTube via ts grid3 client", + }; + + //Deploy VMs + await deploy(grid3, vms); + + //Get the deployment + const result = await getDeployment(grid3, name); + + //Name Gateway Model + const gw: GatewayNameModel = { + name: subdomain, + node_id: gatewayNode.nodeId, + tls_passthrough: false, + backends: ["http://[" + result[0].planetary + "]:9000"], + }; + + //Deploy gateway + await deployGW(grid3, gw); + + //Get the deployment + const gatewayResult = await getDeploymentGW(grid3, gw.name); + + //Get the site link + const domain = "https://" + gatewayResult[0].domain; + log(domain); + + //Uncomment the line below to cancel the deployment + // await cancel(grid3, { name }, { name: subdomain }); + + await grid3.disconnect(); +} + +main(); From a9c49f7efe6ebbf79a5e2cefa8e7a2c107864b26 Mon Sep 17 00:00:00 2001 From: A-Harby Date: Tue, 21 May 2024 12:14:39 +0300 Subject: [PATCH 2/8] improve code --- .../scripts/applications/casberlabs.ts | 63 +++++++------------ .../scripts/applications/funkwhale.ts | 61 +++++++----------- .../scripts/applications/mattermost.ts | 61 +++++++----------- .../scripts/applications/peertube.ts | 61 +++++++----------- 4 files changed, 89 insertions(+), 157 deletions(-) diff --git a/packages/grid_client/scripts/applications/casberlabs.ts b/packages/grid_client/scripts/applications/casberlabs.ts index d2ac562424..a5dca4b131 100644 --- a/packages/grid_client/scripts/applications/casberlabs.ts +++ b/packages/grid_client/scripts/applications/casberlabs.ts @@ -8,40 +8,41 @@ async function pingNodes(client, nodes) { await client.zos.pingNode({ nodeId: node.nodeId }); return node.nodeId; } catch (error) { - console.log("node " + node.nodeId + " is not responding, trying different node."); + throw new Error("node " + node.nodeId + " is not responding, trying different node."); } } throw new Error("No avaiable nodes"); } -async function deploy(client, vms) { - const res = await client.machines.deploy(vms); +async function deploy(client, vms, subdomain, gatewayNode) { + const resultVM = await client.machines.deploy(vms); log("================= Deploying VM ================="); - log(res); + log(resultVM); log("================= Deploying VM ================="); -} -async function deployGW(client, gw) { - const res = await client.gateway.deploy_name(gw); + const vmPlanetary = (await client.machines.getObj(vms.name))[0].planetary; + //Name Gateway Model + const gw: GatewayNameModel = { + name: subdomain, + node_id: gatewayNode.nodeId, + tls_passthrough: false, + backends: ["http://[" + vmPlanetary + "]:80"], + }; + + const resultGateway = await client.gateway.deploy_name(gw); log("================= Deploying name gateway ================="); - log(res); + log(resultGateway); log("================= Deploying name gateway ================="); } -async function getDeployment(client, vms) { - const res = await client.machines.getObj(vms); - log("================= Getting deployment information ================="); - log(res); - log("================= Getting deployment information ================="); - return res; -} - -async function getDeploymentGW(client, gw) { - const res = await client.gateway.getObj(gw); +async function getDeployment(client, vms, gw) { + const resultVM = await client.machines.getObj(vms.name); + const resultGateway = await client.gateway.getObj(gw); log("================= Getting deployment information ================="); - log(res); + log(resultVM); + log(resultGateway); + log("https://" + resultGateway[0].domain); log("================= Getting deployment information ================="); - return res; } async function cancel(client, vms, gw) { @@ -110,28 +111,10 @@ async function main() { }; //Deploy VMs - await deploy(grid3, vms); + await deploy(grid3, vms, subdomain, gatewayNode); //Get the deployment - const result = await getDeployment(grid3, name); - - //Name Gateway Model - const gw: GatewayNameModel = { - name: subdomain, - node_id: gatewayNode.nodeId, - tls_passthrough: false, - backends: ["http://[" + result[0].planetary + "]:80"], - }; - - //Deploy gateway - await deployGW(grid3, gw); - - //Get the deployment - const gatewayResult = await getDeploymentGW(grid3, gw.name); - - //Get the site link - const domain = "https://" + gatewayResult[0].domain; - log(domain); + await getDeployment(grid3, vms, subdomain); //Uncomment the line below to cancel the deployment // await cancel(grid3, { name }, { name: subdomain }); diff --git a/packages/grid_client/scripts/applications/funkwhale.ts b/packages/grid_client/scripts/applications/funkwhale.ts index 8b41a893c7..4c80beccd5 100644 --- a/packages/grid_client/scripts/applications/funkwhale.ts +++ b/packages/grid_client/scripts/applications/funkwhale.ts @@ -14,34 +14,35 @@ async function pingNodes(client, nodes) { throw new Error("No avaiable nodes"); } -async function deploy(client, vms) { - const res = await client.machines.deploy(vms); +async function deploy(client, vms, subdomain, gatewayNode) { + const resultVM = await client.machines.deploy(vms); log("================= Deploying VM ================="); - log(res); + log(resultVM); log("================= Deploying VM ================="); -} -async function deployGW(client, gw) { - const res = await client.gateway.deploy_name(gw); + const vmPlanetary = (await client.machines.getObj(vms.name))[0].planetary; + //Name Gateway Model + const gw: GatewayNameModel = { + name: subdomain, + node_id: gatewayNode.nodeId, + tls_passthrough: false, + backends: ["http://[" + vmPlanetary + "]:80"], + }; + + const resultGateway = await client.gateway.deploy_name(gw); log("================= Deploying name gateway ================="); - log(res); + log(resultGateway); log("================= Deploying name gateway ================="); } -async function getDeployment(client, vms) { - const res = await client.machines.getObj(vms); - log("================= Getting deployment information ================="); - log(res); - log("================= Getting deployment information ================="); - return res; -} - -async function getDeploymentGW(client, gw) { - const res = await client.gateway.getObj(gw); +async function getDeployment(client, vms, gw) { + const resultVM = await client.machines.getObj(vms.name); + const resultGateway = await client.gateway.getObj(gw); log("================= Getting deployment information ================="); - log(res); + log(resultVM); + log(resultGateway); + log("https://" + resultGateway[0].domain); log("================= Getting deployment information ================="); - return res; } async function cancel(client, vms, gw) { @@ -113,28 +114,10 @@ async function main() { }; //Deploy VMs - await deploy(grid3, vms); + await deploy(grid3, vms, subdomain, gatewayNode); //Get the deployment - const result = await getDeployment(grid3, name); - - //Name Gateway Model - const gw: GatewayNameModel = { - name: subdomain, - node_id: gatewayNode.nodeId, - tls_passthrough: false, - backends: ["http://[" + result[0].planetary + "]:80"], - }; - - //Deploy gateway - await deployGW(grid3, gw); - - //Get the deployment - const gatewayResult = await getDeploymentGW(grid3, gw.name); - - //Get the site link - const domain = "https://" + gatewayResult[0].domain; - log(domain); + await getDeployment(grid3, vms, subdomain); //Uncomment the line below to cancel the deployment // await cancel(grid3, { name }, { name: subdomain }); diff --git a/packages/grid_client/scripts/applications/mattermost.ts b/packages/grid_client/scripts/applications/mattermost.ts index 3fe51abc59..89b543e1a2 100644 --- a/packages/grid_client/scripts/applications/mattermost.ts +++ b/packages/grid_client/scripts/applications/mattermost.ts @@ -14,34 +14,35 @@ async function pingNodes(client, nodes) { throw new Error("No avaiable nodes"); } -async function deploy(client, vms) { - const res = await client.machines.deploy(vms); +async function deploy(client, vms, subdomain, gatewayNode) { + const resultVM = await client.machines.deploy(vms); log("================= Deploying VM ================="); - log(res); + log(resultVM); log("================= Deploying VM ================="); -} -async function deployGW(client, gw) { - const res = await client.gateway.deploy_name(gw); + const vmPlanetary = (await client.machines.getObj(vms.name))[0].planetary; + //Name Gateway Model + const gw: GatewayNameModel = { + name: subdomain, + node_id: gatewayNode.nodeId, + tls_passthrough: false, + backends: ["http://[" + vmPlanetary + "]:8000"], + }; + + const resultGateway = await client.gateway.deploy_name(gw); log("================= Deploying name gateway ================="); - log(res); + log(resultGateway); log("================= Deploying name gateway ================="); } -async function getDeployment(client, vms) { - const res = await client.machines.getObj(vms); - log("================= Getting deployment information ================="); - log(res); - log("================= Getting deployment information ================="); - return res; -} - -async function getDeploymentGW(client, gw) { - const res = await client.gateway.getObj(gw); +async function getDeployment(client, vms, gw) { + const resultVM = await client.machines.getObj(vms.name); + const resultGateway = await client.gateway.getObj(gw); log("================= Getting deployment information ================="); - log(res); + log(resultVM); + log(resultGateway); + log("https://" + resultGateway[0].domain); log("================= Getting deployment information ================="); - return res; } async function cancel(client, vms, gw) { @@ -118,28 +119,10 @@ async function main() { }; //Deploy VMs - await deploy(grid3, vms); + await deploy(grid3, vms, subdomain, gatewayNode); //Get the deployment - const result = await getDeployment(grid3, name); - - //Name Gateway Model - const gw: GatewayNameModel = { - name: subdomain, - node_id: gatewayNode.nodeId, - tls_passthrough: false, - backends: ["http://[" + result[0].planetary + "]:8000"], - }; - - //Deploy gateway - await deployGW(grid3, gw); - - //Get the deployment - const gatewayResult = await getDeploymentGW(grid3, gw.name); - - //Get the site link - const domain = "https://" + gatewayResult[0].domain; - log(domain); + await getDeployment(grid3, vms, subdomain); //Uncomment the line below to cancel the deployment // await cancel(grid3, { name }, { name: subdomain }); diff --git a/packages/grid_client/scripts/applications/peertube.ts b/packages/grid_client/scripts/applications/peertube.ts index 7b1161de00..5a39f7beae 100644 --- a/packages/grid_client/scripts/applications/peertube.ts +++ b/packages/grid_client/scripts/applications/peertube.ts @@ -14,34 +14,35 @@ async function pingNodes(client, nodes) { throw new Error("No avaiable nodes"); } -async function deploy(client, vms) { - const res = await client.machines.deploy(vms); +async function deploy(client, vms, subdomain, gatewayNode) { + const resultVM = await client.machines.deploy(vms); log("================= Deploying VM ================="); - log(res); + log(resultVM); log("================= Deploying VM ================="); -} -async function deployGW(client, gw) { - const res = await client.gateway.deploy_name(gw); + const vmPlanetary = (await client.machines.getObj(vms.name))[0].planetary; + //Name Gateway Model + const gw: GatewayNameModel = { + name: subdomain, + node_id: gatewayNode.nodeId, + tls_passthrough: false, + backends: ["http://[" + vmPlanetary + "]:9000"], + }; + + const resultGateway = await client.gateway.deploy_name(gw); log("================= Deploying name gateway ================="); - log(res); + log(resultGateway); log("================= Deploying name gateway ================="); } -async function getDeployment(client, vms) { - const res = await client.machines.getObj(vms); - log("================= Getting deployment information ================="); - log(res); - log("================= Getting deployment information ================="); - return res; -} - -async function getDeploymentGW(client, gw) { - const res = await client.gateway.getObj(gw); +async function getDeployment(client, vms, gw) { + const resultVM = await client.machines.getObj(vms.name); + const resultGateway = await client.gateway.getObj(gw); log("================= Getting deployment information ================="); - log(res); + log(resultVM); + log(resultGateway); + log("https://" + resultGateway[0].domain); log("================= Getting deployment information ================="); - return res; } async function cancel(client, vms, gw) { @@ -112,28 +113,10 @@ async function main() { }; //Deploy VMs - await deploy(grid3, vms); + await deploy(grid3, vms, subdomain, gatewayNode); //Get the deployment - const result = await getDeployment(grid3, name); - - //Name Gateway Model - const gw: GatewayNameModel = { - name: subdomain, - node_id: gatewayNode.nodeId, - tls_passthrough: false, - backends: ["http://[" + result[0].planetary + "]:9000"], - }; - - //Deploy gateway - await deployGW(grid3, gw); - - //Get the deployment - const gatewayResult = await getDeploymentGW(grid3, gw.name); - - //Get the site link - const domain = "https://" + gatewayResult[0].domain; - log(domain); + await getDeployment(grid3, vms, subdomain); //Uncomment the line below to cancel the deployment // await cancel(grid3, { name }, { name: subdomain }); From 2d4e4cf22f2353ba90261ec5622a815484406489 Mon Sep 17 00:00:00 2001 From: A-Harby Date: Tue, 21 May 2024 12:16:19 +0300 Subject: [PATCH 3/8] add throw error instead of log --- packages/grid_client/scripts/applications/funkwhale.ts | 2 +- packages/grid_client/scripts/applications/mattermost.ts | 2 +- packages/grid_client/scripts/applications/peertube.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/grid_client/scripts/applications/funkwhale.ts b/packages/grid_client/scripts/applications/funkwhale.ts index 4c80beccd5..3113e5bd25 100644 --- a/packages/grid_client/scripts/applications/funkwhale.ts +++ b/packages/grid_client/scripts/applications/funkwhale.ts @@ -8,7 +8,7 @@ async function pingNodes(client, nodes) { await client.zos.pingNode({ nodeId: node.nodeId }); return node.nodeId; } catch (error) { - console.log("node " + node.nodeId + " is not responding, trying different node."); + throw new Error("node " + node.nodeId + " is not responding, trying different node."); } } throw new Error("No avaiable nodes"); diff --git a/packages/grid_client/scripts/applications/mattermost.ts b/packages/grid_client/scripts/applications/mattermost.ts index 89b543e1a2..b55201db0a 100644 --- a/packages/grid_client/scripts/applications/mattermost.ts +++ b/packages/grid_client/scripts/applications/mattermost.ts @@ -8,7 +8,7 @@ async function pingNodes(client, nodes) { await client.zos.pingNode({ nodeId: node.nodeId }); return node.nodeId; } catch (error) { - console.log("node " + node.nodeId + " is not responding, trying different node."); + throw new Error("node " + node.nodeId + " is not responding, trying different node."); } } throw new Error("No avaiable nodes"); diff --git a/packages/grid_client/scripts/applications/peertube.ts b/packages/grid_client/scripts/applications/peertube.ts index 5a39f7beae..7a610caf9e 100644 --- a/packages/grid_client/scripts/applications/peertube.ts +++ b/packages/grid_client/scripts/applications/peertube.ts @@ -8,7 +8,7 @@ async function pingNodes(client, nodes) { await client.zos.pingNode({ nodeId: node.nodeId }); return node.nodeId; } catch (error) { - console.log("node " + node.nodeId + " is not responding, trying different node."); + throw new Error("node " + node.nodeId + " is not responding, trying different node."); } } throw new Error("No avaiable nodes"); From 02184e6e51d2a233a10b5340bdffd3e423a7fee4 Mon Sep 17 00:00:00 2001 From: A-Harby Date: Tue, 21 May 2024 12:50:48 +0300 Subject: [PATCH 4/8] add pingnode to utils --- .../scripts/applications/casberlabs.ts | 18 +++--------------- .../scripts/applications/funkwhale.ts | 14 +------------- .../scripts/applications/mattermost.ts | 14 +------------- .../scripts/applications/peertube.ts | 14 +------------- packages/grid_client/scripts/utils.ts | 15 ++++++++++++++- 5 files changed, 20 insertions(+), 55 deletions(-) diff --git a/packages/grid_client/scripts/applications/casberlabs.ts b/packages/grid_client/scripts/applications/casberlabs.ts index a5dca4b131..7e0077d08d 100644 --- a/packages/grid_client/scripts/applications/casberlabs.ts +++ b/packages/grid_client/scripts/applications/casberlabs.ts @@ -1,18 +1,6 @@ import { FilterOptions, GatewayNameModel, MachinesModel } from "../../src"; import { config, getClient } from "../client_loader"; -import { log } from "../utils"; - -async function pingNodes(client, nodes) { - for (const node of nodes) { - try { - await client.zos.pingNode({ nodeId: node.nodeId }); - return node.nodeId; - } catch (error) { - throw new Error("node " + node.nodeId + " is not responding, trying different node."); - } - } - throw new Error("No avaiable nodes"); -} +import { log, pingNodes } from "../utils"; async function deploy(client, vms, subdomain, gatewayNode) { const resultVM = await client.machines.deploy(vms); @@ -63,7 +51,7 @@ async function main() { const vmQueryOptions: FilterOptions = { cru: 2, mru: 4, - sru: 50, + sru: 100, availableFor: grid3.twinId, farmId: 1, }; @@ -87,7 +75,7 @@ async function main() { disks: [ { name: "wedDisk", - size: 50, + size: 100, mountpoint: "/data", }, ], diff --git a/packages/grid_client/scripts/applications/funkwhale.ts b/packages/grid_client/scripts/applications/funkwhale.ts index 3113e5bd25..1a7d2da248 100644 --- a/packages/grid_client/scripts/applications/funkwhale.ts +++ b/packages/grid_client/scripts/applications/funkwhale.ts @@ -1,18 +1,6 @@ import { FilterOptions, GatewayNameModel, MachinesModel } from "../../src"; import { config, getClient } from "../client_loader"; -import { log } from "../utils"; - -async function pingNodes(client, nodes) { - for (const node of nodes) { - try { - await client.zos.pingNode({ nodeId: node.nodeId }); - return node.nodeId; - } catch (error) { - throw new Error("node " + node.nodeId + " is not responding, trying different node."); - } - } - throw new Error("No avaiable nodes"); -} +import { log, pingNodes } from "../utils"; async function deploy(client, vms, subdomain, gatewayNode) { const resultVM = await client.machines.deploy(vms); diff --git a/packages/grid_client/scripts/applications/mattermost.ts b/packages/grid_client/scripts/applications/mattermost.ts index b55201db0a..952350c018 100644 --- a/packages/grid_client/scripts/applications/mattermost.ts +++ b/packages/grid_client/scripts/applications/mattermost.ts @@ -1,18 +1,6 @@ import { FilterOptions, GatewayNameModel, MachinesModel } from "../../src"; import { config, getClient } from "../client_loader"; -import { log } from "../utils"; - -async function pingNodes(client, nodes) { - for (const node of nodes) { - try { - await client.zos.pingNode({ nodeId: node.nodeId }); - return node.nodeId; - } catch (error) { - throw new Error("node " + node.nodeId + " is not responding, trying different node."); - } - } - throw new Error("No avaiable nodes"); -} +import { log, pingNodes } from "../utils"; async function deploy(client, vms, subdomain, gatewayNode) { const resultVM = await client.machines.deploy(vms); diff --git a/packages/grid_client/scripts/applications/peertube.ts b/packages/grid_client/scripts/applications/peertube.ts index 7a610caf9e..e956089132 100644 --- a/packages/grid_client/scripts/applications/peertube.ts +++ b/packages/grid_client/scripts/applications/peertube.ts @@ -1,18 +1,6 @@ import { FilterOptions, GatewayNameModel, MachinesModel } from "../../src"; import { config, getClient } from "../client_loader"; -import { log } from "../utils"; - -async function pingNodes(client, nodes) { - for (const node of nodes) { - try { - await client.zos.pingNode({ nodeId: node.nodeId }); - return node.nodeId; - } catch (error) { - throw new Error("node " + node.nodeId + " is not responding, trying different node."); - } - } - throw new Error("No avaiable nodes"); -} +import { log, pingNodes } from "../utils"; async function deploy(client, vms, subdomain, gatewayNode) { const resultVM = await client.machines.deploy(vms); diff --git a/packages/grid_client/scripts/utils.ts b/packages/grid_client/scripts/utils.ts index 859c78998c..a417a6e8b6 100644 --- a/packages/grid_client/scripts/utils.ts +++ b/packages/grid_client/scripts/utils.ts @@ -3,4 +3,17 @@ import { inspect } from "util"; function log(message) { console.log(inspect(message, { showHidden: false, depth: null, colors: true })); } -export { log }; + +async function pingNodes(client, nodes) { + for (const node of nodes) { + try { + await client.zos.pingNode({ nodeId: node.nodeId }); + return node.nodeId; + } catch (error) { + log("node " + node.nodeId + " is not responding, trying different node."); + } + } + throw new Error("No avaiable nodes"); +} + +export { log, pingNodes }; From 984d09b43246c6742a605d020a4a10e24ffe6584 Mon Sep 17 00:00:00 2001 From: A-Harby Date: Tue, 21 May 2024 15:26:41 +0300 Subject: [PATCH 5/8] add docstrings and improve code --- .../scripts/applications/casberlabs.ts | 12 ++++++----- .../scripts/applications/funkwhale.ts | 19 ++++++++++-------- .../scripts/applications/mattermost.ts | 20 +++++++++++-------- .../scripts/applications/peertube.ts | 17 +++++++++------- packages/grid_client/scripts/utils.ts | 17 ++++++++++++++-- 5 files changed, 55 insertions(+), 30 deletions(-) diff --git a/packages/grid_client/scripts/applications/casberlabs.ts b/packages/grid_client/scripts/applications/casberlabs.ts index 7e0077d08d..fb82f7f2c8 100644 --- a/packages/grid_client/scripts/applications/casberlabs.ts +++ b/packages/grid_client/scripts/applications/casberlabs.ts @@ -34,11 +34,11 @@ async function getDeployment(client, vms, gw) { } async function cancel(client, vms, gw) { - const resvm = await client.machines.delete(vms); - const resgw = await client.gateway.delete_name(gw); + const resultVM = await client.machines.delete(vms); + const resultGateway = await client.gateway.delete_name(gw); log("================= Canceling the deployment ================="); - log(resvm); - log(resgw); + log(resultVM); + log(resultGateway); log("================= Canceling the deployment ================="); } @@ -61,6 +61,8 @@ async function main() { availableFor: grid3.twinId, }; const gatewayNode = (await grid3.capacity.filterNodes(gatewayQueryOptions))[0]; + const nodes = await grid3.capacity.filterNodes(vmQueryOptions); + const vmNode = await pingNodes(grid3, nodes); const vms: MachinesModel = { name, @@ -71,7 +73,7 @@ async function main() { machines: [ { name: "casperlabs", - node_id: +(await pingNodes(grid3, await grid3.capacity.filterNodes(vmQueryOptions))), + node_id: vmNode, disks: [ { name: "wedDisk", diff --git a/packages/grid_client/scripts/applications/funkwhale.ts b/packages/grid_client/scripts/applications/funkwhale.ts index 1a7d2da248..a7770db80f 100644 --- a/packages/grid_client/scripts/applications/funkwhale.ts +++ b/packages/grid_client/scripts/applications/funkwhale.ts @@ -34,11 +34,11 @@ async function getDeployment(client, vms, gw) { } async function cancel(client, vms, gw) { - const resvm = await client.machines.delete(vms); - const resgw = await client.gateway.delete_name(gw); + const resultVM = await client.machines.delete(vms); + const resultGateway = await client.gateway.delete_name(gw); log("================= Canceling the deployment ================="); - log(resvm); - log(resgw); + log(resultVM); + log(resultGateway); log("================= Canceling the deployment ================="); } @@ -61,6 +61,8 @@ async function main() { availableFor: grid3.twinId, }; const gatewayNode = (await grid3.capacity.filterNodes(gatewayQueryOptions))[0]; + const nodes = await grid3.capacity.filterNodes(vmQueryOptions); + const vmNode = await pingNodes(grid3, nodes); const vms: MachinesModel = { name, @@ -71,7 +73,7 @@ async function main() { machines: [ { name: "funkwhale", - node_id: +(await pingNodes(grid3, await grid3.capacity.filterNodes(vmQueryOptions))), + node_id: vmNode, disks: [ { name: "wedDisk", @@ -91,9 +93,10 @@ async function main() { env: { SSH_KEY: config.ssh_key, FUNKWHALE_HOSTNAME: subdomain + "." + gatewayNode.publicConfig.domain, - DJANGO_SUPERUSER_EMAIL: "admin123@funk.whale", // edit me - DJANGO_SUPERUSER_USERNAME: "admin123", // edit me - DJANGO_SUPERUSER_PASSWORD: "admin123", // edit me + // These email, username, and password will be used to log in to your instance, so please update them with your own. + DJANGO_SUPERUSER_EMAIL: "admin123@funk.whale", + DJANGO_SUPERUSER_USERNAME: "admin123", + DJANGO_SUPERUSER_PASSWORD: "admin123", }, }, ], diff --git a/packages/grid_client/scripts/applications/mattermost.ts b/packages/grid_client/scripts/applications/mattermost.ts index 952350c018..b0e2dd88a4 100644 --- a/packages/grid_client/scripts/applications/mattermost.ts +++ b/packages/grid_client/scripts/applications/mattermost.ts @@ -34,11 +34,11 @@ async function getDeployment(client, vms, gw) { } async function cancel(client, vms, gw) { - const resvm = await client.machines.delete(vms); - const resgw = await client.gateway.delete_name(gw); + const resultVM = await client.machines.delete(vms); + const resultGateway = await client.gateway.delete_name(gw); log("================= Canceling the deployment ================="); - log(resvm); - log(resgw); + log(resultVM); + log(resultGateway); log("================= Canceling the deployment ================="); } @@ -61,6 +61,8 @@ async function main() { availableFor: grid3.twinId, }; const gatewayNode = (await grid3.capacity.filterNodes(gatewayQueryOptions))[0]; + const nodes = await grid3.capacity.filterNodes(vmQueryOptions); + const vmNode = await pingNodes(grid3, nodes); const vms: MachinesModel = { name, @@ -71,7 +73,7 @@ async function main() { machines: [ { name: "mattermost", - node_id: +(await pingNodes(grid3, await grid3.capacity.filterNodes(vmQueryOptions))), + node_id: vmNode, disks: [ { name: "wedDisk", @@ -92,9 +94,11 @@ async function main() { SSH_KEY: config.ssh_key, MATTERMOST_DOMAIN: subdomain + "." + gatewayNode.publicConfig.domain, SITE_URL: "https://" + subdomain + "." + gatewayNode.publicConfig.domain, - DJANGO_SUPERUSER_EMAIL: "admin123@matter.most", // edit me - DB_PASSWORD: "admin123", // edit me - // Optional + // These email and password will be used as admin credentials, so please update them with your own. + DJANGO_SUPERUSER_EMAIL: "admin123@matter.most", + DB_PASSWORD: "admin123", + /* The SMTP server is optional, if you would like to enable the access of the SMTP server, you need to send these values. + These credentials will be used as admin credentials, so please configure them with your own. */ // SMTPUsername: "username", // SMTPPassword: "password", // SMTPServer: "hostname", diff --git a/packages/grid_client/scripts/applications/peertube.ts b/packages/grid_client/scripts/applications/peertube.ts index e956089132..f1e3329c69 100644 --- a/packages/grid_client/scripts/applications/peertube.ts +++ b/packages/grid_client/scripts/applications/peertube.ts @@ -34,11 +34,11 @@ async function getDeployment(client, vms, gw) { } async function cancel(client, vms, gw) { - const resvm = await client.machines.delete(vms); - const resgw = await client.gateway.delete_name(gw); + const resultVM = await client.machines.delete(vms); + const resultGateway = await client.gateway.delete_name(gw); log("================= Canceling the deployment ================="); - log(resvm); - log(resgw); + log(resultVM); + log(resultGateway); log("================= Canceling the deployment ================="); } @@ -61,6 +61,8 @@ async function main() { availableFor: grid3.twinId, }; const gatewayNode = (await grid3.capacity.filterNodes(gatewayQueryOptions))[0]; + const nodes = await grid3.capacity.filterNodes(vmQueryOptions); + const vmNode = await pingNodes(grid3, nodes); const vms: MachinesModel = { name, @@ -71,7 +73,7 @@ async function main() { machines: [ { name: "peertube", - node_id: +(await pingNodes(grid3, await grid3.capacity.filterNodes(vmQueryOptions))), + node_id: vmNode, disks: [ { name: "wedDisk", @@ -91,8 +93,9 @@ async function main() { env: { SSH_KEY: config.ssh_key, PEERTUBE_WEBSERVER_HOSTNAME: subdomain + "." + gatewayNode.publicConfig.domain, - PEERTUBE_ADMIN_EMAIL: "admin123@peer.tube", // edit me - PT_INITIAL_ROOT_PASSWORD: "admin123", // edit me + // These email, and password will be used to log in to your instance, so please update them with your own. + PEERTUBE_ADMIN_EMAIL: "admin123@peer.tube", + PT_INITIAL_ROOT_PASSWORD: "admin123", }, }, ], diff --git a/packages/grid_client/scripts/utils.ts b/packages/grid_client/scripts/utils.ts index a417a6e8b6..3405fa05bc 100644 --- a/packages/grid_client/scripts/utils.ts +++ b/packages/grid_client/scripts/utils.ts @@ -1,10 +1,23 @@ import { inspect } from "util"; +import { GridClient, NodeInfo } from "../src"; + function log(message) { console.log(inspect(message, { showHidden: false, depth: null, colors: true })); } -async function pingNodes(client, nodes) { +async function pingNodes(client: GridClient, nodes: NodeInfo[]): Promise { + /** + * Attempts to ping a list of nodes sequentially and returns the ID of the first responsive node. + * + * This function iterates through an array of nodes, pinging each one to check its responsiveness. + * It returns the ID of the first node that responds successfully. If no nodes respond, an error is thrown. + * + * @param {GridClient} client - An instance of the GridClient used to ping the nodes. + * @param {NodeInfo[]} nodes - An array of node information objects. + * @returns {Promise} - A promise that resolves to the nodeId of the first responsive node. + * @throws {Error} - Throws an error if none of the nodes respond successfully. + */ for (const node of nodes) { try { await client.zos.pingNode({ nodeId: node.nodeId }); @@ -13,7 +26,7 @@ async function pingNodes(client, nodes) { log("node " + node.nodeId + " is not responding, trying different node."); } } - throw new Error("No avaiable nodes"); + throw new Error("There are no available nodes. Please try changing the filters you have applied."); } export { log, pingNodes }; From 1efb1e792c6792e1df8b40748d7da87df13cfedc Mon Sep 17 00:00:00 2001 From: A-Harby Date: Wed, 22 May 2024 12:15:34 +0300 Subject: [PATCH 6/8] store domain in const, improve readability --- .../scripts/applications/casberlabs.ts | 3 ++- .../scripts/applications/funkwhale.ts | 3 ++- .../scripts/applications/mattermost.ts | 5 +++-- .../scripts/applications/peertube.ts | 3 ++- packages/grid_client/scripts/utils.ts | 22 +++++++++---------- 5 files changed, 20 insertions(+), 16 deletions(-) diff --git a/packages/grid_client/scripts/applications/casberlabs.ts b/packages/grid_client/scripts/applications/casberlabs.ts index fb82f7f2c8..da5cf6cbad 100644 --- a/packages/grid_client/scripts/applications/casberlabs.ts +++ b/packages/grid_client/scripts/applications/casberlabs.ts @@ -63,6 +63,7 @@ async function main() { const gatewayNode = (await grid3.capacity.filterNodes(gatewayQueryOptions))[0]; const nodes = await grid3.capacity.filterNodes(vmQueryOptions); const vmNode = await pingNodes(grid3, nodes); + const domain = subdomain + "." + gatewayNode.publicConfig.domain; const vms: MachinesModel = { name, @@ -92,7 +93,7 @@ async function main() { entrypoint: "/sbin/zinit init", env: { SSH_KEY: config.ssh_key, - CASPERLABS_HOSTNAME: subdomain + "." + gatewayNode.publicConfig.domain, + CASPERLABS_HOSTNAME: domain, }, }, ], diff --git a/packages/grid_client/scripts/applications/funkwhale.ts b/packages/grid_client/scripts/applications/funkwhale.ts index a7770db80f..63539e1ebe 100644 --- a/packages/grid_client/scripts/applications/funkwhale.ts +++ b/packages/grid_client/scripts/applications/funkwhale.ts @@ -63,6 +63,7 @@ async function main() { const gatewayNode = (await grid3.capacity.filterNodes(gatewayQueryOptions))[0]; const nodes = await grid3.capacity.filterNodes(vmQueryOptions); const vmNode = await pingNodes(grid3, nodes); + const domain = subdomain + "." + gatewayNode.publicConfig.domain; const vms: MachinesModel = { name, @@ -92,7 +93,7 @@ async function main() { entrypoint: "/init.sh", env: { SSH_KEY: config.ssh_key, - FUNKWHALE_HOSTNAME: subdomain + "." + gatewayNode.publicConfig.domain, + FUNKWHALE_HOSTNAME: domain, // These email, username, and password will be used to log in to your instance, so please update them with your own. DJANGO_SUPERUSER_EMAIL: "admin123@funk.whale", DJANGO_SUPERUSER_USERNAME: "admin123", diff --git a/packages/grid_client/scripts/applications/mattermost.ts b/packages/grid_client/scripts/applications/mattermost.ts index b0e2dd88a4..9286583be5 100644 --- a/packages/grid_client/scripts/applications/mattermost.ts +++ b/packages/grid_client/scripts/applications/mattermost.ts @@ -63,6 +63,7 @@ async function main() { const gatewayNode = (await grid3.capacity.filterNodes(gatewayQueryOptions))[0]; const nodes = await grid3.capacity.filterNodes(vmQueryOptions); const vmNode = await pingNodes(grid3, nodes); + const domain = subdomain + "." + gatewayNode.publicConfig.domain; const vms: MachinesModel = { name, @@ -92,8 +93,8 @@ async function main() { entrypoint: "/sbin/zinit init", env: { SSH_KEY: config.ssh_key, - MATTERMOST_DOMAIN: subdomain + "." + gatewayNode.publicConfig.domain, - SITE_URL: "https://" + subdomain + "." + gatewayNode.publicConfig.domain, + MATTERMOST_DOMAIN: domain, + SITE_URL: "https://" + domain, // These email and password will be used as admin credentials, so please update them with your own. DJANGO_SUPERUSER_EMAIL: "admin123@matter.most", DB_PASSWORD: "admin123", diff --git a/packages/grid_client/scripts/applications/peertube.ts b/packages/grid_client/scripts/applications/peertube.ts index f1e3329c69..dd29838172 100644 --- a/packages/grid_client/scripts/applications/peertube.ts +++ b/packages/grid_client/scripts/applications/peertube.ts @@ -63,6 +63,7 @@ async function main() { const gatewayNode = (await grid3.capacity.filterNodes(gatewayQueryOptions))[0]; const nodes = await grid3.capacity.filterNodes(vmQueryOptions); const vmNode = await pingNodes(grid3, nodes); + const domain = subdomain + "." + gatewayNode.publicConfig.domain; const vms: MachinesModel = { name, @@ -92,7 +93,7 @@ async function main() { entrypoint: "/sbin/zinit init", env: { SSH_KEY: config.ssh_key, - PEERTUBE_WEBSERVER_HOSTNAME: subdomain + "." + gatewayNode.publicConfig.domain, + PEERTUBE_WEBSERVER_HOSTNAME: domain, // These email, and password will be used to log in to your instance, so please update them with your own. PEERTUBE_ADMIN_EMAIL: "admin123@peer.tube", PT_INITIAL_ROOT_PASSWORD: "admin123", diff --git a/packages/grid_client/scripts/utils.ts b/packages/grid_client/scripts/utils.ts index 3405fa05bc..35525d7358 100644 --- a/packages/grid_client/scripts/utils.ts +++ b/packages/grid_client/scripts/utils.ts @@ -6,18 +6,18 @@ function log(message) { console.log(inspect(message, { showHidden: false, depth: null, colors: true })); } +/** + * Attempts to ping a list of nodes sequentially and returns the ID of the first responsive node. + * + * This function iterates through an array of nodes, pinging each one to check its responsiveness. + * It returns the ID of the first node that responds successfully. If no nodes respond, an error is thrown. + * + * @param {GridClient} client - An instance of the GridClient used to ping the nodes. + * @param {NodeInfo[]} nodes - An array of node information objects. + * @returns {Promise} - A promise that resolves to the nodeId of the first responsive node. + * @throws {Error} - Throws an error if none of the nodes respond successfully. + */ async function pingNodes(client: GridClient, nodes: NodeInfo[]): Promise { - /** - * Attempts to ping a list of nodes sequentially and returns the ID of the first responsive node. - * - * This function iterates through an array of nodes, pinging each one to check its responsiveness. - * It returns the ID of the first node that responds successfully. If no nodes respond, an error is thrown. - * - * @param {GridClient} client - An instance of the GridClient used to ping the nodes. - * @param {NodeInfo[]} nodes - An array of node information objects. - * @returns {Promise} - A promise that resolves to the nodeId of the first responsive node. - * @throws {Error} - Throws an error if none of the nodes respond successfully. - */ for (const node of nodes) { try { await client.zos.pingNode({ nodeId: node.nodeId }); From 30ae74345e767399b3e1af40ec93b47bc56f9be7 Mon Sep 17 00:00:00 2001 From: A-Harby Date: Wed, 22 May 2024 13:41:05 +0300 Subject: [PATCH 7/8] add new const object to instance capacity for a better usage --- .../grid_client/scripts/applications/casberlabs.ts | 13 +++++++------ .../grid_client/scripts/applications/funkwhale.ts | 13 +++++++------ .../grid_client/scripts/applications/mattermost.ts | 13 +++++++------ .../grid_client/scripts/applications/peertube.ts | 13 +++++++------ 4 files changed, 28 insertions(+), 24 deletions(-) diff --git a/packages/grid_client/scripts/applications/casberlabs.ts b/packages/grid_client/scripts/applications/casberlabs.ts index da5cf6cbad..5a3f7c8bf6 100644 --- a/packages/grid_client/scripts/applications/casberlabs.ts +++ b/packages/grid_client/scripts/applications/casberlabs.ts @@ -46,12 +46,13 @@ async function main() { const name = "newcasperlabs"; const grid3 = await getClient(`casperlabs/${name}`); const subdomain = "cl" + grid3.twinId + name; + const instanceCapacity = { cru: 1, mru: 2, sru: 15 }; // Update the instance capacity values according to your requirements. //VMNode Selection const vmQueryOptions: FilterOptions = { - cru: 2, - mru: 4, - sru: 100, + cru: instanceCapacity.cru, + mru: instanceCapacity.mru, + sru: instanceCapacity.sru, availableFor: grid3.twinId, farmId: 1, }; @@ -78,7 +79,7 @@ async function main() { disks: [ { name: "wedDisk", - size: 100, + size: instanceCapacity.sru, mountpoint: "/data", }, ], @@ -86,8 +87,8 @@ async function main() { public_ip: false, public_ip6: false, mycelium: false, - cpu: 2, - memory: 1024 * 4, + cpu: instanceCapacity.cru, + memory: 1024 * instanceCapacity.mru, rootfs_size: 0, flist: "https://hub.grid.tf/tf-official-apps/casperlabs-latest.flist", entrypoint: "/sbin/zinit init", diff --git a/packages/grid_client/scripts/applications/funkwhale.ts b/packages/grid_client/scripts/applications/funkwhale.ts index 63539e1ebe..b53dde8803 100644 --- a/packages/grid_client/scripts/applications/funkwhale.ts +++ b/packages/grid_client/scripts/applications/funkwhale.ts @@ -46,12 +46,13 @@ async function main() { const name = "newfunkwhale"; const grid3 = await getClient(`funkwhale/${name}`); const subdomain = "fw" + grid3.twinId + name; + const instanceCapacity = { cru: 1, mru: 2, sru: 15 }; // Update the instance capacity values according to your requirements. //VMNode Selection const vmQueryOptions: FilterOptions = { - cru: 1, - mru: 2, - sru: 50, + cru: instanceCapacity.cru, + mru: instanceCapacity.mru, + sru: instanceCapacity.sru, availableFor: grid3.twinId, farmId: 1, }; @@ -78,7 +79,7 @@ async function main() { disks: [ { name: "wedDisk", - size: 50, + size: instanceCapacity.sru, mountpoint: "/data", }, ], @@ -86,8 +87,8 @@ async function main() { public_ip: false, public_ip6: false, mycelium: false, - cpu: 1, - memory: 1024 * 2, + cpu: instanceCapacity.cru, + memory: 1024 * instanceCapacity.mru, rootfs_size: 0, flist: "https://hub.grid.tf/tf-official-apps/funkwhale-dec21.flist", entrypoint: "/init.sh", diff --git a/packages/grid_client/scripts/applications/mattermost.ts b/packages/grid_client/scripts/applications/mattermost.ts index 9286583be5..42a16569fe 100644 --- a/packages/grid_client/scripts/applications/mattermost.ts +++ b/packages/grid_client/scripts/applications/mattermost.ts @@ -46,12 +46,13 @@ async function main() { const name = "newmattermost"; const grid3 = await getClient(`mattermost/${name}`); const subdomain = "mm" + grid3.twinId + name; + const instanceCapacity = { cru: 1, mru: 2, sru: 15 }; // Update the instance capacity values according to your requirements. //VMNode Selection const vmQueryOptions: FilterOptions = { - cru: 1, - mru: 2, - sru: 50, + cru: instanceCapacity.cru, + mru: instanceCapacity.mru, + sru: instanceCapacity.sru, availableFor: grid3.twinId, farmId: 1, }; @@ -78,7 +79,7 @@ async function main() { disks: [ { name: "wedDisk", - size: 50, + size: instanceCapacity.sru, mountpoint: "/var/lib/docker", }, ], @@ -86,8 +87,8 @@ async function main() { public_ip: false, public_ip6: false, mycelium: false, - cpu: 1, - memory: 1024 * 2, + cpu: instanceCapacity.cru, + memory: 1024 * instanceCapacity.mru, rootfs_size: 0, flist: "https://hub.grid.tf/tf-official-apps/mattermost-latest.flist", entrypoint: "/sbin/zinit init", diff --git a/packages/grid_client/scripts/applications/peertube.ts b/packages/grid_client/scripts/applications/peertube.ts index dd29838172..60d94c82d4 100644 --- a/packages/grid_client/scripts/applications/peertube.ts +++ b/packages/grid_client/scripts/applications/peertube.ts @@ -46,12 +46,13 @@ async function main() { const name = "newpeertube"; const grid3 = await getClient(`peertube/${name}`); const subdomain = "pt" + grid3.twinId + name; + const instanceCapacity = { cru: 1, mru: 2, sru: 15 }; // Update the instance capacity values according to your requirements. //VMNode Selection const vmQueryOptions: FilterOptions = { - cru: 1, - mru: 2, - sru: 50, + cru: instanceCapacity.cru, + mru: instanceCapacity.mru, + sru: instanceCapacity.sru, availableFor: grid3.twinId, farmId: 1, }; @@ -78,7 +79,7 @@ async function main() { disks: [ { name: "wedDisk", - size: 50, + size: instanceCapacity.sru, mountpoint: "/data", }, ], @@ -86,8 +87,8 @@ async function main() { public_ip: false, public_ip6: false, mycelium: false, - cpu: 1, - memory: 1024 * 2, + cpu: instanceCapacity.cru, + memory: 1024 * instanceCapacity.mru, rootfs_size: 0, flist: "https://hub.grid.tf/tf-official-apps/peertube-v3.1.1.flist", entrypoint: "/sbin/zinit init", From 1d9536e2b74be597ef3aee75e0d4bd1e5055056a Mon Sep 17 00:00:00 2001 From: A-Harby Date: Wed, 22 May 2024 18:34:19 +0300 Subject: [PATCH 8/8] fix capacity package values --- packages/grid_client/scripts/applications/casberlabs.ts | 2 +- packages/grid_client/scripts/applications/funkwhale.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/grid_client/scripts/applications/casberlabs.ts b/packages/grid_client/scripts/applications/casberlabs.ts index 5a3f7c8bf6..17cab6e1a0 100644 --- a/packages/grid_client/scripts/applications/casberlabs.ts +++ b/packages/grid_client/scripts/applications/casberlabs.ts @@ -46,7 +46,7 @@ async function main() { const name = "newcasperlabs"; const grid3 = await getClient(`casperlabs/${name}`); const subdomain = "cl" + grid3.twinId + name; - const instanceCapacity = { cru: 1, mru: 2, sru: 15 }; // Update the instance capacity values according to your requirements. + const instanceCapacity = { cru: 2, mru: 4, sru: 100 }; // Update the instance capacity values according to your requirements. //VMNode Selection const vmQueryOptions: FilterOptions = { diff --git a/packages/grid_client/scripts/applications/funkwhale.ts b/packages/grid_client/scripts/applications/funkwhale.ts index b53dde8803..ed2adf3691 100644 --- a/packages/grid_client/scripts/applications/funkwhale.ts +++ b/packages/grid_client/scripts/applications/funkwhale.ts @@ -46,7 +46,7 @@ async function main() { const name = "newfunkwhale"; const grid3 = await getClient(`funkwhale/${name}`); const subdomain = "fw" + grid3.twinId + name; - const instanceCapacity = { cru: 1, mru: 2, sru: 15 }; // Update the instance capacity values according to your requirements. + const instanceCapacity = { cru: 1, mru: 2, sru: 50 }; // Update the instance capacity values according to your requirements. //VMNode Selection const vmQueryOptions: FilterOptions = {