Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Node Pilot domain #3010

Merged
merged 8 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/grid_client/src/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export * from "./validator";
export * from "./expose";
export * from "./migration";
export * from "./root_fs";
export * from "./types";
40 changes: 39 additions & 1 deletion packages/grid_client/src/helpers/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ interface ExtendedMountData extends BaseMountData {
// Union type for the mount data
type MountData = BaseMountData | ExtendedMountData;

export interface ZmachineData {
interface ZmachineData {
/** The version of the workload */
version: number;
/** The contract ID associated with the workload */
Expand Down Expand Up @@ -89,3 +89,41 @@ export interface ZmachineData {
/** The list of the GPUs */
gpu: string[] | undefined;
}

interface VM {
version: number;
contractId: number;
Mahmoud-Emad marked this conversation as resolved.
Show resolved Hide resolved
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: MountData[];
env: {
SSH_KEY: string;
};
entrypoint: string;
metadata?: string;
description?: string;
rootfs_size: number;
corex: boolean;
gpu?: string[];
deploymentName: string;
projectName: string;
wireguard: string;
}

export { ZmachineData, VM };
5 changes: 5 additions & 0 deletions packages/playground/src/constants/deployment_list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,9 @@ export const deploymentListEnvironments = {
nostr: {
SSH_KEY: _ssh,
},

nodepilot: {
SSH_KEY: _ssh,
NODE_PILOT_HOSTNAME: "Node Pilot Hostname",
},
};
2 changes: 1 addition & 1 deletion packages/playground/src/weblets/tf_deployment_list.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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"
/>
</template>

Expand Down
62 changes: 53 additions & 9 deletions packages/playground/src/weblets/tf_node_pilot.vue
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
rootFilesystemSize,
}"
v-model="selectionDetails"
require-domain
/>

<manage-ssh-deployemnt @selected-keys="updateSSHkeyEnv($event)" />
Expand All @@ -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";
Expand All @@ -102,20 +103,41 @@ const selectionDetails = ref<SelectionDetails>();
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: VM[];

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,
Expand All @@ -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: [
{
Expand All @@ -141,10 +166,28 @@ async function deploy() {
},
],
});

layout.value.reloadDeploymentsList();
layout.value.setStatus("success", "Successfully deployed a node pilot instance.");
layout.value.openDialog(vm, deploymentListEnvironments.vm);
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."));
}
Expand All @@ -156,13 +199,14 @@ function updateSSHkeyEnv(selectedKeys: string) {
</script>

<script lang="ts">
import type { GridClient } from "@threefold/grid_client";
import type { GridClient, VM } from "@threefold/grid_client";

import SelectSolutionFlavor from "../components/select_solution_flavor.vue";
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";

Expand Down
Loading