pull:初次提交
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
import { which } from 'zx';
|
||||
|
||||
export class DockerComposeClient {
|
||||
/**
|
||||
*
|
||||
* @param {{ $: Shell; verbose?: boolean }} opts
|
||||
*/
|
||||
constructor({ $ }) {
|
||||
this.$$ = $;
|
||||
}
|
||||
|
||||
async $(...args) {
|
||||
await this.resolveExecutableIfNeeded();
|
||||
|
||||
if (this.isCompose) {
|
||||
return await this.$$`docker-compose ${args}`;
|
||||
} else {
|
||||
return await this.$$`docker compose ${args}`;
|
||||
}
|
||||
}
|
||||
|
||||
async resolveExecutableIfNeeded() {
|
||||
if (this.isResolved) {
|
||||
return;
|
||||
}
|
||||
|
||||
// The VM deployment doesn't have `docker compose` available,
|
||||
// so try to resolve the `docker-compose` first
|
||||
const compose = await which('docker-compose', { nothrow: true });
|
||||
if (compose) {
|
||||
this.isResolved = true;
|
||||
this.isCompose = true;
|
||||
return;
|
||||
}
|
||||
|
||||
const docker = await which('docker', { nothrow: true });
|
||||
if (docker) {
|
||||
this.isResolved = true;
|
||||
this.isCompose = false;
|
||||
return;
|
||||
}
|
||||
|
||||
throw new Error('Could not resolve docker-compose or docker');
|
||||
}
|
||||
}
|
||||
37
n8n-n8n-1.109.2/packages/@n8n/benchmark/scripts/clients/ssh-client.mjs
Executable file
37
n8n-n8n-1.109.2/packages/@n8n/benchmark/scripts/clients/ssh-client.mjs
Executable file
@@ -0,0 +1,37 @@
|
||||
// @ts-check
|
||||
import { $ } from 'zx';
|
||||
|
||||
export class SshClient {
|
||||
/**
|
||||
*
|
||||
* @param {{ privateKeyPath: string; ip: string; username: string; verbose?: boolean }} param0
|
||||
*/
|
||||
constructor({ privateKeyPath, ip, username, verbose = false }) {
|
||||
this.verbose = verbose;
|
||||
this.privateKeyPath = privateKeyPath;
|
||||
this.ip = ip;
|
||||
this.username = username;
|
||||
|
||||
this.$$ = $({
|
||||
verbose,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} command
|
||||
* @param {{ verbose?: boolean }} [options]
|
||||
*/
|
||||
async ssh(command, options = {}) {
|
||||
const $$ = options?.verbose ? $({ verbose: true }) : this.$$;
|
||||
|
||||
const target = `${this.username}@${this.ip}`;
|
||||
|
||||
await $$`ssh -i ${this.privateKeyPath} -o StrictHostKeyChecking=accept-new ${target} ${command}`;
|
||||
}
|
||||
|
||||
async scp(source, destination) {
|
||||
const target = `${this.username}@${this.ip}:${destination}`;
|
||||
await this
|
||||
.$$`scp -i ${this.privateKeyPath} -o StrictHostKeyChecking=accept-new ${source} ${target}`;
|
||||
}
|
||||
}
|
||||
71
n8n-n8n-1.109.2/packages/@n8n/benchmark/scripts/clients/terraform-client.mjs
Executable file
71
n8n-n8n-1.109.2/packages/@n8n/benchmark/scripts/clients/terraform-client.mjs
Executable file
@@ -0,0 +1,71 @@
|
||||
// @ts-check
|
||||
|
||||
import path from 'path';
|
||||
import { $, fs } from 'zx';
|
||||
|
||||
const paths = {
|
||||
infraCodeDir: path.resolve('infra'),
|
||||
terraformStateFile: path.join(path.resolve('infra'), 'terraform.tfstate'),
|
||||
};
|
||||
|
||||
export class TerraformClient {
|
||||
constructor({ isVerbose = false }) {
|
||||
this.isVerbose = isVerbose;
|
||||
this.$$ = $({
|
||||
cwd: paths.infraCodeDir,
|
||||
verbose: isVerbose,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Provisions the environment
|
||||
*/
|
||||
async provisionEnvironment() {
|
||||
console.log('Provisioning cloud environment...');
|
||||
|
||||
await this.$$`terraform init`;
|
||||
await this.$$`terraform apply -input=false -auto-approve`;
|
||||
}
|
||||
|
||||
/**
|
||||
* @typedef {Object} BenchmarkEnv
|
||||
* @property {string} vmName
|
||||
* @property {string} ip
|
||||
* @property {string} sshUsername
|
||||
* @property {string} sshPrivateKeyPath
|
||||
*
|
||||
* @returns {Promise<BenchmarkEnv>}
|
||||
*/
|
||||
async getTerraformOutputs() {
|
||||
const privateKeyName = await this.extractPrivateKey();
|
||||
|
||||
return {
|
||||
ip: await this.getTerraformOutput('ip'),
|
||||
sshUsername: await this.getTerraformOutput('ssh_username'),
|
||||
sshPrivateKeyPath: path.join(paths.infraCodeDir, privateKeyName),
|
||||
vmName: await this.getTerraformOutput('vm_name'),
|
||||
};
|
||||
}
|
||||
|
||||
hasTerraformState() {
|
||||
return fs.existsSync(paths.terraformStateFile);
|
||||
}
|
||||
|
||||
async destroyEnvironment() {
|
||||
console.log('Destroying cloud environment...');
|
||||
|
||||
await this.$$`terraform destroy -input=false -auto-approve`;
|
||||
}
|
||||
|
||||
async getTerraformOutput(key) {
|
||||
const output = await this.$$`terraform output -raw ${key}`;
|
||||
return output.stdout.trim();
|
||||
}
|
||||
|
||||
async extractPrivateKey() {
|
||||
await this.$$`terraform output -raw ssh_private_key > privatekey.pem`;
|
||||
await this.$$`chmod 600 privatekey.pem`;
|
||||
|
||||
return 'privatekey.pem';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user