kubiy-paas-cli 0.1.21 → 0.1.26
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/README.md +118 -118
- package/dist/index.js +2 -0
- package/dist/src/api.js +1 -0
- package/dist/src/commands/config.js +1 -0
- package/dist/src/commands/deploy.js +1 -0
- package/dist/src/commands/login.js +1 -0
- package/dist/src/commands/logs.js +1 -0
- package/dist/src/commands/rollback.js +1 -0
- package/dist/src/commands/service-get.js +1 -0
- package/dist/src/commands/service-link.js +1 -0
- package/dist/src/commands/version.js +1 -0
- package/dist/src/commands/whoami.js +1 -0
- package/dist/src/config.js +1 -0
- package/dist/src/git.js +1 -0
- package/dist/src/logger.js +1 -0
- package/package.json +36 -30
- package/index.js +0 -114
- package/src/api.js +0 -85
- package/src/commands/config.js +0 -71
- package/src/commands/deploy.js +0 -544
- package/src/commands/login.js +0 -16
- package/src/commands/logs.js +0 -112
- package/src/commands/rollback.js +0 -81
- package/src/commands/service-get.js +0 -39
- package/src/commands/service-link.js +0 -126
- package/src/commands/version.js +0 -17
- package/src/commands/whoami.js +0 -15
- package/src/config.js +0 -60
- package/src/git.js +0 -24
- package/src/logger.js +0 -31
package/src/commands/rollback.js
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
// src/commands/rollback.js
|
|
2
|
-
const path = require("path");
|
|
3
|
-
const fs = require("fs");
|
|
4
|
-
const { apiPost } = require("../api");
|
|
5
|
-
const { logInfo, logError, logSuccess } = require("../logger");
|
|
6
|
-
|
|
7
|
-
function loadProjectKubiyConfig() {
|
|
8
|
-
const configPath = path.join(process.cwd(), ".kubiy.json");
|
|
9
|
-
if (!fs.existsSync(configPath)) return null;
|
|
10
|
-
try {
|
|
11
|
-
const json = JSON.parse(fs.readFileSync(configPath, "utf8"));
|
|
12
|
-
return json.appId && json.serviceId
|
|
13
|
-
? { appId: json.appId, serviceId: json.serviceId, apikey: json.apikey }
|
|
14
|
-
: null;
|
|
15
|
-
} catch {
|
|
16
|
-
return null;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
async function run(args) {
|
|
21
|
-
const linked = loadProjectKubiyConfig();
|
|
22
|
-
// Soporta: kubiy rollback <deployId> (appId/serviceId desde .kubiy.json) o kubiy rollback <appId> <serviceId> <deployId>
|
|
23
|
-
const appId = args.length === 3 ? args[0] : (linked && linked.appId);
|
|
24
|
-
const serviceId = args.length === 3 ? args[1] : (linked && linked.serviceId);
|
|
25
|
-
const deployId = args.length === 3 ? args[2] : args[0];
|
|
26
|
-
const apikey = linked && linked.apikey;
|
|
27
|
-
|
|
28
|
-
if (!deployId) {
|
|
29
|
-
logError("Uso: kubiy rollback <deployId>\n kubiy rollback <appId> <serviceId> <deployId>\nO ejecuta desde un proyecto con kubiy link y pasa <deployId>.");
|
|
30
|
-
process.exit(1);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
if (!serviceId) {
|
|
34
|
-
logError("Se necesita serviceId. Ejecuta desde el directorio del proyecto con kubiy link o usa: kubiy rollback <appId> <serviceId> <deployId>");
|
|
35
|
-
process.exit(1);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
if (!appId) {
|
|
39
|
-
logError("Se necesita appId. Ejecuta desde el directorio del proyecto con kubiy link o usa: kubiy rollback <appId> <serviceId> <deployId>");
|
|
40
|
-
process.exit(1);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
if (!apikey) {
|
|
44
|
-
logError("No se encontró 'apikey' en .kubiy.json. Vuelve a linkear el proyecto:");
|
|
45
|
-
logError(" kubiy link <appId> --apikey=<tu-api-key>");
|
|
46
|
-
process.exit(1);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
try {
|
|
50
|
-
logInfo(`Iniciando rollback del servicio ${serviceId} al deploy ${deployId} (app: ${appId})...`);
|
|
51
|
-
|
|
52
|
-
const resp = await apiPost(
|
|
53
|
-
`/rollback`,
|
|
54
|
-
{ appId, serviceId, deployId },
|
|
55
|
-
{ headers: { "x-kubiy-token": apikey } }
|
|
56
|
-
);
|
|
57
|
-
logSuccess("Rollback enviado a Kubiy.");
|
|
58
|
-
|
|
59
|
-
if (resp.status) {
|
|
60
|
-
logInfo(`Estado SSM: ${resp.status}`);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (resp.stdout) {
|
|
64
|
-
console.log("---- STDOUT ----");
|
|
65
|
-
process.stdout.write(resp.stdout.endsWith("\n") ? resp.stdout : resp.stdout + "\n");
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
if (resp.stderr) {
|
|
69
|
-
console.log("---- STDERR ----");
|
|
70
|
-
process.stdout.write(resp.stderr.endsWith("\n") ? resp.stderr : resp.stderr + "\n");
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
logInfo(`Tip: puedes revisar los logs de deploy con:\n kubiy logs ${serviceId} --kind=deploy --lines=200`);
|
|
74
|
-
} catch (err) {
|
|
75
|
-
logError("Error en kubiy rollback:");
|
|
76
|
-
logError(err.message || String(err));
|
|
77
|
-
process.exit(1);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
module.exports = { run };
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
const fs = require("fs");
|
|
2
|
-
const path = require("path");
|
|
3
|
-
const { apiGet } = require("../api");
|
|
4
|
-
const { logError, logSuccess } = require("../logger");
|
|
5
|
-
|
|
6
|
-
function loadApiKeyFromLink() {
|
|
7
|
-
const filepath = path.join(process.cwd(), ".kubiy.json");
|
|
8
|
-
if (!fs.existsSync(filepath)) return null;
|
|
9
|
-
try {
|
|
10
|
-
const cfg = JSON.parse(fs.readFileSync(filepath, "utf8"));
|
|
11
|
-
return cfg.apikey || null;
|
|
12
|
-
} catch {
|
|
13
|
-
return null;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
async function run(args) {
|
|
18
|
-
const serviceId = args[0];
|
|
19
|
-
|
|
20
|
-
if (!serviceId) {
|
|
21
|
-
logError("Uso: kubiy service:get <serviceId>");
|
|
22
|
-
process.exit(1);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const apikey = loadApiKeyFromLink();
|
|
26
|
-
if (!apikey) {
|
|
27
|
-
logError("No se encontró 'apikey' en .kubiy.json. Vuelve a linkear el proyecto:");
|
|
28
|
-
logError(" kubiy link <appId> --apikey=<tu-api-key>");
|
|
29
|
-
process.exit(1);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const service = await apiGet(`/services/${serviceId}`, {
|
|
33
|
-
headers: { "x-kubiy-token": apikey },
|
|
34
|
-
});
|
|
35
|
-
logSuccess("Servicio obtenido:");
|
|
36
|
-
console.log(JSON.stringify(service, null, 2));
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
module.exports = { run };
|
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
const fs = require("fs");
|
|
2
|
-
const path = require("path");
|
|
3
|
-
const readline = require("readline");
|
|
4
|
-
const { apiPost, API_BASE } = require("../api");
|
|
5
|
-
const { logInfo, logSuccess, logError } = require("../logger");
|
|
6
|
-
const { log } = require("console");
|
|
7
|
-
|
|
8
|
-
function parseArgs(args) {
|
|
9
|
-
const opts = {
|
|
10
|
-
env: "prod",
|
|
11
|
-
token: null,
|
|
12
|
-
apikey: null,
|
|
13
|
-
saveSecrets: false, // local convenience
|
|
14
|
-
};
|
|
15
|
-
const clean = [];
|
|
16
|
-
|
|
17
|
-
for (const a of args) {
|
|
18
|
-
if (a.startsWith("--env=")) opts.env = a.split("=")[1] || "prod";
|
|
19
|
-
else if (a.startsWith("--token=")) opts.token = a.split("=")[1] || null;
|
|
20
|
-
else if (a.startsWith("--apikey=")) opts.apikey = a.split("=")[1] || null;
|
|
21
|
-
else if (a === "--save-secrets") opts.saveSecrets = true;
|
|
22
|
-
else clean.push(a);
|
|
23
|
-
}
|
|
24
|
-
return { serviceId: clean[0], opts };
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function promptHidden(question) {
|
|
28
|
-
return new Promise((resolve) => {
|
|
29
|
-
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
30
|
-
|
|
31
|
-
// IMPORTANT: override before question to avoid leaking chars
|
|
32
|
-
rl._writeToOutput = function _writeToOutput() {
|
|
33
|
-
rl.output.write("*");
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
rl.question(question, (value) => {
|
|
37
|
-
rl.close();
|
|
38
|
-
resolve((value || "").trim());
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function ensureGitignoreHas(patternLine) {
|
|
44
|
-
const gitignorePath = path.join(process.cwd(), ".gitignore");
|
|
45
|
-
let content = "";
|
|
46
|
-
if (fs.existsSync(gitignorePath)) {
|
|
47
|
-
content = fs.readFileSync(gitignorePath, "utf8");
|
|
48
|
-
if (content.split(/\r?\n/).includes(patternLine)) return;
|
|
49
|
-
}
|
|
50
|
-
const prefix = content && !content.endsWith("\n") ? "\n" : "";
|
|
51
|
-
fs.writeFileSync(gitignorePath, content + prefix + patternLine + "\n");
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function writeJson(filePath, obj) {
|
|
55
|
-
fs.writeFileSync(filePath, JSON.stringify(obj, null, 2));
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
async function run(args) {
|
|
59
|
-
const { opts } = parseArgs(args);
|
|
60
|
-
const appId = args[0];
|
|
61
|
-
|
|
62
|
-
if (!appId) {
|
|
63
|
-
logError("Usage: kubiy link <appId> [--env=prod|stg|dev] [--token=...] [--apikey=...] [--save-secrets]");
|
|
64
|
-
process.exit(1);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
try {
|
|
68
|
-
// 1) API Key: --apikey OR env OR prompt
|
|
69
|
-
let apikey = opts.apikey || process.env.KUBIY_API_KEY || null;
|
|
70
|
-
if (!apikey) apikey = await promptHidden("Paste your API Key (secret): ");
|
|
71
|
-
if (!apikey) throw new Error("API Key is required to link the service.");
|
|
72
|
-
|
|
73
|
-
logInfo(`Linking project to app ${appId} (env=${opts.env})...`);
|
|
74
|
-
|
|
75
|
-
// Llamar a cli/link con appId y appToken (apikey) en el body
|
|
76
|
-
const resp = await apiPost(
|
|
77
|
-
`/app/link`,
|
|
78
|
-
{
|
|
79
|
-
appId: appId,
|
|
80
|
-
appToken: apikey,
|
|
81
|
-
}
|
|
82
|
-
);
|
|
83
|
-
|
|
84
|
-
const {ok, config} = resp || {};
|
|
85
|
-
|
|
86
|
-
// Validar que la respuesta incluya appId (no usar serviceId como fallback)
|
|
87
|
-
if (!ok) {
|
|
88
|
-
throw new Error(
|
|
89
|
-
"La respuesta de la API fue invalida."
|
|
90
|
-
);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
const kubiyConfig = {
|
|
94
|
-
...config,
|
|
95
|
-
apikey: apikey,
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
// 3) Save config (includes apikey and appId from API response)
|
|
99
|
-
writeJson(path.join(process.cwd(), ".kubiy.json"), kubiyConfig);
|
|
100
|
-
|
|
101
|
-
// 4) Optional local secrets file (gitignored)
|
|
102
|
-
if (opts.saveSecrets) {
|
|
103
|
-
const secretsPath = path.join(process.cwd(), ".kubiy.secrets.json");
|
|
104
|
-
writeJson(secretsPath, { KUBIY_TOKEN: token, KUBIY_API_KEY: apikey });
|
|
105
|
-
ensureGitignoreHas(".kubiy.secrets.json");
|
|
106
|
-
logInfo("Saved local secrets in .kubiy.secrets.json (gitignored).");
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
logSuccess("Project linked to Kubiy 🎉");
|
|
110
|
-
logInfo("Saved config in .kubiy.json");
|
|
111
|
-
logInfo(`AppId: ${kubiyConfig.appId} (${kubiyConfig.environment})`);
|
|
112
|
-
logInfo(`ServiceId: ${kubiyConfig.serviceId}`);
|
|
113
|
-
|
|
114
|
-
// 5) Helpful next steps (CI / local)
|
|
115
|
-
logInfo("Next steps:");
|
|
116
|
-
logInfo("- Local (recommended): set env vars:");
|
|
117
|
-
logInfo(" Windows PowerShell: $env:KUBIY_TOKEN='***'; $env:KUBIY_API_KEY='***'");
|
|
118
|
-
logInfo(" Bash: export KUBIY_TOKEN='***' && export KUBIY_API_KEY='***'");
|
|
119
|
-
logInfo("- CI: store KUBIY_TOKEN and KUBIY_API_KEY as secrets.");
|
|
120
|
-
} catch (err) {
|
|
121
|
-
logError(err?.message || String(err));
|
|
122
|
-
process.exit(1);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
module.exports = { run };
|
package/src/commands/version.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
const { logInfo } = require("../logger");
|
|
2
|
-
const { API_BASE, apiGet } = require("../api");
|
|
3
|
-
const pkg = require("../../package.json");
|
|
4
|
-
|
|
5
|
-
async function run() {
|
|
6
|
-
logInfo(`Kubiy CLI version: ${pkg.version}`);
|
|
7
|
-
logInfo(`API base: ${API_BASE}`);
|
|
8
|
-
|
|
9
|
-
try {
|
|
10
|
-
const status = await apiGet("/status"); // ajusta si no tienes este endpoint
|
|
11
|
-
console.log("API status:", status);
|
|
12
|
-
} catch (e) {
|
|
13
|
-
console.log("No se pudo consultar /status de la API:", e.message);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
module.exports = { run };
|
package/src/commands/whoami.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
const { getCliToken } = require("../config");
|
|
2
|
-
const { logInfo, logWarn } = require("../logger");
|
|
3
|
-
|
|
4
|
-
async function run() {
|
|
5
|
-
const token = getCliToken();
|
|
6
|
-
if (!token) {
|
|
7
|
-
logWarn("No hay CLI token configurado. Ejecuta: kubiy login <cliToken>");
|
|
8
|
-
return;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
logInfo("CLI configurado.");
|
|
12
|
-
console.log("Token (truncado):", token.slice(0, 6) + "****");
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
module.exports = { run };
|
package/src/config.js
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
const fs = require("fs");
|
|
2
|
-
const os = require("os");
|
|
3
|
-
const path = require("path");
|
|
4
|
-
|
|
5
|
-
const CONFIG_DIR = path.join(os.homedir(), ".kubiy");
|
|
6
|
-
const CONFIG_FILE = path.join(CONFIG_DIR, "config.json");
|
|
7
|
-
|
|
8
|
-
function ensureConfigDir() {
|
|
9
|
-
if (!fs.existsSync(CONFIG_DIR)) {
|
|
10
|
-
fs.mkdirSync(CONFIG_DIR, { recursive: true });
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
function readConfig() {
|
|
15
|
-
try {
|
|
16
|
-
if (!fs.existsSync(CONFIG_FILE)) return {};
|
|
17
|
-
const raw = fs.readFileSync(CONFIG_FILE, "utf8");
|
|
18
|
-
return JSON.parse(raw);
|
|
19
|
-
} catch (e) {
|
|
20
|
-
return {};
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function writeConfig(obj) {
|
|
25
|
-
ensureConfigDir();
|
|
26
|
-
fs.writeFileSync(CONFIG_FILE, JSON.stringify(obj, null, 2), "utf8");
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function getCliToken() {
|
|
30
|
-
const cfg = readConfig();
|
|
31
|
-
return cfg.cliToken;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function setCliToken(token) {
|
|
35
|
-
const cfg = readConfig();
|
|
36
|
-
cfg.cliToken = token;
|
|
37
|
-
writeConfig(cfg);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function getLang() {
|
|
41
|
-
const cfg = readConfig();
|
|
42
|
-
return cfg.lang;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function setLang(lang) {
|
|
46
|
-
const cfg = readConfig();
|
|
47
|
-
cfg.lang = lang;
|
|
48
|
-
writeConfig(cfg);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
module.exports = {
|
|
52
|
-
CONFIG_DIR,
|
|
53
|
-
CONFIG_FILE,
|
|
54
|
-
readConfig,
|
|
55
|
-
writeConfig,
|
|
56
|
-
getCliToken,
|
|
57
|
-
setCliToken,
|
|
58
|
-
getLang,
|
|
59
|
-
setLang
|
|
60
|
-
};
|
package/src/git.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
const { execSync } = require("child_process");
|
|
2
|
-
const { logInfo, logSuccess, logWarn } = require("./logger");
|
|
3
|
-
|
|
4
|
-
function run(cmd) {
|
|
5
|
-
execSync(cmd, { stdio: "inherit" });
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
function addRemote(name, url) {
|
|
9
|
-
try {
|
|
10
|
-
// quitar si existe
|
|
11
|
-
execSync(`git remote remove ${name}`, { stdio: "ignore" });
|
|
12
|
-
} catch (_) {
|
|
13
|
-
// no pasa nada si no existe
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
logInfo(`Agregando remote '${name}' -> ${url}`);
|
|
17
|
-
execSync(`git remote add ${name} "${url}"`, { stdio: "inherit" });
|
|
18
|
-
logSuccess(`Remote '${name}' configurado.`);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
module.exports = {
|
|
22
|
-
run,
|
|
23
|
-
addRemote
|
|
24
|
-
};
|
package/src/logger.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
const COLORS = {
|
|
2
|
-
reset: "\x1b[0m",
|
|
3
|
-
green: "\x1b[32m",
|
|
4
|
-
yellow: "\x1b[33m",
|
|
5
|
-
red: "\x1b[31m",
|
|
6
|
-
cyan: "\x1b[36m"
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
function logInfo(...args) {
|
|
10
|
-
console.log(COLORS.cyan + "ℹ" + COLORS.reset, ...args);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function logSuccess(...args) {
|
|
14
|
-
console.log(COLORS.green + "✔" + COLORS.reset, ...args);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function logWarn(...args) {
|
|
18
|
-
console.log(COLORS.yellow + "⚠" + COLORS.reset, ...args);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function logError(...args) {
|
|
22
|
-
console.error(COLORS.red + "✖" + COLORS.reset, ...args);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
module.exports = {
|
|
26
|
-
logInfo,
|
|
27
|
-
logSuccess,
|
|
28
|
-
logWarn,
|
|
29
|
-
logError
|
|
30
|
-
};
|
|
31
|
-
|