MCPcopy
hub / github.com/iterative/cml / runLocal

Function runLocal

bin/cml/runner/launch.js:230–357  ·  view source on GitHub ↗
(opts)

Source from the content-addressed store, hash-verified

228};
229
230const runLocal = async (opts) => {
231 logger.info(`Launching ${cml.driver} runner`);
232 const {
233 workdir,
234 name,
235 labels,
236 single,
237 idleTimeout,
238 noRetry,
239 cloudSpot,
240 dockerVolumes,
241 tfResource,
242 tpiVersion
243 } = opts;
244
245 if (tfResource) {
246 await tf.checkMinVersion();
247
248 const tfPath = workdir;
249 await fs.mkdir(tfPath, { recursive: true });
250 const tfMainPath = join(tfPath, 'main.tf.json');
251 const tpl = tf.iterativeProviderTpl({ tpiVersion });
252 await fs.writeFile(tfMainPath, JSON.stringify(tpl));
253
254 await tf.init({ dir: tfPath });
255 await tf.apply({ dir: tfPath });
256
257 const path = join(tfPath, 'terraform.tfstate');
258 const tfstate = await tf.loadTfState({ path });
259 tfstate.resources = [
260 JSON.parse(Buffer.from(tfResource, 'base64').toString('utf-8'))
261 ];
262 await tf.saveTfState({ tfstate, path });
263 }
264
265 if (process.platform === 'linux') {
266 const acpiSock = net.connect('/var/run/acpid.socket');
267 acpiSock.on('connect', () => {
268 logger.info('Connected to acpid service.');
269 });
270 acpiSock.on('error', (err) => {
271 logger.warn(
272 `Error connecting to ACPI socket: ${err.message}. The acpid.service helps with instance termination detection.`
273 );
274 });
275 acpiSock.on('data', (buf) => {
276 const data = buf.toString().toLowerCase();
277 if (data.includes('power') && data.includes('button')) {
278 shutdown({ ...opts, reason: 'ACPI shutdown' });
279 }
280 });
281 }
282
283 const dataHandler =
284 ({ cloudSpot }) =>
285 async (data) => {
286 logger.debug(data.toString());
287 const logs = await cml.parseRunnerLog({ data, name, cloudSpot });

Callers 1

runFunction · 0.85

Calls 5

shutdownFunction · 0.85
dataHandlerFunction · 0.85
toStringMethod · 0.80
warnMethod · 0.45
startRunnerMethod · 0.45

Tested by

no test coverage detected