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