Skip to content
This repository was archived by the owner on Aug 30, 2023. It is now read-only.

Commit 8b1988a

Browse files
authored
Merge pull request #427 from threefoldtech/development_peertube_updates
update peertube weblet with the min requirements
2 parents 9478150 + 1dc345c commit 8b1988a

File tree

3 files changed

+54
-18
lines changed

3 files changed

+54
-18
lines changed

src/elements/peertube/Peertube.wc.svelte

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
import type { IFormField, ITab } from "../../types";
66
import type { IProfile } from "../../types/Profile";
77
// Modules
8-
import VM, { Disk, Env } from "../../types/vm";
8+
import { Disk, Env } from "../../types/vm";
9+
import Peertube from "../../types/peertube";
910
import deployPeertube from "../../utils/deployPeertube";
1011
// Components
1112
import SelectProfile from "../../components/SelectProfile.svelte";
@@ -22,6 +23,7 @@
2223
validateCpu,
2324
validateDisk,
2425
validateMemory,
26+
validateEmail,
2527
} from "../../utils/validateName";
2628
import { noActiveProfile } from "../../utils/message";
2729
import rootFs from "../../utils/rootFs";
@@ -30,11 +32,14 @@
3032
3133
const tabs: ITab[] = [{ label: "Base", value: "base" }];
3234
const nameField: IFormField = { label: "Name", placeholder: "Peertube Instance Name", symbol: "name", type: "text", validator: validateName, invalid: false }; // prettier-ignore
35+
const emailField: IFormField = { label: "Email", placeholder: "Instance Admin Email", symbol: "email", type: "text", validator: validateEmail, invalid: false }; // prettier-ignore
36+
const passField: IFormField = { label: "Password", placeholder: "Instance Admin Password", symbol: "password", type: "password", invalid: false }; // prettier-ignore
3337
3438
// prettier-ignore
3539
const baseFields: IFormField[] = [
3640
{ label: "CPU", symbol: "cpu", placeholder: "CPU Cores", type: "number", validator: validateCpu, invalid: false },
37-
{ label: "Memory (MB)", symbol: "memory", placeholder: "Your Memory in MB", type: "number", validator: validateMemory, invalid: false }
41+
{ label: "Memory (MB)", symbol: "memory", placeholder: "Your Memory in MB", type: "number", validator: validateMemory, invalid: false },
42+
{ label: "Public IP", symbol: "publicIp", placeholder: "", type: 'checkbox' },
3843
];
3944
4045
const diskField: IFormField = {
@@ -47,10 +52,7 @@
4752
};
4853
4954
const deploymentStore = window.configs?.deploymentStore;
50-
let data = new VM(); // set the default specs for peertube
51-
data.cpu = 2;
52-
data.memory = 2048;
53-
data.disks = [new Disk(undefined, undefined, 20, undefined)];
55+
let data = new Peertube();
5456
5557
let active: string = "base";
5658
let loading = false;
@@ -135,6 +137,17 @@
135137
bind:invalid={nameField.invalid}
136138
field={nameField}
137139
/>
140+
<Input
141+
bind:data={data.adminEmail}
142+
bind:invalid={emailField.invalid}
143+
field={emailField}
144+
/>
145+
<Input
146+
bind:data={data.adminPassword}
147+
bind:invalid={passField.invalid}
148+
field={passField}
149+
/>
150+
<Input bind:data={data.disks[0].size} field={diskField} />
138151

139152
{#each baseFields as field (field.symbol)}
140153
{#if field.invalid !== undefined}
@@ -147,10 +160,9 @@
147160
<Input bind:data={data[field.symbol]} {field} />
148161
{/if}
149162
{/each}
150-
<Input bind:data={data.disks[0].size} field={diskField} />
151163

152164
<SelectNodeId
153-
publicIp={false}
165+
publicIp={data.publicIp}
154166
cpu={data.cpu}
155167
memory={data.memory}
156168
ssd={data.disks.reduce(

src/types/peertube.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import generatePassword from "../utils/generatePassword";
2+
import VM, { Disk } from "./vm";
3+
import { v4 } from "uuid";
4+
5+
export default class Peertube extends VM {
6+
public name = `pt${v4().split("-")[0]}`;
7+
public adminEmail = "";
8+
public adminPassword = generatePassword((length = Math.floor(Math.random() * 5) + 10)); // prettier-ignore
9+
public publicIp = false;
10+
public cpu = 2;
11+
public memory = 1024 * 2;
12+
public disks = [new Disk(undefined, undefined, 20, undefined)];
13+
}

src/utils/deployPeertube.ts

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { default as VM } from "../types/vm";
1+
import type { default as Peertube } from "../types/peertube";
22
import type { IProfile } from "../types/Profile";
33
import deploy from "./deploy";
44

@@ -17,10 +17,15 @@ const {
1717
generateString,
1818
} = window.configs?.grid3_client ?? {};
1919

20-
export default async function deployPeertube(data: VM, profile: IProfile) {
20+
export default async function deployPeertube(
21+
data: Peertube,
22+
profile: IProfile
23+
) {
2124
const {
2225
envs,
2326
disks: [{ size }],
27+
adminEmail,
28+
adminPassword,
2429
...base
2530
} = data;
2631
let { name, flist, cpu, memory, entrypoint, network: nw } = base;
@@ -64,7 +69,10 @@ export default async function deployPeertube(data: VM, profile: IProfile) {
6469
memory,
6570
size,
6671
sshKey,
67-
randomSuffix
72+
randomSuffix,
73+
publicIp,
74+
adminEmail,
75+
adminPassword
6876
);
6977

7078
// get the info of peertube deployment
@@ -103,7 +111,10 @@ async function deployPeertubeVM(
103111
memory: number,
104112
diskSize: number,
105113
sshKey: string,
106-
randomSuffix: string
114+
randomSuffix: string,
115+
publicIp: boolean,
116+
email: string,
117+
password: string
107118
) {
108119
// disk
109120
const disk = new DiskModel();
@@ -116,17 +127,18 @@ async function deployPeertubeVM(
116127
vm.name = `vm${randomSuffix}`;
117128
vm.node_id = nodeId;
118129
vm.disks = [disk];
119-
vm.public_ip = false;
130+
vm.public_ip = publicIp;
120131
vm.planetary = true;
121132
vm.cpu = cpu;
122133
vm.memory = memory;
123134
vm.rootfs_size = rootFs(cpu, memory);
124135
vm.flist =
125-
"https://hub.grid.tf/tf-official-apps/threefoldtech-peertube-v3.0.flist";
136+
"https://hub.grid.tf/omarabdul3ziz.3bot/threefoldtech-peertube-v3.1.flist";
126137
vm.entrypoint = "/usr/local/bin/entrypoint.sh";
127138
vm.env = {
128139
SSH_KEY: sshKey,
129-
PEERTUBE_ADMIN_EMAIL: "[email protected]",
140+
PEERTUBE_ADMIN_EMAIL: email,
141+
PT_INITIAL_ROOT_PASSWORD: password,
130142
PEERTUBE_WEBSERVER_HOSTNAME: domain,
131143
PEERTUBE_WEBSERVER_PORT: "443",
132144
PEERTUBE_DB_SUFFIX: "_prod",
@@ -145,11 +157,10 @@ async function deployPeertubeVM(
145157
return grid.machines
146158
.deploy(vms)
147159
.then(async () => {
148-
for(const gw of await grid.gateway._list()){
160+
for (const gw of await grid.gateway._list()) {
149161
try {
150162
await grid.gateway.getObj(gw);
151-
}
152-
catch {}
163+
} catch {}
153164
}
154165
})
155166
.then(() => grid.machines.getObj(name))

0 commit comments

Comments
 (0)