kubiy-paas-cli 0.1.4 → 0.1.8
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.
- package/index.js +4 -0
- package/package.json +1 -2
- package/src/commands/deploy.js +4 -1
- package/src/commands/git-connect.js +1 -0
- package/src/commands/logs.js +106 -0
package/index.js
CHANGED
|
@@ -24,6 +24,9 @@ async function main() {
|
|
|
24
24
|
case "deploy":
|
|
25
25
|
await require("./src/commands/deploy").run();
|
|
26
26
|
break;
|
|
27
|
+
case "logs":
|
|
28
|
+
await require("./src/commands/logs").run(args.slice(1));
|
|
29
|
+
break;
|
|
27
30
|
case "version":
|
|
28
31
|
case "--version":
|
|
29
32
|
case "-v":
|
|
@@ -48,6 +51,7 @@ function printHelp() {
|
|
|
48
51
|
console.log(" kubiy service:get <serviceId>");
|
|
49
52
|
console.log(" kubiy git:connect <serviceId>");
|
|
50
53
|
console.log(" kubiy deploy");
|
|
54
|
+
console.log(" kubiy logs <serviceId> --kind=deploy|app --lines=200");
|
|
51
55
|
console.log(" kubiy version");
|
|
52
56
|
console.log("");
|
|
53
57
|
}
|
package/package.json
CHANGED
package/src/commands/deploy.js
CHANGED
|
@@ -173,7 +173,10 @@ async function run() {
|
|
|
173
173
|
logSuccess("🚀 Deploy completado. Revisa tu servicio Kubiy.");
|
|
174
174
|
} catch (err) {
|
|
175
175
|
const msg = String(err.message || "").toLowerCase();
|
|
176
|
-
|
|
176
|
+
console.error("✖ Error en kubiy deploy:");
|
|
177
|
+
console.error("✖ El git push falló. Muy probablemente el hook de deploy hizo rollback y dejó la versión anterior activa.");
|
|
178
|
+
console.error("ℹ Sugerencia: revisa los logs del deploy con:");
|
|
179
|
+
console.error(` kubiy logs ${serviceId} --kind=deploy --lines=200`);
|
|
177
180
|
|
|
178
181
|
// Caso clásico: el remoto tiene commits que el local no
|
|
179
182
|
if (
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
// src/commands/logs.js
|
|
2
|
+
const { apiGet } = require("../api");
|
|
3
|
+
const { logError, logInfo, logSuccess } = require("../logger");
|
|
4
|
+
const { getCliToken } = require("../config");
|
|
5
|
+
|
|
6
|
+
function parseLogsArgs(args) {
|
|
7
|
+
let serviceId = null;
|
|
8
|
+
let kind = "app";
|
|
9
|
+
let lines = 100;
|
|
10
|
+
|
|
11
|
+
if (!args || args.length === 0) {
|
|
12
|
+
return { serviceId, kind, lines };
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
serviceId = args[0];
|
|
16
|
+
|
|
17
|
+
for (let i = 1; i < args.length; i++) {
|
|
18
|
+
const a = args[i];
|
|
19
|
+
|
|
20
|
+
// --kind deploy | --kind app
|
|
21
|
+
if (a === "--kind" && args[i + 1]) {
|
|
22
|
+
kind = args[i + 1];
|
|
23
|
+
i++;
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
if (a.startsWith("--kind=")) {
|
|
27
|
+
kind = a.split("=")[1];
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// --lines 200 | --lines=200
|
|
32
|
+
if (a === "--lines" && args[i + 1]) {
|
|
33
|
+
const n = parseInt(args[i + 1], 10);
|
|
34
|
+
if (!isNaN(n)) lines = n;
|
|
35
|
+
i++;
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
if (a.startsWith("--lines=")) {
|
|
39
|
+
const n = parseInt(a.split("=")[1], 10);
|
|
40
|
+
if (!isNaN(n)) lines = n;
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return { serviceId, kind, lines };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async function run(args) {
|
|
49
|
+
const { serviceId, kind, lines } = parseLogsArgs(args);
|
|
50
|
+
|
|
51
|
+
if (!serviceId) {
|
|
52
|
+
logError("Uso: kubiy logs <serviceId> [--kind app|deploy] [--lines N]");
|
|
53
|
+
process.exit(1);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const token = getCliToken();
|
|
57
|
+
if (!token) {
|
|
58
|
+
logError("No hay CLI token. Ejecuta: kubiy login <cliToken>");
|
|
59
|
+
process.exit(1);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
logInfo(
|
|
63
|
+
`Obteniendo logs (${kind}) del servicio ${serviceId} (últimas ${lines} líneas)...`
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
try {
|
|
67
|
+
const qs = `kind=${encodeURIComponent(kind)}&lines=${lines}`;
|
|
68
|
+
const data = await apiGet(`/services/${serviceId}/logs?${qs}`);
|
|
69
|
+
|
|
70
|
+
// Esperamos algo tipo:
|
|
71
|
+
// { serviceId, kind, lines, status, output, errorOutput?, error? }
|
|
72
|
+
if (data.error) {
|
|
73
|
+
logError("Error al obtener logs:", data.error);
|
|
74
|
+
if (data.hint) {
|
|
75
|
+
console.log("Hint:", data.hint);
|
|
76
|
+
}
|
|
77
|
+
process.exit(1);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
logSuccess("Logs recibidos:\n");
|
|
81
|
+
|
|
82
|
+
const output = data.output || "";
|
|
83
|
+
const errorOutput = data.errorOutput || "";
|
|
84
|
+
|
|
85
|
+
if (!output && !errorOutput) {
|
|
86
|
+
console.log("<sin salida de logs>");
|
|
87
|
+
} else {
|
|
88
|
+
if (output) {
|
|
89
|
+
console.log(output.trimEnd());
|
|
90
|
+
}
|
|
91
|
+
if (errorOutput) {
|
|
92
|
+
console.log("\n[STDERR]");
|
|
93
|
+
console.log(errorOutput.trimEnd());
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (data.status && data.status !== "Success") {
|
|
98
|
+
console.log(`\n[Estado SSM: ${data.status}]`);
|
|
99
|
+
}
|
|
100
|
+
} catch (err) {
|
|
101
|
+
logError("Error llamando a la API de logs:", err.message || err);
|
|
102
|
+
process.exit(1);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
module.exports = { run };
|