Skip to content

Commit 2a600a7

Browse files
authored
Use the standalone command-line tool to destroy runners (#1225)
1 parent 3fc2217 commit 2a600a7

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

bin/cml/runner/launch.js

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const kebabcaseKeys = require('kebabcase-keys');
66
const timestring = require('timestring');
77
const winston = require('winston');
88

9-
const { randid, sleep } = require('../../../src/utils');
9+
const { exec, randid, sleep } = require('../../../src/utils');
1010
const tf = require('../../../src/terraform');
1111

1212
let cml;
@@ -23,15 +23,7 @@ const shutdown = async (opts) => {
2323
RUNNER_SHUTTING_DOWN = true;
2424

2525
const { error, cloud } = opts;
26-
const {
27-
name,
28-
workdir = '',
29-
tfResource,
30-
noRetry,
31-
reason,
32-
destroyDelay
33-
} = opts;
34-
const tfPath = workdir;
26+
const { name, tfResource, noRetry, reason, destroyDelay } = opts;
3527

3628
const unregisterRunner = async () => {
3729
if (!RUNNER) return;
@@ -63,16 +55,22 @@ const shutdown = async (opts) => {
6355
}
6456
};
6557

66-
const destroyTerraform = async () => {
58+
const destroyLeo = async () => {
6759
if (!tfResource) return;
6860

6961
winston.info(`Waiting ${destroyDelay} seconds to destroy`);
7062
await sleep(destroyDelay);
7163

64+
const { cloud, id, region } = JSON.parse(
65+
Buffer.from(tfResource, 'base64').toString('utf-8')
66+
).instances[0].attributes;
67+
7268
try {
73-
winston.debug(await tf.destroy({ dir: tfPath }));
69+
return await exec(
70+
`leo destroy-runner --cloud=${cloud} --region=${region} ${id}`
71+
);
7472
} catch (err) {
75-
winston.error(`\tFailed destroying terraform: ${err.message}`);
73+
winston.error(`\tFailed destroying with LEO: ${err.message}`);
7674
}
7775
};
7876

@@ -85,7 +83,7 @@ const shutdown = async (opts) => {
8583
}
8684
}
8785

88-
await destroyTerraform();
86+
await destroyLeo();
8987

9088
if (error) throw error;
9189

0 commit comments

Comments
 (0)