fix: Fixes to cloud benchmarks (no-changelog) (#10634)
This commit is contained in:
@@ -4,12 +4,13 @@ import { $ } from 'zx';
|
||||
export class SshClient {
|
||||
/**
|
||||
*
|
||||
* @param {{ vmName: string; resourceGroupName: string; verbose?: boolean }} param0
|
||||
* @param {{ privateKeyPath: string; ip: string; username: string; verbose?: boolean }} param0
|
||||
*/
|
||||
constructor({ vmName, resourceGroupName, verbose = false }) {
|
||||
this.vmName = vmName;
|
||||
this.resourceGroupName = resourceGroupName;
|
||||
constructor({ privateKeyPath, ip, username, verbose = false }) {
|
||||
this.verbose = verbose;
|
||||
this.privateKeyPath = privateKeyPath;
|
||||
this.ip = ip;
|
||||
this.username = username;
|
||||
|
||||
this.$$ = $({
|
||||
verbose,
|
||||
@@ -23,6 +24,14 @@ export class SshClient {
|
||||
async ssh(command, options = {}) {
|
||||
const $$ = options?.verbose ? $({ verbose: true }) : this.$$;
|
||||
|
||||
await $$`az ssh vm -n ${this.vmName} -g ${this.resourceGroupName} --yes -- -o StrictHostKeyChecking=accept-new ${command}`;
|
||||
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}`;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,9 @@ export class TerraformClient {
|
||||
/**
|
||||
* @typedef {Object} BenchmarkEnv
|
||||
* @property {string} vmName
|
||||
* @property {string} ip
|
||||
* @property {string} sshUsername
|
||||
* @property {string} sshPrivateKeyPath
|
||||
*
|
||||
* @returns {Promise<BenchmarkEnv>}
|
||||
*/
|
||||
@@ -27,9 +30,14 @@ export class TerraformClient {
|
||||
console.log('Provisioning cloud environment...');
|
||||
|
||||
await this.$$`terraform init`;
|
||||
await this.$$`terraform apply -input=false -auto-approve`;
|
||||
// await this.$$`terraform apply -input=false -auto-approve`;
|
||||
|
||||
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'),
|
||||
};
|
||||
}
|
||||
@@ -42,11 +50,18 @@ export class TerraformClient {
|
||||
|
||||
console.log('Destroying cloud environment...');
|
||||
|
||||
await this.$$`terraform destroy -input=false -auto-approve`;
|
||||
// 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