From 4c0467ee952f293e955dad4c9c35561114998d7a Mon Sep 17 00:00:00 2001 From: A-Harby Date: Thu, 23 May 2024 16:24:30 +0300 Subject: [PATCH 1/3] add rest of solution scripts --- .../scripts/applications/algorand.ts | 99 +++++++++++++ .../scripts/applications/discourse.ts | 136 ++++++++++++++++++ .../scripts/applications/nextcloud.ts | 121 ++++++++++++++++ .../scripts/applications/nodepilot.ts | 94 ++++++++++++ .../scripts/applications/presearch.ts | 96 +++++++++++++ .../scripts/applications/subsquid.ts | 119 +++++++++++++++ .../grid_client/scripts/applications/taiga.ts | 129 +++++++++++++++++ .../scripts/applications/umbrel.ts | 99 +++++++++++++ .../scripts/applications/wordpress.ts | 122 ++++++++++++++++ 9 files changed, 1015 insertions(+) create mode 100644 packages/grid_client/scripts/applications/algorand.ts create mode 100644 packages/grid_client/scripts/applications/discourse.ts create mode 100644 packages/grid_client/scripts/applications/nextcloud.ts create mode 100644 packages/grid_client/scripts/applications/nodepilot.ts create mode 100644 packages/grid_client/scripts/applications/presearch.ts create mode 100644 packages/grid_client/scripts/applications/subsquid.ts create mode 100644 packages/grid_client/scripts/applications/taiga.ts create mode 100644 packages/grid_client/scripts/applications/umbrel.ts create mode 100644 packages/grid_client/scripts/applications/wordpress.ts diff --git a/packages/grid_client/scripts/applications/algorand.ts b/packages/grid_client/scripts/applications/algorand.ts new file mode 100644 index 0000000000..2581861176 --- /dev/null +++ b/packages/grid_client/scripts/applications/algorand.ts @@ -0,0 +1,99 @@ +import { FilterOptions, MachinesModel } from "../../src"; +import { config, getClient } from "../client_loader"; +import { log, pingNodes } from "../utils"; + +async function deploy(client, vms) { + const resultVM = await client.machines.deploy(vms); + log("================= Deploying VM ================="); + log(resultVM); + log("================= Deploying VM ================="); +} + +async function getDeployment(client, vms) { + const resultVM = await client.machines.getObj(vms.name); + log("================= Getting deployment information ================="); + log(resultVM); + log("================= Getting deployment information ================="); +} + +async function cancel(client, vms) { + const resultVM = await client.machines.delete(vms); + log("================= Canceling the deployment ================="); + log(resultVM); + log("================= Canceling the deployment ================="); +} + +async function main() { + const name = "newalgorand"; + const grid3 = await getClient(`algorand/${name}`); + const instanceCapacity = { cru: 2, mru: 4, sru: 50 }; // Update the instance capacity values according to your requirements. + + //VMNode Selection + const vmQueryOptions: FilterOptions = { + cru: instanceCapacity.cru, + mru: instanceCapacity.mru, + sru: instanceCapacity.sru, + availableFor: grid3.twinId, + farmId: 1, + }; + const nodes = await grid3.capacity.filterNodes(vmQueryOptions); + const vmNode = await pingNodes(grid3, nodes); + + const vms: MachinesModel = { + name, + network: { + name: "wedtest", + ip_range: "10.249.0.0/16", + }, + machines: [ + { + name: "algorand", + node_id: vmNode, + disks: [ + { + name: "docker", + size: instanceCapacity.sru, + mountpoint: "/var/lib/docker", + }, + ], + planetary: true, + public_ip: false, + public_ip6: false, + mycelium: false, + cpu: instanceCapacity.cru, + memory: 1024 * instanceCapacity.mru, + rootfs_size: 0, + flist: "https://hub.grid.tf/tf-official-apps/algorand-latest.flist", + entrypoint: "/sbin/zinit init", + env: { + SSH_KEY: config.ssh_key, + // Select a network to work against. + NETWORK: "mainnet", + // Defualt, Relay, Participant, Indexer + NODE_TYPE: "default", + // Account mnemonic is the private key of your Algorand wallet and it consists of 24 words, and these 3 options are only enabled on Participant. + //ACCOUNT_MNEMONICS: "", + // First Validation Block. + //FIRST_ROUND: "24000000", + // Last Validation Block + //LAST_ROUND: "26000000", + }, + }, + ], + metadata: "", + description: "test deploying Presearch via ts grid3 client", + }; + + //Deploy VMs + await deploy(grid3, vms); + + //Get the deployment + await getDeployment(grid3, vms); + + //Uncomment the line below to cancel the deployment + // await cancel(grid3, { name }); + + await grid3.disconnect(); +} + +main(); diff --git a/packages/grid_client/scripts/applications/discourse.ts b/packages/grid_client/scripts/applications/discourse.ts new file mode 100644 index 0000000000..ded54a4566 --- /dev/null +++ b/packages/grid_client/scripts/applications/discourse.ts @@ -0,0 +1,136 @@ +import { Buffer } from "buffer"; +import TweetNACL from "tweetnacl"; + +import { FilterOptions, GatewayNameModel, MachinesModel } from "../../src"; +import { config, getClient } from "../client_loader"; +import { log, pingNodes } from "../utils"; + +async function deploy(client, vms, subdomain, gatewayNode) { + const resultVM = await client.machines.deploy(vms); + log("================= Deploying VM ================="); + log(resultVM); + log("================= Deploying VM ================="); + + 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 + "]:88"], + }; + + const resultGateway = await client.gateway.deploy_name(gw); + log("================= Deploying name gateway ================="); + log(resultGateway); + log("================= Deploying name gateway ================="); +} + +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(resultVM); + log(resultGateway); + log("https://" + resultGateway[0].domain); + log("================= Getting deployment information ================="); +} + +async function cancel(client, vms, gw) { + const resultVM = await client.machines.delete(vms); + const resultGateway = await client.gateway.delete_name(gw); + log("================= Canceling the deployment ================="); + log(resultVM); + log(resultGateway); + log("================= Canceling the deployment ================="); +} + +function generatePubKey(): string { + const keypair = TweetNACL.box.keyPair(); + return Buffer.from(keypair.publicKey).toString("base64"); +} + +async function main() { + const name = "newdiscourse"; + const grid3 = await getClient(`discourse/${name}`); + const subdomain = "dc" + 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: instanceCapacity.cru, + mru: instanceCapacity.mru, + sru: instanceCapacity.sru, + availableFor: grid3.twinId, + farmId: 1, + }; + //GatewayNode Selection + const gatewayQueryOptions: FilterOptions = { + gateway: true, + 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 domain = subdomain + "." + gatewayNode.publicConfig.domain; + + const vms: MachinesModel = { + name, + network: { + name: "wedtest", + ip_range: "10.249.0.0/16", + }, + machines: [ + { + name: "discourse", + node_id: vmNode, + disks: [ + { + name: "wedDisk", + size: instanceCapacity.sru, + mountpoint: "/var/lib/docker", + }, + ], + planetary: true, + public_ip: false, + public_ip6: false, + mycelium: false, + cpu: instanceCapacity.cru, + memory: 1024 * instanceCapacity.mru, + rootfs_size: 0, + flist: "https://hub.grid.tf/tf-official-apps/forum-docker-v3.1.2.flist", + entrypoint: "/sbin/zinit init", + env: { + SSH_KEY: config.ssh_key, + DISCOURSE_HOSTNAME: domain, + THREEBOT_PRIVATE_KEY: generatePubKey(), + // This email will be used to log in to your instance, so please update them with your own. + DISCOURSE_DEVELOPER_EMAILS: "admin123@dis.course", + /* The SMTP server is required, you need to send these values. + These credentials will be used as admin credentials, so please configure them with your own. */ + DISCOURSE_SMTP_ADDRESS: "smtp.gmail.com", + DISCOURSE_SMTP_PORT: "587", + DISCOURSE_SMTP_ENABLE_START_TLS: "false", + DISCOURSE_SMTP_USER_NAME: "admin123@dis.course", + DISCOURSE_SMTP_PASSWORD: "NPwTGc7dVj9W", + FLASK_SECRET_KEY: "Admin123", + }, + }, + ], + metadata: "", + description: "test deploying DisCourse via ts grid3 client", + }; + + //Deploy VMs + await deploy(grid3, vms, subdomain, gatewayNode); + + //Get the deployment + await getDeployment(grid3, vms, subdomain); + + //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/nextcloud.ts b/packages/grid_client/scripts/applications/nextcloud.ts new file mode 100644 index 0000000000..550125991b --- /dev/null +++ b/packages/grid_client/scripts/applications/nextcloud.ts @@ -0,0 +1,121 @@ +import { FilterOptions, GatewayNameModel, MachinesModel } from "../../src"; +import { config, getClient } from "../client_loader"; +import { log, pingNodes } from "../utils"; + +async function deploy(client, vms, subdomain, gatewayNode) { + const resultVM = await client.machines.deploy(vms); + log("================= Deploying VM ================="); + log(resultVM); + log("================= Deploying VM ================="); + + 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(resultGateway); + log("================= Deploying name gateway ================="); +} + +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(resultVM); + log(resultGateway); + log("https://" + resultGateway[0].domain); + log("================= Getting deployment information ================="); +} + +async function cancel(client, vms, gw) { + const resultVM = await client.machines.delete(vms); + const resultGateway = await client.gateway.delete_name(gw); + log("================= Canceling the deployment ================="); + log(resultVM); + log(resultGateway); + log("================= Canceling the deployment ================="); +} + +async function main() { + const name = "newnextcloud"; + const grid3 = await getClient(`nextcloud/${name}`); + const subdomain = "nc" + grid3.twinId + name; + const instanceCapacity = { cru: 2, mru: 4, sru: 50 }; // Update the instance capacity values according to your requirements. + + //VMNode Selection + const vmQueryOptions: FilterOptions = { + cru: instanceCapacity.cru, + mru: instanceCapacity.mru, + sru: instanceCapacity.sru, + availableFor: grid3.twinId, + farmId: 1, + }; + //GatewayNode Selection + const gatewayQueryOptions: FilterOptions = { + gateway: true, + 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 domain = subdomain + "." + gatewayNode.publicConfig.domain; + + const vms: MachinesModel = { + name, + network: { + name: "wedtest", + ip_range: "10.249.0.0/16", + }, + machines: [ + { + name: "nextcloud", + node_id: vmNode, + disks: [ + { + name: "wedDisk", + size: instanceCapacity.sru, + mountpoint: "/mnt/data", + }, + ], + planetary: true, + public_ip: false, + public_ip6: false, + mycelium: false, + cpu: instanceCapacity.cru, + memory: 1024 * instanceCapacity.mru, + rootfs_size: 0, + flist: "https://hub.grid.tf/tf-official-apps/threefoldtech-nextcloudaio-latest.flist", + entrypoint: "/sbin/zinit init", + env: { + SSH_KEY: config.ssh_key, + NEXTCLOUD_DOMAIN: domain, + NEXTCLOUD_AIO_LINK: domain + "/aio", + // Update the boolean value here if you choose to deploy with a Public IPv4 and gateway. + GATEWAY: "true", + IPV4: "false", + }, + }, + ], + metadata: "", + description: "test deploying NextCloud via ts grid3 client", + }; + + //Deploy VMs + await deploy(grid3, vms, subdomain, gatewayNode); + + //Get the deployment + await getDeployment(grid3, vms, subdomain); + + //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/nodepilot.ts b/packages/grid_client/scripts/applications/nodepilot.ts new file mode 100644 index 0000000000..327729b423 --- /dev/null +++ b/packages/grid_client/scripts/applications/nodepilot.ts @@ -0,0 +1,94 @@ +import { FilterOptions, MachinesModel } from "../../src"; +import { config, getClient } from "../client_loader"; +import { log, pingNodes } from "../utils"; + +async function deploy(client, vms) { + const resultVM = await client.machines.deploy(vms); + log("================= Deploying VM ================="); + log(resultVM); + log("================= Deploying VM ================="); +} + +async function getDeployment(client, vms) { + const resultVM = await client.machines.getObj(vms.name); + log("================= Getting deployment information ================="); + log(resultVM); + log("================= Getting deployment information ================="); +} + +async function cancel(client, vms) { + const resultVM = await client.machines.delete(vms); + log("================= Canceling the deployment ================="); + log(resultVM); + log("================= Canceling the deployment ================="); +} + +async function main() { + const name = "newnodepilot"; + const grid3 = await getClient(`nodepilot/${name}`); + const instanceCapacity = { cru: 8, mru: 8, sru: 32 }; // Update the instance capacity values according to your requirements. + + //VMNode Selection + const vmQueryOptions: FilterOptions = { + cru: instanceCapacity.cru, + mru: instanceCapacity.mru, + sru: instanceCapacity.sru, + availableFor: grid3.twinId, + farmId: 1, + }; + const nodes = await grid3.capacity.filterNodes(vmQueryOptions); + const vmNode = await pingNodes(grid3, nodes); + + const vms: MachinesModel = { + name, + network: { + name: "wedtest", + ip_range: "10.249.0.0/16", + }, + machines: [ + { + name: "nodepilot", + node_id: vmNode, + disks: [ + { + name: "disk1", + size: 15, + mountpoint: "/mnt/disk1", + }, + { + name: "disk2", + size: 15, + mountpoint: "/mnt/disk2", + }, + ], + planetary: false, + public_ip: true, + public_ip6: true, + mycelium: false, + cpu: instanceCapacity.cru, + memory: 1024 * instanceCapacity.mru, + rootfs_size: 2, + flist: "https://hub.grid.tf/tf-official-vms/node-pilot-zdbfs.flist", + entrypoint: "/", + env: { + SSH_KEY: config.ssh_key, + }, + }, + ], + metadata: "", + description: "test deploying Node Pilot via ts grid3 client", + }; + + //Deploy VMs + await deploy(grid3, vms); + + //Get the deployment + await getDeployment(grid3, vms); + + //Uncomment the line below to cancel the deployment + // await cancel(grid3, { name }); + + await grid3.disconnect(); +} + +main(); diff --git a/packages/grid_client/scripts/applications/presearch.ts b/packages/grid_client/scripts/applications/presearch.ts new file mode 100644 index 0000000000..e43f8ef270 --- /dev/null +++ b/packages/grid_client/scripts/applications/presearch.ts @@ -0,0 +1,96 @@ +import { FilterOptions, MachinesModel } from "../../src"; +import { config, getClient } from "../client_loader"; +import { log, pingNodes } from "../utils"; + +async function deploy(client, vms) { + const resultVM = await client.machines.deploy(vms); + log("================= Deploying VM ================="); + log(resultVM); + log("================= Deploying VM ================="); +} + +async function getDeployment(client, vms) { + const resultVM = await client.machines.getObj(vms.name); + log("================= Getting deployment information ================="); + log(resultVM); + log("================= Getting deployment information ================="); +} + +async function cancel(client, vms) { + const resultVM = await client.machines.delete(vms); + log("================= Canceling the deployment ================="); + log(resultVM); + log("================= Canceling the deployment ================="); +} + +async function main() { + const name = "newpresearch"; + const grid3 = await getClient(`presearch/${name}`); + const instanceCapacity = { cru: 1, mru: 1, sru: 10 }; // Update the instance capacity values according to your requirements. + + //VMNode Selection + const vmQueryOptions: FilterOptions = { + cru: instanceCapacity.cru, + mru: instanceCapacity.mru, + sru: instanceCapacity.sru, + availableFor: grid3.twinId, + farmId: 1, + }; + const nodes = await grid3.capacity.filterNodes(vmQueryOptions); + const vmNode = await pingNodes(grid3, nodes); + + const vms: MachinesModel = { + name, + network: { + name: "wedtest", + ip_range: "10.249.0.0/16", + }, + machines: [ + { + name: "presearch", + node_id: vmNode, + disks: [ + { + name: "docker", + size: instanceCapacity.sru, + mountpoint: "/var/lib/docker", + }, + ], + planetary: true, + public_ip: false, + public_ip6: false, + mycelium: false, + cpu: instanceCapacity.cru, + memory: 1024 * instanceCapacity.mru, + rootfs_size: 0, + flist: "https://hub.grid.tf/tf-official-apps/presearch-v2.3.flist", + entrypoint: "/sbin/zinit init", + env: { + SSH_KEY: config.ssh_key, + //Presearch Registeration Code. + PRESEARCH_REGISTRATION_CODE: "", + //You need to fill in these inputs only if you already have a Presearch node deployed somewhere and would like to migrate to Threefold. + //The Private Presearch Restore Key is a unique cryptographic key associated with your Presearch account. + PRESEARCH_BACKUP_PRI_KEY: "", + //The Public Presearch Restore Key is a unique cryptographic key associated with your Presearch account. + PRESEARCH_BACKUP_PUB_KEY: "", + }, + }, + ], + metadata: "", + description: "test deploying Presearch via ts grid3 client", + }; + + //Deploy VMs + await deploy(grid3, vms); + + //Get the deployment + await getDeployment(grid3, vms); + + //Uncomment the line below to cancel the deployment + // await cancel(grid3, { name }); + + await grid3.disconnect(); +} + +main(); diff --git a/packages/grid_client/scripts/applications/subsquid.ts b/packages/grid_client/scripts/applications/subsquid.ts new file mode 100644 index 0000000000..32f844100b --- /dev/null +++ b/packages/grid_client/scripts/applications/subsquid.ts @@ -0,0 +1,119 @@ +import { FilterOptions, GatewayNameModel, MachinesModel } from "../../src"; +import { config, getClient } from "../client_loader"; +import { log, pingNodes } from "../utils"; + +async function deploy(client, vms, subdomain, gatewayNode) { + const resultVM = await client.machines.deploy(vms); + log("================= Deploying VM ================="); + log(resultVM); + log("================= Deploying VM ================="); + + 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 + "]:4444"], + }; + + const resultGateway = await client.gateway.deploy_name(gw); + log("================= Deploying name gateway ================="); + log(resultGateway); + log("================= Deploying name gateway ================="); +} + +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(resultVM); + log(resultGateway); + log("https://" + resultGateway[0].domain); + log("================= Getting deployment information ================="); +} + +async function cancel(client, vms, gw) { + const resultVM = await client.machines.delete(vms); + const resultGateway = await client.gateway.delete_name(gw); + log("================= Canceling the deployment ================="); + log(resultVM); + log(resultGateway); + log("================= Canceling the deployment ================="); +} + +async function main() { + const name = "newsubsquid"; + const grid3 = await getClient(`subsquid/${name}`); + const subdomain = "ss" + grid3.twinId + name; + const instanceCapacity = { cru: 1, mru: 2, sru: 50 }; // Update the instance capacity values according to your requirements. + + //VMNode Selection + const vmQueryOptions: FilterOptions = { + cru: instanceCapacity.cru, + mru: instanceCapacity.mru, + sru: instanceCapacity.sru, + availableFor: grid3.twinId, + farmId: 1, + }; + //GatewayNode Selection + const gatewayQueryOptions: FilterOptions = { + gateway: true, + 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 domain = subdomain + "." + gatewayNode.publicConfig.domain; + + const vms: MachinesModel = { + name, + network: { + name: "wedtest", + ip_range: "10.249.0.0/16", + }, + machines: [ + { + name: "subsquid", + node_id: vmNode, + disks: [ + { + name: "wedDisk", + size: instanceCapacity.sru, + mountpoint: "/var/lib/docker", + }, + ], + planetary: true, + public_ip: false, + public_ip6: false, + mycelium: false, + cpu: instanceCapacity.cru, + memory: 1024 * instanceCapacity.mru, + rootfs_size: 0, + flist: "https://hub.grid.tf/tf-official-apps/subsquid-latest.flist", + entrypoint: "/sbin/zinit init", + env: { + SSH_KEY: config.ssh_key, + SUBSQUID_WEBSERVER_HOSTNAME: domain, + // Update the Subsquid websocket endpoint for a supported substrate chain. + CHAIN_ENDPOINT: "wss://polkadex-mainnet-rpc.dwellir.com", + }, + }, + ], + metadata: "", + description: "test deploying Taiga via ts grid3 client", + }; + + //Deploy VMs + await deploy(grid3, vms, subdomain, gatewayNode); + + //Get the deployment + await getDeployment(grid3, vms, subdomain); + + //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/taiga.ts b/packages/grid_client/scripts/applications/taiga.ts new file mode 100644 index 0000000000..42e85453ed --- /dev/null +++ b/packages/grid_client/scripts/applications/taiga.ts @@ -0,0 +1,129 @@ +import { FilterOptions, GatewayNameModel, MachinesModel } from "../../src"; +import { config, getClient } from "../client_loader"; +import { log, pingNodes } from "../utils"; + +async function deploy(client, vms, subdomain, gatewayNode) { + const resultVM = await client.machines.deploy(vms); + log("================= Deploying VM ================="); + log(resultVM); + log("================= Deploying VM ================="); + + 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(resultGateway); + log("================= Deploying name gateway ================="); +} + +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(resultVM); + log(resultGateway); + log("https://" + resultGateway[0].domain); + log("================= Getting deployment information ================="); +} + +async function cancel(client, vms, gw) { + const resultVM = await client.machines.delete(vms); + const resultGateway = await client.gateway.delete_name(gw); + log("================= Canceling the deployment ================="); + log(resultVM); + log(resultGateway); + log("================= Canceling the deployment ================="); +} + +async function main() { + const name = "newtaiga"; + const grid3 = await getClient(`taiga/${name}`); + const subdomain = "tg" + grid3.twinId + name; + const instanceCapacity = { cru: 2, mru: 4, sru: 50 }; // Update the instance capacity values according to your requirements. + + //VMNode Selection + const vmQueryOptions: FilterOptions = { + cru: instanceCapacity.cru, + mru: instanceCapacity.mru, + sru: instanceCapacity.sru, + availableFor: grid3.twinId, + farmId: 1, + }; + //GatewayNode Selection + const gatewayQueryOptions: FilterOptions = { + gateway: true, + 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 domain = subdomain + "." + gatewayNode.publicConfig.domain; + + const vms: MachinesModel = { + name, + network: { + name: "wedtest", + ip_range: "10.249.0.0/16", + }, + machines: [ + { + name: "taiga", + node_id: vmNode, + disks: [ + { + name: "wedDisk", + size: instanceCapacity.sru, + mountpoint: "/var/lib/docker", + }, + ], + planetary: true, + public_ip: false, + public_ip6: false, + mycelium: false, + cpu: instanceCapacity.cru, + memory: 1024 * instanceCapacity.mru, + rootfs_size: 0, + flist: "https://hub.grid.tf/tf-official-apps/grid3_taiga_docker-latest.flist", + entrypoint: "/sbin/zinit init", + env: { + SSH_KEY: config.ssh_key, + DOMAIN_NAME: domain, + // These email, username and password will be used as admin credentials, so please update them with your own. + ADMIN_USERNAME: "admin123", + ADMIN_PASSWORD: "admin123", + ADMIN_EMAIL: "admin123@taiga.com", + /* 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. */ + // EMAIL_HOST: "false", + // EMAIL_PORT: "admin123@taiga.com", + // EMAIL_HOST_USER: "admin123", + // EMAIL_HOST_PASSWORD: "admin123", + // EMAIL_USE_TLS: "false", + // EMAIL_USE_SSL: "false", + }, + }, + ], + metadata: "", + description: "test deploying Taiga via ts grid3 client", + }; + + //Deploy VMs + await deploy(grid3, vms, subdomain, gatewayNode); + + //Get the deployment + await getDeployment(grid3, vms, subdomain); + + //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/umbrel.ts b/packages/grid_client/scripts/applications/umbrel.ts new file mode 100644 index 0000000000..7060f9067e --- /dev/null +++ b/packages/grid_client/scripts/applications/umbrel.ts @@ -0,0 +1,99 @@ +import { FilterOptions, MachinesModel } from "../../src"; +import { config, getClient } from "../client_loader"; +import { log, pingNodes } from "../utils"; + +async function deploy(client, vms) { + const resultVM = await client.machines.deploy(vms); + log("================= Deploying VM ================="); + log(resultVM); + log("================= Deploying VM ================="); +} + +async function getDeployment(client, vms) { + const resultVM = await client.machines.getObj(vms.name); + log("================= Getting deployment information ================="); + log(resultVM); + log("http://[" + resultVM[0].planetary + "]/"); + log("================= Getting deployment information ================="); +} + +async function cancel(client, vms) { + const resultVM = await client.machines.delete(vms); + log("================= Canceling the deployment ================="); + log(resultVM); + log("================= Canceling the deployment ================="); +} + +async function main() { + const name = "newumbrel"; + const grid3 = await getClient(`umbrel/${name}`); + const instanceCapacity = { cru: 1, mru: 2, sru: 20 }; // Update the instance capacity values according to your requirements. + + //VMNode Selection + const vmQueryOptions: FilterOptions = { + cru: instanceCapacity.cru, + mru: instanceCapacity.mru, + sru: instanceCapacity.sru, + availableFor: grid3.twinId, + farmId: 1, + }; + const nodes = await grid3.capacity.filterNodes(vmQueryOptions); + const vmNode = await pingNodes(grid3, nodes); + + const vms: MachinesModel = { + name, + network: { + name: "wedtest", + ip_range: "10.249.0.0/16", + }, + machines: [ + { + name: "umbrel", + node_id: vmNode, + disks: [ + { + name: "docker", + size: 10, + mountpoint: "/var/lib/docker", + }, + { + name: "umbrelDisk", + size: 10, + mountpoint: "/umbrelDisk", + }, + ], + planetary: true, + public_ip: false, + public_ip6: false, + mycelium: false, + cpu: instanceCapacity.cru, + memory: 1024 * instanceCapacity.mru, + rootfs_size: 0, + flist: "https://hub.grid.tf/tf-official-apps/umbrel-latest.flist", + entrypoint: "/sbin/zinit init", + env: { + SSH_KEY: config.ssh_key, + UMBREL_DISK: "/umbrelDisk", + // These username and password will be used as admin credentials, so please update them with your own. + USERNAME: "admin", + PASSWORD: "admin1234567", + }, + }, + ], + metadata: "", + description: "test deploying Umbrel via ts grid3 client", + }; + + //Deploy VMs + await deploy(grid3, vms); + + //Get the deployment + await getDeployment(grid3, vms); + + //Uncomment the line below to cancel the deployment + // await cancel(grid3, { name }); + + await grid3.disconnect(); +} + +main(); diff --git a/packages/grid_client/scripts/applications/wordpress.ts b/packages/grid_client/scripts/applications/wordpress.ts new file mode 100644 index 0000000000..b3f6851a23 --- /dev/null +++ b/packages/grid_client/scripts/applications/wordpress.ts @@ -0,0 +1,122 @@ +import { FilterOptions, GatewayNameModel, MachinesModel } from "../../src"; +import { config, getClient } from "../client_loader"; +import { log, pingNodes } from "../utils"; + +async function deploy(client, vms, subdomain, gatewayNode) { + const resultVM = await client.machines.deploy(vms); + log("================= Deploying VM ================="); + log(resultVM); + log("================= Deploying VM ================="); + + 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(resultGateway); + log("================= Deploying name gateway ================="); +} + +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(resultVM); + log(resultGateway); + log("https://" + resultGateway[0].domain); + log("https://" + resultGateway[0].domain + "/wp-admin"); + log("================= Getting deployment information ================="); +} + +async function cancel(client, vms, gw) { + const resultVM = await client.machines.delete(vms); + const resultGateway = await client.gateway.delete_name(gw); + log("================= Canceling the deployment ================="); + log(resultVM); + log(resultGateway); + log("================= Canceling the deployment ================="); +} + +async function main() { + const name = "newwordpress"; + const grid3 = await getClient(`wordpress/${name}`); + const subdomain = "wp" + grid3.twinId + name; + const instanceCapacity = { cru: 2, mru: 4, sru: 50 }; // Update the instance capacity values according to your requirements. + + //VMNode Selection + const vmQueryOptions: FilterOptions = { + cru: instanceCapacity.cru, + mru: instanceCapacity.mru, + sru: instanceCapacity.sru, + availableFor: grid3.twinId, + farmId: 1, + }; + //GatewayNode Selection + const gatewayQueryOptions: FilterOptions = { + gateway: true, + 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 domain = subdomain + "." + gatewayNode.publicConfig.domain; + + const vms: MachinesModel = { + name, + network: { + name: "wedtest", + ip_range: "10.249.0.0/16", + }, + machines: [ + { + name: "wordpress", + node_id: vmNode, + disks: [ + { + name: "wedDisk", + size: instanceCapacity.sru, + mountpoint: "/var/www/html", + }, + ], + planetary: true, + public_ip: false, + public_ip6: false, + mycelium: false, + cpu: instanceCapacity.cru, + memory: 1024 * instanceCapacity.mru, + rootfs_size: 0, + flist: "https://hub.grid.tf/tf-official-apps/tf-wordpress-latest.flist", + entrypoint: "/sbin/zinit init", + env: { + SSH_KEY: config.ssh_key, + WP_URL: domain, + // These email, username and password will be used as admin credentials, so please update them with your own. + MYSQL_USER: "admin123", + MYSQL_PASSWORD: "admin123", + ADMIN_EMAIL: "admin123@wordpress.com", + }, + }, + ], + metadata: "", + description: "test deploying WordPress via ts grid3 client", + }; + + //Deploy VMs + await deploy(grid3, vms, subdomain, gatewayNode); + + //Get the deployment + await getDeployment(grid3, vms, subdomain); + + //Uncomment the line below to cancel the deployment + // await cancel(grid3, { name }, { name: subdomain }); + + await grid3.disconnect(); +} + +main(); From 8a6cbcb54f3c3a9b3c1dc0b9677917f66767aeba Mon Sep 17 00:00:00 2001 From: A-Harby Date: Mon, 27 May 2024 14:40:34 +0300 Subject: [PATCH 2/3] fix description typo and update algorand capacity --- packages/grid_client/scripts/applications/algorand.ts | 4 ++-- packages/grid_client/scripts/applications/discourse.ts | 2 +- packages/grid_client/scripts/applications/nextcloud.ts | 2 +- packages/grid_client/scripts/applications/subsquid.ts | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/grid_client/scripts/applications/algorand.ts b/packages/grid_client/scripts/applications/algorand.ts index 2581861176..c3da01d283 100644 --- a/packages/grid_client/scripts/applications/algorand.ts +++ b/packages/grid_client/scripts/applications/algorand.ts @@ -26,7 +26,7 @@ async function cancel(client, vms) { async function main() { const name = "newalgorand"; const grid3 = await getClient(`algorand/${name}`); - const instanceCapacity = { cru: 2, mru: 4, sru: 50 }; // 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 = { @@ -81,7 +81,7 @@ async function main() { }, ], metadata: "", - description: "test deploying Presearch via ts grid3 client", + description: "test deploying Algorand via ts grid3 client", }; //Deploy VMs diff --git a/packages/grid_client/scripts/applications/discourse.ts b/packages/grid_client/scripts/applications/discourse.ts index ded54a4566..0bcb60b84a 100644 --- a/packages/grid_client/scripts/applications/discourse.ts +++ b/packages/grid_client/scripts/applications/discourse.ts @@ -118,7 +118,7 @@ async function main() { }, ], metadata: "", - description: "test deploying DisCourse via ts grid3 client", + description: "test deploying Discourse via ts grid3 client", }; //Deploy VMs diff --git a/packages/grid_client/scripts/applications/nextcloud.ts b/packages/grid_client/scripts/applications/nextcloud.ts index 550125991b..85e576b97b 100644 --- a/packages/grid_client/scripts/applications/nextcloud.ts +++ b/packages/grid_client/scripts/applications/nextcloud.ts @@ -103,7 +103,7 @@ async function main() { }, ], metadata: "", - description: "test deploying NextCloud via ts grid3 client", + description: "test deploying Nextcloud via ts grid3 client", }; //Deploy VMs diff --git a/packages/grid_client/scripts/applications/subsquid.ts b/packages/grid_client/scripts/applications/subsquid.ts index 32f844100b..e074abf67d 100644 --- a/packages/grid_client/scripts/applications/subsquid.ts +++ b/packages/grid_client/scripts/applications/subsquid.ts @@ -101,7 +101,7 @@ async function main() { }, ], metadata: "", - description: "test deploying Taiga via ts grid3 client", + description: "test deploying Subsquid via ts grid3 client", }; //Deploy VMs From c9a5630292d80a0f766e2b64b78aa67c15c814bf Mon Sep 17 00:00:00 2001 From: A-Harby Date: Mon, 27 May 2024 17:52:27 +0300 Subject: [PATCH 3/3] move kubernetes and caprovers scripts into new orchestrators direcotry --- .../scripts/{ => orchestrators}/caprover_leader.ts | 6 +++--- .../scripts/{ => orchestrators}/caprover_worker.ts | 6 +++--- .../{kubernetes.ts => orchestrators/kubernetes_leader.ts} | 6 +++--- .../scripts/{ => orchestrators}/kubernetes_mycelium.ts | 6 +++--- .../scripts/{ => orchestrators}/kubernetes_with_qsfs.ts | 6 +++--- .../{add_worker.ts => orchestrators/kubernetes_worker.ts} | 6 +++--- 6 files changed, 18 insertions(+), 18 deletions(-) rename packages/grid_client/scripts/{ => orchestrators}/caprover_leader.ts (94%) rename packages/grid_client/scripts/{ => orchestrators}/caprover_worker.ts (93%) rename packages/grid_client/scripts/{kubernetes.ts => orchestrators/kubernetes_leader.ts} (94%) rename packages/grid_client/scripts/{ => orchestrators}/kubernetes_mycelium.ts (95%) rename packages/grid_client/scripts/{ => orchestrators}/kubernetes_with_qsfs.ts (96%) rename packages/grid_client/scripts/{add_worker.ts => orchestrators/kubernetes_worker.ts} (92%) diff --git a/packages/grid_client/scripts/caprover_leader.ts b/packages/grid_client/scripts/orchestrators/caprover_leader.ts similarity index 94% rename from packages/grid_client/scripts/caprover_leader.ts rename to packages/grid_client/scripts/orchestrators/caprover_leader.ts index 1456b365ce..c9b6298e78 100644 --- a/packages/grid_client/scripts/caprover_leader.ts +++ b/packages/grid_client/scripts/orchestrators/caprover_leader.ts @@ -1,6 +1,6 @@ -import { FilterOptions, MachinesModel } from "../src"; -import { config, getClient } from "./client_loader"; -import { log } from "./utils"; +import { FilterOptions, MachinesModel } from "../../src"; +import { config, getClient } from "../client_loader"; +import { log } from "../utils"; async function deploy(client, vms) { const res = await client.machines.deploy(vms); diff --git a/packages/grid_client/scripts/caprover_worker.ts b/packages/grid_client/scripts/orchestrators/caprover_worker.ts similarity index 93% rename from packages/grid_client/scripts/caprover_worker.ts rename to packages/grid_client/scripts/orchestrators/caprover_worker.ts index 23b53149ca..585f78699d 100644 --- a/packages/grid_client/scripts/caprover_worker.ts +++ b/packages/grid_client/scripts/orchestrators/caprover_worker.ts @@ -1,6 +1,6 @@ -import { FilterOptions, MachinesModel } from "../src"; -import { config, getClient } from "./client_loader"; -import { log } from "./utils"; +import { FilterOptions, MachinesModel } from "../../src"; +import { config, getClient } from "../client_loader"; +import { log } from "../utils"; async function deploy(client, vms) { const res = await client.machines.deploy(vms); diff --git a/packages/grid_client/scripts/kubernetes.ts b/packages/grid_client/scripts/orchestrators/kubernetes_leader.ts similarity index 94% rename from packages/grid_client/scripts/kubernetes.ts rename to packages/grid_client/scripts/orchestrators/kubernetes_leader.ts index b3963fbf6f..7960ee5176 100644 --- a/packages/grid_client/scripts/kubernetes.ts +++ b/packages/grid_client/scripts/orchestrators/kubernetes_leader.ts @@ -1,6 +1,6 @@ -import { FilterOptions, K8SModel } from "../src"; -import { config, getClient } from "./client_loader"; -import { log } from "./utils"; +import { FilterOptions, K8SModel } from "../../src"; +import { config, getClient } from "../client_loader"; +import { log } from "../utils"; async function deploy(client, k8s) { const res = await client.k8s.deploy(k8s); diff --git a/packages/grid_client/scripts/kubernetes_mycelium.ts b/packages/grid_client/scripts/orchestrators/kubernetes_mycelium.ts similarity index 95% rename from packages/grid_client/scripts/kubernetes_mycelium.ts rename to packages/grid_client/scripts/orchestrators/kubernetes_mycelium.ts index e927979964..d8305cda18 100644 --- a/packages/grid_client/scripts/kubernetes_mycelium.ts +++ b/packages/grid_client/scripts/orchestrators/kubernetes_mycelium.ts @@ -1,6 +1,6 @@ -import { FilterOptions, K8SModel } from "../src"; -import { config, getClient } from "./client_loader"; -import { log } from "./utils"; +import { FilterOptions, K8SModel } from "../../src"; +import { config, getClient } from "../client_loader"; +import { log } from "../utils"; async function deploy(client, k8s) { const res = await client.k8s.deploy(k8s); diff --git a/packages/grid_client/scripts/kubernetes_with_qsfs.ts b/packages/grid_client/scripts/orchestrators/kubernetes_with_qsfs.ts similarity index 96% rename from packages/grid_client/scripts/kubernetes_with_qsfs.ts rename to packages/grid_client/scripts/orchestrators/kubernetes_with_qsfs.ts index e55b24ce4d..b3122d542e 100644 --- a/packages/grid_client/scripts/kubernetes_with_qsfs.ts +++ b/packages/grid_client/scripts/orchestrators/kubernetes_with_qsfs.ts @@ -1,6 +1,6 @@ -import { FilterOptions, K8SModel, QSFSZDBSModel } from "../src"; -import { config, getClient } from "./client_loader"; -import { log } from "./utils"; +import { FilterOptions, K8SModel, QSFSZDBSModel } from "../../src"; +import { config, getClient } from "../client_loader"; +import { log } from "../utils"; async function deployQsfs(client, qsfs) { const res = await client.qsfs_zdbs.deploy(qsfs); diff --git a/packages/grid_client/scripts/add_worker.ts b/packages/grid_client/scripts/orchestrators/kubernetes_worker.ts similarity index 92% rename from packages/grid_client/scripts/add_worker.ts rename to packages/grid_client/scripts/orchestrators/kubernetes_worker.ts index 4eaaac06c2..aaf027099c 100644 --- a/packages/grid_client/scripts/add_worker.ts +++ b/packages/grid_client/scripts/orchestrators/kubernetes_worker.ts @@ -1,6 +1,6 @@ -import { AddWorkerModel, FilterOptions } from "../src"; -import { getClient } from "./client_loader"; -import { log } from "./utils"; +import { AddWorkerModel, FilterOptions } from "../../src"; +import { getClient } from "../client_loader"; +import { log } from "../utils"; // Please run kubernetes script first before running this one to create the cluster.