From 1f916fe2464a74cdd0bc69836a535cac5df6a16d Mon Sep 17 00:00:00 2001 From: zaelgohary Date: Sun, 23 Jun 2024 15:06:33 +0300 Subject: [PATCH 1/6] Add domain to node pilot --- .../src/constants/deployment_list.ts | 5 ++ .../src/weblets/tf_deployment_list.vue | 2 +- .../playground/src/weblets/tf_node_pilot.vue | 63 ++++++++++++++++--- 3 files changed, 61 insertions(+), 9 deletions(-) diff --git a/packages/playground/src/constants/deployment_list.ts b/packages/playground/src/constants/deployment_list.ts index 45fa7c37ec..3b0cab13ac 100644 --- a/packages/playground/src/constants/deployment_list.ts +++ b/packages/playground/src/constants/deployment_list.ts @@ -169,4 +169,9 @@ export const deploymentListEnvironments = { nostr: { SSH_KEY: _ssh, }, + + nodepilot: { + SSH_KEY: _ssh, + NODE_PILOT_HOSTNAME: "Node Pilot Hostname", + }, }; diff --git a/packages/playground/src/weblets/tf_deployment_list.vue b/packages/playground/src/weblets/tf_deployment_list.vue index 8b98883e0d..db7ec2069f 100644 --- a/packages/playground/src/weblets/tf_deployment_list.vue +++ b/packages/playground/src/weblets/tf_deployment_list.vue @@ -249,7 +249,7 @@ tooltip="Visit" icon="mdi-web" color="anchor" - :href="'http://' + (item.publicIP?.ip ? item.publicIP.ip.slice(0, -3) : '[' + item.planetary + ']')" + :href="'https://' + item.env.NODE_PILOT_HOSTNAME" /> diff --git a/packages/playground/src/weblets/tf_node_pilot.vue b/packages/playground/src/weblets/tf_node_pilot.vue index 1f9e927c31..a3a74f7ed9 100644 --- a/packages/playground/src/weblets/tf_node_pilot.vue +++ b/packages/playground/src/weblets/tf_node_pilot.vue @@ -62,6 +62,7 @@ rootFilesystemSize, }" v-model="selectionDetails" + require-domain /> @@ -80,7 +81,7 @@ import { manual } from "@/utils/manual"; import Network from "../components/networks.vue"; import { useLayout } from "../components/weblet_layout.vue"; -import { useGrid } from "../stores"; +import { useGrid, useProfileManager } from "../stores"; import { type Flist, ProjectName } from "../types"; import { deployVM } from "../utils/deploy_vm"; import { generateName } from "../utils/strings"; @@ -102,20 +103,41 @@ const selectionDetails = ref(); const selectedSSHKeys = ref(""); const gridStore = useGrid(); const grid = gridStore.client as GridClient; +const profileManager = useProfileManager(); +function finalize(deployment: any) { + layout.value.reloadDeploymentsList(); + layout.value.setStatus("success", "Successfully deployed a Node Pilot instance."); + layout.value.openDialog(deployment, deploymentListEnvironments.nodepilot); +} async function deploy() { layout.value.setStatus("deploy"); const projectName = ProjectName.NodePilot.toLowerCase() + "/" + name.value; + const subdomain = getSubdomain({ + deploymentName: name.value, + projectName, + twinId: profileManager.profile!.twinId, + }); + + const domain = selectionDetails.value?.domain?.enabledCustomDomain + ? selectionDetails.value.domain.customDomain + : subdomain + "." + selectionDetails.value?.domain?.selectedDomain?.publicConfig.domain; + + let vm: any; + try { layout.value?.validateSSH(); updateGrid(grid, { projectName }); await layout.value.validateBalance(grid!); - - const vm = await deployVM(grid!, { + vm = await deployVM(grid!, { name: name.value, + network: { + addAccess: selectionDetails.value!.domain!.enableSelectedDomain, + accessNodeId: selectionDetails.value!.domain?.selectedDomain?.nodeId, + }, machines: [ { name: name.value, @@ -127,7 +149,10 @@ async function deploy() { publicIpv6: ipv6.value, planetary: planetary.value, mycelium: mycelium.value, - envs: [{ key: "SSH_KEY", value: selectedSSHKeys.value }], + envs: [ + { key: "SSH_KEY", value: selectedSSHKeys.value }, + { key: "NODE_PILOT_HOSTNAME", value: domain }, + ], rootFilesystemSize, disks: [ { @@ -141,13 +166,34 @@ async function deploy() { }, ], }); - - layout.value.reloadDeploymentsList(); - layout.value.setStatus("success", "Successfully deployed a node pilot instance."); - layout.value.openDialog(vm, deploymentListEnvironments.vm); } catch (e) { layout.value.setStatus("failed", normalizeError(e, "Failed to deploy a Node Pilot instance.")); } + + if (!selectionDetails.value?.domain?.enableSelectedDomain) { + vm[0].customDomain = selectionDetails.value?.domain?.customDomain; + finalize(vm); + return; + } + + try { + layout.value.setStatus("deploy", "Preparing to deploy gateway..."); + console.log("vm[0]", vm[0]); + + await deployGatewayName(grid, selectionDetails.value.domain, { + subdomain, + ip: vm[0].interfaces[0].ip, + port: 34416, + network: vm[0].interfaces[0].network, + }); + + finalize(vm); + } catch (e) { + layout.value.setStatus("deploy", "Rollbacking back due to fail to deploy gateway..."); + + await rollbackDeployment(grid!, name.value); + layout.value.setStatus("failed", normalizeError(e, "Failed to deploy a Casperlabs instance.")); + } } function updateSSHkeyEnv(selectedKeys: string) { @@ -163,6 +209,7 @@ import ManageSshDeployemnt from "../components/ssh_keys/ManageSshDeployemnt.vue" import { deploymentListEnvironments } from "../constants"; import type { solutionFlavor as SolutionFlavor } from "../types"; import type { SelectionDetails } from "../types/nodeSelector"; +import { deployGatewayName, getSubdomain, rollbackDeployment } from "../utils/gateway"; import { updateGrid } from "../utils/grid"; import { normalizeError } from "../utils/helpers"; From c776d6aca4ed3e979f9aa4c52ba889a1a644f1eb Mon Sep 17 00:00:00 2001 From: zaelgohary Date: Tue, 25 Jun 2024 11:31:03 +0300 Subject: [PATCH 2/6] Create VM interface, Fix typos --- packages/playground/src/utils/types.ts | 32 +++++++++++++++++++ .../playground/src/weblets/tf_node_pilot.vue | 7 ++-- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/packages/playground/src/utils/types.ts b/packages/playground/src/utils/types.ts index 881c7398fa..77b4d20c09 100644 --- a/packages/playground/src/utils/types.ts +++ b/packages/playground/src/utils/types.ts @@ -14,3 +14,35 @@ export interface IPublicConfig { gw6?: string; domain?: string; } + +export interface VM { + version: number; + contractId: number; + nodeId: number; + name: string; + created: number; + status: string; + message: string; + flist: string; + publicIP: string; + planetary: string; + myceliumIP: string; + interfaces: { + network: string; + ip: string; + }[]; + capacity: { + cpu: number; + memory: number; + }; + mounts: any[]; + env: { + SSH_KEY: string; + }; + entrypoint: string; + metadata?: any; + description?: any; + rootfs_size: number; + corex: boolean; + gpu: any[]; +} diff --git a/packages/playground/src/weblets/tf_node_pilot.vue b/packages/playground/src/weblets/tf_node_pilot.vue index a3a74f7ed9..eb86d4446c 100644 --- a/packages/playground/src/weblets/tf_node_pilot.vue +++ b/packages/playground/src/weblets/tf_node_pilot.vue @@ -125,7 +125,7 @@ async function deploy() { ? selectionDetails.value.domain.customDomain : subdomain + "." + selectionDetails.value?.domain?.selectedDomain?.publicConfig.domain; - let vm: any; + let vm: VM; try { layout.value?.validateSSH(); @@ -178,8 +178,6 @@ async function deploy() { try { layout.value.setStatus("deploy", "Preparing to deploy gateway..."); - console.log("vm[0]", vm[0]); - await deployGatewayName(grid, selectionDetails.value.domain, { subdomain, ip: vm[0].interfaces[0].ip, @@ -192,7 +190,7 @@ async function deploy() { layout.value.setStatus("deploy", "Rollbacking back due to fail to deploy gateway..."); await rollbackDeployment(grid!, name.value); - layout.value.setStatus("failed", normalizeError(e, "Failed to deploy a Casperlabs instance.")); + layout.value.setStatus("failed", normalizeError(e, "Failed to deploy a Node Pilot instance.")); } } @@ -212,6 +210,7 @@ import type { SelectionDetails } from "../types/nodeSelector"; import { deployGatewayName, getSubdomain, rollbackDeployment } from "../utils/gateway"; import { updateGrid } from "../utils/grid"; import { normalizeError } from "../utils/helpers"; +import { VM } from "../utils/types"; export default { name: "NodePilot", From 349d24d97a7b26c55997fa934aa2e68b910f5bd4 Mon Sep 17 00:00:00 2001 From: zaelgohary Date: Tue, 25 Jun 2024 12:51:44 +0300 Subject: [PATCH 3/6] Fix import, edit type --- packages/playground/src/utils/types.ts | 4 ++ .../playground/src/weblets/tf_node_pilot.vue | 49 +++++++++---------- 2 files changed, 28 insertions(+), 25 deletions(-) diff --git a/packages/playground/src/utils/types.ts b/packages/playground/src/utils/types.ts index 77b4d20c09..23160f45a5 100644 --- a/packages/playground/src/utils/types.ts +++ b/packages/playground/src/utils/types.ts @@ -27,6 +27,7 @@ export interface VM { publicIP: string; planetary: string; myceliumIP: string; + customDomain?: string; interfaces: { network: string; ip: string; @@ -45,4 +46,7 @@ export interface VM { rootfs_size: number; corex: boolean; gpu: any[]; + deploymentName: string; + projectName: string; + wireguard: string; } diff --git a/packages/playground/src/weblets/tf_node_pilot.vue b/packages/playground/src/weblets/tf_node_pilot.vue index eb86d4446c..aa07e3bde2 100644 --- a/packages/playground/src/weblets/tf_node_pilot.vue +++ b/packages/playground/src/weblets/tf_node_pilot.vue @@ -125,7 +125,7 @@ async function deploy() { ? selectionDetails.value.domain.customDomain : subdomain + "." + selectionDetails.value?.domain?.selectedDomain?.publicConfig.domain; - let vm: VM; + let vm: VM[]; try { layout.value?.validateSSH(); @@ -166,32 +166,31 @@ async function deploy() { }, ], }); + if (!selectionDetails.value?.domain?.enableSelectedDomain) { + vm[0].customDomain = selectionDetails.value?.domain?.customDomain; + finalize(vm); + return; + } + + try { + layout.value.setStatus("deploy", "Preparing to deploy gateway..."); + await deployGatewayName(grid, selectionDetails.value.domain, { + subdomain, + ip: vm[0].interfaces[0].ip, + port: 34416, + network: vm[0].interfaces[0].network, + }); + + finalize(vm); + } catch (e) { + layout.value.setStatus("deploy", "Rollbacking back due to fail to deploy gateway..."); + + await rollbackDeployment(grid!, name.value); + layout.value.setStatus("failed", normalizeError(e, "Failed to deploy a Node Pilot instance.")); + } } catch (e) { layout.value.setStatus("failed", normalizeError(e, "Failed to deploy a Node Pilot instance.")); } - - if (!selectionDetails.value?.domain?.enableSelectedDomain) { - vm[0].customDomain = selectionDetails.value?.domain?.customDomain; - finalize(vm); - return; - } - - try { - layout.value.setStatus("deploy", "Preparing to deploy gateway..."); - await deployGatewayName(grid, selectionDetails.value.domain, { - subdomain, - ip: vm[0].interfaces[0].ip, - port: 34416, - network: vm[0].interfaces[0].network, - }); - - finalize(vm); - } catch (e) { - layout.value.setStatus("deploy", "Rollbacking back due to fail to deploy gateway..."); - - await rollbackDeployment(grid!, name.value); - layout.value.setStatus("failed", normalizeError(e, "Failed to deploy a Node Pilot instance.")); - } } function updateSSHkeyEnv(selectedKeys: string) { @@ -210,7 +209,7 @@ import type { SelectionDetails } from "../types/nodeSelector"; import { deployGatewayName, getSubdomain, rollbackDeployment } from "../utils/gateway"; import { updateGrid } from "../utils/grid"; import { normalizeError } from "../utils/helpers"; -import { VM } from "../utils/types"; +import type { VM } from "../utils/types"; export default { name: "NodePilot", From 72ec46c627e4ecf1687124d2f0c85d1c28e60431 Mon Sep 17 00:00:00 2001 From: zaelgohary Date: Wed, 26 Jun 2024 15:02:05 +0300 Subject: [PATCH 4/6] Replace VM type in Grid Client instead of Playground --- packages/grid_client/src/helpers/index.ts | 1 + packages/grid_client/src/helpers/types.ts | 37 +++++++++++++++++++ packages/playground/src/utils/types.ts | 36 ------------------ .../playground/src/weblets/tf_node_pilot.vue | 3 +- 4 files changed, 39 insertions(+), 38 deletions(-) create mode 100644 packages/grid_client/src/helpers/types.ts diff --git a/packages/grid_client/src/helpers/index.ts b/packages/grid_client/src/helpers/index.ts index df0e217c10..9426b9396b 100644 --- a/packages/grid_client/src/helpers/index.ts +++ b/packages/grid_client/src/helpers/index.ts @@ -5,3 +5,4 @@ export * from "./validator"; export * from "./expose"; export * from "./migration"; export * from "./root_fs"; +export * from "./types"; diff --git a/packages/grid_client/src/helpers/types.ts b/packages/grid_client/src/helpers/types.ts new file mode 100644 index 0000000000..736b8b4b6c --- /dev/null +++ b/packages/grid_client/src/helpers/types.ts @@ -0,0 +1,37 @@ +interface VM { + version: number; + contractId: number; + nodeId: number; + name: string; + created: number; + status: string; + message: string; + flist: string; + publicIP: string; + planetary: string; + myceliumIP: string; + customDomain?: string; + interfaces: { + network: string; + ip: string; + }[]; + capacity: { + cpu: number; + memory: number; + }; + mounts: any[]; + env: { + SSH_KEY: string; + }; + entrypoint: string; + metadata?: any; + description?: any; + rootfs_size: number; + corex: boolean; + gpu: any[]; + deploymentName: string; + projectName: string; + wireguard: string; +} + +export { VM }; diff --git a/packages/playground/src/utils/types.ts b/packages/playground/src/utils/types.ts index 23160f45a5..881c7398fa 100644 --- a/packages/playground/src/utils/types.ts +++ b/packages/playground/src/utils/types.ts @@ -14,39 +14,3 @@ export interface IPublicConfig { gw6?: string; domain?: string; } - -export interface VM { - version: number; - contractId: number; - nodeId: number; - name: string; - created: number; - status: string; - message: string; - flist: string; - publicIP: string; - planetary: string; - myceliumIP: string; - customDomain?: string; - interfaces: { - network: string; - ip: string; - }[]; - capacity: { - cpu: number; - memory: number; - }; - mounts: any[]; - env: { - SSH_KEY: string; - }; - entrypoint: string; - metadata?: any; - description?: any; - rootfs_size: number; - corex: boolean; - gpu: any[]; - deploymentName: string; - projectName: string; - wireguard: string; -} diff --git a/packages/playground/src/weblets/tf_node_pilot.vue b/packages/playground/src/weblets/tf_node_pilot.vue index aa07e3bde2..6e1c08fed1 100644 --- a/packages/playground/src/weblets/tf_node_pilot.vue +++ b/packages/playground/src/weblets/tf_node_pilot.vue @@ -199,7 +199,7 @@ function updateSSHkeyEnv(selectedKeys: string) {