runVm function
Implementation
Future<lume.LumeVM> runVm(String vmName) async {
final process = await lume.run(
name: vmName,
noDisplay: true,
showLogs: false,
);
final timeoutMinsEnv = Platform.environment['OPENCI_VM_BOOT_TIMEOUT_MINS'];
final timeoutMins = timeoutMinsEnv != null
? int.tryParse(timeoutMinsEnv) ?? 10
: 10;
final timeout = Duration(minutes: timeoutMins);
final stopTime = DateTime.now().add(timeout);
while (DateTime.now().isBefore(stopTime)) {
try {
final vms = await lume
.ls(showLogs: false)
.timeout(
const Duration(seconds: 15),
onTimeout: () => throw TimeoutException('lume ls timed out'),
);
final vm = vms.firstWhere((v) => v.name == vmName);
if (vm.status == 'running' && vm.ipAddress != null) {
try {
final socket = await Socket.connect(
vm.ipAddress!,
22,
timeout: const Duration(seconds: 2),
);
await socket.close();
return vm;
} catch (_) {
if (vm.sshAvailable == true) {
return vm;
}
}
}
} catch (e, stack) {
print('DEBUG: Error in runVm loop: $e\n$stack');
}
await Future<void>.delayed(const Duration(seconds: 2));
}
process.kill();
throw TimeoutException(
'Timeout waiting for Lume VM "$vmName" to boot and become SSH available.',
);
}