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

adding scripts and test modules #2238

Closed
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
97 changes: 97 additions & 0 deletions packages/grid_client/scripts/casperlabs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import { FilterOptions, MachinesModel } from "../src";
import { config, getClient } from "./client_loader";
import { log } from "./utils";

async function deploy(client, vms) {
try {
const res = await client.machines.deploy(vms);
log("================= Deploying casperlabs =================");
log(res);
log("================= Deploying casperlabs =================");
} catch (error) {
log("Error while Deploying the VM " + error);
}
}

async function getDeployment(client, vms) {
try {
const res = await client.machines.getObj(vms);
log("================= Getting deployment information =================");
log(res);
log(`You can access casperlabs via the browser using: http://newVMS5.${res[0].env.CASPERLABS_WEBSERVER_HOSTNAME}`);
log("================= Getting deployment information =================");
} catch (error) {
log("Error while getting the deployment " + error);
}
}

async function cancel(client, vms) {
try {
const res = await client.machines.delete(vms);
log("================= Canceling the deployment =================");
log(res);
log("================= Canceling the deployment =================");
} catch (error) {
log("Error while canceling the deployment " + error);
}
}

async function main() {
const grid3 = await getClient();

const vmQueryOptions: FilterOptions = {
cru: 4,
mru: 4, // GB
sru: 10,
farmId: 1,
};

const vms: MachinesModel = {
name: "newVMS5",
network: {
name: "wedtest",
ip_range: "10.249.0.0/16",
},
machines: [
{
name: "testvm",
node_id: +(await grid3.capacity.filterNodes(vmQueryOptions))[0].nodeId,
disks: [
{
name: "wedDisk",
size: 8,
mountpoint: "/var/lib/docker",
},
],
public_ip: true,
public_ip6: false,
planetary: false,
mycelium: true,
cpu: 4,
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: "gent01.dev.grid.tf",
},
},
],
metadata: "",
description: "casperlabs machine",
};

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

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

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

// await grid3.disconnect();
khaledyoussef24 marked this conversation as resolved.
Show resolved Hide resolved
}

main();
105 changes: 105 additions & 0 deletions packages/grid_client/scripts/discourse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import { FilterOptions, generateString, MachinesModel } from "../src";
import { config, getClient } from "./client_loader";
import { log } from "./utils";

async function deploy(client, vms) {
try {
const res = await client.machines.deploy(vms);
log("================= Deploying discourse =================");
log(res);
log("================= Deploying discourse =================");
} catch (error) {
log("Error while Deploying the VM " + error);
}
}

async function getDeployment(client, vms) {
try {
const res = await client.machines.getObj(vms);
log("================= Getting deployment information =================");
log(res);
log(`You can access discourse via the browser using: http://captain.${res[0].env.CAPROVER_ROOT_DOMAIN}`);
log("================= Getting deployment information =================");
} catch (error) {
log("Error while getting the deployment " + error);
}
}

async function cancel(client, vms) {
try {
const res = await client.machines.delete(vms);
log("================= Canceling the deployment =================");
log(res);
log("================= Canceling the deployment =================");
} catch (error) {
log("Error while canceling the deployment " + error);
}
}

async function main() {
const grid3 = await getClient();

const vmQueryOptions: FilterOptions = {
cru: 4,
mru: 4, // GB
sru: 10,
farmId: 1,
};

const vms: MachinesModel = {
name: "newVMS5",
network: {
name: "wedtest",
ip_range: "10.249.0.0/16",
},
machines: [
{
name: "testvm",
node_id: +(await grid3.capacity.filterNodes(vmQueryOptions))[0].nodeId,
disks: [
{
name: "wedDisk",
size: 8,
mountpoint: "/var/lib/docker",
},
],
public_ip: true,
public_ip6: false,
planetary: false,
mycelium: true,
cpu: 4,
memory: 1024 * 4,
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: "gent02.dev.grid.tf",
DISCOURSE_DEVELOPER_EMAILS: "[email protected]",
DISCOURSE_SMTP_ADDRESS: "",
DISCOURSE_SMTP_PORT: "",
DISCOURSE_SMTP_ENABLE_START_TLS: "",
DISCOURSE_SMTP_USER_NAME: "",
DISCOURSE_SMTP_PASSWORD: "",
THREEBOT_PRIVATE_KEY: "",
FLASK_SECRET_KEY: generateString(6),
},
},
],
metadata: "",
description: "discourse machine/node",
};

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

//Get the deployment
await getDeployment(grid3, vms.name);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get the following error while running the discourse script.

image

Copy link
Contributor

@zaelgohary zaelgohary Apr 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, the script should not have continued if an error happened while deploying. Same goes for all scripts.


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

await grid3.disconnect();
}

main();
100 changes: 100 additions & 0 deletions packages/grid_client/scripts/funkwhale.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import { FilterOptions, MachinesModel } from "../src";
import { config, getClient } from "./client_loader";
import { log } from "./utils";

async function deploy(client, vms) {
try {
const res = await client.machines.deploy(vms);
log("================= Deploying funkwhale =================");
log(res);
log("================= Deploying funkwhale =================");
} catch (error) {
log("Error while Deploying the VM " + error);
}
}

async function getDeployment(client, vms) {
try {
const res = await client.machines.getObj(vms);
log("================= Getting deployment information =================");
log(res);
log(`You can access funkwhale via the browser using: http://newVMS5.${res[0].env.funkwhale_WEBSERVER_HOSTNAME}`);
log("================= Getting deployment information =================");
} catch (error) {
log("Error while getting the deployment " + error);
}
}

async function cancel(client, vms) {
try {
const res = await client.machines.delete(vms);
log("================= Canceling the deployment =================");
log(res);
log("================= Canceling the deployment =================");
} catch (error) {
log("Error while canceling the deployment " + error);
}
}

async function main() {
const grid3 = await getClient();

const vmQueryOptions: FilterOptions = {
cru: 4,
mru: 4, // GB
sru: 10,
farmId: 1,
};

const vms: MachinesModel = {
name: "newVMS5",
network: {
name: "wedtest",
ip_range: "10.249.0.0/16",
},
machines: [
{
name: "testvm",
node_id: +(await grid3.capacity.filterNodes(vmQueryOptions))[0].nodeId,
disks: [
{
name: "wedDisk",
size: 8,
mountpoint: "/var/lib/docker",
},
],
public_ip: true,
public_ip6: false,
planetary: false,
mycelium: true,
cpu: 4,
memory: 1024 * 4,
rootfs_size: 0,
flist: "https://hub.grid.tf/tf-official-apps/funkwhale-dec21.flist",
entrypoint: "/init.sh",
env: {
SSH_KEY: config.ssh_key,
DJANGO_SUPERUSER_EMAIL:"[email protected]",
DJANGO_SUPERUSER_USERNAME :"",
DJANGO_SUPERUSER_PASSWORD : "test123",
FUNKWHALE_HOSTNAME : "gent02.dev.grid.tf"
},
}
],
metadata: "",
description: "funkwhale machine/node",
};

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

//Get the deployment
await getDeployment(grid3, vms.name);
khaledyoussef24 marked this conversation as resolved.
Show resolved Hide resolved

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

await grid3.disconnect();
}

main();
Loading
Loading