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

Edit Nostr solution #3159

Merged
merged 1 commit into from
Jul 28, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion packages/playground/public/info/nostr.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
title: Nostr
---

Nostr is a simple, open protocol that enables global, decentralized, and censorship-resistant social media.
Nostr is a simple, open protocol that enables global, decentralized, and censorship-resistant social media. For more details, check [Nostr documentation](https://www.manual.grid.tf/documentation/dashboard/solutions/nostr.html)
1 change: 1 addition & 0 deletions packages/playground/src/constants/deployment_list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ export const deploymentListEnvironments = {
},
nostr: {
SSH_KEY: _ssh,
NOSTR_HOSTNAME: "Nostr Hostname",
},

nodepilot: {
Expand Down
1 change: 1 addition & 0 deletions packages/playground/src/weblets/tf_deployment_list.vue
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@
icon="mdi-eye-outline"
@click="openDialog(tabs[activeTab].value, item)"
/>
<IconActionBtn tooltip="Visit" icon="mdi-web" color="anchor" :href="'https://' + item.env.NOSTR_HOSTNAME" />
</template>

<template #Wordpress-actions="{ item }">
Expand Down
91 changes: 57 additions & 34 deletions packages/playground/src/weblets/tf_nostr.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<template>
<weblet-layout
ref="layout"
@mount="layoutMount"
:cpu="solution?.cpu"
:memory="solution?.memory"
:disk="disks.reduce((total, disk) => total + disk.size, rootFilesystemSize)"
Expand Down Expand Up @@ -44,7 +43,7 @@
v-model:ipv6="ipv6"
v-model:planetary="planetary"
v-model:mycelium="mycelium"
ref="network"
v-model:wireguard="wireguard"
/>
<input-tooltip inline tooltip="Click to know more about dedicated machines." :href="manual.dedicated_machines">
<v-switch color="primary" inset label="Dedicated" v-model="dedicated" hide-details />
Expand All @@ -67,6 +66,7 @@
rootFilesystemSize,
}"
v-model="selectionDetails"
require-domain
/>

<manage-ssh-deployemnt @selected-keys="updateSSHkeyEnv($event)" />
Expand All @@ -80,16 +80,16 @@
</template>

<script lang="ts" setup>
import { computed, type Ref, ref, watch } from "vue";
import { computed, type Ref, ref } from "vue";

import { manual } from "@/utils/manual";

import Network from "../components/networks.vue";
import SelectSolutionFlavor from "../components/select_solution_flavor.vue";
import { useLayout } from "../components/weblet_layout.vue";
import { useGrid } from "../stores";
import { useGrid, useProfileManager } from "../stores";
import { ProjectName } from "../types";
import { deployVM, type Disk, type Env } from "../utils/deploy_vm";
import { deployVM, type Disk } from "../utils/deploy_vm";
import { generateName } from "../utils/strings";

const layout = useLayout();
Expand All @@ -98,53 +98,51 @@ const tabs = ref();
const name = ref(generateName({ prefix: "nt" }));
const ipv4 = ref(false);
const ipv6 = ref(false);
const wireguard = ref(false);
const planetary = ref(true);
const mycelium = ref(true);
const envs = ref<Env[]>([]);
const disks = ref<Disk[]>([]);
const network = ref();
const dedicated = ref(false);
const certified = ref(false);
const rootFilesystemSize = computed(() => solution.value?.disk);
const selectionDetails = ref<SelectionDetails>();
const selectedSSHKeys = ref("");
const gridStore = useGrid();
const grid = gridStore.client as GridClient;
const profileManager = useProfileManager();

function layoutMount() {
if (envs.value.length > 0) {
envs.value.splice(0, 1);
}

envs.value.unshift({
key: "SSH_KEY",
value: selectedSSHKeys.value,
});
}

function addDisk() {
const name = generateName();
disks.value.push({
name: "disk" + name,
size: 50,
mountPoint: "/mnt/" + name,
});
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.Nostr.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 {
updateGrid(grid, { projectName });

await layout.value.validateBalance(grid!);

const vm = await deployVM(grid!, {
vm = await deployVM(grid!, {
name: name.value,
network: {
addAccess: false,
addAccess: selectionDetails.value!.domain!.enableSelectedDomain,
accessNodeId: selectionDetails.value?.domain?.selectedDomain?.nodeId,
},
machines: [
{
Expand All @@ -154,7 +152,13 @@ async function deploy() {
flist: "https://hub.grid.tf/tf-official-apps/nostr_relay-mycelium.flist",
entryPoint: "/sbin/zinit init",
disks: disks.value,
envs: envs.value,
envs: [
{
key: "SSH_KEY",
value: selectedSSHKeys.value,
},
{ key: "NOSTR_HOSTNAME", value: domain },
],
planetary: planetary.value,
mycelium: mycelium.value,
publicIpv4: ipv4.value,
Expand All @@ -167,9 +171,28 @@ async function deploy() {
],
});

layout.value.reloadDeploymentsList();
layout.value.setStatus("success", "Successfully deployed a Nostr machine.");
layout.value.openDialog(vm, deploymentListEnvironments.nostr);
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: 8080,
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 Nostr macine instance."));
}
} catch (e) {
layout.value.setStatus("failed", normalizeError(e, "Failed to deploy Nostr machine instance."));
}
Expand All @@ -178,17 +201,16 @@ async function deploy() {
function updateSSHkeyEnv(selectedKeys: string) {
selectedSSHKeys.value = selectedKeys;
}

watch(selectedSSHKeys, layoutMount, { deep: true });
</script>

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

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 All @@ -197,6 +219,7 @@ const solution = ref() as Ref<SolutionFlavor>;
export default {
name: "Nostr",
components: {
ManageSshDeployemnt,
SelectSolutionFlavor,
},
};
Expand Down
Loading