@deinossrl/dgp-agent 1.4.35 → 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 +31 -41
  2. package/package.json +1 -1
package/index.mjs CHANGED
@@ -346,7 +346,7 @@ function getPlinkPath() {
346
346
  }
347
347
 
348
348
  // Versión del agente
349
- const AGENT_VERSION = '1.4.35';
349
+ const AGENT_VERSION = '1.4.36';
350
350
  let AGENT_MODE = 'smart'; // Siempre inteligente
351
351
 
352
352
  // Configuración (prioridad: env vars > archivo config > platform config > defaults)
@@ -1192,66 +1192,56 @@ async function executeDeploy(command) {
1192
1192
  // Mark as running
1193
1193
  await updateCommandStatus(id, 'running');
1194
1194
 
1195
- // Step 1: Git fetch and checkout
1196
- currentStep = 'git_checkout';
1197
- logCommand(`[1/5] Checkout branch ${branch}...`);
1198
- steps.push({ step: currentStep, status: 'running' });
1199
-
1200
- await shellAsync(`git fetch origin`);
1201
- await shellAsync(`git checkout ${branch}`);
1202
- 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/');
1203
1199
 
1204
- steps[steps.length - 1].status = 'success';
1205
- 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}`;
1206
1204
 
1207
- // Step 2: Install dependencies
1208
- currentStep = 'npm_install';
1209
- 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})...`);
1210
1208
  steps.push({ step: currentStep, status: 'running' });
1211
1209
 
1212
- await shellAsync(`npm ci`);
1210
+ const gitPullCmd = `${sshBase} "cd ${projectFolder} && git fetch origin && git checkout ${branch} && git pull origin ${branch}"`;
1211
+ await shellAsync(gitPullCmd);
1213
1212
 
1214
1213
  steps[steps.length - 1].status = 'success';
1215
- logSuccess(`Dependencies installed`);
1214
+ logSuccess(`Code updated on server`);
1216
1215
 
1217
- // Step 3: Build
1218
- currentStep = 'npm_build';
1219
- 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...`);
1220
1219
  steps.push({ step: currentStep, status: 'running' });
1221
1220
 
1222
- await shellAsync(`npm run build`);
1221
+ const npmInstallCmd = `${sshBase} "cd ${projectFolder} && npm ci"`;
1222
+ await shellAsync(npmInstallCmd);
1223
1223
 
1224
1224
  steps[steps.length - 1].status = 'success';
1225
- logSuccess(`Build completed`);
1225
+ logSuccess(`Dependencies installed on server`);
1226
1226
 
1227
- // Step 4: Deploy via rsync
1228
- currentStep = 'rsync_deploy';
1229
- 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...`);
1230
1230
  steps.push({ step: currentStep, status: 'running' });
1231
1231
 
1232
- const deployFolder = environment === 'production'
1233
- ? '/var/www/tenminuteia-prod/'
1234
- : '/var/www/tenminuteia-staging/';
1235
-
1236
- // Rsync the dist folder (con SSH key si disponible)
1237
- const rsyncCmd = sshOptions
1238
- ? `rsync -avz --delete ${sshOptions} dist/ ${ssh_user}@${server_host}:${deployFolder}`
1239
- : `rsync -avz --delete dist/ ${ssh_user}@${server_host}:${deployFolder}`;
1240
- await shellAsync(rsyncCmd);
1232
+ const npmBuildCmd = `${sshBase} "cd ${projectFolder} && npm run build"`;
1233
+ await shellAsync(npmBuildCmd);
1241
1234
 
1242
1235
  steps[steps.length - 1].status = 'success';
1243
- logSuccess(`Files deployed to ${server_host}:${deployFolder}`);
1236
+ logSuccess(`Build completed on server`);
1244
1237
 
1245
- // Step 5: Reload nginx
1238
+ // Step 4: Reload nginx
1246
1239
  currentStep = 'reload_nginx';
1247
- logCommand(`[5/5] Reloading Nginx...`);
1240
+ logCommand(`[4/4] Reloading Nginx...`);
1248
1241
  steps.push({ step: currentStep, status: 'running' });
1249
1242
 
1250
- // SSH con key si disponible
1251
- const sshCmd = sshKeyPath
1252
- ? `ssh -i ${sshKeyPath} -o StrictHostKeyChecking=no ${ssh_user}@${server_host} "sudo nginx -t && sudo systemctl reload nginx"`
1253
- : `ssh ${ssh_user}@${server_host} "sudo nginx -t && sudo systemctl reload nginx"`;
1254
- await shellAsync(sshCmd);
1243
+ const reloadNginxCmd = `${sshBase} "sudo nginx -t && sudo systemctl reload nginx"`;
1244
+ await shellAsync(reloadNginxCmd);
1255
1245
 
1256
1246
  steps[steps.length - 1].status = 'success';
1257
1247
  logSuccess(`Nginx reloaded`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deinossrl/dgp-agent",
3
- "version": "1.4.35",
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": {