runVm function

Future<LumeVM> runVm(
  1. String vmName
)

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 &&
          vm.sshAvailable == true) {
        return vm;
      }
    } catch (_) {
      // Ignore transient errors while VM is booting
    }
    await Future<void>.delayed(const Duration(seconds: 2));
  }

  process.kill();
  throw TimeoutException(
    'Timeout waiting for Lume VM "$vmName" to boot and become SSH available.',
  );
}