@deinossrl/dgp-agent 1.4.34 → 1.4.36

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.
Files changed (2) hide show
  1. package/index.mjs +38 -43
  2. package/package.json +1 -1
package/index.mjs CHANGED
@@ -227,8 +227,13 @@ function saveSshKeyLocally(sshPrivateKey) {
227
227
  // Verificar si la key tiene los delimitadores BEGIN/END
228
228
  if (!normalizedKey.includes('-----BEGIN')) {
229
229
  console.log('[!] SSH Key sin delimitadores, agregándolos automáticamente...');
230
- // Agregar header y footer OpenSSH
231
- normalizedKey = `-----BEGIN OPENSSH PRIVATE KEY-----\n${normalizedKey}\n-----END OPENSSH PRIVATE KEY-----`;
230
+ // Agregar header y footer OpenSSH (con salto de línea final)
231
+ normalizedKey = `-----BEGIN OPENSSH PRIVATE KEY-----\n${normalizedKey}\n-----END OPENSSH PRIVATE KEY-----\n`;
232
+ }
233
+
234
+ // Asegurar que siempre termine con salto de línea
235
+ if (!normalizedKey.endsWith('\n')) {
236
+ normalizedKey += '\n';
232
237
  }
233
238
 
234
239
  writeFileSync(keyPath, normalizedKey);
@@ -341,7 +346,7 @@ function getPlinkPath() {
341
346
  }
342
347
 
343
348
  // Versión del agente
344
- const AGENT_VERSION = '1.4.34';
349
+ const AGENT_VERSION = '1.4.36';
345
350
  let AGENT_MODE = 'smart'; // Siempre inteligente
346
351
 
347
352
  // Configuración (prioridad: env vars > archivo config > platform config > defaults)
@@ -1187,66 +1192,56 @@ async function executeDeploy(command) {
1187
1192
  // Mark as running
1188
1193
  await updateCommandStatus(id, 'running');
1189
1194
 
1190
- // Step 1: Git fetch and checkout
1191
- currentStep = 'git_checkout';
1192
- logCommand(`[1/5] Checkout branch ${branch}...`);
1193
- steps.push({ step: currentStep, status: 'running' });
1194
-
1195
- await shellAsync(`git fetch origin`);
1196
- await shellAsync(`git checkout ${branch}`);
1197
- await shellAsync(`git pull origin ${branch}`);
1195
+ // Determinar carpeta de proyecto en el servidor
1196
+ const projectFolder = params?.project_path || (environment === 'production'
1197
+ ? '/var/www/tenminuteia-prod/'
1198
+ : '/var/www/tenminuteia-staging/');
1198
1199
 
1199
- steps[steps.length - 1].status = 'success';
1200
- logSuccess(`Branch ${branch} updated`);
1200
+ // Construir base del comando SSH
1201
+ const sshBase = sshKeyPath
1202
+ ? `ssh -i ${sshKeyPath} -o StrictHostKeyChecking=no ${ssh_user}@${server_host}`
1203
+ : `ssh ${ssh_user}@${server_host}`;
1201
1204
 
1202
- // Step 2: Install dependencies
1203
- currentStep = 'npm_install';
1204
- logCommand(`[2/5] Installing dependencies...`);
1205
+ // Step 1: Git pull on server
1206
+ currentStep = 'git_pull_server';
1207
+ logCommand(`[1/4] Pulling latest code on server (${branch})...`);
1205
1208
  steps.push({ step: currentStep, status: 'running' });
1206
1209
 
1207
- await shellAsync(`npm ci`);
1210
+ const gitPullCmd = `${sshBase} "cd ${projectFolder} && git fetch origin && git checkout ${branch} && git pull origin ${branch}"`;
1211
+ await shellAsync(gitPullCmd);
1208
1212
 
1209
1213
  steps[steps.length - 1].status = 'success';
1210
- logSuccess(`Dependencies installed`);
1214
+ logSuccess(`Code updated on server`);
1211
1215
 
1212
- // Step 3: Build
1213
- currentStep = 'npm_build';
1214
- logCommand(`[3/5] Building application...`);
1216
+ // Step 2: Install dependencies on server
1217
+ currentStep = 'npm_install_server';
1218
+ logCommand(`[2/4] Installing dependencies on server...`);
1215
1219
  steps.push({ step: currentStep, status: 'running' });
1216
1220
 
1217
- await shellAsync(`npm run build`);
1221
+ const npmInstallCmd = `${sshBase} "cd ${projectFolder} && npm ci"`;
1222
+ await shellAsync(npmInstallCmd);
1218
1223
 
1219
1224
  steps[steps.length - 1].status = 'success';
1220
- logSuccess(`Build completed`);
1225
+ logSuccess(`Dependencies installed on server`);
1221
1226
 
1222
- // Step 4: Deploy via rsync
1223
- currentStep = 'rsync_deploy';
1224
- logCommand(`[4/5] Deploying to server...`);
1227
+ // Step 3: Build on server
1228
+ currentStep = 'npm_build_server';
1229
+ logCommand(`[3/4] Building application on server...`);
1225
1230
  steps.push({ step: currentStep, status: 'running' });
1226
1231
 
1227
- const deployFolder = environment === 'production'
1228
- ? '/var/www/tenminuteia-prod/'
1229
- : '/var/www/tenminuteia-staging/';
1230
-
1231
- // Rsync the dist folder (con SSH key si disponible)
1232
- const rsyncCmd = sshOptions
1233
- ? `rsync -avz --delete ${sshOptions} dist/ ${ssh_user}@${server_host}:${deployFolder}`
1234
- : `rsync -avz --delete dist/ ${ssh_user}@${server_host}:${deployFolder}`;
1235
- await shellAsync(rsyncCmd);
1232
+ const npmBuildCmd = `${sshBase} "cd ${projectFolder} && npm run build"`;
1233
+ await shellAsync(npmBuildCmd);
1236
1234
 
1237
1235
  steps[steps.length - 1].status = 'success';
1238
- logSuccess(`Files deployed to ${server_host}:${deployFolder}`);
1236
+ logSuccess(`Build completed on server`);
1239
1237
 
1240
- // Step 5: Reload nginx
1238
+ // Step 4: Reload nginx
1241
1239
  currentStep = 'reload_nginx';
1242
- logCommand(`[5/5] Reloading Nginx...`);
1240
+ logCommand(`[4/4] Reloading Nginx...`);
1243
1241
  steps.push({ step: currentStep, status: 'running' });
1244
1242
 
1245
- // SSH con key si disponible
1246
- const sshCmd = sshKeyPath
1247
- ? `ssh -i ${sshKeyPath} -o StrictHostKeyChecking=no ${ssh_user}@${server_host} "sudo nginx -t && sudo systemctl reload nginx"`
1248
- : `ssh ${ssh_user}@${server_host} "sudo nginx -t && sudo systemctl reload nginx"`;
1249
- await shellAsync(sshCmd);
1243
+ const reloadNginxCmd = `${sshBase} "sudo nginx -t && sudo systemctl reload nginx"`;
1244
+ await shellAsync(reloadNginxCmd);
1250
1245
 
1251
1246
  steps[steps.length - 1].status = 'success';
1252
1247
  logSuccess(`Nginx reloaded`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deinossrl/dgp-agent",
3
- "version": "1.4.34",
3
+ "version": "1.4.36",
4
4
  "description": "Agente local para Despliegue-GPT - Reporta el estado del repositorio Git a la plataforma TenMinute IA",
5
5
  "main": "index.mjs",
6
6
  "bin": {