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 rest of solution scripts to deploy an instance from the Grid Client. #2766

Merged
merged 3 commits into from
May 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
99 changes: 99 additions & 0 deletions packages/grid_client/scripts/applications/algorand.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import { FilterOptions, MachinesModel } from "../../src";
import { config, getClient } from "../client_loader";
import { log, pingNodes } from "../utils";

async function deploy(client, vms) {
const resultVM = await client.machines.deploy(vms);
log("================= Deploying VM =================");
log(resultVM);
log("================= Deploying VM =================");
}

async function getDeployment(client, vms) {
const resultVM = await client.machines.getObj(vms.name);
log("================= Getting deployment information =================");
log(resultVM);
log("================= Getting deployment information =================");
}

async function cancel(client, vms) {

Check warning on line 19 in packages/grid_client/scripts/applications/algorand.ts

View workflow job for this annotation

GitHub Actions / lint (18.x)

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

async function main() {
const name = "newalgorand";
const grid3 = await getClient(`algorand/${name}`);
const instanceCapacity = { cru: 2, mru: 4, sru: 100 }; // 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,
};
const nodes = await grid3.capacity.filterNodes(vmQueryOptions);
const vmNode = await pingNodes(grid3, nodes);

const vms: MachinesModel = {
name,
network: {
name: "wedtest",
ip_range: "10.249.0.0/16",
},
machines: [
{
name: "algorand",
node_id: vmNode,
disks: [
{
name: "docker",
size: instanceCapacity.sru,
mountpoint: "/var/lib/docker",
},
],
planetary: true,
public_ip: false,
public_ip6: false,
mycelium: false,
cpu: instanceCapacity.cru,
memory: 1024 * instanceCapacity.mru,
rootfs_size: 0,
flist: "https://hub.grid.tf/tf-official-apps/algorand-latest.flist",
entrypoint: "/sbin/zinit init",
env: {
SSH_KEY: config.ssh_key,
// Select a network to work against.
NETWORK: "mainnet",
// Defualt, Relay, Participant, Indexer
NODE_TYPE: "default",
// Account mnemonic is the private key of your Algorand wallet and it consists of 24 words, and these 3 options are only enabled on Participant.
//ACCOUNT_MNEMONICS: "",
// First Validation Block.
//FIRST_ROUND: "24000000",
// Last Validation Block
//LAST_ROUND: "26000000",
},
},
],
metadata: "",
description: "test deploying Algorand via ts grid3 client",
};

//Deploy VMs
await deploy(grid3, vms);

//Get the deployment
await getDeployment(grid3, vms);

//Uncomment the line below to cancel the deployment
// await cancel(grid3, { name });

await grid3.disconnect();
}

main();
136 changes: 136 additions & 0 deletions packages/grid_client/scripts/applications/discourse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
import { Buffer } from "buffer";
import TweetNACL from "tweetnacl";

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

async function cancel(client, vms, gw) {

Check warning on line 39 in packages/grid_client/scripts/applications/discourse.ts

View workflow job for this annotation

GitHub Actions / lint (18.x)

'cancel' is defined but never used
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,
};
//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: false,
cpu: instanceCapacity.cru,
memory: 1024 * instanceCapacity.mru,
rootfs_size: 0,
flist: "https://hub.grid.tf/tf-official-apps/forum-docker-v3.1.2.flist",
entrypoint: "/sbin/zinit init",
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: "[email protected]",
/* 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: "[email protected]",
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();
121 changes: 121 additions & 0 deletions packages/grid_client/scripts/applications/nextcloud.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 + "]: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/nextcloud.ts

View workflow job for this annotation

GitHub Actions / lint (18.x)

'cancel' is defined but never used
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 =================");
}

async function main() {
const name = "newnextcloud";
const grid3 = await getClient(`nextcloud/${name}`);
const subdomain = "nc" + grid3.twinId + name;
const instanceCapacity = { cru: 2, mru: 4, sru: 50 }; // 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,
};
//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: "nextcloud",
node_id: vmNode,
disks: [
{
name: "wedDisk",
size: instanceCapacity.sru,
mountpoint: "/mnt/data",
},
],
planetary: true,
public_ip: false,
public_ip6: false,
mycelium: false,
cpu: instanceCapacity.cru,
memory: 1024 * instanceCapacity.mru,
rootfs_size: 0,
flist: "https://hub.grid.tf/tf-official-apps/threefoldtech-nextcloudaio-latest.flist",
entrypoint: "/sbin/zinit init",
env: {
SSH_KEY: config.ssh_key,
NEXTCLOUD_DOMAIN: domain,
NEXTCLOUD_AIO_LINK: domain + "/aio",
// Update the boolean value here if you choose to deploy with a Public IPv4 and gateway.
GATEWAY: "true",
IPV4: "false",
},
},
],
metadata: "",
description: "test deploying Nextcloud 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