-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathdiscourse.ts
More file actions
139 lines (124 loc) · 4.67 KB
/
discourse.ts
File metadata and controls
139 lines (124 loc) · 4.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import { Buffer } from "buffer";
import TweetNACL from "tweetnacl";
import { Features, FilterOptions, GatewayNameModel, MachinesModel } from "../../src";
import { FLISTS } from "../../src/helpers/flists";
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 =================");
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
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,
features: [Features.ip, Features.ipv4, Features.wireguard],
};
//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: true,
cpu: instanceCapacity.cru,
memory: 1024 * instanceCapacity.mru,
rootfs_size: 0,
flist: FLISTS.DISCOURSE.value,
entrypoint: FLISTS.DISCOURSE.entryPoint,
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();