@fabioplunser/epd 0.5.4 → 0.5.6
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 +394 -30
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -576,6 +576,7 @@ function normalize(raw, configPath, root, destination) {
|
|
|
576
576
|
"host",
|
|
577
577
|
"replicas",
|
|
578
578
|
"port",
|
|
579
|
+
"host_port",
|
|
579
580
|
"command",
|
|
580
581
|
"routes",
|
|
581
582
|
"domain",
|
|
@@ -614,6 +615,7 @@ function normalize(raw, configPath, root, destination) {
|
|
|
614
615
|
if (!hosts.length && !svcHetzner)
|
|
615
616
|
fail(`${p}.hosts`, "at least one host is required");
|
|
616
617
|
const port = asNumber(o.port, `${p}.port`, asNumber(raw.port, "epd.yml.port", 3000));
|
|
618
|
+
const hostPort = o.host_port !== undefined ? asNumber(o.host_port, `${p}.host_port`) : undefined;
|
|
617
619
|
const routes = [];
|
|
618
620
|
for (const d of [...asList(o.domain, `${p}.domain`), ...asList(o.domains, `${p}.domains`)]) {
|
|
619
621
|
routes.push(parseRoute(d, `${p}.domains`, { port, ssl: proxy.ssl }));
|
|
@@ -628,6 +630,7 @@ function normalize(raw, configPath, root, destination) {
|
|
|
628
630
|
hetzner: svcHetzner,
|
|
629
631
|
replicas: asNumber(o.replicas, `${p}.replicas`, 1),
|
|
630
632
|
port,
|
|
633
|
+
hostPort,
|
|
631
634
|
command: o.command === undefined ? undefined : asString(o.command, `${p}.command`),
|
|
632
635
|
routes,
|
|
633
636
|
env: { ...envClear, ...svcEnv },
|
|
@@ -863,12 +866,6 @@ function validateCrossReferences(cfg) {
|
|
|
863
866
|
}
|
|
864
867
|
}
|
|
865
868
|
}
|
|
866
|
-
if (cfg.proxy.enabled && cfg.proxy.ssl && cfg.proxy.challenge !== "dns" && !cfg.proxy.email) {
|
|
867
|
-
const anySsl = cfg.services.some((s) => s.routes.some((r) => r.ssl));
|
|
868
|
-
if (anySsl)
|
|
869
|
-
fail("epd.yml.proxy.email", "is required for Let's Encrypt certificates", `proxy:
|
|
870
|
-
email: you@example.com`);
|
|
871
|
-
}
|
|
872
869
|
if (cfg.mode === "docker" && !cfg.registry && cfg.services.some((s) => s.hosts.length > 1)) {}
|
|
873
870
|
}
|
|
874
871
|
|
|
@@ -2120,21 +2117,24 @@ function hostPort(cfg, svc, slot, replica) {
|
|
|
2120
2117
|
if (replica >= MAX_REPLICAS) {
|
|
2121
2118
|
throw new EpdError(`${svc.name}: at most ${MAX_REPLICAS} replicas per server are supported`, "Add more servers instead, or run several epd apps.");
|
|
2122
2119
|
}
|
|
2123
|
-
const j = serviceIndex(cfg, svc);
|
|
2124
2120
|
const s = SLOTS.indexOf(slot);
|
|
2121
|
+
if (svc.hostPort !== undefined) {
|
|
2122
|
+
return svc.hostPort + s * MAX_REPLICAS + replica;
|
|
2123
|
+
}
|
|
2124
|
+
const j = serviceIndex(cfg, svc);
|
|
2125
2125
|
return cfg.portBase + j * PORTS_PER_SERVICE + s * MAX_REPLICAS + replica;
|
|
2126
2126
|
}
|
|
2127
2127
|
function portBlock(cfg) {
|
|
2128
2128
|
return { from: cfg.portBase, to: cfg.portBase + MAX_SERVICES * PORTS_PER_SERVICE - 1 };
|
|
2129
2129
|
}
|
|
2130
2130
|
function usesHostPorts(cfg) {
|
|
2131
|
-
return cfg.mode === "process" || cfg.proxy.crossHost;
|
|
2131
|
+
return cfg.mode === "process" || cfg.proxy.crossHost || !cfg.proxy.enabled;
|
|
2132
2132
|
}
|
|
2133
2133
|
function privateAddress(cfg, host) {
|
|
2134
2134
|
return cfg.proxy.privateIps[host] ?? host;
|
|
2135
2135
|
}
|
|
2136
2136
|
function bindAddress(cfg, host) {
|
|
2137
|
-
return cfg.proxy.privateIps[host] ?? "0.0.0.0";
|
|
2137
|
+
return cfg.proxy.privateIps[host] ?? (cfg.proxy.enabled ? "0.0.0.0" : "127.0.0.1");
|
|
2138
2138
|
}
|
|
2139
2139
|
function endpointsFor(cfg, svc, slot, serverHost, containerIp) {
|
|
2140
2140
|
const out = [];
|
|
@@ -2605,8 +2605,347 @@ function validateKey(value) {
|
|
|
2605
2605
|
return key;
|
|
2606
2606
|
}
|
|
2607
2607
|
|
|
2608
|
+
// src/proxy/detect.ts
|
|
2609
|
+
import { existsSync as existsSync5, readFileSync as readFileSync5, writeFileSync as writeFileSync3 } from "fs";
|
|
2610
|
+
import { basename as basename2, resolve as resolve2 } from "path";
|
|
2611
|
+
async function detectExistingProxy(host, checkPorts = [80, 443]) {
|
|
2612
|
+
const portsSet = new Set(checkPorts);
|
|
2613
|
+
const filter = `( ${[...portsSet].map((p) => `sport = :${p}`).join(" or ")} )`;
|
|
2614
|
+
const ssOutput = await host.capture(`if command -v ss >/dev/null 2>&1; then ss -H -ltnp ${shq(filter)} 2>/dev/null; else echo ""; fi`).catch(() => "");
|
|
2615
|
+
const activePorts = new Set;
|
|
2616
|
+
let matchedType = null;
|
|
2617
|
+
let matchedName = "";
|
|
2618
|
+
let matchedDetails = "";
|
|
2619
|
+
for (const line of ssOutput.split(`
|
|
2620
|
+
`).filter(Boolean)) {
|
|
2621
|
+
const parts = line.trim().split(/\s+/);
|
|
2622
|
+
const local = parts[3] ?? "";
|
|
2623
|
+
const port = Number(/:(\d+)$/.exec(local)?.[1]);
|
|
2624
|
+
if (port && portsSet.has(port))
|
|
2625
|
+
activePorts.add(port);
|
|
2626
|
+
const lower = line.toLowerCase();
|
|
2627
|
+
if (lower.includes("caddy")) {
|
|
2628
|
+
matchedType = "caddy";
|
|
2629
|
+
matchedName = "Caddy";
|
|
2630
|
+
matchedDetails = line.trim();
|
|
2631
|
+
} else if (lower.includes("nginx")) {
|
|
2632
|
+
matchedType = "nginx";
|
|
2633
|
+
matchedName = "Nginx";
|
|
2634
|
+
matchedDetails = line.trim();
|
|
2635
|
+
} else if (lower.includes("apache") || lower.includes("httpd")) {
|
|
2636
|
+
matchedType = "apache";
|
|
2637
|
+
matchedName = "Apache2";
|
|
2638
|
+
matchedDetails = line.trim();
|
|
2639
|
+
} else if (lower.includes("traefik")) {
|
|
2640
|
+
matchedType = "traefik";
|
|
2641
|
+
matchedName = "Traefik";
|
|
2642
|
+
matchedDetails = line.trim();
|
|
2643
|
+
} else if (!matchedType && parts.length > 5) {
|
|
2644
|
+
matchedDetails = line.trim();
|
|
2645
|
+
}
|
|
2646
|
+
}
|
|
2647
|
+
if (!matchedType) {
|
|
2648
|
+
const containers = await host.capture(`docker ps --format '{{.Names}}|{{.Image}}|{{.Ports}}' 2>/dev/null`).catch(() => "");
|
|
2649
|
+
for (const line of containers.split(`
|
|
2650
|
+
`).filter(Boolean)) {
|
|
2651
|
+
const [name, image, ports = ""] = line.split("|");
|
|
2652
|
+
const published = [...ports.matchAll(/:(\d+)->\d+\/tcp/g)].map((m) => Number(m[1]));
|
|
2653
|
+
const hits = published.filter((p) => portsSet.has(p));
|
|
2654
|
+
if (hits.length) {
|
|
2655
|
+
hits.forEach((p) => activePorts.add(p));
|
|
2656
|
+
const lower = `${name} ${image}`.toLowerCase();
|
|
2657
|
+
if (lower.includes("caddy")) {
|
|
2658
|
+
matchedType = "caddy";
|
|
2659
|
+
matchedName = "Caddy (Docker)";
|
|
2660
|
+
matchedDetails = `Container ${name} (${image})`;
|
|
2661
|
+
break;
|
|
2662
|
+
} else if (lower.includes("nginx")) {
|
|
2663
|
+
matchedType = "nginx";
|
|
2664
|
+
matchedName = "Nginx (Docker)";
|
|
2665
|
+
matchedDetails = `Container ${name} (${image})`;
|
|
2666
|
+
break;
|
|
2667
|
+
} else if (lower.includes("apache") || lower.includes("httpd")) {
|
|
2668
|
+
matchedType = "apache";
|
|
2669
|
+
matchedName = "Apache2 (Docker)";
|
|
2670
|
+
matchedDetails = `Container ${name} (${image})`;
|
|
2671
|
+
break;
|
|
2672
|
+
} else if (lower.includes("traefik")) {
|
|
2673
|
+
matchedType = "traefik";
|
|
2674
|
+
matchedName = "Traefik (Docker)";
|
|
2675
|
+
matchedDetails = `Container ${name} (${image})`;
|
|
2676
|
+
break;
|
|
2677
|
+
} else {
|
|
2678
|
+
matchedDetails = `Container ${name} (${image})`;
|
|
2679
|
+
}
|
|
2680
|
+
}
|
|
2681
|
+
}
|
|
2682
|
+
}
|
|
2683
|
+
if (!matchedType && activePorts.size > 0) {
|
|
2684
|
+
const systemdCheck = await host.capture(`for s in caddy nginx apache2 httpd traefik; do systemctl is-active --quiet $s 2>/dev/null && echo $s; done`).catch(() => "");
|
|
2685
|
+
const activeServices = systemdCheck.trim().split(`
|
|
2686
|
+
`).filter(Boolean);
|
|
2687
|
+
if (activeServices.includes("caddy")) {
|
|
2688
|
+
matchedType = "caddy";
|
|
2689
|
+
matchedName = "Caddy";
|
|
2690
|
+
matchedDetails = "systemd service caddy";
|
|
2691
|
+
} else if (activeServices.includes("nginx")) {
|
|
2692
|
+
matchedType = "nginx";
|
|
2693
|
+
matchedName = "Nginx";
|
|
2694
|
+
matchedDetails = "systemd service nginx";
|
|
2695
|
+
} else if (activeServices.includes("apache2") || activeServices.includes("httpd")) {
|
|
2696
|
+
matchedType = "apache";
|
|
2697
|
+
matchedName = "Apache2";
|
|
2698
|
+
matchedDetails = `systemd service ${activeServices.find((s) => s.includes("apache") || s.includes("httpd"))}`;
|
|
2699
|
+
} else if (activeServices.includes("traefik")) {
|
|
2700
|
+
matchedType = "traefik";
|
|
2701
|
+
matchedName = "Traefik";
|
|
2702
|
+
matchedDetails = "systemd service traefik";
|
|
2703
|
+
}
|
|
2704
|
+
}
|
|
2705
|
+
if (activePorts.size === 0)
|
|
2706
|
+
return null;
|
|
2707
|
+
return {
|
|
2708
|
+
type: matchedType ?? "unknown",
|
|
2709
|
+
name: matchedName || "Unknown Reverse Proxy",
|
|
2710
|
+
ports: [...activePorts].sort((a, b) => a - b),
|
|
2711
|
+
source: matchedType ? "systemd" : "ss",
|
|
2712
|
+
details: matchedDetails || `Process listening on port(s) ${[...activePorts].join(", ")}`
|
|
2713
|
+
};
|
|
2714
|
+
}
|
|
2715
|
+
function getConfigDomains(cfg) {
|
|
2716
|
+
const domains = new Set;
|
|
2717
|
+
for (const svc of cfg.services) {
|
|
2718
|
+
for (const r of svc.routes) {
|
|
2719
|
+
for (const h of r.hosts)
|
|
2720
|
+
domains.add(h);
|
|
2721
|
+
}
|
|
2722
|
+
}
|
|
2723
|
+
return domains.size ? [...domains] : [cfg.name.toLowerCase() + ".example.com"];
|
|
2724
|
+
}
|
|
2725
|
+
function getServiceUpstreamPort(cfg) {
|
|
2726
|
+
const mainSvc = cfg.services[0];
|
|
2727
|
+
if (!mainSvc)
|
|
2728
|
+
return 8080;
|
|
2729
|
+
if (mainSvc.hostPort)
|
|
2730
|
+
return mainSvc.hostPort;
|
|
2731
|
+
if (mainSvc.port > 1024)
|
|
2732
|
+
return mainSvc.port;
|
|
2733
|
+
return 8080;
|
|
2734
|
+
}
|
|
2735
|
+
function generateCaddyConfig(cfg, upstreamHost = "127.0.0.1", upstreamPort = getServiceUpstreamPort(cfg)) {
|
|
2736
|
+
const domains = getConfigDomains(cfg);
|
|
2737
|
+
return `# EPD Reverse Proxy Configuration for ${cfg.name}
|
|
2738
|
+
${domains.join(", ")} {
|
|
2739
|
+
reverse_proxy ${upstreamHost}:${upstreamPort}
|
|
2740
|
+
}
|
|
2741
|
+
`;
|
|
2742
|
+
}
|
|
2743
|
+
function generateNginxConfig(cfg, upstreamHost = "127.0.0.1", upstreamPort = getServiceUpstreamPort(cfg)) {
|
|
2744
|
+
const domains = getConfigDomains(cfg);
|
|
2745
|
+
return `# EPD Reverse Proxy Configuration for ${cfg.name}
|
|
2746
|
+
server {
|
|
2747
|
+
listen 80;
|
|
2748
|
+
listen [::]:80;
|
|
2749
|
+
server_name ${domains.join(" ")};
|
|
2750
|
+
|
|
2751
|
+
location / {
|
|
2752
|
+
proxy_pass http://${upstreamHost}:${upstreamPort};
|
|
2753
|
+
proxy_http_version 1.1;
|
|
2754
|
+
proxy_set_header Upgrade $http_upgrade;
|
|
2755
|
+
proxy_set_header Connection "upgrade";
|
|
2756
|
+
proxy_set_header Host $host;
|
|
2757
|
+
proxy_set_header X-Real-IP $remote_addr;
|
|
2758
|
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
2759
|
+
proxy_set_header X-Forwarded-Proto $scheme;
|
|
2760
|
+
}
|
|
2761
|
+
}
|
|
2762
|
+
`;
|
|
2763
|
+
}
|
|
2764
|
+
function generateApacheConfig(cfg, upstreamHost = "127.0.0.1", upstreamPort = getServiceUpstreamPort(cfg)) {
|
|
2765
|
+
const domains = getConfigDomains(cfg);
|
|
2766
|
+
const serverName = domains[0] ?? `${cfg.name.toLowerCase()}.example.com`;
|
|
2767
|
+
const aliases = domains.slice(1).map((d) => ` ServerAlias ${d}`).join(`
|
|
2768
|
+
`);
|
|
2769
|
+
return `# EPD Reverse Proxy Configuration for ${cfg.name}
|
|
2770
|
+
<VirtualHost *:80>
|
|
2771
|
+
ServerName ${serverName}
|
|
2772
|
+
${aliases ? `${aliases}
|
|
2773
|
+
` : ""}
|
|
2774
|
+
ProxyPreserveHost On
|
|
2775
|
+
ProxyPass / http://${upstreamHost}:${upstreamPort}/
|
|
2776
|
+
ProxyPassReverse / http://${upstreamHost}:${upstreamPort}/
|
|
2777
|
+
</VirtualHost>
|
|
2778
|
+
`;
|
|
2779
|
+
}
|
|
2780
|
+
function generateTraefikConfig(cfg, upstreamHost = "127.0.0.1", upstreamPort = getServiceUpstreamPort(cfg)) {
|
|
2781
|
+
const domains = getConfigDomains(cfg);
|
|
2782
|
+
const routerRule = `Host(${domains.map((d) => `\`${d}\``).join(", ")})`;
|
|
2783
|
+
return `# EPD Reverse Proxy Configuration for ${cfg.name}
|
|
2784
|
+
http:
|
|
2785
|
+
routers:
|
|
2786
|
+
${cfg.name}:
|
|
2787
|
+
rule: "${routerRule}"
|
|
2788
|
+
service: ${cfg.name}
|
|
2789
|
+
entryPoints:
|
|
2790
|
+
- web
|
|
2791
|
+
- websecure
|
|
2792
|
+
tls:
|
|
2793
|
+
certResolver: letsencrypt
|
|
2794
|
+
services:
|
|
2795
|
+
${cfg.name}:
|
|
2796
|
+
loadBalancer:
|
|
2797
|
+
servers:
|
|
2798
|
+
- url: "http://${upstreamHost}:${upstreamPort}"
|
|
2799
|
+
`;
|
|
2800
|
+
}
|
|
2801
|
+
function updateLocalConfigDisableProxy(configPath = "epd.yml") {
|
|
2802
|
+
const configFile = resolve2(configPath);
|
|
2803
|
+
if (!existsSync5(configFile))
|
|
2804
|
+
return;
|
|
2805
|
+
try {
|
|
2806
|
+
const raw = readFileSync5(configFile, "utf8");
|
|
2807
|
+
if (/^\s*proxy\s*:\s*false\b/m.test(raw))
|
|
2808
|
+
return;
|
|
2809
|
+
let updated = raw;
|
|
2810
|
+
if (/^\s*proxy\s*:/m.test(raw)) {
|
|
2811
|
+
updated = raw.replace(/^(\s*proxy\s*:\s*)(?:\{[^}]*\}|[^\n]*\n(?:\s{2,}[^\n]*\n*)*)/m, `proxy: false
|
|
2812
|
+
`);
|
|
2813
|
+
} else {
|
|
2814
|
+
updated = raw.replace(/^(\s*name\s*:[^\n]*\n)/m, `$1proxy: false
|
|
2815
|
+
`);
|
|
2816
|
+
}
|
|
2817
|
+
if (updated !== raw) {
|
|
2818
|
+
writeFileSync3(configFile, updated, "utf8");
|
|
2819
|
+
log.ok("Updated epd.yml: set proxy: false");
|
|
2820
|
+
}
|
|
2821
|
+
} catch (err) {
|
|
2822
|
+
log.warn(`Could not update epd.yml automatically: ${err instanceof Error ? err.message : String(err)}`);
|
|
2823
|
+
}
|
|
2824
|
+
}
|
|
2825
|
+
async function handleExistingProxy(host, cfg, detected) {
|
|
2826
|
+
if (!interactive()) {
|
|
2827
|
+
log.warn(`${host.name}: port(s) ${detected.ports.join("/")} are in use by ${c.bold(detected.name)} (${detected.details}). ` + `To use ${detected.name}, set 'proxy: false' in epd.yml and configure it to forward to 127.0.0.1:${getServiceUpstreamPort(cfg)}.`);
|
|
2828
|
+
return false;
|
|
2829
|
+
}
|
|
2830
|
+
const domains = getConfigDomains(cfg);
|
|
2831
|
+
const upstreamPort = getServiceUpstreamPort(cfg);
|
|
2832
|
+
log.plain("");
|
|
2833
|
+
log.info(`${c.bold(host.name)}: Found existing ${c.bold(c.cyan(detected.name))} listening on port ${detected.ports.join("/")}.`);
|
|
2834
|
+
if (detected.details)
|
|
2835
|
+
log.plain(` ${c.gray(detected.details)}`);
|
|
2836
|
+
const useExisting = await confirm(`Use your existing ${c.bold(detected.name)} proxy instead of running EPD's Traefik?`, true);
|
|
2837
|
+
if (!useExisting)
|
|
2838
|
+
return false;
|
|
2839
|
+
cfg.proxy.enabled = false;
|
|
2840
|
+
updateLocalConfigDisableProxy(cfg.configPath);
|
|
2841
|
+
if (detected.type === "caddy") {
|
|
2842
|
+
const snippet = generateCaddyConfig(cfg, "127.0.0.1", upstreamPort);
|
|
2843
|
+
log.plain(`
|
|
2844
|
+
${c.bold("Generated Caddy configuration:")}
|
|
2845
|
+
${c.gray(snippet)}`);
|
|
2846
|
+
const caddyfile = await host.readFile("/etc/caddy/Caddyfile") ?? "";
|
|
2847
|
+
const alreadyConfigured = domains.some((d) => caddyfile.includes(d));
|
|
2848
|
+
if (alreadyConfigured) {
|
|
2849
|
+
log.ok(`${host.name}: /etc/caddy/Caddyfile already contains a route for ${domains.join(", ")}`);
|
|
2850
|
+
} else {
|
|
2851
|
+
const install = await confirm(`Install configuration snippet to /etc/caddy/conf.d/${cfg.name}.caddy on ${host.name}?`, true);
|
|
2852
|
+
if (install) {
|
|
2853
|
+
await host.writeFile(`/etc/caddy/conf.d/${cfg.name}.caddy`, snippet);
|
|
2854
|
+
if (!caddyfile.includes("import conf.d/*") && !caddyfile.includes("import /etc/caddy/conf.d/*")) {
|
|
2855
|
+
await host.writeFile("/etc/caddy/Caddyfile", `${caddyfile}
|
|
2856
|
+
import /etc/caddy/conf.d/*
|
|
2857
|
+
`);
|
|
2858
|
+
}
|
|
2859
|
+
await host.exec("systemctl reload caddy || caddy reload || true", {
|
|
2860
|
+
allowFailure: true,
|
|
2861
|
+
label: `${host.name}: reload caddy`
|
|
2862
|
+
});
|
|
2863
|
+
log.ok(`${host.name}: installed Caddy configuration and reloaded Caddy`);
|
|
2864
|
+
}
|
|
2865
|
+
}
|
|
2866
|
+
} else if (detected.type === "nginx") {
|
|
2867
|
+
const snippet = generateNginxConfig(cfg, "127.0.0.1", upstreamPort);
|
|
2868
|
+
log.plain(`
|
|
2869
|
+
${c.bold("Generated Nginx configuration:")}
|
|
2870
|
+
${c.gray(snippet)}`);
|
|
2871
|
+
const confPath = `/etc/nginx/sites-available/${cfg.name}.conf`;
|
|
2872
|
+
const install = await confirm(`Install configuration to ${confPath} on ${host.name}?`, true);
|
|
2873
|
+
if (install) {
|
|
2874
|
+
await host.writeFile(confPath, snippet);
|
|
2875
|
+
await host.exec(`ln -sf ${shq(confPath)} /etc/nginx/sites-enabled/${cfg.name}.conf && nginx -t && systemctl reload nginx`, { allowFailure: true, label: `${host.name}: enable and reload nginx` });
|
|
2876
|
+
log.ok(`${host.name}: installed Nginx configuration and reloaded Nginx`);
|
|
2877
|
+
}
|
|
2878
|
+
} else if (detected.type === "apache") {
|
|
2879
|
+
const snippet = generateApacheConfig(cfg, "127.0.0.1", upstreamPort);
|
|
2880
|
+
log.plain(`
|
|
2881
|
+
${c.bold("Generated Apache2 configuration:")}
|
|
2882
|
+
${c.gray(snippet)}`);
|
|
2883
|
+
const confPath = `/etc/apache2/sites-available/${cfg.name}.conf`;
|
|
2884
|
+
const install = await confirm(`Install configuration to ${confPath} on ${host.name}?`, true);
|
|
2885
|
+
if (install) {
|
|
2886
|
+
await host.writeFile(confPath, snippet);
|
|
2887
|
+
await host.exec(`a2ensite ${shq(`${cfg.name}.conf`)} 2>/dev/null && systemctl reload apache2 || systemctl reload httpd`, { allowFailure: true, label: `${host.name}: enable and reload apache2` });
|
|
2888
|
+
log.ok(`${host.name}: installed Apache2 configuration and reloaded Apache2`);
|
|
2889
|
+
}
|
|
2890
|
+
} else if (detected.type === "traefik") {
|
|
2891
|
+
const snippet = generateTraefikConfig(cfg, "127.0.0.1", upstreamPort);
|
|
2892
|
+
log.plain(`
|
|
2893
|
+
${c.bold("Generated Traefik dynamic configuration:")}
|
|
2894
|
+
${c.gray(snippet)}`);
|
|
2895
|
+
const confPath = `/etc/traefik/dynamic/${cfg.name}.yml`;
|
|
2896
|
+
const install = await confirm(`Install configuration to ${confPath} on ${host.name}?`, true);
|
|
2897
|
+
if (install) {
|
|
2898
|
+
await host.writeFile(confPath, snippet);
|
|
2899
|
+
log.ok(`${host.name}: installed Traefik dynamic configuration`);
|
|
2900
|
+
}
|
|
2901
|
+
} else {
|
|
2902
|
+
log.plain(`
|
|
2903
|
+
${c.yellow("!")} Unrecognized reverse proxy detected (${detected.details}).`);
|
|
2904
|
+
const customConfig = await ask("Provide path to your custom proxy configuration file to deploy (or leave empty to configure manually):");
|
|
2905
|
+
if (customConfig && existsSync5(customConfig)) {
|
|
2906
|
+
const content = readFileSync5(customConfig, "utf8");
|
|
2907
|
+
const defaultRemote = `/etc/proxy/${basename2(customConfig)}`;
|
|
2908
|
+
const remotePath = await ask(`Remote destination path on ${host.name}:`, defaultRemote);
|
|
2909
|
+
await host.writeFile(remotePath, content);
|
|
2910
|
+
log.ok(`${host.name}: uploaded proxy configuration to ${remotePath}`);
|
|
2911
|
+
} else if (customConfig) {
|
|
2912
|
+
log.warn(`File not found: ${customConfig}. Skipping file upload.`);
|
|
2913
|
+
}
|
|
2914
|
+
}
|
|
2915
|
+
return true;
|
|
2916
|
+
}
|
|
2917
|
+
async function checkExistingProxySetup(host, cfg) {
|
|
2918
|
+
const detected = await detectExistingProxy(host);
|
|
2919
|
+
if (!detected)
|
|
2920
|
+
return;
|
|
2921
|
+
const domains = getConfigDomains(cfg);
|
|
2922
|
+
const upstreamPort = getServiceUpstreamPort(cfg);
|
|
2923
|
+
log.host(host.name, `proxy is disabled in epd.yml; active ${detected.name} detected on port(s) ${detected.ports.join("/")}`);
|
|
2924
|
+
if (detected.type === "caddy") {
|
|
2925
|
+
const caddyfile = await host.readFile("/etc/caddy/Caddyfile") ?? "";
|
|
2926
|
+
const confDExists = await host.readFile(`/etc/caddy/conf.d/${cfg.name}.caddy`) !== null;
|
|
2927
|
+
const isConfigured = confDExists || domains.some((d) => caddyfile.includes(d));
|
|
2928
|
+
if (isConfigured) {
|
|
2929
|
+
log.host(host.name, `Caddy is already configured for ${domains.join(", ")}`);
|
|
2930
|
+
} else if (interactive()) {
|
|
2931
|
+
const install = await confirm(`Would you like EPD to generate and install the Caddy configuration for ${domains.join(", ")}?`, true);
|
|
2932
|
+
if (install) {
|
|
2933
|
+
const snippet = generateCaddyConfig(cfg, "127.0.0.1", upstreamPort);
|
|
2934
|
+
await host.writeFile(`/etc/caddy/conf.d/${cfg.name}.caddy`, snippet);
|
|
2935
|
+
if (!caddyfile.includes("import conf.d/*") && !caddyfile.includes("import /etc/caddy/conf.d/*")) {
|
|
2936
|
+
await host.writeFile("/etc/caddy/Caddyfile", `${caddyfile}
|
|
2937
|
+
import /etc/caddy/conf.d/*
|
|
2938
|
+
`);
|
|
2939
|
+
}
|
|
2940
|
+
await host.exec("systemctl reload caddy || caddy reload || true", { allowFailure: true });
|
|
2941
|
+
log.ok(`${host.name}: Caddy configuration installed and reloaded`);
|
|
2942
|
+
}
|
|
2943
|
+
}
|
|
2944
|
+
}
|
|
2945
|
+
}
|
|
2946
|
+
|
|
2608
2947
|
// src/proxy/ports.ts
|
|
2609
|
-
async function checkProxyPorts(host, ports) {
|
|
2948
|
+
async function checkProxyPorts(host, ports, cfg) {
|
|
2610
2949
|
const wanted = new Set(ports);
|
|
2611
2950
|
const owned = new Set;
|
|
2612
2951
|
const conflicts = [];
|
|
@@ -2639,6 +2978,14 @@ async function checkProxyPorts(host, ports) {
|
|
|
2639
2978
|
conflicts.push(`TCP ${port}: ${line.trim()}`);
|
|
2640
2979
|
}
|
|
2641
2980
|
if (conflicts.length) {
|
|
2981
|
+
if (cfg) {
|
|
2982
|
+
const detected = await detectExistingProxy(host, ports);
|
|
2983
|
+
if (detected) {
|
|
2984
|
+
const handled = await handleExistingProxy(host, cfg, detected);
|
|
2985
|
+
if (handled)
|
|
2986
|
+
return;
|
|
2987
|
+
}
|
|
2988
|
+
}
|
|
2642
2989
|
throw new EpdError(`${host.name}: proxy port conflict`, [
|
|
2643
2990
|
...conflicts,
|
|
2644
2991
|
"An existing service already owns a required port. EPD has not stopped it.",
|
|
@@ -2951,7 +3298,16 @@ async function ensureProxy(host, cfg, opts = {}) {
|
|
|
2951
3298
|
if (!Object.keys(merged.entrypoints).length)
|
|
2952
3299
|
merged.entrypoints = cfg.proxy.entrypoints;
|
|
2953
3300
|
if (containerMode) {
|
|
2954
|
-
await checkProxyPorts(host, [...Object.values(merged.entrypoints), ...merged.dashboard ? [8080] : []]);
|
|
3301
|
+
await checkProxyPorts(host, [...Object.values(merged.entrypoints), ...merged.dashboard ? [8080] : []], cfg);
|
|
3302
|
+
if (!cfg.proxy.enabled)
|
|
3303
|
+
return;
|
|
3304
|
+
}
|
|
3305
|
+
if (cfg.proxy.ssl && cfg.proxy.challenge !== "dns" && !cfg.proxy.email) {
|
|
3306
|
+
const anySsl = cfg.services.some((s) => s.routes.some((r) => r.ssl));
|
|
3307
|
+
if (anySsl) {
|
|
3308
|
+
throw new EpdError("epd.yml.proxy.email: is required for Let's Encrypt certificates", `proxy:
|
|
3309
|
+
email: you@example.com`);
|
|
3310
|
+
}
|
|
2955
3311
|
}
|
|
2956
3312
|
await host.writeFile(p.proxyApp, JSON.stringify(declaration, null, 2), "644");
|
|
2957
3313
|
const where = containerMode ? CONTAINER_PATHS : { dynamicDir: p.proxyDynamicDir, acmeFile: `${p.acmeDir}/acme.json` };
|
|
@@ -3322,12 +3678,12 @@ function recordDeploy(state, version, by, keep) {
|
|
|
3322
3678
|
}
|
|
3323
3679
|
|
|
3324
3680
|
// src/deploy/image.ts
|
|
3325
|
-
import { existsSync as
|
|
3681
|
+
import { existsSync as existsSync6 } from "fs";
|
|
3326
3682
|
import { join as join6 } from "path";
|
|
3327
3683
|
async function resolveVersion(cfg, explicit) {
|
|
3328
3684
|
if (explicit)
|
|
3329
3685
|
return { id: explicit, source: "explicit", dirty: false };
|
|
3330
|
-
if (
|
|
3686
|
+
if (existsSync6(join6(cfg.root, ".git")) && await which("git")) {
|
|
3331
3687
|
const sha = await run(["git", "-C", cfg.root, "rev-parse", "--short=12", "HEAD"], { allowFailure: true });
|
|
3332
3688
|
if (sha.code === 0 && sha.stdout) {
|
|
3333
3689
|
const status = await run(["git", "-C", cfg.root, "status", "--porcelain"], { allowFailure: true });
|
|
@@ -3343,7 +3699,7 @@ async function hasBuildx() {
|
|
|
3343
3699
|
}
|
|
3344
3700
|
async function buildImage(cfg, version, env) {
|
|
3345
3701
|
const dockerfile = join6(cfg.root, cfg.build.dockerfile);
|
|
3346
|
-
if (!
|
|
3702
|
+
if (!existsSync6(dockerfile)) {
|
|
3347
3703
|
throw new EpdError(`${cfg.build.dockerfile} not found`, "Add a Dockerfile, point build.dockerfile at yours, or switch to `mode: process`.");
|
|
3348
3704
|
}
|
|
3349
3705
|
const ref = imageRef(cfg, version);
|
|
@@ -3622,7 +3978,7 @@ ${args.map((a) => shq(a)).join(" ")} >/dev/null`, { label: `${host.name}: access
|
|
|
3622
3978
|
}
|
|
3623
3979
|
|
|
3624
3980
|
// src/deploy/process.ts
|
|
3625
|
-
import { existsSync as
|
|
3981
|
+
import { existsSync as existsSync7 } from "fs";
|
|
3626
3982
|
import { join as join7 } from "path";
|
|
3627
3983
|
var asUser = { sudo: false };
|
|
3628
3984
|
var pm2 = (cfg, args) => `${pathPrelude(cfg)} pm2 ${args}`;
|
|
@@ -3634,7 +3990,7 @@ async function uploadSource(host, cfg, version) {
|
|
|
3634
3990
|
const p = paths(cfg);
|
|
3635
3991
|
await host.exec(`mkdir -p ${shq(p.releases)} ${shq(p.shared)}`, asUser);
|
|
3636
3992
|
if (cfg.process.source === "git") {
|
|
3637
|
-
if (!
|
|
3993
|
+
if (!existsSync7(join7(cfg.root, ".git")))
|
|
3638
3994
|
throw new EpdError('process.source is "git" but this is not a git repository');
|
|
3639
3995
|
log.host(host.name, `uploading HEAD as ${version}`);
|
|
3640
3996
|
await host.pipeInto(`mkdir -p ${shq(dest)} && tar -x -C ${shq(dest)}`, ["/bin/sh", "-c", `git -C ${shq(cfg.root)} archive --format=tar HEAD`]);
|
|
@@ -4580,6 +4936,10 @@ Options
|
|
|
4580
4936
|
if (cfg.proxy.enabled && proxyHosts(cfg).length) {
|
|
4581
4937
|
log.step("Starting the proxy");
|
|
4582
4938
|
await pool(proxyHosts(cfg).filter((h) => names.includes(h)).map((h) => host(h, cfg.ssh)), 4, (host) => ensureProxy(host, cfg, { secrets: loaded.env }));
|
|
4939
|
+
} else if (!cfg.proxy.enabled) {
|
|
4940
|
+
await pool(hosts, 4, async (host) => {
|
|
4941
|
+
await checkExistingProxySetup(host, cfg);
|
|
4942
|
+
});
|
|
4583
4943
|
}
|
|
4584
4944
|
if (cfg.dns?.enabled && cfg.dns.autoSync || cfg.cloudflare?.enabled && cfg.cloudflare.autoSync) {
|
|
4585
4945
|
try {
|
|
@@ -6303,7 +6663,7 @@ function stripAnsi2(str) {
|
|
|
6303
6663
|
}
|
|
6304
6664
|
|
|
6305
6665
|
// src/core/update.ts
|
|
6306
|
-
import { chmodSync as chmodSync2, existsSync as
|
|
6666
|
+
import { chmodSync as chmodSync2, existsSync as existsSync8, mkdirSync as mkdirSync5, readFileSync as readFileSync6, renameSync, writeFileSync as writeFileSync4 } from "fs";
|
|
6307
6667
|
import { homedir as homedir4 } from "os";
|
|
6308
6668
|
import { dirname as dirname2, join as join8 } from "path";
|
|
6309
6669
|
function parseSemver(v) {
|
|
@@ -6330,8 +6690,8 @@ function getCachePath() {
|
|
|
6330
6690
|
function readCache() {
|
|
6331
6691
|
try {
|
|
6332
6692
|
const p = getCachePath();
|
|
6333
|
-
if (
|
|
6334
|
-
return JSON.parse(
|
|
6693
|
+
if (existsSync8(p)) {
|
|
6694
|
+
return JSON.parse(readFileSync6(p, "utf8"));
|
|
6335
6695
|
}
|
|
6336
6696
|
} catch {}
|
|
6337
6697
|
return null;
|
|
@@ -6341,7 +6701,7 @@ function writeCache(latestVersion) {
|
|
|
6341
6701
|
const p = getCachePath();
|
|
6342
6702
|
mkdirSync5(dirname2(p), { recursive: true });
|
|
6343
6703
|
const data = { lastChecked: Date.now(), latestVersion };
|
|
6344
|
-
|
|
6704
|
+
writeFileSync4(p, JSON.stringify(data));
|
|
6345
6705
|
} catch {}
|
|
6346
6706
|
}
|
|
6347
6707
|
async function fetchLatestNpmVersion() {
|
|
@@ -6408,7 +6768,7 @@ async function performUpdate(targetVersion) {
|
|
|
6408
6768
|
throw new Error(`HTTP ${res.status} ${res.statusText}`);
|
|
6409
6769
|
const buf = await res.arrayBuffer();
|
|
6410
6770
|
const tmpPath = `${execPath}.tmp.${Date.now()}`;
|
|
6411
|
-
|
|
6771
|
+
writeFileSync4(tmpPath, Buffer.from(buf));
|
|
6412
6772
|
chmodSync2(tmpPath, 493);
|
|
6413
6773
|
renameSync(tmpPath, execPath);
|
|
6414
6774
|
return true;
|
|
@@ -6464,7 +6824,7 @@ async function promptAutoUpdate(currentVersion) {
|
|
|
6464
6824
|
}
|
|
6465
6825
|
|
|
6466
6826
|
// src/version.ts
|
|
6467
|
-
var VERSION = "0.5.
|
|
6827
|
+
var VERSION = "0.5.6";
|
|
6468
6828
|
|
|
6469
6829
|
// src/commands/update.ts
|
|
6470
6830
|
var update = {
|
|
@@ -6906,6 +7266,10 @@ Options
|
|
|
6906
7266
|
async run(ctx) {
|
|
6907
7267
|
const loaded = ctx.load();
|
|
6908
7268
|
const cfg = loaded.config;
|
|
7269
|
+
if (!cfg.proxy.enabled) {
|
|
7270
|
+
log.info("Proxy is disabled in epd.yml (SSL is handled by your external reverse proxy, e.g. Caddy, Nginx, or Apache).");
|
|
7271
|
+
return;
|
|
7272
|
+
}
|
|
6909
7273
|
let names = proxyHosts(cfg);
|
|
6910
7274
|
if (ctx.values.host)
|
|
6911
7275
|
names = names.filter((h) => h === ctx.values.host);
|
|
@@ -7190,7 +7554,7 @@ Options
|
|
|
7190
7554
|
|
|
7191
7555
|
// src/commands/backup.ts
|
|
7192
7556
|
import { createWriteStream, mkdirSync as mkdirSync6, statSync } from "fs";
|
|
7193
|
-
import { dirname as dirname3, join as join9, resolve as
|
|
7557
|
+
import { dirname as dirname3, join as join9, resolve as resolve3 } from "path";
|
|
7194
7558
|
function detectAccessoryType(decl, cfg) {
|
|
7195
7559
|
const name = decl.name;
|
|
7196
7560
|
const img = (decl.image || "").toLowerCase();
|
|
@@ -7280,7 +7644,7 @@ Options
|
|
|
7280
7644
|
} else {
|
|
7281
7645
|
targets = accessories.map((a) => detectAccessoryType(a, cfg));
|
|
7282
7646
|
}
|
|
7283
|
-
const outBaseDir =
|
|
7647
|
+
const outBaseDir = resolve3(process.cwd(), "backups");
|
|
7284
7648
|
mkdirSync6(outBaseDir, { recursive: true });
|
|
7285
7649
|
for (const target of targets) {
|
|
7286
7650
|
const host2 = host(target.hostName, cfg.ssh);
|
|
@@ -7292,7 +7656,7 @@ Options
|
|
|
7292
7656
|
const timestamp = new Date().toISOString().replace(/[:.]/g, "-").replace("T", "_").slice(0, 19);
|
|
7293
7657
|
const ext = target.type === "volume" ? "tar.gz" : "sql.gz";
|
|
7294
7658
|
const filename = `${cfg.name}-${target.name}-${timestamp}.${ext}`;
|
|
7295
|
-
const localFile = ctx.values.output ?
|
|
7659
|
+
const localFile = ctx.values.output ? resolve3(String(ctx.values.output)) : join9(outBaseDir, filename);
|
|
7296
7660
|
mkdirSync6(dirname3(localFile), { recursive: true });
|
|
7297
7661
|
let dumpCmd = "";
|
|
7298
7662
|
if (target.type === "postgres") {
|
|
@@ -7340,8 +7704,8 @@ Options
|
|
|
7340
7704
|
};
|
|
7341
7705
|
|
|
7342
7706
|
// src/commands/restore.ts
|
|
7343
|
-
import { createReadStream, existsSync as
|
|
7344
|
-
import { basename as
|
|
7707
|
+
import { createReadStream, existsSync as existsSync9 } from "fs";
|
|
7708
|
+
import { basename as basename3, resolve as resolve4 } from "path";
|
|
7345
7709
|
var restore = {
|
|
7346
7710
|
name: "restore",
|
|
7347
7711
|
summary: "Restore a database or volume backup into a running accessory",
|
|
@@ -7360,12 +7724,12 @@ Options
|
|
|
7360
7724
|
const backupPath = ctx.positionals[0];
|
|
7361
7725
|
if (!backupPath)
|
|
7362
7726
|
throw new EpdError("Please provide a path to the backup file to restore.");
|
|
7363
|
-
const absPath =
|
|
7364
|
-
if (!
|
|
7727
|
+
const absPath = resolve4(backupPath);
|
|
7728
|
+
if (!existsSync9(absPath))
|
|
7365
7729
|
throw new EpdError(`Backup file not found: ${absPath}`);
|
|
7366
7730
|
const loaded = ctx.load();
|
|
7367
7731
|
const cfg = loaded.config;
|
|
7368
|
-
const fileBase =
|
|
7732
|
+
const fileBase = basename3(absPath);
|
|
7369
7733
|
const accessories = cfg.accessories;
|
|
7370
7734
|
if (!accessories.length)
|
|
7371
7735
|
throw new EpdError("No accessories configured in epd.yml.");
|
package/package.json
CHANGED