Skip to content

Commit

Permalink
Use the standalone command-line tool to destroy runners (#1225)
Browse files Browse the repository at this point in the history
  • Loading branch information
0x2b3bfa0 authored and tasdomas committed Oct 27, 2022
1 parent 832dd85 commit c8702a1
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions bin/cml/runner/launch.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const kebabcaseKeys = require('kebabcase-keys');
const timestring = require('timestring');
const winston = require('winston');

const { randid, sleep } = require('../../../src/utils');
const { exec, randid, sleep } = require('../../../src/utils');
const tf = require('../../../src/terraform');

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

const { error, cloud } = opts;
const {
name,
workdir = '',
tfResource,
noRetry,
reason,
destroyDelay
} = opts;
const tfPath = workdir;
const { name, tfResource, noRetry, reason, destroyDelay } = opts;

const unregisterRunner = async () => {
if (!RUNNER) return;
Expand Down Expand Up @@ -63,16 +55,22 @@ const shutdown = async (opts) => {
}
};

const destroyTerraform = async () => {
const destroyLeo = async () => {
if (!tfResource) return;

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

const { cloud, id, region } = JSON.parse(
Buffer.from(tfResource, 'base64').toString('utf-8')
).instances[0].attributes;

try {
winston.debug(await tf.destroy({ dir: tfPath }));
return await exec(
`leo destroy-runner --cloud=${cloud} --region=${region} ${id}`
);
} catch (err) {
winston.error(`\tFailed destroying terraform: ${err.message}`);
winston.error(`\tFailed destroying with LEO: ${err.message}`);
}
};

Expand All @@ -85,7 +83,7 @@ const shutdown = async (opts) => {
}
}

await destroyTerraform();
await destroyLeo();

if (error) throw error;

Expand Down

0 comments on commit c8702a1

Please sign in to comment.