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 the peertube, mattermost, funkwhale, and casperlabs scripts to deploy an instance from the GridClient. #2743

Merged
merged 8 commits into from
May 23, 2024
113 changes: 113 additions & 0 deletions packages/grid_client/scripts/applications/casberlabs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import { FilterOptions, GatewayNameModel, MachinesModel } from "../../src";
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 + "]:80"],
};

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 =================");
}

async function cancel(client, vms, gw) {

Check warning on line 36 in packages/grid_client/scripts/applications/casberlabs.ts

View workflow job for this annotation

GitHub Actions / lint (18.x)

'cancel' is defined but never used
const resvm = await client.machines.delete(vms);
const resgw = await client.gateway.delete_name(gw);
log("================= Canceling the deployment =================");
log(resvm);
log(resgw);
log("================= Canceling the deployment =================");
}

async function main() {
const name = "newcasperlabs";
const grid3 = await getClient(`casperlabs/${name}`);
const subdomain = "cl" + grid3.twinId + name;

//VMNode Selection
const vmQueryOptions: FilterOptions = {
cru: 2,
mru: 4,
sru: 100,
availableFor: grid3.twinId,
farmId: 1,
};
//GatewayNode Selection
const gatewayQueryOptions: FilterOptions = {
gateway: true,
availableFor: grid3.twinId,
};
const gatewayNode = (await grid3.capacity.filterNodes(gatewayQueryOptions))[0];

const vms: MachinesModel = {
name,
network: {
name: "wedtest",
ip_range: "10.249.0.0/16",
},
machines: [
{
name: "casperlabs",
node_id: +(await pingNodes(grid3, await grid3.capacity.filterNodes(vmQueryOptions))),
A-Harby marked this conversation as resolved.
Show resolved Hide resolved
disks: [
{
name: "wedDisk",
size: 100,
mountpoint: "/data",
},
],
planetary: true,
public_ip: false,
public_ip6: false,
mycelium: false,
cpu: 2,
memory: 1024 * 4,
rootfs_size: 0,
flist: "https://hub.grid.tf/tf-official-apps/casperlabs-latest.flist",
entrypoint: "/sbin/zinit init",
env: {
SSH_KEY: config.ssh_key,
CASPERLABS_HOSTNAME: subdomain + "." + gatewayNode.publicConfig.domain,
},
},
],
metadata: "",
description: "test deploying CasberLabs 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();
116 changes: 116 additions & 0 deletions packages/grid_client/scripts/applications/funkwhale.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import { FilterOptions, GatewayNameModel, MachinesModel } from "../../src";
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 + "]:80"],
};

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 =================");
}

async function cancel(client, vms, gw) {

Check warning on line 36 in packages/grid_client/scripts/applications/funkwhale.ts

View workflow job for this annotation

GitHub Actions / lint (18.x)

'cancel' is defined but never used
const resvm = await client.machines.delete(vms);
const resgw = await client.gateway.delete_name(gw);
log("================= Canceling the deployment =================");
log(resvm);
log(resgw);
log("================= Canceling the deployment =================");
}

async function main() {
const name = "newfunkwhale";
const grid3 = await getClient(`funkwhale/${name}`);
const subdomain = "fw" + grid3.twinId + name;

//VMNode Selection
const vmQueryOptions: FilterOptions = {
cru: 1,
mru: 2,
sru: 50,
availableFor: grid3.twinId,
farmId: 1,
};
//GatewayNode Selection
const gatewayQueryOptions: FilterOptions = {
gateway: true,
availableFor: grid3.twinId,
};
const gatewayNode = (await grid3.capacity.filterNodes(gatewayQueryOptions))[0];

const vms: MachinesModel = {
name,
network: {
name: "wedtest",
ip_range: "10.249.0.0/16",
},
machines: [
{
name: "funkwhale",
node_id: +(await pingNodes(grid3, await grid3.capacity.filterNodes(vmQueryOptions))),
disks: [
{
name: "wedDisk",
size: 50,
mountpoint: "/data",
},
],
planetary: true,
public_ip: false,
public_ip6: false,
mycelium: false,
cpu: 1,
memory: 1024 * 2,
rootfs_size: 0,
flist: "https://hub.grid.tf/tf-official-apps/funkwhale-dec21.flist",
entrypoint: "/init.sh",
env: {
SSH_KEY: config.ssh_key,
FUNKWHALE_HOSTNAME: subdomain + "." + gatewayNode.publicConfig.domain,
DJANGO_SUPERUSER_EMAIL: "admin123@funk.whale", // edit me
DJANGO_SUPERUSER_USERNAME: "admin123", // edit me
DJANGO_SUPERUSER_PASSWORD: "admin123", // edit me
},
},
],
metadata: "",
description: "test deploying FunkWhale 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();
121 changes: 121 additions & 0 deletions packages/grid_client/scripts/applications/mattermost.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
import { FilterOptions, GatewayNameModel, MachinesModel } from "../../src";
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 + "]:8000"],
};

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 =================");
}

async function cancel(client, vms, gw) {

Check warning on line 36 in packages/grid_client/scripts/applications/mattermost.ts

View workflow job for this annotation

GitHub Actions / lint (18.x)

'cancel' is defined but never used
const resvm = await client.machines.delete(vms);
const resgw = await client.gateway.delete_name(gw);
log("================= Canceling the deployment =================");
log(resvm);
log(resgw);
log("================= Canceling the deployment =================");
}

async function main() {
const name = "newmattermost";
const grid3 = await getClient(`mattermost/${name}`);
const subdomain = "mm" + grid3.twinId + name;

//VMNode Selection
const vmQueryOptions: FilterOptions = {
cru: 1,
mru: 2,
sru: 50,
availableFor: grid3.twinId,
farmId: 1,
};
//GatewayNode Selection
const gatewayQueryOptions: FilterOptions = {
gateway: true,
availableFor: grid3.twinId,
};
const gatewayNode = (await grid3.capacity.filterNodes(gatewayQueryOptions))[0];

const vms: MachinesModel = {
name,
network: {
name: "wedtest",
ip_range: "10.249.0.0/16",
},
machines: [
{
name: "mattermost",
node_id: +(await pingNodes(grid3, await grid3.capacity.filterNodes(vmQueryOptions))),
disks: [
{
name: "wedDisk",
size: 50,
mountpoint: "/var/lib/docker",
},
],
planetary: true,
public_ip: false,
public_ip6: false,
mycelium: false,
cpu: 1,
memory: 1024 * 2,
rootfs_size: 0,
flist: "https://hub.grid.tf/tf-official-apps/mattermost-latest.flist",
entrypoint: "/sbin/zinit init",
env: {
SSH_KEY: config.ssh_key,
MATTERMOST_DOMAIN: subdomain + "." + gatewayNode.publicConfig.domain,
SITE_URL: "https://" + subdomain + "." + gatewayNode.publicConfig.domain,
DJANGO_SUPERUSER_EMAIL: "admin123@matter.most", // edit me
DB_PASSWORD: "admin123", // edit me
// Optional
A-Harby marked this conversation as resolved.
Show resolved Hide resolved
// SMTPUsername: "username",
// SMTPPassword: "password",
// SMTPServer: "hostname",
// SMTPPort: "port",
},
},
],
metadata: "",
description: "test deploying MatterMost 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();
Loading
Loading