duoops 0.2.3 → 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.
@@ -11,6 +11,7 @@ import { fileURLToPath } from 'node:url';
11
11
  import { configManager } from '../lib/config.js';
12
12
  import { detectGcpProject, enableApis, validateProjectAccess } from '../lib/gcloud.js';
13
13
  import McpDeploy from './mcp/deploy.js';
14
+ const gitlabAuthHeaders = (token) => token.startsWith('glpat-') ? { 'PRIVATE-TOKEN': token } : { Authorization: `Bearer ${token}` };
14
15
  const hasBinary = (command) => {
15
16
  try {
16
17
  execSync(`${command} --version`, { stdio: 'ignore' });
@@ -50,7 +51,7 @@ const setGitlabVariable = async (auth, projectPath, variable) => {
50
51
  const apiUrl = `${base}/api/v4/projects/${project}/variables`;
51
52
  await axios
52
53
  .delete(`${apiUrl}/${variable.key}`, {
53
- headers: { 'PRIVATE-TOKEN': auth.token },
54
+ headers: gitlabAuthHeaders(auth.token),
54
55
  })
55
56
  .catch(() => { });
56
57
  await axios.post(apiUrl, {
@@ -58,7 +59,7 @@ const setGitlabVariable = async (auth, projectPath, variable) => {
58
59
  masked: Boolean(variable.masked),
59
60
  protected: false,
60
61
  value: variable.value,
61
- }, { headers: { 'PRIVATE-TOKEN': auth.token } });
62
+ }, { headers: gitlabAuthHeaders(auth.token) });
62
63
  };
63
64
  const ensureServiceAccount = (projectId, serviceAccount) => {
64
65
  try {
@@ -558,7 +559,7 @@ export default class Init extends Command {
558
559
  if (!hasBinary('gcloud')) {
559
560
  this.error('gcloud CLI is required to provision a runner. Install it from https://cloud.google.com/sdk');
560
561
  }
561
- const vmName = await input({
562
+ let vmName = await input({
562
563
  default: 'duoops-runner',
563
564
  message: 'Runner VM name',
564
565
  });
@@ -591,6 +592,54 @@ export default class Init extends Command {
591
592
  if (!runnerToken) {
592
593
  this.error('Runner token required to register the VM.');
593
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
+ }
594
643
  const startupScript = buildStartupScript({
595
644
  gitlabUrl: normalizeGitLabUrl(auth.baseUrl),
596
645
  runnerTag,
@@ -669,5 +669,5 @@
669
669
  ]
670
670
  }
671
671
  },
672
- "version": "0.2.3"
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.3",
4
+ "version": "0.2.5",
5
5
  "author": "Younes Laaroussi",
6
6
  "bin": {
7
7
  "duoops": "./bin/run.js"