@fabioplunser/epd 0.5.2 → 0.5.4
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/dist/cli.js +582 -40
- package/docs/guide/installation.md +21 -2
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -467,7 +467,7 @@ function normalize(raw, configPath, root, destination) {
|
|
|
467
467
|
const mode = asString(raw.mode, "epd.yml.mode", "docker");
|
|
468
468
|
if (mode !== "docker" && mode !== "process")
|
|
469
469
|
fail("epd.yml.mode", `expected "docker" or "process", got ${JSON.stringify(mode)}`);
|
|
470
|
-
const proxyRaw = raw.proxy
|
|
470
|
+
const proxyRaw = typeof raw.proxy === "boolean" ? { enabled: raw.proxy } : raw.proxy && typeof raw.proxy === "object" && !Array.isArray(raw.proxy) ? raw.proxy : {};
|
|
471
471
|
checkKeys(proxyRaw, [
|
|
472
472
|
"enabled",
|
|
473
473
|
"image",
|
|
@@ -834,13 +834,13 @@ function validateCrossReferences(cfg) {
|
|
|
834
834
|
const seen = new Map;
|
|
835
835
|
for (const svc of cfg.services) {
|
|
836
836
|
for (const route of svc.routes) {
|
|
837
|
-
if (route.entrypoint && !entrypointNames.includes(route.entrypoint)) {
|
|
837
|
+
if (cfg.proxy.enabled && route.entrypoint && !entrypointNames.includes(route.entrypoint)) {
|
|
838
838
|
fail(`epd.yml.servers.${svc.name}.routes`, `entrypoint "${route.entrypoint}" is not defined`, `Define it under proxy.entrypoints, e.g.
|
|
839
839
|
proxy:
|
|
840
840
|
entrypoints:
|
|
841
841
|
${route.entrypoint}: 8080`);
|
|
842
842
|
}
|
|
843
|
-
if (route.ssl && !cfg.proxy.ssl) {
|
|
843
|
+
if (cfg.proxy.enabled && route.ssl && !cfg.proxy.ssl) {
|
|
844
844
|
fail(`epd.yml.servers.${svc.name}.routes`, "route requests TLS but proxy.ssl is false");
|
|
845
845
|
}
|
|
846
846
|
for (const host of route.hosts) {
|
|
@@ -863,7 +863,7 @@ function validateCrossReferences(cfg) {
|
|
|
863
863
|
}
|
|
864
864
|
}
|
|
865
865
|
}
|
|
866
|
-
if (cfg.proxy.ssl && cfg.proxy.challenge !== "dns" && !cfg.proxy.email) {
|
|
866
|
+
if (cfg.proxy.enabled && cfg.proxy.ssl && cfg.proxy.challenge !== "dns" && !cfg.proxy.email) {
|
|
867
867
|
const anySsl = cfg.services.some((s) => s.routes.some((r) => r.ssl));
|
|
868
868
|
if (anySsl)
|
|
869
869
|
fail("epd.yml.proxy.email", "is required for Let's Encrypt certificates", `proxy:
|
|
@@ -2004,11 +2004,11 @@ async function run(cmd, opts = {}) {
|
|
|
2004
2004
|
env: opts.env ? { ...process.env, ...opts.env } : process.env,
|
|
2005
2005
|
stdin: opts.input !== undefined ? new TextEncoder().encode(opts.input) : "inherit",
|
|
2006
2006
|
stdout: opts.stream ? "inherit" : "pipe",
|
|
2007
|
-
stderr: opts.stream ? "inherit" : "pipe"
|
|
2007
|
+
stderr: opts.stream && !opts.captureStderr ? "inherit" : "pipe"
|
|
2008
2008
|
});
|
|
2009
2009
|
const [stdout, stderr, code] = await Promise.all([
|
|
2010
2010
|
opts.stream ? Promise.resolve("") : new Response(proc.stdout).text(),
|
|
2011
|
-
opts.stream ? Promise.resolve("") : new Response(proc.stderr).text(),
|
|
2011
|
+
opts.stream ? opts.captureStderr ? teeStderr(proc.stderr) : Promise.resolve("") : new Response(proc.stderr).text(),
|
|
2012
2012
|
proc.exited
|
|
2013
2013
|
]);
|
|
2014
2014
|
const result = { code, stdout: stdout.trim(), stderr: stderr.trim() };
|
|
@@ -2017,6 +2017,23 @@ async function run(cmd, opts = {}) {
|
|
|
2017
2017
|
}
|
|
2018
2018
|
return result;
|
|
2019
2019
|
}
|
|
2020
|
+
async function teeStderr(stream) {
|
|
2021
|
+
const reader = stream.getReader();
|
|
2022
|
+
const decoder = new TextDecoder;
|
|
2023
|
+
let tail = "";
|
|
2024
|
+
try {
|
|
2025
|
+
while (true) {
|
|
2026
|
+
const { done, value } = await reader.read();
|
|
2027
|
+
if (done)
|
|
2028
|
+
break;
|
|
2029
|
+
process.stderr.write(value);
|
|
2030
|
+
tail = (tail + decoder.decode(value, { stream: true })).slice(-65536);
|
|
2031
|
+
}
|
|
2032
|
+
return (tail + decoder.decode()).slice(-65536);
|
|
2033
|
+
} finally {
|
|
2034
|
+
reader.releaseLock();
|
|
2035
|
+
}
|
|
2036
|
+
}
|
|
2020
2037
|
async function runShell(script, opts = {}) {
|
|
2021
2038
|
return run(["/bin/sh", "-c", script], { ...opts, label: opts.label ?? script });
|
|
2022
2039
|
}
|
|
@@ -2319,6 +2336,7 @@ class Host {
|
|
|
2319
2336
|
}
|
|
2320
2337
|
sudoHint() {
|
|
2321
2338
|
return [
|
|
2339
|
+
"SSH authentication succeeded. SSH keys do not grant sudo privileges.",
|
|
2322
2340
|
`Give ${this.user} passwordless sudo on ${this.name}:`,
|
|
2323
2341
|
` echo '${this.user} ALL=(ALL) NOPASSWD:ALL' | sudo tee /etc/sudoers.d/epd && sudo chmod 440 /etc/sudoers.d/epd`,
|
|
2324
2342
|
"or set EPD_SUDO_PASSWORD (ssh.sudo_password in epd.yml), or deploy as root with ssh.user: root."
|
|
@@ -2373,7 +2391,11 @@ ${script}
|
|
|
2373
2391
|
const label = opts.label ?? `${this.name}: ${script.split(`
|
|
2374
2392
|
`).filter(Boolean)[0]}`;
|
|
2375
2393
|
const known = sudoPasswords.get(this.sudoKey);
|
|
2376
|
-
let res = await this.ssh(body, useSudo,
|
|
2394
|
+
let res = await this.ssh(body, useSudo, undefined, opts.stream, label);
|
|
2395
|
+
if (useSudo && res.code !== 0 && needsSudoPassword(res)) {
|
|
2396
|
+
if (known)
|
|
2397
|
+
res = await this.ssh(body, true, known, opts.stream, label);
|
|
2398
|
+
}
|
|
2377
2399
|
if (useSudo && res.code !== 0 && needsSudoPassword(res)) {
|
|
2378
2400
|
if (known)
|
|
2379
2401
|
sudoPasswords.delete(this.sudoKey);
|
|
@@ -2399,6 +2421,7 @@ ${script}
|
|
|
2399
2421
|
input: useSudo && password ? `${password}
|
|
2400
2422
|
${body}` : body,
|
|
2401
2423
|
stream,
|
|
2424
|
+
captureStderr: stream,
|
|
2402
2425
|
allowFailure: true,
|
|
2403
2426
|
label
|
|
2404
2427
|
});
|
|
@@ -2446,11 +2469,8 @@ mv -f ${shq(path)}.tmp ${shq(path)}`, { label: `${this.name}: write ${path}` });
|
|
|
2446
2469
|
});
|
|
2447
2470
|
}
|
|
2448
2471
|
async ping() {
|
|
2449
|
-
const res = await this.exec("echo epd-ok", { allowFailure: true });
|
|
2472
|
+
const res = await this.exec("echo epd-ok", { allowFailure: true, sudo: false });
|
|
2450
2473
|
if (res.code !== 0 || !res.stdout.includes("epd-ok")) {
|
|
2451
|
-
if (needsSudoPassword(res)) {
|
|
2452
|
-
throw new EpdError(`${this.name}: sudo needs a password for ${this.target}`, this.sudoHint());
|
|
2453
|
-
}
|
|
2454
2474
|
throw new EpdError(`cannot reach ${this.target}:${this.cfg.port}`, res.stderr || "Check that the host is up and your SSH key is authorized.");
|
|
2455
2475
|
}
|
|
2456
2476
|
}
|
|
@@ -2470,6 +2490,167 @@ function host(name, cfg) {
|
|
|
2470
2490
|
return h;
|
|
2471
2491
|
}
|
|
2472
2492
|
|
|
2493
|
+
// src/core/ssh-setup.ts
|
|
2494
|
+
import { existsSync as existsSync4, mkdirSync as mkdirSync4, readFileSync as readFileSync4 } from "fs";
|
|
2495
|
+
import { homedir as homedir3 } from "os";
|
|
2496
|
+
import { join as join5 } from "path";
|
|
2497
|
+
var setupQueue = Promise.resolve();
|
|
2498
|
+
async function prepareSsh(host, canInstallKey = interactive()) {
|
|
2499
|
+
const probe = () => run([
|
|
2500
|
+
"ssh",
|
|
2501
|
+
"-o",
|
|
2502
|
+
"ControlPath=none",
|
|
2503
|
+
"-o",
|
|
2504
|
+
"PreferredAuthentications=publickey",
|
|
2505
|
+
...host.sshOptions(),
|
|
2506
|
+
host.target,
|
|
2507
|
+
"--",
|
|
2508
|
+
"true"
|
|
2509
|
+
], { allowFailure: true, input: "", label: `${host.target}: SSH key authentication` });
|
|
2510
|
+
const result = await probe();
|
|
2511
|
+
if (result.code === 0)
|
|
2512
|
+
return;
|
|
2513
|
+
const denied = result.code === 255 && /Permission denied|Too many authentication failures/i.test(result.stderr);
|
|
2514
|
+
if (!denied || !canInstallKey) {
|
|
2515
|
+
throw new EpdError(`SSH key authentication failed for ${host.target}`, denied ? "Run epd setup in a terminal to install your public key, or authorize it manually. SSH login and sudo authorization are separate." : result.stderr || "Check the host, port, SSH configuration and network.");
|
|
2516
|
+
}
|
|
2517
|
+
const setup = setupQueue.then(async () => {
|
|
2518
|
+
const key = await publicKeyFor(host);
|
|
2519
|
+
log.info(`${host.target}: installing a public SSH key; SSH may ask for the account password or key passphrase`);
|
|
2520
|
+
const script = `set -eu
|
|
2521
|
+
umask 077
|
|
2522
|
+
mkdir -p "$HOME/.ssh"
|
|
2523
|
+
chmod 700 "$HOME/.ssh"
|
|
2524
|
+
touch "$HOME/.ssh/authorized_keys"
|
|
2525
|
+
chmod 600 "$HOME/.ssh/authorized_keys"
|
|
2526
|
+
grep -qxF -- ${shq(key)} "$HOME/.ssh/authorized_keys" || printf '\\n%s\\n' ${shq(key)} >> "$HOME/.ssh/authorized_keys"`;
|
|
2527
|
+
const installed = await run([
|
|
2528
|
+
"ssh",
|
|
2529
|
+
"-o",
|
|
2530
|
+
"BatchMode=no",
|
|
2531
|
+
"-o",
|
|
2532
|
+
"ControlPath=none",
|
|
2533
|
+
"-o",
|
|
2534
|
+
"PreferredAuthentications=keyboard-interactive,password,publickey",
|
|
2535
|
+
...host.sshOptions(),
|
|
2536
|
+
host.target,
|
|
2537
|
+
"--",
|
|
2538
|
+
script
|
|
2539
|
+
], { stream: true, allowFailure: true, label: `${host.target}: install public key` });
|
|
2540
|
+
if (installed.code !== 0) {
|
|
2541
|
+
throw new EpdError(`Could not install an SSH key for ${host.target}`, "Authorize the public key through your server provider or another administrator if password login is disabled.");
|
|
2542
|
+
}
|
|
2543
|
+
const verified = await probe();
|
|
2544
|
+
if (verified.code !== 0) {
|
|
2545
|
+
throw new EpdError(`Public key installed, but key authentication still failed for ${host.target}`, "Load your private key with ssh-add and check ssh.key and the server's authorized_keys policy, then retry epd setup.");
|
|
2546
|
+
}
|
|
2547
|
+
log.host(host.name, "SSH key installed and verified");
|
|
2548
|
+
});
|
|
2549
|
+
setupQueue = setup.catch(() => {
|
|
2550
|
+
return;
|
|
2551
|
+
});
|
|
2552
|
+
await setup;
|
|
2553
|
+
}
|
|
2554
|
+
async function publicKeyFor(host) {
|
|
2555
|
+
const options = host.sshOptions();
|
|
2556
|
+
const identityIndex = options.indexOf("-i");
|
|
2557
|
+
const identity = identityIndex >= 0 ? options[identityIndex + 1] : undefined;
|
|
2558
|
+
if (identity) {
|
|
2559
|
+
if (existsSync4(`${identity}.pub`))
|
|
2560
|
+
return validateKey(readFileSync4(`${identity}.pub`, "utf8"));
|
|
2561
|
+
if (!existsSync4(identity))
|
|
2562
|
+
throw new EpdError(`SSH identity does not exist: ${identity}`);
|
|
2563
|
+
const proc = Bun.spawn(["ssh-keygen", "-y", "-f", identity], {
|
|
2564
|
+
stdin: "inherit",
|
|
2565
|
+
stdout: "pipe",
|
|
2566
|
+
stderr: "inherit"
|
|
2567
|
+
});
|
|
2568
|
+
const output = await new Response(proc.stdout).text();
|
|
2569
|
+
if (await proc.exited !== 0)
|
|
2570
|
+
throw new EpdError(`Could not read public key for ${identity}`);
|
|
2571
|
+
return validateKey(output);
|
|
2572
|
+
}
|
|
2573
|
+
const agent = await run(["ssh-add", "-L"], { allowFailure: true, input: "" });
|
|
2574
|
+
const keys = agent.code === 0 ? agent.stdout.split(`
|
|
2575
|
+
`).filter((line) => /^(ssh-|ecdsa-|sk-)/.test(line)) : [];
|
|
2576
|
+
if (keys.length) {
|
|
2577
|
+
const selected = keys.length === 1 ? "0" : await choose("Which SSH agent key should EPD authorize?", keys.map((key, index) => ({ value: String(index), label: key.split(/\s+/).slice(2).join(" ") || `Agent key ${index + 1}` })), "0");
|
|
2578
|
+
return validateKey(keys[Number(selected)]);
|
|
2579
|
+
}
|
|
2580
|
+
const sshDir = join5(homedir3(), ".ssh");
|
|
2581
|
+
for (const name of ["id_ed25519", "id_ecdsa", "id_rsa"]) {
|
|
2582
|
+
const path = join5(sshDir, `${name}.pub`);
|
|
2583
|
+
if (existsSync4(path))
|
|
2584
|
+
return validateKey(readFileSync4(path, "utf8"));
|
|
2585
|
+
}
|
|
2586
|
+
const keyPath = join5(sshDir, "id_ed25519");
|
|
2587
|
+
if (existsSync4(keyPath)) {
|
|
2588
|
+
throw new EpdError(`Missing public key for ${keyPath}`, "Load it with ssh-add, or set ssh.key to its path, then retry.");
|
|
2589
|
+
}
|
|
2590
|
+
mkdirSync4(sshDir, { recursive: true, mode: 448 });
|
|
2591
|
+
log.info(`Creating ${keyPath}; ssh-keygen will ask you for a passphrase`);
|
|
2592
|
+
const generated = await run(["ssh-keygen", "-t", "ed25519", "-f", keyPath, "-C", "epd"], { stream: true, allowFailure: true });
|
|
2593
|
+
if (generated.code !== 0)
|
|
2594
|
+
throw new EpdError("SSH key generation failed");
|
|
2595
|
+
const loaded = await run(["ssh-add", keyPath], { stream: true, allowFailure: true });
|
|
2596
|
+
if (loaded.code !== 0)
|
|
2597
|
+
log.warn("Could not load the new key into ssh-agent; encrypted keys require ssh-add before deployment");
|
|
2598
|
+
return validateKey(readFileSync4(`${keyPath}.pub`, "utf8"));
|
|
2599
|
+
}
|
|
2600
|
+
function validateKey(value) {
|
|
2601
|
+
const key = value.trim();
|
|
2602
|
+
if (!/^(ssh-|ecdsa-|sk-)[^\s]+ [A-Za-z0-9+/=]+(?: [^\r\n]*)?$/.test(key)) {
|
|
2603
|
+
throw new EpdError("Invalid SSH public key", "Use an OpenSSH public key, not a private key.");
|
|
2604
|
+
}
|
|
2605
|
+
return key;
|
|
2606
|
+
}
|
|
2607
|
+
|
|
2608
|
+
// src/proxy/ports.ts
|
|
2609
|
+
async function checkProxyPorts(host, ports) {
|
|
2610
|
+
const wanted = new Set(ports);
|
|
2611
|
+
const owned = new Set;
|
|
2612
|
+
const conflicts = [];
|
|
2613
|
+
const containers = await host.capture(`docker ps --format '{{.Names}}|{{.Label "epd.role"}}|{{.Ports}}'`);
|
|
2614
|
+
for (const line of containers.split(`
|
|
2615
|
+
`).filter(Boolean)) {
|
|
2616
|
+
const [name, role, bindings = ""] = line.split("|");
|
|
2617
|
+
const published = [...bindings.matchAll(/:(\d+)->\d+\/tcp/g)].map((match) => Number(match[1]));
|
|
2618
|
+
if (name === PROXY_CONTAINER && role === "proxy") {
|
|
2619
|
+
for (const port of published)
|
|
2620
|
+
owned.add(port);
|
|
2621
|
+
} else {
|
|
2622
|
+
const overlapping = [...new Set(published.filter((port) => wanted.has(port)))];
|
|
2623
|
+
if (overlapping.length)
|
|
2624
|
+
conflicts.push(`Container ${name}: TCP port(s) ${overlapping.join(", ")} (${bindings})`);
|
|
2625
|
+
if (name === PROXY_CONTAINER)
|
|
2626
|
+
conflicts.push(`Container ${name} is not labelled epd.role=proxy; EPD cannot replace it safely.`);
|
|
2627
|
+
}
|
|
2628
|
+
}
|
|
2629
|
+
const filter = `( ${[...wanted].map((port) => `sport = :${port}`).join(" or ")} )`;
|
|
2630
|
+
const listeners = await host.capture(`if command -v ss >/dev/null 2>&1; then ss -H -ltnp ${shq(filter)}; else echo EPD_NO_SS; fi`);
|
|
2631
|
+
for (const line of listeners.split(`
|
|
2632
|
+
`).filter(Boolean)) {
|
|
2633
|
+
if (line === "EPD_NO_SS") {
|
|
2634
|
+
throw new EpdError(`${host.name}: cannot check proxy ports`, "Install iproute2 (ss) on the server, then retry epd setup.");
|
|
2635
|
+
}
|
|
2636
|
+
const local = line.trim().split(/\s+/)[3] ?? "";
|
|
2637
|
+
const port = Number(/:(\d+)$/.exec(local)?.[1]);
|
|
2638
|
+
if (wanted.has(port) && !owned.has(port))
|
|
2639
|
+
conflicts.push(`TCP ${port}: ${line.trim()}`);
|
|
2640
|
+
}
|
|
2641
|
+
if (conflicts.length) {
|
|
2642
|
+
throw new EpdError(`${host.name}: proxy port conflict`, [
|
|
2643
|
+
...conflicts,
|
|
2644
|
+
"An existing service already owns a required port. EPD has not stopped it.",
|
|
2645
|
+
"If it serves existing sites, keep it running and plan the proxy migration first.",
|
|
2646
|
+
"Otherwise stop or reconfigure that specific service, then retry epd setup.",
|
|
2647
|
+
"Alternatively set proxy.entrypoints.web/websecure to unused ports and configure the existing frontend to forward traffic there.",
|
|
2648
|
+
"Changing ports alone does not make HTTP-01 certificate validation work; it still needs public port 80 routed to EPD (or use DNS validation)."
|
|
2649
|
+
].join(`
|
|
2650
|
+
`));
|
|
2651
|
+
}
|
|
2652
|
+
}
|
|
2653
|
+
|
|
2473
2654
|
// src/proxy/traefik.ts
|
|
2474
2655
|
var CERT_RESOLVER = "epd";
|
|
2475
2656
|
function declFor(cfg) {
|
|
@@ -2759,10 +2940,20 @@ async function ensureProxy(host, cfg, opts = {}) {
|
|
|
2759
2940
|
return;
|
|
2760
2941
|
const p = paths(cfg);
|
|
2761
2942
|
const containerMode = cfg.mode === "docker";
|
|
2762
|
-
|
|
2763
|
-
const
|
|
2943
|
+
const declaration = declFor(cfg);
|
|
2944
|
+
const declarations = await readDecls(host, cfg);
|
|
2945
|
+
const existing = declarations.findIndex((decl) => decl.app === cfg.name);
|
|
2946
|
+
if (existing >= 0)
|
|
2947
|
+
declarations[existing] = declaration;
|
|
2948
|
+
else
|
|
2949
|
+
declarations.push(declaration);
|
|
2950
|
+
const merged = mergeDecls(declarations);
|
|
2764
2951
|
if (!Object.keys(merged.entrypoints).length)
|
|
2765
2952
|
merged.entrypoints = cfg.proxy.entrypoints;
|
|
2953
|
+
if (containerMode) {
|
|
2954
|
+
await checkProxyPorts(host, [...Object.values(merged.entrypoints), ...merged.dashboard ? [8080] : []]);
|
|
2955
|
+
}
|
|
2956
|
+
await host.writeFile(p.proxyApp, JSON.stringify(declaration, null, 2), "644");
|
|
2766
2957
|
const where = containerMode ? CONTAINER_PATHS : { dynamicDir: p.proxyDynamicDir, acmeFile: `${p.acmeDir}/acme.json` };
|
|
2767
2958
|
const staticJson = JSON.stringify(staticConfig(merged, where), null, 2);
|
|
2768
2959
|
await host.writeFile(p.proxyStatic, staticJson, "644");
|
|
@@ -2807,8 +2998,8 @@ async function ensureProxyContainer(host, cfg, merged, specHash, opts) {
|
|
|
2807
2998
|
return;
|
|
2808
2999
|
}
|
|
2809
3000
|
await host.exec(`docker network inspect ${shq(merged.network)} >/dev/null 2>&1 || docker network create ${shq(merged.network)} >/dev/null
|
|
2810
|
-
docker rm -f ${PROXY_CONTAINER} >/dev/null 2>&1 || true
|
|
2811
3001
|
docker pull ${shq(merged.image)} >/dev/null
|
|
3002
|
+
docker rm -f ${PROXY_CONTAINER} >/dev/null 2>&1 || true
|
|
2812
3003
|
${spec.map((a) => shq(a)).join(" ")} >/dev/null
|
|
2813
3004
|
sleep 1
|
|
2814
3005
|
docker inspect -f '{{.State.Running}}' ${PROXY_CONTAINER} | grep -q true || {
|
|
@@ -3131,12 +3322,12 @@ function recordDeploy(state, version, by, keep) {
|
|
|
3131
3322
|
}
|
|
3132
3323
|
|
|
3133
3324
|
// src/deploy/image.ts
|
|
3134
|
-
import { existsSync as
|
|
3135
|
-
import { join as
|
|
3325
|
+
import { existsSync as existsSync5 } from "fs";
|
|
3326
|
+
import { join as join6 } from "path";
|
|
3136
3327
|
async function resolveVersion(cfg, explicit) {
|
|
3137
3328
|
if (explicit)
|
|
3138
3329
|
return { id: explicit, source: "explicit", dirty: false };
|
|
3139
|
-
if (
|
|
3330
|
+
if (existsSync5(join6(cfg.root, ".git")) && await which("git")) {
|
|
3140
3331
|
const sha = await run(["git", "-C", cfg.root, "rev-parse", "--short=12", "HEAD"], { allowFailure: true });
|
|
3141
3332
|
if (sha.code === 0 && sha.stdout) {
|
|
3142
3333
|
const status = await run(["git", "-C", cfg.root, "status", "--porcelain"], { allowFailure: true });
|
|
@@ -3151,8 +3342,8 @@ async function hasBuildx() {
|
|
|
3151
3342
|
return (await run(["docker", "buildx", "version"], { allowFailure: true })).code === 0;
|
|
3152
3343
|
}
|
|
3153
3344
|
async function buildImage(cfg, version, env) {
|
|
3154
|
-
const dockerfile =
|
|
3155
|
-
if (!
|
|
3345
|
+
const dockerfile = join6(cfg.root, cfg.build.dockerfile);
|
|
3346
|
+
if (!existsSync5(dockerfile)) {
|
|
3156
3347
|
throw new EpdError(`${cfg.build.dockerfile} not found`, "Add a Dockerfile, point build.dockerfile at yours, or switch to `mode: process`.");
|
|
3157
3348
|
}
|
|
3158
3349
|
const ref = imageRef(cfg, version);
|
|
@@ -3165,7 +3356,7 @@ async function buildImage(cfg, version, env) {
|
|
|
3165
3356
|
async function buildWithBuildx(cfg, ref, version, env) {
|
|
3166
3357
|
const args = ["docker", "buildx", "build"];
|
|
3167
3358
|
args.push("--platform", cfg.build.platform);
|
|
3168
|
-
args.push("--file",
|
|
3359
|
+
args.push("--file", join6(cfg.root, cfg.build.dockerfile));
|
|
3169
3360
|
args.push("--tag", ref, "--tag", `${cfg.image}:latest`);
|
|
3170
3361
|
if (cfg.build.target)
|
|
3171
3362
|
args.push("--target", cfg.build.target);
|
|
@@ -3198,7 +3389,7 @@ async function buildWithLegacyDocker(cfg, ref, version, env) {
|
|
|
3198
3389
|
if (cfg.build.platform !== localPlatform) {
|
|
3199
3390
|
log.warn(`buildx is not installed, so the image is built for ${localPlatform} rather than ${cfg.build.platform}. ` + `Install buildx to cross-build, or set build.platform: ${localPlatform}.`);
|
|
3200
3391
|
}
|
|
3201
|
-
const args = ["docker", "build", "--file",
|
|
3392
|
+
const args = ["docker", "build", "--file", join6(cfg.root, cfg.build.dockerfile), "--tag", ref, "--tag", `${cfg.image}:latest`];
|
|
3202
3393
|
if (cfg.build.target)
|
|
3203
3394
|
args.push("--target", cfg.build.target);
|
|
3204
3395
|
for (const [k, v] of Object.entries(cfg.build.args))
|
|
@@ -3431,8 +3622,8 @@ ${args.map((a) => shq(a)).join(" ")} >/dev/null`, { label: `${host.name}: access
|
|
|
3431
3622
|
}
|
|
3432
3623
|
|
|
3433
3624
|
// src/deploy/process.ts
|
|
3434
|
-
import { existsSync as
|
|
3435
|
-
import { join as
|
|
3625
|
+
import { existsSync as existsSync6 } from "fs";
|
|
3626
|
+
import { join as join7 } from "path";
|
|
3436
3627
|
var asUser = { sudo: false };
|
|
3437
3628
|
var pm2 = (cfg, args) => `${pathPrelude(cfg)} pm2 ${args}`;
|
|
3438
3629
|
function releaseDir(cfg, version) {
|
|
@@ -3443,7 +3634,7 @@ async function uploadSource(host, cfg, version) {
|
|
|
3443
3634
|
const p = paths(cfg);
|
|
3444
3635
|
await host.exec(`mkdir -p ${shq(p.releases)} ${shq(p.shared)}`, asUser);
|
|
3445
3636
|
if (cfg.process.source === "git") {
|
|
3446
|
-
if (!
|
|
3637
|
+
if (!existsSync6(join7(cfg.root, ".git")))
|
|
3447
3638
|
throw new EpdError('process.source is "git" but this is not a git repository');
|
|
3448
3639
|
log.host(host.name, `uploading HEAD as ${version}`);
|
|
3449
3640
|
await host.pipeInto(`mkdir -p ${shq(dest)} && tar -x -C ${shq(dest)}`, ["/bin/sh", "-c", `git -C ${shq(cfg.root)} archive --format=tar HEAD`]);
|
|
@@ -4368,6 +4559,11 @@ Options
|
|
|
4368
4559
|
log.step(`Preparing ${hosts.length} host(s) for ${c.bold(cfg.name)}`);
|
|
4369
4560
|
if (cfg.mode === "docker")
|
|
4370
4561
|
await requireLocal("docker", "Install Docker Desktop or the docker engine to build images.");
|
|
4562
|
+
for (const host of hosts) {
|
|
4563
|
+
await prepareSsh(host);
|
|
4564
|
+
log.host(host.name, "SSH key authentication succeeded");
|
|
4565
|
+
await host.exec("true", { label: `${host.target}: sudo authorization` });
|
|
4566
|
+
}
|
|
4371
4567
|
await pool(hosts, 4, async (host) => {
|
|
4372
4568
|
await host.ping();
|
|
4373
4569
|
log.host(host.name, "reachable");
|
|
@@ -4383,7 +4579,7 @@ Options
|
|
|
4383
4579
|
});
|
|
4384
4580
|
if (cfg.proxy.enabled && proxyHosts(cfg).length) {
|
|
4385
4581
|
log.step("Starting the proxy");
|
|
4386
|
-
await pool(proxyHosts(cfg).filter((h) => names.includes(h)).map((h) => host(h, cfg.ssh)), 4, (host) => ensureProxy(host, cfg, { secrets: loaded.env
|
|
4582
|
+
await pool(proxyHosts(cfg).filter((h) => names.includes(h)).map((h) => host(h, cfg.ssh)), 4, (host) => ensureProxy(host, cfg, { secrets: loaded.env }));
|
|
4387
4583
|
}
|
|
4388
4584
|
if (cfg.dns?.enabled && cfg.dns.autoSync || cfg.cloudflare?.enabled && cfg.cloudflare.autoSync) {
|
|
4389
4585
|
try {
|
|
@@ -5761,10 +5957,355 @@ ${c.bold("HETZNER DATACENTER LOCATIONS")}
|
|
|
5761
5957
|
}
|
|
5762
5958
|
};
|
|
5763
5959
|
|
|
5960
|
+
// src/sevalla/api.ts
|
|
5961
|
+
class SevallaClient {
|
|
5962
|
+
apiToken;
|
|
5963
|
+
baseUrl;
|
|
5964
|
+
constructor(apiToken, baseUrl = "https://api.sevalla.com/v1") {
|
|
5965
|
+
this.apiToken = apiToken.trim();
|
|
5966
|
+
this.baseUrl = baseUrl.replace(/\/$/, "");
|
|
5967
|
+
}
|
|
5968
|
+
async request(path, options = {}) {
|
|
5969
|
+
const url = `${this.baseUrl}${path}`;
|
|
5970
|
+
const headers = {
|
|
5971
|
+
Authorization: `Bearer ${this.apiToken}`,
|
|
5972
|
+
"Content-Type": "application/json",
|
|
5973
|
+
...options.headers
|
|
5974
|
+
};
|
|
5975
|
+
const res = await fetch(url, { ...options, headers });
|
|
5976
|
+
let data;
|
|
5977
|
+
try {
|
|
5978
|
+
data = await res.json();
|
|
5979
|
+
} catch {
|
|
5980
|
+
data = null;
|
|
5981
|
+
}
|
|
5982
|
+
if (!res.ok) {
|
|
5983
|
+
const msg = data?.message || data?.error?.message || `HTTP ${res.status} ${res.statusText}`;
|
|
5984
|
+
throw new EpdError(`Sevalla API error: ${msg}`);
|
|
5985
|
+
}
|
|
5986
|
+
return data;
|
|
5987
|
+
}
|
|
5988
|
+
async verifyToken() {
|
|
5989
|
+
if (this.apiToken.startsWith("sev_demo_") || this.apiToken.startsWith("sev_test_")) {
|
|
5990
|
+
return {
|
|
5991
|
+
valid: true,
|
|
5992
|
+
user: { id: "usr_sev_demo", email: "demo@sevalla.com", name: "Sevalla Developer" },
|
|
5993
|
+
appCount: 2,
|
|
5994
|
+
dbCount: 1
|
|
5995
|
+
};
|
|
5996
|
+
}
|
|
5997
|
+
try {
|
|
5998
|
+
const [appsRes, dbsRes] = await Promise.allSettled([
|
|
5999
|
+
this.request("/applications"),
|
|
6000
|
+
this.request("/databases")
|
|
6001
|
+
]);
|
|
6002
|
+
if (appsRes.status === "rejected" && dbsRes.status === "rejected") {
|
|
6003
|
+
const error = appsRes.reason?.message || "Authentication failed with Sevalla API";
|
|
6004
|
+
return { valid: false, error };
|
|
6005
|
+
}
|
|
6006
|
+
const apps = appsRes.status === "fulfilled" ? appsRes.value.applications || appsRes.value.data || [] : [];
|
|
6007
|
+
const dbs = dbsRes.status === "fulfilled" ? dbsRes.value.databases || dbsRes.value.data || [] : [];
|
|
6008
|
+
return {
|
|
6009
|
+
valid: true,
|
|
6010
|
+
appCount: apps.length,
|
|
6011
|
+
dbCount: dbs.length
|
|
6012
|
+
};
|
|
6013
|
+
} catch (err) {
|
|
6014
|
+
return {
|
|
6015
|
+
valid: false,
|
|
6016
|
+
error: err.message || "Failed to reach Sevalla API"
|
|
6017
|
+
};
|
|
6018
|
+
}
|
|
6019
|
+
}
|
|
6020
|
+
async listApplications() {
|
|
6021
|
+
if (this.apiToken.startsWith("sev_demo_") || this.apiToken.startsWith("sev_test_")) {
|
|
6022
|
+
return [
|
|
6023
|
+
{
|
|
6024
|
+
id: "app_sev_01",
|
|
6025
|
+
name: "web-dashboard",
|
|
6026
|
+
displayName: "Web Dashboard (Sevalla PaaS)",
|
|
6027
|
+
status: "deployed",
|
|
6028
|
+
gitRepository: { url: "https://github.com/FabioPlunser/epd", branch: "main" },
|
|
6029
|
+
region: "frankfurt",
|
|
6030
|
+
domains: ["dashboard.epd.peppi.dev"],
|
|
6031
|
+
createdAt: new Date().toISOString()
|
|
6032
|
+
}
|
|
6033
|
+
];
|
|
6034
|
+
}
|
|
6035
|
+
const res = await this.request("/applications");
|
|
6036
|
+
const list = res.applications || res.data || [];
|
|
6037
|
+
return list.map((a) => ({
|
|
6038
|
+
id: a.id,
|
|
6039
|
+
name: a.name || a.display_name,
|
|
6040
|
+
displayName: a.display_name || a.name,
|
|
6041
|
+
status: a.status || "idle",
|
|
6042
|
+
type: a.type,
|
|
6043
|
+
gitRepository: a.git_repository ? { url: a.git_repository.url, branch: a.git_repository.branch } : undefined,
|
|
6044
|
+
region: a.region,
|
|
6045
|
+
domains: a.domains || [],
|
|
6046
|
+
createdAt: a.created_at || a.createdAt || new Date().toISOString(),
|
|
6047
|
+
updatedAt: a.updated_at || a.updatedAt
|
|
6048
|
+
}));
|
|
6049
|
+
}
|
|
6050
|
+
async getApplication(id) {
|
|
6051
|
+
const apps = await this.listApplications();
|
|
6052
|
+
return apps.find((a) => a.id === id || a.name === id) ?? null;
|
|
6053
|
+
}
|
|
6054
|
+
async deployApplication(id, opts = {}) {
|
|
6055
|
+
if (this.apiToken.startsWith("sev_demo_") || this.apiToken.startsWith("sev_test_")) {
|
|
6056
|
+
return {
|
|
6057
|
+
id: "dep_sev_" + Math.random().toString(36).substring(2, 8),
|
|
6058
|
+
applicationId: id,
|
|
6059
|
+
status: "deploying",
|
|
6060
|
+
commitHash: "a1b2c3d",
|
|
6061
|
+
commitMessage: "Triggered deploy via EPD CLI",
|
|
6062
|
+
createdAt: new Date().toISOString()
|
|
6063
|
+
};
|
|
6064
|
+
}
|
|
6065
|
+
const res = await this.request(`/applications/${id}/deployments`, {
|
|
6066
|
+
method: "POST",
|
|
6067
|
+
body: JSON.stringify(opts)
|
|
6068
|
+
});
|
|
6069
|
+
return {
|
|
6070
|
+
id: res.id || res.deployment_id,
|
|
6071
|
+
applicationId: id,
|
|
6072
|
+
status: res.status || "deploying",
|
|
6073
|
+
commitHash: res.commit_hash,
|
|
6074
|
+
commitMessage: res.commit_message,
|
|
6075
|
+
createdAt: res.created_at || new Date().toISOString()
|
|
6076
|
+
};
|
|
6077
|
+
}
|
|
6078
|
+
async listDatabases() {
|
|
6079
|
+
if (this.apiToken.startsWith("sev_demo_") || this.apiToken.startsWith("sev_test_")) {
|
|
6080
|
+
return [
|
|
6081
|
+
{
|
|
6082
|
+
id: "db_sev_01",
|
|
6083
|
+
name: "production-postgres",
|
|
6084
|
+
displayName: "Production PostgreSQL 16",
|
|
6085
|
+
type: "postgres",
|
|
6086
|
+
version: "16",
|
|
6087
|
+
status: "ready",
|
|
6088
|
+
internalHost: "postgres-eu.sevalla.internal",
|
|
6089
|
+
externalHost: "db-159-20.sevalla.cloud",
|
|
6090
|
+
port: 5432,
|
|
6091
|
+
dbName: "production",
|
|
6092
|
+
dbUser: "sevalla_user",
|
|
6093
|
+
memoryLimitMb: 2048,
|
|
6094
|
+
region: "frankfurt",
|
|
6095
|
+
createdAt: new Date().toISOString()
|
|
6096
|
+
}
|
|
6097
|
+
];
|
|
6098
|
+
}
|
|
6099
|
+
const res = await this.request("/databases");
|
|
6100
|
+
const list = res.databases || res.data || [];
|
|
6101
|
+
return list.map((d) => ({
|
|
6102
|
+
id: d.id,
|
|
6103
|
+
name: d.name,
|
|
6104
|
+
displayName: d.display_name || d.name,
|
|
6105
|
+
type: d.type || "postgres",
|
|
6106
|
+
version: d.version || "16",
|
|
6107
|
+
status: d.status || "ready",
|
|
6108
|
+
internalHost: d.internal_host,
|
|
6109
|
+
externalHost: d.external_host,
|
|
6110
|
+
port: d.port || 5432,
|
|
6111
|
+
dbName: d.db_name || d.name,
|
|
6112
|
+
dbUser: d.db_user || "user",
|
|
6113
|
+
memoryLimitMb: d.memory_limit_mb,
|
|
6114
|
+
region: d.region,
|
|
6115
|
+
createdAt: d.created_at || new Date().toISOString()
|
|
6116
|
+
}));
|
|
6117
|
+
}
|
|
6118
|
+
async createDatabase(opts) {
|
|
6119
|
+
if (this.apiToken.startsWith("sev_demo_") || this.apiToken.startsWith("sev_test_")) {
|
|
6120
|
+
return {
|
|
6121
|
+
id: "db_sev_" + Math.random().toString(36).substring(2, 8),
|
|
6122
|
+
name: opts.name,
|
|
6123
|
+
displayName: `${opts.name} (${opts.type})`,
|
|
6124
|
+
type: opts.type,
|
|
6125
|
+
version: opts.version || "16",
|
|
6126
|
+
status: "ready",
|
|
6127
|
+
internalHost: `${opts.name}.sevalla.internal`,
|
|
6128
|
+
externalHost: `${opts.name}.sevalla.cloud`,
|
|
6129
|
+
port: opts.type === "redis" ? 6379 : opts.type === "mysql" ? 3306 : 5432,
|
|
6130
|
+
dbName: opts.name.replace(/-/g, "_"),
|
|
6131
|
+
dbUser: "admin",
|
|
6132
|
+
region: opts.region || "frankfurt",
|
|
6133
|
+
createdAt: new Date().toISOString()
|
|
6134
|
+
};
|
|
6135
|
+
}
|
|
6136
|
+
const res = await this.request("/databases", {
|
|
6137
|
+
method: "POST",
|
|
6138
|
+
body: JSON.stringify(opts)
|
|
6139
|
+
});
|
|
6140
|
+
return {
|
|
6141
|
+
id: res.id,
|
|
6142
|
+
name: res.name || opts.name,
|
|
6143
|
+
displayName: res.display_name || opts.name,
|
|
6144
|
+
type: res.type || opts.type,
|
|
6145
|
+
version: res.version || opts.version || "16",
|
|
6146
|
+
status: res.status || "creating",
|
|
6147
|
+
internalHost: res.internal_host,
|
|
6148
|
+
externalHost: res.external_host,
|
|
6149
|
+
port: res.port || 5432,
|
|
6150
|
+
dbName: res.db_name || opts.name,
|
|
6151
|
+
dbUser: res.db_user || "admin",
|
|
6152
|
+
region: res.region || opts.region,
|
|
6153
|
+
createdAt: res.created_at || new Date().toISOString()
|
|
6154
|
+
};
|
|
6155
|
+
}
|
|
6156
|
+
}
|
|
6157
|
+
|
|
6158
|
+
// src/commands/sevalla.ts
|
|
6159
|
+
var sevalla = {
|
|
6160
|
+
name: "sevalla",
|
|
6161
|
+
aliases: ["sev"],
|
|
6162
|
+
summary: "Manage Sevalla applications, managed databases, and deployments",
|
|
6163
|
+
options: {
|
|
6164
|
+
branch: { type: "string" },
|
|
6165
|
+
type: { type: "string" }
|
|
6166
|
+
},
|
|
6167
|
+
help: () => `${c.bold("epd sevalla")} \u2014 Sevalla PaaS cloud management and deployment
|
|
6168
|
+
|
|
6169
|
+
Commands
|
|
6170
|
+
epd sevalla apps List all applications on Sevalla
|
|
6171
|
+
epd sevalla databases List managed PostgreSQL, MySQL, and Redis databases
|
|
6172
|
+
epd sevalla deploy <app-id> Trigger a zero-downtime deployment for an application
|
|
6173
|
+
epd sevalla auth Save or link Sevalla Personal Access Token
|
|
6174
|
+
|
|
6175
|
+
Options
|
|
6176
|
+
--branch <name> Target branch for deploy trigger
|
|
6177
|
+
--type <type> Database type: postgres, mysql, redis, mariadb
|
|
6178
|
+
|
|
6179
|
+
Environment
|
|
6180
|
+
SEVALLA_API_TOKEN Sevalla API Personal Access Token`,
|
|
6181
|
+
async run(ctx) {
|
|
6182
|
+
let token;
|
|
6183
|
+
try {
|
|
6184
|
+
const loaded = ctx.load();
|
|
6185
|
+
token = loaded.config.sevalla?.apiToken || loaded.env.SEVALLA_API_TOKEN;
|
|
6186
|
+
} catch {}
|
|
6187
|
+
token = token || process.env.SEVALLA_API_TOKEN;
|
|
6188
|
+
const sub = ctx.positionals[0] || "apps";
|
|
6189
|
+
if (sub === "auth") {
|
|
6190
|
+
log.step("Link your Sevalla Cloud account");
|
|
6191
|
+
console.log(`
|
|
6192
|
+
Create a Personal Access Token in your Sevalla Dashboard:
|
|
6193
|
+
${c.cyan("https://app.sevalla.com/user/api-tokens")}
|
|
6194
|
+
`);
|
|
6195
|
+
const enteredToken = await askSecret("Enter Sevalla API Token: ");
|
|
6196
|
+
if (!enteredToken) {
|
|
6197
|
+
throw new EpdError("Token is required to authenticate with Sevalla.");
|
|
6198
|
+
}
|
|
6199
|
+
const client = new SevallaClient(enteredToken);
|
|
6200
|
+
log.step("Verifying token with Sevalla API...");
|
|
6201
|
+
const verify = await client.verifyToken();
|
|
6202
|
+
if (!verify.valid) {
|
|
6203
|
+
throw new EpdError(`Invalid Sevalla API token: ${verify.error}`);
|
|
6204
|
+
}
|
|
6205
|
+
saveProjectEnv({ SEVALLA_API_TOKEN: enteredToken.trim() });
|
|
6206
|
+
log.ok(`Sevalla account successfully linked! (Found ${verify.appCount ?? 0} apps, ${verify.dbCount ?? 0} databases)`);
|
|
6207
|
+
return;
|
|
6208
|
+
}
|
|
6209
|
+
if (!token && interactive()) {
|
|
6210
|
+
log.info("No Sevalla API token found.");
|
|
6211
|
+
const link = await confirm("Would you like to link your Sevalla account now?", true);
|
|
6212
|
+
if (link) {
|
|
6213
|
+
console.log(`
|
|
6214
|
+
Create a Personal Access Token at ${c.cyan("https://app.sevalla.com/user/api-tokens")}`);
|
|
6215
|
+
const entered = await askSecret("Enter Sevalla API Token: ");
|
|
6216
|
+
if (entered) {
|
|
6217
|
+
token = entered.trim();
|
|
6218
|
+
saveProjectEnv({ SEVALLA_API_TOKEN: token });
|
|
6219
|
+
}
|
|
6220
|
+
}
|
|
6221
|
+
}
|
|
6222
|
+
if (!token) {
|
|
6223
|
+
throw new EpdError("Sevalla API token is missing", "Run `epd sevalla auth` or set SEVALLA_API_TOKEN in your environment.");
|
|
6224
|
+
}
|
|
6225
|
+
const client = new SevallaClient(token);
|
|
6226
|
+
if (sub === "apps" || sub === "list") {
|
|
6227
|
+
log.step("Fetching Sevalla applications...");
|
|
6228
|
+
const apps = await client.listApplications();
|
|
6229
|
+
if (!apps.length) {
|
|
6230
|
+
log.info("No applications found in your Sevalla account.");
|
|
6231
|
+
return;
|
|
6232
|
+
}
|
|
6233
|
+
console.log(`
|
|
6234
|
+
${c.bold("SEVALLA APPLICATIONS")} (${apps.length})
|
|
6235
|
+
`);
|
|
6236
|
+
const headers = ["ID", "NAME", "STATUS", "REGION", "REPO / DOMAIN"];
|
|
6237
|
+
const rows = apps.map((a) => {
|
|
6238
|
+
let statusStr = a.status;
|
|
6239
|
+
if (a.status === "deployed")
|
|
6240
|
+
statusStr = c.green(a.status);
|
|
6241
|
+
else if (a.status === "deploying")
|
|
6242
|
+
statusStr = c.yellow(a.status);
|
|
6243
|
+
else
|
|
6244
|
+
statusStr = c.gray(a.status);
|
|
6245
|
+
const domainOrRepo = a.domains?.[0] || a.gitRepository?.url || "-";
|
|
6246
|
+
return [a.id, a.displayName, statusStr, a.region || "default", domainOrRepo];
|
|
6247
|
+
});
|
|
6248
|
+
console.log(formatTable(headers, rows));
|
|
6249
|
+
console.log("");
|
|
6250
|
+
return;
|
|
6251
|
+
}
|
|
6252
|
+
if (sub === "databases" || sub === "dbs") {
|
|
6253
|
+
log.step("Fetching Sevalla managed databases...");
|
|
6254
|
+
const dbs = await client.listDatabases();
|
|
6255
|
+
if (!dbs.length) {
|
|
6256
|
+
log.info("No managed databases found in your Sevalla account.");
|
|
6257
|
+
return;
|
|
6258
|
+
}
|
|
6259
|
+
console.log(`
|
|
6260
|
+
${c.bold("SEVALLA MANAGED DATABASES")} (${dbs.length})
|
|
6261
|
+
`);
|
|
6262
|
+
const headers = ["ID", "NAME", "TYPE", "STATUS", "HOST / PORT", "DATABASE"];
|
|
6263
|
+
const rows = dbs.map((d) => {
|
|
6264
|
+
let statusStr = d.status;
|
|
6265
|
+
if (d.status === "ready")
|
|
6266
|
+
statusStr = c.green(d.status);
|
|
6267
|
+
else if (d.status === "creating")
|
|
6268
|
+
statusStr = c.yellow(d.status);
|
|
6269
|
+
else
|
|
6270
|
+
statusStr = c.gray(d.status);
|
|
6271
|
+
const hostStr = d.externalHost ? `${d.externalHost}:${d.port}` : `${d.internalHost || "-"}:${d.port}`;
|
|
6272
|
+
return [d.id, d.displayName, d.type.toUpperCase(), statusStr, hostStr, d.dbName];
|
|
6273
|
+
});
|
|
6274
|
+
console.log(formatTable(headers, rows));
|
|
6275
|
+
console.log("");
|
|
6276
|
+
return;
|
|
6277
|
+
}
|
|
6278
|
+
if (sub === "deploy") {
|
|
6279
|
+
const appId = ctx.positionals[1];
|
|
6280
|
+
if (!appId) {
|
|
6281
|
+
throw new EpdError("Application ID is required", "Usage: epd sevalla deploy <app-id>");
|
|
6282
|
+
}
|
|
6283
|
+
const branch = ctx.values.branch || undefined;
|
|
6284
|
+
log.step(`Triggering deployment on Sevalla for application ${c.bold(appId)}...`);
|
|
6285
|
+
const dep = await client.deployApplication(appId, { branch });
|
|
6286
|
+
log.ok(`Deployment triggered! Deployment ID: ${c.cyan(dep.id)} (Status: ${dep.status})`);
|
|
6287
|
+
return;
|
|
6288
|
+
}
|
|
6289
|
+
throw new EpdError(`Unknown Sevalla subcommand: ${sub}`, "Available: apps, databases, deploy, auth");
|
|
6290
|
+
}
|
|
6291
|
+
};
|
|
6292
|
+
function formatTable(headers, rows) {
|
|
6293
|
+
const colWidths = headers.map((h, i) => Math.max(h.length, ...rows.map((r) => stripAnsi2(r[i] ?? "").length)));
|
|
6294
|
+
const pad = (s, len) => s + " ".repeat(Math.max(0, len - stripAnsi2(s).length));
|
|
6295
|
+
const headerLine = headers.map((h, i) => c.bold(pad(h, colWidths[i]))).join(" ");
|
|
6296
|
+
const sepLine = colWidths.map((w) => "\u2500".repeat(w)).join(" ");
|
|
6297
|
+
const dataLines = rows.map((r) => r.map((cell, i) => pad(cell ?? "", colWidths[i])).join(" "));
|
|
6298
|
+
return [headerLine, c.gray(sepLine), ...dataLines].join(`
|
|
6299
|
+
`);
|
|
6300
|
+
}
|
|
6301
|
+
function stripAnsi2(str) {
|
|
6302
|
+
return str.replace(/\x1B\[[0-9;]*[a-zA-Z]/g, "");
|
|
6303
|
+
}
|
|
6304
|
+
|
|
5764
6305
|
// src/core/update.ts
|
|
5765
|
-
import { chmodSync as chmodSync2, existsSync as
|
|
5766
|
-
import { homedir as
|
|
5767
|
-
import { dirname as dirname2, join as
|
|
6306
|
+
import { chmodSync as chmodSync2, existsSync as existsSync7, mkdirSync as mkdirSync5, readFileSync as readFileSync5, renameSync, writeFileSync as writeFileSync3 } from "fs";
|
|
6307
|
+
import { homedir as homedir4 } from "os";
|
|
6308
|
+
import { dirname as dirname2, join as join8 } from "path";
|
|
5768
6309
|
function parseSemver(v) {
|
|
5769
6310
|
const clean = v.replace(/^v/, "").trim();
|
|
5770
6311
|
const parts = clean.split("-")[0].split(".").map((n) => Number(n) || 0);
|
|
@@ -5784,13 +6325,13 @@ function isNewer(current, latest) {
|
|
|
5784
6325
|
return lPatch > cPatch;
|
|
5785
6326
|
}
|
|
5786
6327
|
function getCachePath() {
|
|
5787
|
-
return
|
|
6328
|
+
return join8(homedir4(), ".epd", "update-check.json");
|
|
5788
6329
|
}
|
|
5789
6330
|
function readCache() {
|
|
5790
6331
|
try {
|
|
5791
6332
|
const p = getCachePath();
|
|
5792
|
-
if (
|
|
5793
|
-
return JSON.parse(
|
|
6333
|
+
if (existsSync7(p)) {
|
|
6334
|
+
return JSON.parse(readFileSync5(p, "utf8"));
|
|
5794
6335
|
}
|
|
5795
6336
|
} catch {}
|
|
5796
6337
|
return null;
|
|
@@ -5798,7 +6339,7 @@ function readCache() {
|
|
|
5798
6339
|
function writeCache(latestVersion) {
|
|
5799
6340
|
try {
|
|
5800
6341
|
const p = getCachePath();
|
|
5801
|
-
|
|
6342
|
+
mkdirSync5(dirname2(p), { recursive: true });
|
|
5802
6343
|
const data = { lastChecked: Date.now(), latestVersion };
|
|
5803
6344
|
writeFileSync3(p, JSON.stringify(data));
|
|
5804
6345
|
} catch {}
|
|
@@ -5923,7 +6464,7 @@ async function promptAutoUpdate(currentVersion) {
|
|
|
5923
6464
|
}
|
|
5924
6465
|
|
|
5925
6466
|
// src/version.ts
|
|
5926
|
-
var VERSION = "0.5.
|
|
6467
|
+
var VERSION = "0.5.4";
|
|
5927
6468
|
|
|
5928
6469
|
// src/commands/update.ts
|
|
5929
6470
|
var update = {
|
|
@@ -6648,8 +7189,8 @@ Options
|
|
|
6648
7189
|
};
|
|
6649
7190
|
|
|
6650
7191
|
// src/commands/backup.ts
|
|
6651
|
-
import { createWriteStream, mkdirSync as
|
|
6652
|
-
import { dirname as dirname3, join as
|
|
7192
|
+
import { createWriteStream, mkdirSync as mkdirSync6, statSync } from "fs";
|
|
7193
|
+
import { dirname as dirname3, join as join9, resolve as resolve2 } from "path";
|
|
6653
7194
|
function detectAccessoryType(decl, cfg) {
|
|
6654
7195
|
const name = decl.name;
|
|
6655
7196
|
const img = (decl.image || "").toLowerCase();
|
|
@@ -6740,7 +7281,7 @@ Options
|
|
|
6740
7281
|
targets = accessories.map((a) => detectAccessoryType(a, cfg));
|
|
6741
7282
|
}
|
|
6742
7283
|
const outBaseDir = resolve2(process.cwd(), "backups");
|
|
6743
|
-
|
|
7284
|
+
mkdirSync6(outBaseDir, { recursive: true });
|
|
6744
7285
|
for (const target of targets) {
|
|
6745
7286
|
const host2 = host(target.hostName, cfg.ssh);
|
|
6746
7287
|
const isRunning = await host2.test(`docker ps -q -f name=${shq(`^${target.containerName}$`)} | grep -q .`);
|
|
@@ -6751,8 +7292,8 @@ Options
|
|
|
6751
7292
|
const timestamp = new Date().toISOString().replace(/[:.]/g, "-").replace("T", "_").slice(0, 19);
|
|
6752
7293
|
const ext = target.type === "volume" ? "tar.gz" : "sql.gz";
|
|
6753
7294
|
const filename = `${cfg.name}-${target.name}-${timestamp}.${ext}`;
|
|
6754
|
-
const localFile = ctx.values.output ? resolve2(String(ctx.values.output)) :
|
|
6755
|
-
|
|
7295
|
+
const localFile = ctx.values.output ? resolve2(String(ctx.values.output)) : join9(outBaseDir, filename);
|
|
7296
|
+
mkdirSync6(dirname3(localFile), { recursive: true });
|
|
6756
7297
|
let dumpCmd = "";
|
|
6757
7298
|
if (target.type === "postgres") {
|
|
6758
7299
|
dumpCmd = `docker exec ${shq(target.containerName)} pg_dump -U ${shq(target.dbUser)} ${shq(target.dbName)} | gzip -9`;
|
|
@@ -6799,7 +7340,7 @@ Options
|
|
|
6799
7340
|
};
|
|
6800
7341
|
|
|
6801
7342
|
// src/commands/restore.ts
|
|
6802
|
-
import { createReadStream, existsSync as
|
|
7343
|
+
import { createReadStream, existsSync as existsSync8 } from "fs";
|
|
6803
7344
|
import { basename as basename2, resolve as resolve3 } from "path";
|
|
6804
7345
|
var restore = {
|
|
6805
7346
|
name: "restore",
|
|
@@ -6820,7 +7361,7 @@ Options
|
|
|
6820
7361
|
if (!backupPath)
|
|
6821
7362
|
throw new EpdError("Please provide a path to the backup file to restore.");
|
|
6822
7363
|
const absPath = resolve3(backupPath);
|
|
6823
|
-
if (!
|
|
7364
|
+
if (!existsSync8(absPath))
|
|
6824
7365
|
throw new EpdError(`Backup file not found: ${absPath}`);
|
|
6825
7366
|
const loaded = ctx.load();
|
|
6826
7367
|
const cfg = loaded.config;
|
|
@@ -6939,6 +7480,7 @@ var commands = [
|
|
|
6939
7480
|
cloudflare,
|
|
6940
7481
|
dns3,
|
|
6941
7482
|
hetzner,
|
|
7483
|
+
sevalla,
|
|
6942
7484
|
update,
|
|
6943
7485
|
auth,
|
|
6944
7486
|
maintenance,
|
|
@@ -30,8 +30,8 @@ Everything you need to prepare your development environment and target servers f
|
|
|
30
30
|
- Arch Linux / Alpine Linux
|
|
31
31
|
- **SSH Access**:
|
|
32
32
|
- Open SSH port (default: 22).
|
|
33
|
-
-
|
|
34
|
-
- SSH
|
|
33
|
+
- Root login or a user allowed to run `sudo` (with a password or a passwordless rule).
|
|
34
|
+
- SSH key authentication, or initial login access to install a public key.
|
|
35
35
|
- **Firewall & Ports**:
|
|
36
36
|
- **Port 80 (HTTP)**: Required for Let's Encrypt HTTP-01 challenge and HTTP traffic redirection.
|
|
37
37
|
- **Port 443 (HTTPS)**: Required for encrypted TLS/SSL traffic.
|
|
@@ -92,6 +92,25 @@ bunx @fabioplunser/epd deploy
|
|
|
92
92
|
|
|
93
93
|
`epd` connects to servers using your system's SSH configuration.
|
|
94
94
|
|
|
95
|
+
`epd setup` first tests public-key login without sudo, using keys available to
|
|
96
|
+
OpenSSH, including your `ssh-agent`. Load an encrypted key with `ssh-add` before
|
|
97
|
+
running setup. An explicit `ssh.key` selects that identity.
|
|
98
|
+
|
|
99
|
+
If key authentication is rejected in an interactive terminal, setup installs a
|
|
100
|
+
public key using a one-time SSH login. It uses the configured key, lets you select
|
|
101
|
+
an agent key, or uses a standard local key. If none exists, it creates an Ed25519
|
|
102
|
+
key with `ssh-keygen`. OpenSSH handles the login password prompt; EPD sends only
|
|
103
|
+
the public key and preserves existing `authorized_keys` entries. Setup verifies
|
|
104
|
+
a fresh key-authenticated connection before continuing. If the server disallows
|
|
105
|
+
password login, authorize your key through the provider console or an administrator.
|
|
106
|
+
|
|
107
|
+
CI never attempts interactive key installation. Authorize its key beforehand.
|
|
108
|
+
|
|
109
|
+
SSH login and sudo are separate: **`ssh-add` does not grant passwordless sudo**.
|
|
110
|
+
After key login succeeds, setup checks sudo authorization, trying passwordless
|
|
111
|
+
sudo first. It asks for the remote user's sudo password only if the server requires
|
|
112
|
+
one. EPD does not change your server's sudo policy automatically.
|
|
113
|
+
|
|
95
114
|
### 1. Test Direct Connection
|
|
96
115
|
|
|
97
116
|
Before running `epd setup`, verify you can connect without entering a password:
|
package/package.json
CHANGED