duoops 0.2.4 → 0.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -559,7 +559,7 @@ export default class Init extends Command {
559
559
  if (!hasBinary('gcloud')) {
560
560
  this.error('gcloud CLI is required to provision a runner. Install it from https://cloud.google.com/sdk');
561
561
  }
562
- const vmName = await input({
562
+ let vmName = await input({
563
563
  default: 'duoops-runner',
564
564
  message: 'Runner VM name',
565
565
  });
@@ -592,6 +592,54 @@ export default class Init extends Command {
592
592
  if (!runnerToken) {
593
593
  this.error('Runner token required to register the VM.');
594
594
  }
595
+ let vmExists = false;
596
+ try {
597
+ execSync(`gcloud compute instances describe ${vmName} --project=${gcpProjectId} --zone=${gcpZone} --format="value(name)"`, { stdio: ['pipe', 'pipe', 'pipe'] });
598
+ vmExists = true;
599
+ }
600
+ catch { /* does not exist */ }
601
+ if (vmExists) {
602
+ const vmAction = await select({
603
+ choices: [
604
+ { name: 'Use existing VM', value: 'use' },
605
+ { name: 'Delete and recreate', value: 'recreate' },
606
+ { name: 'Use a different name', value: 'rename' },
607
+ ],
608
+ message: `VM "${vmName}" already exists in ${gcpZone}. What would you like to do?`,
609
+ });
610
+ if (vmAction === 'use') {
611
+ this.log(green(`Using existing VM "${vmName}".`));
612
+ let gcpInstanceId = '';
613
+ try {
614
+ gcpInstanceId = execSync(`gcloud compute instances describe ${vmName} --project=${gcpProjectId} --zone=${gcpZone} --format="value(id)"`, { encoding: 'utf8' }).trim();
615
+ }
616
+ catch {
617
+ this.warn('Unable to read instance ID automatically.');
618
+ }
619
+ return {
620
+ gcpInstanceId,
621
+ gcpZone,
622
+ instanceName: vmName,
623
+ machineType,
624
+ runnerTag,
625
+ };
626
+ }
627
+ if (vmAction === 'recreate') {
628
+ this.log(gray(`Deleting VM "${vmName}"...`));
629
+ try {
630
+ execSync(`gcloud compute instances delete ${vmName} --project=${gcpProjectId} --zone=${gcpZone} --quiet`, { stdio: 'inherit' });
631
+ this.log(green(`Deleted "${vmName}".`));
632
+ }
633
+ catch {
634
+ this.error(`Failed to delete VM "${vmName}". Delete it manually and retry.`);
635
+ }
636
+ }
637
+ if (vmAction === 'rename') {
638
+ vmName = await input({
639
+ message: 'New VM name',
640
+ });
641
+ }
642
+ }
595
643
  const startupScript = buildStartupScript({
596
644
  gitlabUrl: normalizeGitLabUrl(auth.baseUrl),
597
645
  runnerTag,
@@ -669,5 +669,5 @@
669
669
  ]
670
670
  }
671
671
  },
672
- "version": "0.2.4"
672
+ "version": "0.2.5"
673
673
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "duoops",
3
3
  "description": "Toolset for Explainable and Sustainable CI on Gitlab.",
4
- "version": "0.2.4",
4
+ "version": "0.2.5",
5
5
  "author": "Younes Laaroussi",
6
6
  "bin": {
7
7
  "duoops": "./bin/run.js"