@fabioplunser/epd 0.2.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +116 -14
- package/dist/cli.js +1287 -46
- package/docs/.vitepress/config.mts +50 -0
- package/docs/ci-cd.md +144 -0
- package/docs/guide.md +59 -11
- package/docs/hetzner-dns.md +87 -0
- package/docs/index.md +76 -0
- package/package.json +6 -2
package/dist/cli.js
CHANGED
|
@@ -72,6 +72,7 @@ import { dirname, join, resolve } from "path";
|
|
|
72
72
|
import { homedir } from "os";
|
|
73
73
|
|
|
74
74
|
// src/util/misc.ts
|
|
75
|
+
var sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
75
76
|
function hash32(s) {
|
|
76
77
|
let h = 2166136261;
|
|
77
78
|
for (let i = 0;i < s.length; i++) {
|
|
@@ -435,7 +436,9 @@ var TOP_LEVEL_KEYS = [
|
|
|
435
436
|
"drain",
|
|
436
437
|
"stop_timeout",
|
|
437
438
|
"docker_options",
|
|
438
|
-
"cloudflare"
|
|
439
|
+
"cloudflare",
|
|
440
|
+
"dns",
|
|
441
|
+
"hetzner"
|
|
439
442
|
];
|
|
440
443
|
function normalize(raw, configPath, root, destination) {
|
|
441
444
|
checkKeys(raw, TOP_LEVEL_KEYS, "epd.yml");
|
|
@@ -567,10 +570,26 @@ function normalize(raw, configPath, root, destination) {
|
|
|
567
570
|
"cpus",
|
|
568
571
|
"memory",
|
|
569
572
|
"drain",
|
|
570
|
-
"stop_timeout"
|
|
573
|
+
"stop_timeout",
|
|
574
|
+
"hetzner"
|
|
571
575
|
], p);
|
|
576
|
+
let svcHetzner = undefined;
|
|
577
|
+
if (o.hetzner !== undefined) {
|
|
578
|
+
if (typeof o.hetzner === "string") {
|
|
579
|
+
svcHetzner = { server: asString(o.hetzner, `${p}.hetzner`) };
|
|
580
|
+
} else if (typeof o.hetzner === "object" && !Array.isArray(o.hetzner)) {
|
|
581
|
+
const hz = o.hetzner;
|
|
582
|
+
checkKeys(hz, ["server", "label_selector"], `${p}.hetzner`);
|
|
583
|
+
svcHetzner = {
|
|
584
|
+
server: hz.server ? asString(hz.server, `${p}.hetzner.server`) : undefined,
|
|
585
|
+
labelSelector: hz.label_selector ? asString(hz.label_selector, `${p}.hetzner.label_selector`) : undefined
|
|
586
|
+
};
|
|
587
|
+
} else {
|
|
588
|
+
fail(`${p}.hetzner`, "expected a server name string or a mapping");
|
|
589
|
+
}
|
|
590
|
+
}
|
|
572
591
|
const hosts = [...asList(o.host, `${p}.host`), ...asList(o.hosts, `${p}.hosts`)];
|
|
573
|
-
if (!hosts.length)
|
|
592
|
+
if (!hosts.length && !svcHetzner)
|
|
574
593
|
fail(`${p}.hosts`, "at least one host is required");
|
|
575
594
|
const port = asNumber(o.port, `${p}.port`, asNumber(raw.port, "epd.yml.port", 3000));
|
|
576
595
|
const routes = [];
|
|
@@ -584,6 +603,7 @@ function normalize(raw, configPath, root, destination) {
|
|
|
584
603
|
return {
|
|
585
604
|
name: svcName,
|
|
586
605
|
hosts,
|
|
606
|
+
hetzner: svcHetzner,
|
|
587
607
|
replicas: asNumber(o.replicas, `${p}.replicas`, 1),
|
|
588
608
|
port,
|
|
589
609
|
command: o.command === undefined ? undefined : asString(o.command, `${p}.command`),
|
|
@@ -683,6 +703,58 @@ function normalize(raw, configPath, root, destination) {
|
|
|
683
703
|
domains: cfRaw.domains ? asList(cfRaw.domains, "epd.yml.cloudflare.domains") : undefined
|
|
684
704
|
};
|
|
685
705
|
}
|
|
706
|
+
let dnsConfig = undefined;
|
|
707
|
+
if (raw.dns !== undefined && raw.dns !== false) {
|
|
708
|
+
if (raw.dns !== true && (typeof raw.dns !== "object" || Array.isArray(raw.dns))) {
|
|
709
|
+
fail("epd.yml.dns", "expected a mapping or boolean");
|
|
710
|
+
}
|
|
711
|
+
const dRaw = raw.dns === true ? {} : raw.dns;
|
|
712
|
+
checkKeys(dRaw, ["provider", "enabled", "api_token", "zone_id", "proxied", "ttl", "auto_sync", "domains"], "epd.yml.dns");
|
|
713
|
+
const provider = asString(dRaw.provider, "epd.yml.dns.provider", "cloudflare");
|
|
714
|
+
if (provider !== "cloudflare" && provider !== "hetzner") {
|
|
715
|
+
fail("epd.yml.dns.provider", 'expected "cloudflare" or "hetzner"');
|
|
716
|
+
}
|
|
717
|
+
const defaultToken = provider === "cloudflare" ? process.env.CLOUDFLARE_API_TOKEN || process.env.CF_DNS_API_TOKEN || "" : process.env.HETZNER_DNS_API_TOKEN || process.env.HETZNER_DNS_TOKEN || "";
|
|
718
|
+
const apiToken = dRaw.api_token ? asString(dRaw.api_token, "epd.yml.dns.api_token") : defaultToken;
|
|
719
|
+
dnsConfig = {
|
|
720
|
+
provider,
|
|
721
|
+
enabled: asBool(dRaw.enabled, "epd.yml.dns.enabled", true),
|
|
722
|
+
apiToken,
|
|
723
|
+
zoneId: dRaw.zone_id ? asString(dRaw.zone_id, "epd.yml.dns.zone_id") : undefined,
|
|
724
|
+
proxied: asBool(dRaw.proxied, "epd.yml.dns.proxied", provider === "cloudflare"),
|
|
725
|
+
ttl: asNumber(dRaw.ttl, "epd.yml.dns.ttl", provider === "hetzner" ? 300 : 1),
|
|
726
|
+
autoSync: asBool(dRaw.auto_sync, "epd.yml.dns.auto_sync", true),
|
|
727
|
+
domains: dRaw.domains ? asList(dRaw.domains, "epd.yml.dns.domains") : undefined
|
|
728
|
+
};
|
|
729
|
+
} else if (cloudflare) {
|
|
730
|
+
dnsConfig = {
|
|
731
|
+
provider: "cloudflare",
|
|
732
|
+
enabled: cloudflare.enabled,
|
|
733
|
+
apiToken: cloudflare.apiToken,
|
|
734
|
+
zoneId: cloudflare.zoneId,
|
|
735
|
+
proxied: cloudflare.proxied,
|
|
736
|
+
ttl: cloudflare.ttl,
|
|
737
|
+
autoSync: cloudflare.autoSync,
|
|
738
|
+
domains: cloudflare.domains
|
|
739
|
+
};
|
|
740
|
+
}
|
|
741
|
+
let hetznerConfig = undefined;
|
|
742
|
+
if (raw.hetzner !== undefined && raw.hetzner !== false) {
|
|
743
|
+
if (typeof raw.hetzner !== "object" || Array.isArray(raw.hetzner)) {
|
|
744
|
+
fail("epd.yml.hetzner", "expected a mapping");
|
|
745
|
+
}
|
|
746
|
+
const hzRaw = raw.hetzner;
|
|
747
|
+
checkKeys(hzRaw, ["api_token", "server_type", "location", "image", "ssh_key", "label_selector"], "epd.yml.hetzner");
|
|
748
|
+
const apiToken = hzRaw.api_token ? asString(hzRaw.api_token, "epd.yml.hetzner.api_token") : process.env.HETZNER_API_TOKEN || process.env.HCLOUD_TOKEN || "";
|
|
749
|
+
hetznerConfig = {
|
|
750
|
+
apiToken,
|
|
751
|
+
serverType: hzRaw.server_type ? asString(hzRaw.server_type, "epd.yml.hetzner.server_type") : undefined,
|
|
752
|
+
location: hzRaw.location ? asString(hzRaw.location, "epd.yml.hetzner.location") : undefined,
|
|
753
|
+
image: hzRaw.image ? asString(hzRaw.image, "epd.yml.hetzner.image") : undefined,
|
|
754
|
+
sshKey: hzRaw.ssh_key ? asString(hzRaw.ssh_key, "epd.yml.hetzner.ssh_key") : undefined,
|
|
755
|
+
labelSelector: hzRaw.label_selector ? asString(hzRaw.label_selector, "epd.yml.hetzner.label_selector") : undefined
|
|
756
|
+
};
|
|
757
|
+
}
|
|
686
758
|
const cfg = {
|
|
687
759
|
name,
|
|
688
760
|
mode,
|
|
@@ -722,7 +794,9 @@ function normalize(raw, configPath, root, destination) {
|
|
|
722
794
|
onFailure: hooksRaw.on_failure ? asString(hooksRaw.on_failure, "epd.yml.hooks.on_failure") : undefined
|
|
723
795
|
},
|
|
724
796
|
process: processCfg,
|
|
797
|
+
dns: dnsConfig,
|
|
725
798
|
cloudflare,
|
|
799
|
+
hetzner: hetznerConfig,
|
|
726
800
|
portBase: asNumber(raw.port_base, "epd.yml.port_base", 20000 + hash32(name) % 117 * 256),
|
|
727
801
|
strategy,
|
|
728
802
|
keepReleases: asNumber(raw.keep_releases, "epd.yml.keep_releases", 5),
|
|
@@ -775,7 +849,7 @@ function validateCrossReferences(cfg) {
|
|
|
775
849
|
}
|
|
776
850
|
|
|
777
851
|
// src/commands/init.ts
|
|
778
|
-
import { existsSync as existsSync2, readFileSync as readFileSync2, writeFileSync } from "fs";
|
|
852
|
+
import { existsSync as existsSync2, mkdirSync, readFileSync as readFileSync2, writeFileSync } from "fs";
|
|
779
853
|
import { basename, join as join2 } from "path";
|
|
780
854
|
|
|
781
855
|
// src/util/prompt.ts
|
|
@@ -1013,7 +1087,8 @@ var init = {
|
|
|
1013
1087
|
email: { type: "string" },
|
|
1014
1088
|
replicas: { type: "string" },
|
|
1015
1089
|
force: { type: "boolean" },
|
|
1016
|
-
dockerfile: { type: "boolean" }
|
|
1090
|
+
dockerfile: { type: "boolean" },
|
|
1091
|
+
ci: { type: "boolean" }
|
|
1017
1092
|
},
|
|
1018
1093
|
help: () => `${c.bold("epd init")} \u2014 create an epd.yml for this project
|
|
1019
1094
|
|
|
@@ -1026,6 +1101,7 @@ Options
|
|
|
1026
1101
|
--email <email> Contact address for Let's Encrypt
|
|
1027
1102
|
--replicas <n> Replicas per host (default 1)
|
|
1028
1103
|
--dockerfile Also write a starter Dockerfile
|
|
1104
|
+
--ci Also generate a GitHub Actions deploy workflow (.github/workflows/deploy.yml)
|
|
1029
1105
|
--force Overwrite an existing epd.yml`,
|
|
1030
1106
|
async run(ctx) {
|
|
1031
1107
|
const root = process.cwd();
|
|
@@ -1067,6 +1143,42 @@ Options
|
|
|
1067
1143
|
log.warn(`no Dockerfile template for ${detected.runtime}; write one yourself or use \`mode: process\``);
|
|
1068
1144
|
}
|
|
1069
1145
|
}
|
|
1146
|
+
const wantCi = Boolean(ctx.values.ci) || interactive() && await confirm("Generate GitHub Actions deploy workflow (.github/workflows/deploy.yml)?", false);
|
|
1147
|
+
if (wantCi) {
|
|
1148
|
+
const workflowDir = join2(root, ".github", "workflows");
|
|
1149
|
+
mkdirSync(workflowDir, { recursive: true });
|
|
1150
|
+
const ciYaml = `name: Deploy
|
|
1151
|
+
|
|
1152
|
+
on:
|
|
1153
|
+
push:
|
|
1154
|
+
branches: [main]
|
|
1155
|
+
|
|
1156
|
+
concurrency:
|
|
1157
|
+
group: deploy-\${{ github.ref }}
|
|
1158
|
+
cancel-in-progress: false
|
|
1159
|
+
|
|
1160
|
+
jobs:
|
|
1161
|
+
deploy:
|
|
1162
|
+
runs-on: ubuntu-latest
|
|
1163
|
+
steps:
|
|
1164
|
+
- name: Checkout code
|
|
1165
|
+
uses: actions/checkout@v4
|
|
1166
|
+
|
|
1167
|
+
- name: Setup SSH Agent
|
|
1168
|
+
uses: webfactory/ssh-agent@v0.9.0
|
|
1169
|
+
with:
|
|
1170
|
+
ssh-private-key: \${{ secrets.SSH_PRIVATE_KEY }}
|
|
1171
|
+
|
|
1172
|
+
- name: Deploy with EPD
|
|
1173
|
+
run: npx @fabioplunser/epd deploy
|
|
1174
|
+
env:
|
|
1175
|
+
CLOUDFLARE_API_TOKEN: \${{ secrets.CLOUDFLARE_API_TOKEN }}
|
|
1176
|
+
HETZNER_API_TOKEN: \${{ secrets.HETZNER_API_TOKEN }}
|
|
1177
|
+
HETZNER_DNS_API_TOKEN: \${{ secrets.HETZNER_DNS_API_TOKEN }}
|
|
1178
|
+
`;
|
|
1179
|
+
writeFileSync(join2(workflowDir, "deploy.yml"), ciYaml);
|
|
1180
|
+
log.ok(`wrote ${c.bold(".github/workflows/deploy.yml")}`);
|
|
1181
|
+
}
|
|
1070
1182
|
console.log(`
|
|
1071
1183
|
${c.bold("Next")}
|
|
1072
1184
|
1. Edit ${c.cyan("epd.yml")} \u2014 servers, domains, env.
|
|
@@ -1349,11 +1461,11 @@ true`, { allowFailure: true, stream: true, label: `${host.name}: install package
|
|
|
1349
1461
|
}
|
|
1350
1462
|
|
|
1351
1463
|
// src/core/ssh.ts
|
|
1352
|
-
import { mkdirSync } from "fs";
|
|
1464
|
+
import { mkdirSync as mkdirSync2 } from "fs";
|
|
1353
1465
|
import { tmpdir } from "os";
|
|
1354
1466
|
import { join as join3 } from "path";
|
|
1355
1467
|
var controlDir = join3(tmpdir(), `epd-${process.getuid?.() ?? 0}`);
|
|
1356
|
-
|
|
1468
|
+
mkdirSync2(controlDir, { recursive: true, mode: 448 });
|
|
1357
1469
|
|
|
1358
1470
|
class Host {
|
|
1359
1471
|
name;
|
|
@@ -2575,9 +2687,12 @@ ls -1dt ${shq(p.releases)}/*/ 2>/dev/null | tail -n +$(( ${cfg.keepReleases} + 1
|
|
|
2575
2687
|
done`, { ...asUser, allowFailure: true });
|
|
2576
2688
|
}
|
|
2577
2689
|
|
|
2578
|
-
// src/
|
|
2690
|
+
// src/dns/index.ts
|
|
2579
2691
|
import dns from "dns/promises";
|
|
2692
|
+
|
|
2693
|
+
// src/dns/cloudflare.ts
|
|
2580
2694
|
class CloudflareClient {
|
|
2695
|
+
name = "cloudflare";
|
|
2581
2696
|
apiToken;
|
|
2582
2697
|
baseUrl;
|
|
2583
2698
|
constructor(apiToken, baseUrl = "https://api.cloudflare.com/client/v4") {
|
|
@@ -2605,7 +2720,7 @@ class CloudflareClient {
|
|
|
2605
2720
|
}
|
|
2606
2721
|
async findZoneForDomain(domain, explicitZoneId) {
|
|
2607
2722
|
if (explicitZoneId) {
|
|
2608
|
-
return { id: explicitZoneId, name: domain
|
|
2723
|
+
return { id: explicitZoneId, name: domain };
|
|
2609
2724
|
}
|
|
2610
2725
|
const cleanDomain = domain.replace(/^\*\./, "").toLowerCase();
|
|
2611
2726
|
const parts = cleanDomain.split(".");
|
|
@@ -2614,7 +2729,7 @@ class CloudflareClient {
|
|
|
2614
2729
|
const zones = await this.listZones(candidate);
|
|
2615
2730
|
const match = zones.find((z) => z.name.toLowerCase() === candidate);
|
|
2616
2731
|
if (match)
|
|
2617
|
-
return match;
|
|
2732
|
+
return { id: match.id, name: match.name };
|
|
2618
2733
|
}
|
|
2619
2734
|
throw new EpdError(`Cloudflare zone for domain "${domain}" not found`, `Make sure the domain is registered under your Cloudflare account and your API token has Zone.Read permissions.`);
|
|
2620
2735
|
}
|
|
@@ -2625,21 +2740,243 @@ class CloudflareClient {
|
|
|
2625
2740
|
params.set("name", name);
|
|
2626
2741
|
if (type)
|
|
2627
2742
|
params.set("type", type);
|
|
2628
|
-
|
|
2743
|
+
const raw = await this.request(`/zones/${zoneId}/dns_records?${params.toString()}`);
|
|
2744
|
+
return raw.map((r) => ({
|
|
2745
|
+
id: String(r.id),
|
|
2746
|
+
zoneId: String(r.zone_id ?? zoneId),
|
|
2747
|
+
name: r.name,
|
|
2748
|
+
type: r.type,
|
|
2749
|
+
content: r.content,
|
|
2750
|
+
proxied: Boolean(r.proxied),
|
|
2751
|
+
ttl: Number(r.ttl ?? 1)
|
|
2752
|
+
}));
|
|
2753
|
+
}
|
|
2754
|
+
async createDnsRecord(zoneId, record) {
|
|
2755
|
+
const res = await this.request(`/zones/${zoneId}/dns_records`, {
|
|
2756
|
+
method: "POST",
|
|
2757
|
+
body: JSON.stringify({
|
|
2758
|
+
name: record.name,
|
|
2759
|
+
type: record.type,
|
|
2760
|
+
content: record.content,
|
|
2761
|
+
proxied: Boolean(record.proxied),
|
|
2762
|
+
ttl: record.ttl,
|
|
2763
|
+
comment: record.comment
|
|
2764
|
+
})
|
|
2765
|
+
});
|
|
2766
|
+
return {
|
|
2767
|
+
id: String(res.id),
|
|
2768
|
+
zoneId: String(res.zone_id ?? zoneId),
|
|
2769
|
+
name: res.name,
|
|
2770
|
+
type: res.type,
|
|
2771
|
+
content: res.content,
|
|
2772
|
+
proxied: Boolean(res.proxied),
|
|
2773
|
+
ttl: Number(res.ttl ?? 1)
|
|
2774
|
+
};
|
|
2775
|
+
}
|
|
2776
|
+
async updateDnsRecord(zoneId, recordId, record) {
|
|
2777
|
+
const res = await this.request(`/zones/${zoneId}/dns_records/${recordId}`, {
|
|
2778
|
+
method: "PUT",
|
|
2779
|
+
body: JSON.stringify({
|
|
2780
|
+
name: record.name,
|
|
2781
|
+
type: record.type,
|
|
2782
|
+
content: record.content,
|
|
2783
|
+
proxied: Boolean(record.proxied),
|
|
2784
|
+
ttl: record.ttl,
|
|
2785
|
+
comment: record.comment
|
|
2786
|
+
})
|
|
2787
|
+
});
|
|
2788
|
+
return {
|
|
2789
|
+
id: String(res.id),
|
|
2790
|
+
zoneId: String(res.zone_id ?? zoneId),
|
|
2791
|
+
name: res.name,
|
|
2792
|
+
type: res.type,
|
|
2793
|
+
content: res.content,
|
|
2794
|
+
proxied: Boolean(res.proxied),
|
|
2795
|
+
ttl: Number(res.ttl ?? 1)
|
|
2796
|
+
};
|
|
2797
|
+
}
|
|
2798
|
+
async deleteDnsRecord(zoneId, recordId) {
|
|
2799
|
+
await this.request(`/zones/${zoneId}/dns_records/${recordId}`, {
|
|
2800
|
+
method: "DELETE"
|
|
2801
|
+
});
|
|
2802
|
+
}
|
|
2803
|
+
}
|
|
2804
|
+
|
|
2805
|
+
// src/dns/hetzner.ts
|
|
2806
|
+
class HetznerDnsClient {
|
|
2807
|
+
name = "hetzner";
|
|
2808
|
+
apiToken;
|
|
2809
|
+
baseUrl;
|
|
2810
|
+
zoneCache = new Map;
|
|
2811
|
+
constructor(apiToken, baseUrl = "https://dns.hetzner.com/api/v1") {
|
|
2812
|
+
this.apiToken = apiToken;
|
|
2813
|
+
this.baseUrl = baseUrl.replace(/\/$/, "");
|
|
2814
|
+
}
|
|
2815
|
+
async request(path, options = {}) {
|
|
2816
|
+
const url = `${this.baseUrl}${path}`;
|
|
2817
|
+
const headers = {
|
|
2818
|
+
"Auth-API-Token": this.apiToken,
|
|
2819
|
+
"Content-Type": "application/json",
|
|
2820
|
+
...options.headers
|
|
2821
|
+
};
|
|
2822
|
+
const res = await fetch(url, { ...options, headers });
|
|
2823
|
+
let data;
|
|
2824
|
+
try {
|
|
2825
|
+
data = await res.json();
|
|
2826
|
+
} catch {
|
|
2827
|
+
data = null;
|
|
2828
|
+
}
|
|
2829
|
+
if (!res.ok) {
|
|
2830
|
+
const msg = data?.error?.message || data?.message || `HTTP ${res.status} ${res.statusText}`;
|
|
2831
|
+
throw new EpdError(`Hetzner DNS API error: ${msg}`);
|
|
2832
|
+
}
|
|
2833
|
+
return data;
|
|
2834
|
+
}
|
|
2835
|
+
async listZones(name) {
|
|
2836
|
+
const query = name ? `?name=${encodeURIComponent(name)}` : "";
|
|
2837
|
+
const res = await this.request(`/zones${query}`);
|
|
2838
|
+
return (res.zones ?? []).map((z) => ({ id: z.id, name: z.name }));
|
|
2839
|
+
}
|
|
2840
|
+
async findZoneForDomain(domain, explicitZoneId) {
|
|
2841
|
+
if (explicitZoneId) {
|
|
2842
|
+
const cached = this.zoneCache.get(explicitZoneId);
|
|
2843
|
+
if (cached)
|
|
2844
|
+
return cached;
|
|
2845
|
+
const zones = await this.listZones();
|
|
2846
|
+
const match = zones.find((z) => z.id === explicitZoneId);
|
|
2847
|
+
const zone = match ?? { id: explicitZoneId, name: domain };
|
|
2848
|
+
this.zoneCache.set(explicitZoneId, zone);
|
|
2849
|
+
return zone;
|
|
2850
|
+
}
|
|
2851
|
+
const cleanDomain = domain.replace(/^\*\./, "").toLowerCase();
|
|
2852
|
+
const parts = cleanDomain.split(".");
|
|
2853
|
+
for (let i = 0;i < parts.length - 1; i++) {
|
|
2854
|
+
const candidate = parts.slice(i).join(".");
|
|
2855
|
+
const zones = await this.listZones(candidate);
|
|
2856
|
+
const match = zones.find((z) => z.name.toLowerCase() === candidate);
|
|
2857
|
+
if (match) {
|
|
2858
|
+
this.zoneCache.set(match.id, match);
|
|
2859
|
+
return match;
|
|
2860
|
+
}
|
|
2861
|
+
}
|
|
2862
|
+
throw new EpdError(`Hetzner DNS zone for domain "${domain}" not found`, `Ensure the zone is added in Hetzner DNS Console (https://dns.hetzner.com) and your Auth-API-Token has permission to manage it.`);
|
|
2863
|
+
}
|
|
2864
|
+
toHetznerName(fqdn, zoneName) {
|
|
2865
|
+
const cleanFqdn = fqdn.replace(/^\*\./, "").toLowerCase();
|
|
2866
|
+
const cleanZone = zoneName.toLowerCase();
|
|
2867
|
+
if (cleanFqdn === cleanZone)
|
|
2868
|
+
return "@";
|
|
2869
|
+
if (cleanFqdn.endsWith("." + cleanZone)) {
|
|
2870
|
+
return cleanFqdn.slice(0, -(cleanZone.length + 1));
|
|
2871
|
+
}
|
|
2872
|
+
return cleanFqdn;
|
|
2873
|
+
}
|
|
2874
|
+
toFqdnName(hetznerName, zoneName) {
|
|
2875
|
+
if (hetznerName === "@" || hetznerName === "")
|
|
2876
|
+
return zoneName;
|
|
2877
|
+
return `${hetznerName}.${zoneName}`;
|
|
2878
|
+
}
|
|
2879
|
+
async listDnsRecords(zoneId, name, type) {
|
|
2880
|
+
let zone = this.zoneCache.get(zoneId);
|
|
2881
|
+
if (!zone) {
|
|
2882
|
+
const zones = await this.listZones();
|
|
2883
|
+
zone = zones.find((z) => z.id === zoneId);
|
|
2884
|
+
if (zone)
|
|
2885
|
+
this.zoneCache.set(zoneId, zone);
|
|
2886
|
+
}
|
|
2887
|
+
const zoneName = zone?.name ?? "";
|
|
2888
|
+
const res = await this.request(`/records?zone_id=${encodeURIComponent(zoneId)}`);
|
|
2889
|
+
const records = res.records ?? [];
|
|
2890
|
+
let mapped = records.map((r) => ({
|
|
2891
|
+
id: r.id,
|
|
2892
|
+
zoneId: r.zone_id,
|
|
2893
|
+
name: zoneName ? this.toFqdnName(r.name, zoneName) : r.name,
|
|
2894
|
+
type: r.type,
|
|
2895
|
+
content: r.value,
|
|
2896
|
+
proxied: false,
|
|
2897
|
+
ttl: r.ttl
|
|
2898
|
+
}));
|
|
2899
|
+
if (name) {
|
|
2900
|
+
const targetName = name.toLowerCase();
|
|
2901
|
+
mapped = mapped.filter((r) => r.name.toLowerCase() === targetName);
|
|
2902
|
+
}
|
|
2903
|
+
if (type) {
|
|
2904
|
+
mapped = mapped.filter((r) => r.type === type);
|
|
2905
|
+
}
|
|
2906
|
+
return mapped;
|
|
2629
2907
|
}
|
|
2630
2908
|
async createDnsRecord(zoneId, record) {
|
|
2631
|
-
|
|
2909
|
+
let zone = this.zoneCache.get(zoneId);
|
|
2910
|
+
if (!zone) {
|
|
2911
|
+
const zones = await this.listZones();
|
|
2912
|
+
zone = zones.find((z) => z.id === zoneId);
|
|
2913
|
+
if (zone)
|
|
2914
|
+
this.zoneCache.set(zoneId, zone);
|
|
2915
|
+
}
|
|
2916
|
+
const zoneName = zone?.name ?? "";
|
|
2917
|
+
const hetznerName = zoneName ? this.toHetznerName(record.name, zoneName) : record.name;
|
|
2918
|
+
const ttl = record.ttl <= 1 ? 300 : record.ttl;
|
|
2919
|
+
const res = await this.request("/records", {
|
|
2632
2920
|
method: "POST",
|
|
2633
|
-
body: JSON.stringify(
|
|
2921
|
+
body: JSON.stringify({
|
|
2922
|
+
zone_id: zoneId,
|
|
2923
|
+
type: record.type,
|
|
2924
|
+
name: hetznerName,
|
|
2925
|
+
value: record.content,
|
|
2926
|
+
ttl
|
|
2927
|
+
})
|
|
2634
2928
|
});
|
|
2929
|
+
const created = res.record;
|
|
2930
|
+
return {
|
|
2931
|
+
id: created.id,
|
|
2932
|
+
zoneId: created.zone_id,
|
|
2933
|
+
name: zoneName ? this.toFqdnName(created.name, zoneName) : record.name,
|
|
2934
|
+
type: created.type,
|
|
2935
|
+
content: created.value,
|
|
2936
|
+
proxied: false,
|
|
2937
|
+
ttl: created.ttl
|
|
2938
|
+
};
|
|
2635
2939
|
}
|
|
2636
2940
|
async updateDnsRecord(zoneId, recordId, record) {
|
|
2637
|
-
|
|
2941
|
+
let zone = this.zoneCache.get(zoneId);
|
|
2942
|
+
if (!zone) {
|
|
2943
|
+
const zones = await this.listZones();
|
|
2944
|
+
zone = zones.find((z) => z.id === zoneId);
|
|
2945
|
+
if (zone)
|
|
2946
|
+
this.zoneCache.set(zoneId, zone);
|
|
2947
|
+
}
|
|
2948
|
+
const zoneName = zone?.name ?? "";
|
|
2949
|
+
const hetznerName = zoneName ? this.toHetznerName(record.name, zoneName) : record.name;
|
|
2950
|
+
const ttl = record.ttl <= 1 ? 300 : record.ttl;
|
|
2951
|
+
const res = await this.request(`/records/${recordId}`, {
|
|
2638
2952
|
method: "PUT",
|
|
2639
|
-
body: JSON.stringify(
|
|
2953
|
+
body: JSON.stringify({
|
|
2954
|
+
zone_id: zoneId,
|
|
2955
|
+
type: record.type,
|
|
2956
|
+
name: hetznerName,
|
|
2957
|
+
value: record.content,
|
|
2958
|
+
ttl
|
|
2959
|
+
})
|
|
2960
|
+
});
|
|
2961
|
+
const updated = res.record;
|
|
2962
|
+
return {
|
|
2963
|
+
id: updated.id,
|
|
2964
|
+
zoneId: updated.zone_id,
|
|
2965
|
+
name: zoneName ? this.toFqdnName(updated.name, zoneName) : record.name,
|
|
2966
|
+
type: updated.type,
|
|
2967
|
+
content: updated.value,
|
|
2968
|
+
proxied: false,
|
|
2969
|
+
ttl: updated.ttl
|
|
2970
|
+
};
|
|
2971
|
+
}
|
|
2972
|
+
async deleteDnsRecord(zoneId, recordId) {
|
|
2973
|
+
await this.request(`/records/${recordId}`, {
|
|
2974
|
+
method: "DELETE"
|
|
2640
2975
|
});
|
|
2641
2976
|
}
|
|
2642
2977
|
}
|
|
2978
|
+
|
|
2979
|
+
// src/dns/index.ts
|
|
2643
2980
|
function isIPv4(ip) {
|
|
2644
2981
|
const parts = ip.split(".");
|
|
2645
2982
|
if (parts.length !== 4)
|
|
@@ -2665,6 +3002,9 @@ async function resolveHostIps(target) {
|
|
|
2665
3002
|
return [clean];
|
|
2666
3003
|
}
|
|
2667
3004
|
function getRouteDomains(cfg) {
|
|
3005
|
+
if (cfg.dns?.domains && cfg.dns.domains.length > 0) {
|
|
3006
|
+
return cfg.dns.domains;
|
|
3007
|
+
}
|
|
2668
3008
|
if (cfg.cloudflare?.domains && cfg.cloudflare.domains.length > 0) {
|
|
2669
3009
|
return cfg.cloudflare.domains;
|
|
2670
3010
|
}
|
|
@@ -2689,16 +3029,40 @@ function getRouteDomains(cfg) {
|
|
|
2689
3029
|
}
|
|
2690
3030
|
return [...domains];
|
|
2691
3031
|
}
|
|
3032
|
+
function createDnsProvider(config) {
|
|
3033
|
+
switch (config.provider) {
|
|
3034
|
+
case "cloudflare":
|
|
3035
|
+
return new CloudflareClient(config.apiToken);
|
|
3036
|
+
case "hetzner":
|
|
3037
|
+
return new HetznerDnsClient(config.apiToken);
|
|
3038
|
+
default:
|
|
3039
|
+
throw new EpdError(`Unsupported DNS provider: ${String(config.provider)}`, "Supported providers: cloudflare, hetzner");
|
|
3040
|
+
}
|
|
3041
|
+
}
|
|
2692
3042
|
async function syncDns(cfg, opts = {}) {
|
|
2693
|
-
|
|
2694
|
-
if (
|
|
2695
|
-
|
|
3043
|
+
let provider;
|
|
3044
|
+
if (opts.provider) {
|
|
3045
|
+
provider = opts.provider;
|
|
3046
|
+
} else if (opts.client) {
|
|
3047
|
+
provider = opts.client;
|
|
3048
|
+
} else if (cfg.dns?.enabled && cfg.dns.apiToken) {
|
|
3049
|
+
provider = createDnsProvider(cfg.dns);
|
|
3050
|
+
} else if (cfg.cloudflare) {
|
|
3051
|
+
const token = cfg.cloudflare.apiToken || process.env.CLOUDFLARE_API_TOKEN || process.env.CF_DNS_API_TOKEN;
|
|
3052
|
+
if (!token) {
|
|
3053
|
+
throw new EpdError("Cloudflare API token is missing", "Set CLOUDFLARE_API_TOKEN in your environment or specify api_token in epd.yml under cloudflare.");
|
|
3054
|
+
}
|
|
3055
|
+
provider = new CloudflareClient(token);
|
|
3056
|
+
} else if (process.env.HETZNER_DNS_API_TOKEN || process.env.HETZNER_DNS_TOKEN) {
|
|
3057
|
+
const token = process.env.HETZNER_DNS_API_TOKEN || process.env.HETZNER_DNS_TOKEN;
|
|
3058
|
+
provider = new HetznerDnsClient(token);
|
|
3059
|
+
} else {
|
|
3060
|
+
throw new EpdError("No DNS provider configured", "Configure `dns:` or `cloudflare:` in epd.yml, or set CLOUDFLARE_API_TOKEN / HETZNER_DNS_API_TOKEN in environment.");
|
|
2696
3061
|
}
|
|
2697
|
-
const client = opts.client ?? new CloudflareClient(token);
|
|
2698
3062
|
const domains = getRouteDomains(cfg);
|
|
2699
3063
|
if (!domains.length) {
|
|
2700
3064
|
if (opts.log)
|
|
2701
|
-
log.step(
|
|
3065
|
+
log.step(`${provider.name} DNS: no domain names found in routes to sync`);
|
|
2702
3066
|
return [];
|
|
2703
3067
|
}
|
|
2704
3068
|
const routedHosts = new Set;
|
|
@@ -2718,30 +3082,33 @@ async function syncDns(cfg, opts = {}) {
|
|
|
2718
3082
|
}
|
|
2719
3083
|
if (!ips.size) {
|
|
2720
3084
|
if (opts.log)
|
|
2721
|
-
log.step(
|
|
3085
|
+
log.step(`${provider.name} DNS: no server IP addresses resolved to sync`);
|
|
2722
3086
|
return [];
|
|
2723
3087
|
}
|
|
2724
|
-
const isProxied = opts.proxied ?? cfg.cloudflare?.proxied ?? true;
|
|
2725
|
-
const ttl = cfg.cloudflare?.ttl ?? 1;
|
|
3088
|
+
const isProxied = opts.proxied ?? cfg.dns?.proxied ?? cfg.cloudflare?.proxied ?? true;
|
|
3089
|
+
const ttl = cfg.dns?.ttl ?? cfg.cloudflare?.ttl ?? (provider.name === "hetzner" ? 300 : 1);
|
|
3090
|
+
const explicitZoneId = cfg.dns?.zoneId ?? cfg.cloudflare?.zoneId;
|
|
2726
3091
|
const results = [];
|
|
2727
3092
|
if (opts.log) {
|
|
2728
|
-
log.step(
|
|
3093
|
+
log.step(`${provider.name} DNS: syncing ${c.bold(domains.length.toString())} domain(s) across ${c.bold(ips.size.toString())} server IP(s)`);
|
|
2729
3094
|
}
|
|
2730
3095
|
const zoneCache = new Map;
|
|
2731
3096
|
for (const domain of domains) {
|
|
2732
3097
|
let zone = zoneCache.get(domain);
|
|
2733
3098
|
if (!zone) {
|
|
2734
|
-
zone = await
|
|
3099
|
+
zone = await provider.findZoneForDomain(domain, explicitZoneId);
|
|
2735
3100
|
zoneCache.set(domain, zone);
|
|
2736
3101
|
}
|
|
2737
|
-
const existingRecords = await
|
|
3102
|
+
const existingRecords = await provider.listDnsRecords(zone.id, domain);
|
|
2738
3103
|
for (const ip of ips) {
|
|
2739
3104
|
const type = isIPv6(ip) ? "AAAA" : "A";
|
|
2740
3105
|
const existing = existingRecords.find((r) => r.name.toLowerCase() === domain.toLowerCase() && r.type === type && r.content === ip);
|
|
2741
3106
|
if (existing) {
|
|
2742
|
-
|
|
3107
|
+
const needsProxyUpdate = provider.name === "cloudflare" && existing.proxied !== isProxied;
|
|
3108
|
+
const needsTtlUpdate = ttl !== 1 && existing.ttl !== ttl;
|
|
3109
|
+
if (needsProxyUpdate || needsTtlUpdate) {
|
|
2743
3110
|
if (!opts.dryRun) {
|
|
2744
|
-
await
|
|
3111
|
+
await provider.updateDnsRecord(zone.id, existing.id, {
|
|
2745
3112
|
name: domain,
|
|
2746
3113
|
type,
|
|
2747
3114
|
content: ip,
|
|
@@ -2750,20 +3117,20 @@ async function syncDns(cfg, opts = {}) {
|
|
|
2750
3117
|
comment: `Managed by epd (${cfg.name})`
|
|
2751
3118
|
});
|
|
2752
3119
|
}
|
|
2753
|
-
results.push({ domain, ip, type, action: "updated", recordId: existing.id, proxied: isProxied });
|
|
3120
|
+
results.push({ provider: provider.name, domain, ip, type, action: "updated", recordId: existing.id, proxied: isProxied });
|
|
2754
3121
|
if (opts.log) {
|
|
2755
|
-
log.ok(
|
|
3122
|
+
log.ok(`${provider.name}: updated ${type} ${c.bold(domain)} \u2192 ${ip}${provider.name === "cloudflare" ? ` (${isProxied ? "proxied" : "DNS only"})` : ""}`);
|
|
2756
3123
|
}
|
|
2757
3124
|
} else {
|
|
2758
|
-
results.push({ domain, ip, type, action: "unchanged", recordId: existing.id, proxied: isProxied });
|
|
3125
|
+
results.push({ provider: provider.name, domain, ip, type, action: "unchanged", recordId: existing.id, proxied: isProxied });
|
|
2759
3126
|
if (opts.log) {
|
|
2760
|
-
log.debug(`${type} ${domain} \u2192 ${ip}
|
|
3127
|
+
log.debug(`${type} ${domain} \u2192 ${ip} already in sync`);
|
|
2761
3128
|
}
|
|
2762
3129
|
}
|
|
2763
3130
|
} else {
|
|
2764
3131
|
let recordId;
|
|
2765
3132
|
if (!opts.dryRun) {
|
|
2766
|
-
const created = await
|
|
3133
|
+
const created = await provider.createDnsRecord(zone.id, {
|
|
2767
3134
|
name: domain,
|
|
2768
3135
|
type,
|
|
2769
3136
|
content: ip,
|
|
@@ -2773,19 +3140,314 @@ async function syncDns(cfg, opts = {}) {
|
|
|
2773
3140
|
});
|
|
2774
3141
|
recordId = created.id;
|
|
2775
3142
|
}
|
|
2776
|
-
results.push({ domain, ip, type, action: "created", recordId, proxied: isProxied });
|
|
3143
|
+
results.push({ provider: provider.name, domain, ip, type, action: "created", recordId, proxied: isProxied });
|
|
2777
3144
|
if (opts.log) {
|
|
2778
|
-
log.ok(
|
|
3145
|
+
log.ok(`${provider.name}: created ${type} ${c.bold(domain)} \u2192 ${ip}${provider.name === "cloudflare" ? ` (${isProxied ? "proxied" : "DNS only"})` : ""}${opts.dryRun ? " [dry-run]" : ""}`);
|
|
2779
3146
|
}
|
|
2780
3147
|
}
|
|
2781
3148
|
}
|
|
2782
3149
|
}
|
|
2783
3150
|
return results;
|
|
2784
3151
|
}
|
|
3152
|
+
// src/hetzner/api.ts
|
|
3153
|
+
class HetznerCloudClient {
|
|
3154
|
+
apiToken;
|
|
3155
|
+
baseUrl;
|
|
3156
|
+
constructor(apiToken, baseUrl = "https://api.hetzner.cloud/v1") {
|
|
3157
|
+
this.apiToken = apiToken;
|
|
3158
|
+
this.baseUrl = baseUrl.replace(/\/$/, "");
|
|
3159
|
+
}
|
|
3160
|
+
async request(path, options = {}) {
|
|
3161
|
+
const url = `${this.baseUrl}${path}`;
|
|
3162
|
+
const headers = {
|
|
3163
|
+
Authorization: `Bearer ${this.apiToken}`,
|
|
3164
|
+
"Content-Type": "application/json",
|
|
3165
|
+
...options.headers
|
|
3166
|
+
};
|
|
3167
|
+
const res = await fetch(url, { ...options, headers });
|
|
3168
|
+
let data;
|
|
3169
|
+
try {
|
|
3170
|
+
data = await res.json();
|
|
3171
|
+
} catch {
|
|
3172
|
+
data = null;
|
|
3173
|
+
}
|
|
3174
|
+
if (!res.ok) {
|
|
3175
|
+
const msg = data?.error?.message || data?.message || `HTTP ${res.status} ${res.statusText}`;
|
|
3176
|
+
throw new EpdError(`Hetzner Cloud API error: ${msg}`);
|
|
3177
|
+
}
|
|
3178
|
+
return data;
|
|
3179
|
+
}
|
|
3180
|
+
mapServer(s) {
|
|
3181
|
+
return {
|
|
3182
|
+
id: s.id,
|
|
3183
|
+
name: s.name,
|
|
3184
|
+
status: s.status,
|
|
3185
|
+
created: s.created,
|
|
3186
|
+
publicNet: {
|
|
3187
|
+
ipv4: {
|
|
3188
|
+
ip: s.public_net?.ipv4?.ip ?? "",
|
|
3189
|
+
blocked: Boolean(s.public_net?.ipv4?.blocked),
|
|
3190
|
+
dnsPtr: s.public_net?.ipv4?.dns_ptr
|
|
3191
|
+
},
|
|
3192
|
+
ipv6: s.public_net?.ipv6 ? {
|
|
3193
|
+
ip: s.public_net.ipv6.ip ?? "",
|
|
3194
|
+
blocked: Boolean(s.public_net.ipv6.blocked)
|
|
3195
|
+
} : undefined
|
|
3196
|
+
},
|
|
3197
|
+
serverType: {
|
|
3198
|
+
id: s.server_type?.id ?? 0,
|
|
3199
|
+
name: s.server_type?.name ?? "",
|
|
3200
|
+
description: s.server_type?.description ?? "",
|
|
3201
|
+
cores: s.server_type?.cores ?? 0,
|
|
3202
|
+
memory: s.server_type?.memory ?? 0,
|
|
3203
|
+
disk: s.server_type?.disk ?? 0,
|
|
3204
|
+
cpuType: s.server_type?.cpu_type ?? "shared",
|
|
3205
|
+
architecture: s.server_type?.architecture ?? "x86"
|
|
3206
|
+
},
|
|
3207
|
+
datacenter: {
|
|
3208
|
+
id: s.datacenter?.id ?? 0,
|
|
3209
|
+
name: s.datacenter?.name ?? "",
|
|
3210
|
+
description: s.datacenter?.description ?? "",
|
|
3211
|
+
location: {
|
|
3212
|
+
id: s.datacenter?.location?.id ?? 0,
|
|
3213
|
+
name: s.datacenter?.location?.name ?? "",
|
|
3214
|
+
description: s.datacenter?.location?.description ?? "",
|
|
3215
|
+
country: s.datacenter?.location?.country ?? "",
|
|
3216
|
+
city: s.datacenter?.location?.city ?? ""
|
|
3217
|
+
}
|
|
3218
|
+
},
|
|
3219
|
+
image: s.image ? {
|
|
3220
|
+
id: s.image.id,
|
|
3221
|
+
name: s.image.name ?? "",
|
|
3222
|
+
osFlavor: s.image.os_flavor ?? "",
|
|
3223
|
+
description: s.image.description ?? ""
|
|
3224
|
+
} : undefined,
|
|
3225
|
+
labels: s.labels ?? {}
|
|
3226
|
+
};
|
|
3227
|
+
}
|
|
3228
|
+
async listServers(opts = {}) {
|
|
3229
|
+
const params = new URLSearchParams;
|
|
3230
|
+
if (opts.name)
|
|
3231
|
+
params.set("name", opts.name);
|
|
3232
|
+
if (opts.labelSelector)
|
|
3233
|
+
params.set("label_selector", opts.labelSelector);
|
|
3234
|
+
params.set("per_page", "50");
|
|
3235
|
+
const query = params.toString() ? `?${params.toString()}` : "";
|
|
3236
|
+
const res = await this.request(`/servers${query}`);
|
|
3237
|
+
return (res.servers ?? []).map((s) => this.mapServer(s));
|
|
3238
|
+
}
|
|
3239
|
+
async getServer(idOrName) {
|
|
3240
|
+
if (typeof idOrName === "number" || /^\d+$/.test(String(idOrName))) {
|
|
3241
|
+
try {
|
|
3242
|
+
const res = await this.request(`/servers/${idOrName}`);
|
|
3243
|
+
return this.mapServer(res.server);
|
|
3244
|
+
} catch (e) {
|
|
3245
|
+
if (e instanceof EpdError && e.message.includes("404"))
|
|
3246
|
+
return null;
|
|
3247
|
+
throw e;
|
|
3248
|
+
}
|
|
3249
|
+
}
|
|
3250
|
+
const servers = await this.listServers({ name: String(idOrName) });
|
|
3251
|
+
return servers.find((s) => s.name === String(idOrName)) ?? null;
|
|
3252
|
+
}
|
|
3253
|
+
async createServer(opts) {
|
|
3254
|
+
const body = {
|
|
3255
|
+
name: opts.name,
|
|
3256
|
+
server_type: opts.serverType ?? "cx22",
|
|
3257
|
+
image: opts.image ?? "ubuntu-24.04",
|
|
3258
|
+
start_after_create: opts.startAfterCreate ?? true
|
|
3259
|
+
};
|
|
3260
|
+
if (opts.location)
|
|
3261
|
+
body.location = opts.location;
|
|
3262
|
+
if (opts.datacenter)
|
|
3263
|
+
body.datacenter = opts.datacenter;
|
|
3264
|
+
if (opts.sshKeys?.length)
|
|
3265
|
+
body.ssh_keys = opts.sshKeys;
|
|
3266
|
+
if (opts.labels)
|
|
3267
|
+
body.labels = opts.labels;
|
|
3268
|
+
if (opts.userData)
|
|
3269
|
+
body.user_data = opts.userData;
|
|
3270
|
+
const res = await this.request("/servers", {
|
|
3271
|
+
method: "POST",
|
|
3272
|
+
body: JSON.stringify(body)
|
|
3273
|
+
});
|
|
3274
|
+
return {
|
|
3275
|
+
server: this.mapServer(res.server),
|
|
3276
|
+
action: res.action,
|
|
3277
|
+
rootPassword: res.root_password
|
|
3278
|
+
};
|
|
3279
|
+
}
|
|
3280
|
+
async deleteServer(id) {
|
|
3281
|
+
await this.request(`/servers/${id}`, {
|
|
3282
|
+
method: "DELETE"
|
|
3283
|
+
});
|
|
3284
|
+
}
|
|
3285
|
+
async listServerTypes() {
|
|
3286
|
+
const res = await this.request("/server_types");
|
|
3287
|
+
return (res.server_types ?? []).map((st) => ({
|
|
3288
|
+
id: st.id,
|
|
3289
|
+
name: st.name,
|
|
3290
|
+
description: st.description,
|
|
3291
|
+
cores: st.cores,
|
|
3292
|
+
memory: st.memory,
|
|
3293
|
+
disk: st.disk,
|
|
3294
|
+
cpuType: st.cpu_type,
|
|
3295
|
+
architecture: st.architecture,
|
|
3296
|
+
prices: (st.prices ?? []).map((p) => ({
|
|
3297
|
+
location: p.location,
|
|
3298
|
+
priceHourly: { net: p.price_hourly?.net ?? "", gross: p.price_hourly?.gross ?? "" },
|
|
3299
|
+
priceMonthly: { net: p.price_monthly?.net ?? "", gross: p.price_monthly?.gross ?? "" }
|
|
3300
|
+
}))
|
|
3301
|
+
}));
|
|
3302
|
+
}
|
|
3303
|
+
async listLocations() {
|
|
3304
|
+
const res = await this.request("/locations");
|
|
3305
|
+
return (res.locations ?? []).map((l) => ({
|
|
3306
|
+
id: l.id,
|
|
3307
|
+
name: l.name,
|
|
3308
|
+
description: l.description,
|
|
3309
|
+
country: l.country,
|
|
3310
|
+
city: l.city,
|
|
3311
|
+
networkZone: l.network_zone
|
|
3312
|
+
}));
|
|
3313
|
+
}
|
|
3314
|
+
async listSshKeys() {
|
|
3315
|
+
const res = await this.request("/ssh_keys");
|
|
3316
|
+
return (res.ssh_keys ?? []).map((k) => ({
|
|
3317
|
+
id: k.id,
|
|
3318
|
+
name: k.name,
|
|
3319
|
+
fingerprint: k.fingerprint,
|
|
3320
|
+
publicKey: k.public_key
|
|
3321
|
+
}));
|
|
3322
|
+
}
|
|
3323
|
+
async getAction(id) {
|
|
3324
|
+
const res = await this.request(`/actions/${id}`);
|
|
3325
|
+
return res.action;
|
|
3326
|
+
}
|
|
3327
|
+
async waitForAction(actionId, timeoutMs = 120000) {
|
|
3328
|
+
const deadline = Date.now() + timeoutMs;
|
|
3329
|
+
while (Date.now() < deadline) {
|
|
3330
|
+
const action = await this.getAction(actionId);
|
|
3331
|
+
if (action.status === "success")
|
|
3332
|
+
return;
|
|
3333
|
+
if (action.status === "error") {
|
|
3334
|
+
throw new EpdError(`Hetzner action failed: ${action.error?.message || "Unknown error"}`);
|
|
3335
|
+
}
|
|
3336
|
+
await sleep(1500);
|
|
3337
|
+
}
|
|
3338
|
+
throw new EpdError(`Hetzner action ${actionId} timed out after ${Math.round(timeoutMs / 1000)}s`);
|
|
3339
|
+
}
|
|
3340
|
+
async waitForServerRunning(serverId, timeoutMs = 120000) {
|
|
3341
|
+
const deadline = Date.now() + timeoutMs;
|
|
3342
|
+
while (Date.now() < deadline) {
|
|
3343
|
+
const server = await this.getServer(serverId);
|
|
3344
|
+
if (server && server.status === "running" && server.publicNet.ipv4.ip) {
|
|
3345
|
+
return server;
|
|
3346
|
+
}
|
|
3347
|
+
await sleep(2000);
|
|
3348
|
+
}
|
|
3349
|
+
throw new EpdError(`Timed out waiting for Hetzner server ${serverId} to become running`);
|
|
3350
|
+
}
|
|
3351
|
+
}
|
|
3352
|
+
|
|
3353
|
+
// src/hetzner/resolve.ts
|
|
3354
|
+
async function resolveDynamicHosts(cfg, env = {}, clientOverride) {
|
|
3355
|
+
let needsHetzner = Boolean(cfg.hetzner);
|
|
3356
|
+
for (const s of cfg.services) {
|
|
3357
|
+
if (s.hetzner)
|
|
3358
|
+
needsHetzner = true;
|
|
3359
|
+
for (const h of s.hosts) {
|
|
3360
|
+
if (h.startsWith("hetzner:"))
|
|
3361
|
+
needsHetzner = true;
|
|
3362
|
+
}
|
|
3363
|
+
}
|
|
3364
|
+
for (const a of cfg.accessories) {
|
|
3365
|
+
if (a.host.startsWith("hetzner:"))
|
|
3366
|
+
needsHetzner = true;
|
|
3367
|
+
}
|
|
3368
|
+
if (!needsHetzner)
|
|
3369
|
+
return;
|
|
3370
|
+
const token = cfg.hetzner?.apiToken || env.HETZNER_API_TOKEN || env.HCLOUD_TOKEN || process.env.HETZNER_API_TOKEN || process.env.HCLOUD_TOKEN;
|
|
3371
|
+
if (!token && !clientOverride) {
|
|
3372
|
+
throw new EpdError("Hetzner Cloud API token is missing", "Set HETZNER_API_TOKEN or HCLOUD_TOKEN in your environment or configure hetzner.api_token in epd.yml.");
|
|
3373
|
+
}
|
|
3374
|
+
const client = clientOverride ?? new HetznerCloudClient(token);
|
|
3375
|
+
const serverCache = new Map;
|
|
3376
|
+
const resolveServerIp = async (target) => {
|
|
3377
|
+
const cached = serverCache.get(target);
|
|
3378
|
+
if (cached)
|
|
3379
|
+
return cached;
|
|
3380
|
+
const server = await client.getServer(target);
|
|
3381
|
+
if (!server) {
|
|
3382
|
+
throw new EpdError(`Hetzner server "${target}" not found in your Hetzner Cloud project`);
|
|
3383
|
+
}
|
|
3384
|
+
const ip = server.publicNet.ipv4.ip;
|
|
3385
|
+
if (!ip) {
|
|
3386
|
+
throw new EpdError(`Hetzner server "${target}" does not have a public IPv4 address`);
|
|
3387
|
+
}
|
|
3388
|
+
serverCache.set(target, ip);
|
|
3389
|
+
return ip;
|
|
3390
|
+
};
|
|
3391
|
+
const resolveLabelSelector = async (selector) => {
|
|
3392
|
+
const servers = await client.listServers({ labelSelector: selector });
|
|
3393
|
+
if (!servers.length) {
|
|
3394
|
+
throw new EpdError(`No Hetzner servers matched label selector "${selector}"`);
|
|
3395
|
+
}
|
|
3396
|
+
const ips = [];
|
|
3397
|
+
for (const s of servers) {
|
|
3398
|
+
if (s.publicNet.ipv4.ip) {
|
|
3399
|
+
serverCache.set(s.name, s.publicNet.ipv4.ip);
|
|
3400
|
+
ips.push(s.publicNet.ipv4.ip);
|
|
3401
|
+
}
|
|
3402
|
+
}
|
|
3403
|
+
if (!ips.length) {
|
|
3404
|
+
throw new EpdError(`Matched Hetzner servers for "${selector}" have no public IPv4 addresses`);
|
|
3405
|
+
}
|
|
3406
|
+
return ips;
|
|
3407
|
+
};
|
|
3408
|
+
for (const s of cfg.services) {
|
|
3409
|
+
const newHosts = [];
|
|
3410
|
+
if (s.hetzner) {
|
|
3411
|
+
if (s.hetzner.server) {
|
|
3412
|
+
const ip = await resolveServerIp(s.hetzner.server);
|
|
3413
|
+
newHosts.push(ip);
|
|
3414
|
+
}
|
|
3415
|
+
if (s.hetzner.labelSelector) {
|
|
3416
|
+
const ips = await resolveLabelSelector(s.hetzner.labelSelector);
|
|
3417
|
+
newHosts.push(...ips);
|
|
3418
|
+
}
|
|
3419
|
+
}
|
|
3420
|
+
for (const h of s.hosts) {
|
|
3421
|
+
if (h.startsWith("hetzner:")) {
|
|
3422
|
+
const rest = h.slice("hetzner:".length);
|
|
3423
|
+
if (rest.startsWith("label:")) {
|
|
3424
|
+
const selector = rest.slice("label:".length);
|
|
3425
|
+
const ips = await resolveLabelSelector(selector);
|
|
3426
|
+
newHosts.push(...ips);
|
|
3427
|
+
} else {
|
|
3428
|
+
const nameOrId = rest.startsWith("name:") ? rest.slice("name:".length) : rest;
|
|
3429
|
+
const ip = await resolveServerIp(nameOrId);
|
|
3430
|
+
newHosts.push(ip);
|
|
3431
|
+
}
|
|
3432
|
+
} else {
|
|
3433
|
+
newHosts.push(h);
|
|
3434
|
+
}
|
|
3435
|
+
}
|
|
3436
|
+
s.hosts = [...new Set(newHosts)];
|
|
3437
|
+
}
|
|
3438
|
+
for (const a of cfg.accessories) {
|
|
3439
|
+
if (a.host.startsWith("hetzner:")) {
|
|
3440
|
+
const rest = a.host.slice("hetzner:".length);
|
|
3441
|
+
const nameOrId = rest.startsWith("name:") ? rest.slice("name:".length) : rest;
|
|
3442
|
+
a.host = await resolveServerIp(nameOrId);
|
|
3443
|
+
}
|
|
3444
|
+
}
|
|
3445
|
+
}
|
|
2785
3446
|
|
|
2786
3447
|
// src/deploy/deploy.ts
|
|
2787
3448
|
async function deploy(loaded, opts = {}) {
|
|
2788
3449
|
const { config: cfg, env } = loaded;
|
|
3450
|
+
await resolveDynamicHosts(cfg, env);
|
|
2789
3451
|
const started = Date.now();
|
|
2790
3452
|
const services = selectServices(cfg, opts.onlyServices);
|
|
2791
3453
|
const targetHosts = selectHosts(cfg, services, opts.onlyHosts);
|
|
@@ -2837,11 +3499,11 @@ async function deploy(loaded, opts = {}) {
|
|
|
2837
3499
|
});
|
|
2838
3500
|
}
|
|
2839
3501
|
});
|
|
2840
|
-
if (cfg.cloudflare?.enabled && cfg.cloudflare.autoSync) {
|
|
3502
|
+
if (cfg.dns?.enabled && cfg.dns.autoSync || cfg.cloudflare?.enabled && cfg.cloudflare.autoSync) {
|
|
2841
3503
|
try {
|
|
2842
3504
|
await syncDns(cfg, { log: true });
|
|
2843
3505
|
} catch (e) {
|
|
2844
|
-
log.warn(`
|
|
3506
|
+
log.warn(`DNS sync: ${e instanceof Error ? e.message : String(e)}`);
|
|
2845
3507
|
}
|
|
2846
3508
|
}
|
|
2847
3509
|
if (!opts.skipHooks && cfg.hooks.postDeploy)
|
|
@@ -3103,6 +3765,7 @@ Options
|
|
|
3103
3765
|
async run(ctx) {
|
|
3104
3766
|
const loaded = ctx.load();
|
|
3105
3767
|
const cfg = loaded.config;
|
|
3768
|
+
await resolveDynamicHosts(cfg, loaded.env);
|
|
3106
3769
|
const only = ctx.values.host;
|
|
3107
3770
|
const names = allHosts(cfg).filter((h) => !only?.length || only.includes(h));
|
|
3108
3771
|
const hosts = names.map((h) => host(h, cfg.ssh));
|
|
@@ -3126,11 +3789,11 @@ Options
|
|
|
3126
3789
|
log.step("Starting the proxy");
|
|
3127
3790
|
await pool(proxyHosts(cfg).filter((h) => names.includes(h)).map((h) => host(h, cfg.ssh)), 4, (host) => ensureProxy(host, cfg, { secrets: loaded.env, force: true }));
|
|
3128
3791
|
}
|
|
3129
|
-
if (cfg.cloudflare?.enabled && cfg.cloudflare.autoSync) {
|
|
3792
|
+
if (cfg.dns?.enabled && cfg.dns.autoSync || cfg.cloudflare?.enabled && cfg.cloudflare.autoSync) {
|
|
3130
3793
|
try {
|
|
3131
3794
|
await syncDns(cfg, { log: true });
|
|
3132
3795
|
} catch (e) {
|
|
3133
|
-
log.warn(`
|
|
3796
|
+
log.warn(`DNS sync: ${e instanceof Error ? e.message : String(e)}`);
|
|
3134
3797
|
}
|
|
3135
3798
|
}
|
|
3136
3799
|
log.ok("servers are ready");
|
|
@@ -3286,7 +3949,8 @@ each server answers on.
|
|
|
3286
3949
|
Options
|
|
3287
3950
|
--json Machine readable output`,
|
|
3288
3951
|
async run(ctx) {
|
|
3289
|
-
const { config: cfg } = ctx.load();
|
|
3952
|
+
const { config: cfg, env } = ctx.load();
|
|
3953
|
+
await resolveDynamicHosts(cfg, env);
|
|
3290
3954
|
const names = allHosts(cfg);
|
|
3291
3955
|
const proxied = new Set(proxyHosts(cfg));
|
|
3292
3956
|
const report = await pool(names, 8, async (name) => {
|
|
@@ -3381,7 +4045,8 @@ Options
|
|
|
3381
4045
|
--grep <text> Only lines containing this
|
|
3382
4046
|
--since <time> docker --since value, e.g. 10m`,
|
|
3383
4047
|
async run(ctx) {
|
|
3384
|
-
const { config: cfg } = ctx.load();
|
|
4048
|
+
const { config: cfg, env } = ctx.load();
|
|
4049
|
+
await resolveDynamicHosts(cfg, env);
|
|
3385
4050
|
const lines = String(ctx.values.lines ?? "100");
|
|
3386
4051
|
const service = ctx.values.service;
|
|
3387
4052
|
const accessory = ctx.values.accessory;
|
|
@@ -3480,7 +4145,8 @@ Examples
|
|
|
3480
4145
|
epd exec --reuse -i -- sh
|
|
3481
4146
|
epd exec --accessory db -i -- psql -U blog`,
|
|
3482
4147
|
async run(ctx) {
|
|
3483
|
-
const { config: cfg } = ctx.load();
|
|
4148
|
+
const { config: cfg, env } = ctx.load();
|
|
4149
|
+
await resolveDynamicHosts(cfg, env);
|
|
3484
4150
|
const command = ctx.positionals.join(" ").trim();
|
|
3485
4151
|
if (!command)
|
|
3486
4152
|
throw new EpdError("nothing to run", "epd exec -- <command>");
|
|
@@ -3792,7 +4458,8 @@ var lock = {
|
|
|
3792
4458
|
epd takes a lock on every server while deploying so two deploys cannot overlap.
|
|
3793
4459
|
If a deploy was killed halfway, release it by hand.`,
|
|
3794
4460
|
async run(ctx) {
|
|
3795
|
-
const { config: cfg } = ctx.load();
|
|
4461
|
+
const { config: cfg, env } = ctx.load();
|
|
4462
|
+
await resolveDynamicHosts(cfg, env);
|
|
3796
4463
|
const hosts = allHosts(cfg).map((h) => host(h, cfg.ssh));
|
|
3797
4464
|
const sub = ctx.positionals[0] ?? "status";
|
|
3798
4465
|
if (sub === "release") {
|
|
@@ -3823,7 +4490,8 @@ Options
|
|
|
3823
4490
|
--keep-data Leave ${"{remote_root}"}/apps/<app> in place (releases, env files)
|
|
3824
4491
|
--host <ip> Only this host`,
|
|
3825
4492
|
async run(ctx) {
|
|
3826
|
-
const { config: cfg } = ctx.load();
|
|
4493
|
+
const { config: cfg, env } = ctx.load();
|
|
4494
|
+
await resolveDynamicHosts(cfg, env);
|
|
3827
4495
|
const only = ctx.values.host;
|
|
3828
4496
|
const names = allHosts(cfg).filter((h) => !only?.length || only.includes(h));
|
|
3829
4497
|
if (!ctx.values.yes) {
|
|
@@ -4082,6 +4750,574 @@ ${c.bold(domain)}: ${c.red(e instanceof Error ? e.message : String(e))}`);
|
|
|
4082
4750
|
}
|
|
4083
4751
|
};
|
|
4084
4752
|
|
|
4753
|
+
// src/commands/dns.ts
|
|
4754
|
+
var dns3 = {
|
|
4755
|
+
name: "dns",
|
|
4756
|
+
summary: "Manage DNS records across Cloudflare, Hetzner, or custom providers",
|
|
4757
|
+
options: {
|
|
4758
|
+
"dry-run": { type: "boolean" },
|
|
4759
|
+
proxied: { type: "boolean" },
|
|
4760
|
+
"no-proxied": { type: "boolean" },
|
|
4761
|
+
provider: { type: "string" }
|
|
4762
|
+
},
|
|
4763
|
+
help: () => `${c.bold("epd dns")} \u2014 Unified DNS management (Cloudflare & Hetzner DNS)
|
|
4764
|
+
|
|
4765
|
+
Commands
|
|
4766
|
+
epd dns [sync] Sync domain A/AAAA records to target server IPs
|
|
4767
|
+
epd dns status Show current DNS status for app domains
|
|
4768
|
+
|
|
4769
|
+
Options
|
|
4770
|
+
--dry-run Preview DNS changes without applying them
|
|
4771
|
+
--proxied Force proxied mode (Cloudflare only)
|
|
4772
|
+
--no-proxied Force DNS-only mode
|
|
4773
|
+
--provider <cloudflare|hetzner> Override DNS provider
|
|
4774
|
+
-c, --config <file> Path to epd.yml
|
|
4775
|
+
-d, --destination <d> Overlay epd.<d>.yml
|
|
4776
|
+
|
|
4777
|
+
Environment
|
|
4778
|
+
CLOUDFLARE_API_TOKEN Cloudflare API Token
|
|
4779
|
+
HETZNER_DNS_API_TOKEN Hetzner DNS API Token (Auth-API-Token)`,
|
|
4780
|
+
async run(ctx) {
|
|
4781
|
+
const loaded = ctx.load();
|
|
4782
|
+
const cfg = loaded.config;
|
|
4783
|
+
await resolveDynamicHosts(cfg, loaded.env);
|
|
4784
|
+
const sub = ctx.positionals[0] || "sync";
|
|
4785
|
+
const action = ctx.positionals[1] || (sub === "status" ? "status" : "sync");
|
|
4786
|
+
const providerName = ctx.values.provider || cfg.dns?.provider || (cfg.cloudflare ? "cloudflare" : undefined) || (process.env.CLOUDFLARE_API_TOKEN || process.env.CF_DNS_API_TOKEN ? "cloudflare" : undefined) || (process.env.HETZNER_DNS_API_TOKEN || process.env.HETZNER_DNS_TOKEN ? "hetzner" : undefined) || "cloudflare";
|
|
4787
|
+
let provider;
|
|
4788
|
+
if (providerName === "cloudflare") {
|
|
4789
|
+
const token = cfg.dns?.apiToken || cfg.cloudflare?.apiToken || process.env.CLOUDFLARE_API_TOKEN || process.env.CF_DNS_API_TOKEN;
|
|
4790
|
+
if (!token) {
|
|
4791
|
+
throw new EpdError("Cloudflare API token is missing", "Set CLOUDFLARE_API_TOKEN in environment or add it to epd.yml under dns or cloudflare.");
|
|
4792
|
+
}
|
|
4793
|
+
provider = new CloudflareClient(token);
|
|
4794
|
+
} else if (providerName === "hetzner") {
|
|
4795
|
+
const token = cfg.dns?.apiToken || process.env.HETZNER_DNS_API_TOKEN || process.env.HETZNER_DNS_TOKEN;
|
|
4796
|
+
if (!token) {
|
|
4797
|
+
throw new EpdError("Hetzner DNS API token is missing", "Set HETZNER_DNS_API_TOKEN in environment or add it to epd.yml under dns.api_token.");
|
|
4798
|
+
}
|
|
4799
|
+
provider = new HetznerDnsClient(token);
|
|
4800
|
+
} else {
|
|
4801
|
+
throw new EpdError(`Unknown DNS provider: ${providerName}`, "Supported providers: cloudflare, hetzner");
|
|
4802
|
+
}
|
|
4803
|
+
const domains = getRouteDomains(cfg);
|
|
4804
|
+
if (!domains.length) {
|
|
4805
|
+
log.warn("No domains found in service routes. Add domains to your routes or configure dns.domains in epd.yml.");
|
|
4806
|
+
return;
|
|
4807
|
+
}
|
|
4808
|
+
const routedHosts = new Set;
|
|
4809
|
+
for (const svc of cfg.services) {
|
|
4810
|
+
if (svc.routes.length) {
|
|
4811
|
+
for (const h of svc.hosts)
|
|
4812
|
+
routedHosts.add(h);
|
|
4813
|
+
}
|
|
4814
|
+
}
|
|
4815
|
+
const ips = new Set;
|
|
4816
|
+
for (const h of routedHosts) {
|
|
4817
|
+
const resolved = await resolveHostIps(h);
|
|
4818
|
+
for (const ip of resolved)
|
|
4819
|
+
ips.add(ip);
|
|
4820
|
+
}
|
|
4821
|
+
if (sub === "status" || action === "status") {
|
|
4822
|
+
log.step(`Checking ${c.bold(provider.name)} DNS status for ${c.bold(cfg.name)} (${domains.length} domain(s))`);
|
|
4823
|
+
console.log(`
|
|
4824
|
+
${c.bold("Configured Server IPs:")} ${[...ips].join(", ") || "none"}`);
|
|
4825
|
+
const explicitZoneId = cfg.dns?.zoneId ?? cfg.cloudflare?.zoneId;
|
|
4826
|
+
for (const domain of domains) {
|
|
4827
|
+
try {
|
|
4828
|
+
const zone = await provider.findZoneForDomain(domain, explicitZoneId);
|
|
4829
|
+
const records = await provider.listDnsRecords(zone.id, domain);
|
|
4830
|
+
console.log(`
|
|
4831
|
+
${c.bold(domain)} (Zone: ${zone.name} [${zone.id}])`);
|
|
4832
|
+
if (!records.length) {
|
|
4833
|
+
console.log(` ${c.yellow("! No DNS records found for this domain")}`);
|
|
4834
|
+
} else {
|
|
4835
|
+
for (const r of records) {
|
|
4836
|
+
const matchesServer = ips.has(r.content);
|
|
4837
|
+
const statusTag = matchesServer ? c.green("\u2713 points to server") : c.yellow("! points elsewhere");
|
|
4838
|
+
const proxyTag = r.proxied ? c.cyan("[proxied (CDN)]") : c.gray("[DNS only]");
|
|
4839
|
+
console.log(` \u2022 ${r.type.padEnd(4)} ${r.content.padEnd(20)} ${proxyTag.padEnd(18)} ${statusTag}`);
|
|
4840
|
+
}
|
|
4841
|
+
}
|
|
4842
|
+
} catch (e) {
|
|
4843
|
+
console.log(`
|
|
4844
|
+
${c.bold(domain)}: ${c.red(e instanceof Error ? e.message : String(e))}`);
|
|
4845
|
+
}
|
|
4846
|
+
}
|
|
4847
|
+
console.log("");
|
|
4848
|
+
return;
|
|
4849
|
+
}
|
|
4850
|
+
let proxied = undefined;
|
|
4851
|
+
if (ctx.values.proxied === true)
|
|
4852
|
+
proxied = true;
|
|
4853
|
+
if (ctx.values["no-proxied"] === true || ctx.values.proxied === false)
|
|
4854
|
+
proxied = false;
|
|
4855
|
+
const dryRun = Boolean(ctx.values["dry-run"]);
|
|
4856
|
+
if (dryRun)
|
|
4857
|
+
log.step(`Previewing ${provider.name} DNS changes (dry-run)`);
|
|
4858
|
+
const results = await syncDns(cfg, {
|
|
4859
|
+
dryRun,
|
|
4860
|
+
log: true,
|
|
4861
|
+
provider,
|
|
4862
|
+
proxied
|
|
4863
|
+
});
|
|
4864
|
+
const created = results.filter((r) => r.action === "created").length;
|
|
4865
|
+
const updated = results.filter((r) => r.action === "updated").length;
|
|
4866
|
+
const unchanged = results.filter((r) => r.action === "unchanged").length;
|
|
4867
|
+
log.ok(`DNS sync finished: ${created} created, ${updated} updated, ${unchanged} unchanged`);
|
|
4868
|
+
}
|
|
4869
|
+
};
|
|
4870
|
+
|
|
4871
|
+
// src/commands/hetzner.ts
|
|
4872
|
+
var hetzner = {
|
|
4873
|
+
name: "hetzner",
|
|
4874
|
+
aliases: ["hcloud"],
|
|
4875
|
+
summary: "Manage Hetzner Cloud servers and deploy targets",
|
|
4876
|
+
options: {
|
|
4877
|
+
type: { type: "string" },
|
|
4878
|
+
location: { type: "string" },
|
|
4879
|
+
image: { type: "string" },
|
|
4880
|
+
"ssh-key": { type: "string" },
|
|
4881
|
+
label: { type: "string", multiple: true },
|
|
4882
|
+
setup: { type: "boolean" },
|
|
4883
|
+
yes: { type: "boolean", short: "y" }
|
|
4884
|
+
},
|
|
4885
|
+
help: () => `${c.bold("epd hetzner")} \u2014 Hetzner Cloud server management and provisioning
|
|
4886
|
+
|
|
4887
|
+
Commands
|
|
4888
|
+
epd hetzner list List all servers in your Hetzner Cloud project
|
|
4889
|
+
epd hetzner create <name> Create and provision a new server
|
|
4890
|
+
epd hetzner delete <name|id> Delete a cloud server
|
|
4891
|
+
epd hetzner types List available server types and pricing
|
|
4892
|
+
epd hetzner locations List available datacenter locations
|
|
4893
|
+
|
|
4894
|
+
Create options
|
|
4895
|
+
--type <type> Server type (default: cx22)
|
|
4896
|
+
--location <loc> Location: fsn1 (Falkenstein), nbg1, hel1, ash, hil (default: fsn1)
|
|
4897
|
+
--image <os> OS image (default: ubuntu-24.04)
|
|
4898
|
+
--ssh-key <name|id> Hetzner SSH key name or ID to attach
|
|
4899
|
+
--label <k=v> Labels to attach to the server (repeatable)
|
|
4900
|
+
--setup Automatically run "epd setup" once the server is ready
|
|
4901
|
+
|
|
4902
|
+
Environment
|
|
4903
|
+
HETZNER_API_TOKEN / HCLOUD_TOKEN Hetzner Cloud API token (Read/Write)`,
|
|
4904
|
+
async run(ctx) {
|
|
4905
|
+
let token;
|
|
4906
|
+
let projectName;
|
|
4907
|
+
try {
|
|
4908
|
+
const loaded = ctx.load();
|
|
4909
|
+
token = loaded.config.hetzner?.apiToken || loaded.env.HETZNER_API_TOKEN || loaded.env.HCLOUD_TOKEN;
|
|
4910
|
+
projectName = loaded.config.name;
|
|
4911
|
+
} catch {}
|
|
4912
|
+
token = token || process.env.HETZNER_API_TOKEN || process.env.HCLOUD_TOKEN;
|
|
4913
|
+
if (!token) {
|
|
4914
|
+
throw new EpdError("Hetzner Cloud API token is missing", "Set HETZNER_API_TOKEN or HCLOUD_TOKEN in your environment, or configure `hetzner.api_token` in epd.yml.");
|
|
4915
|
+
}
|
|
4916
|
+
const client = new HetznerCloudClient(token);
|
|
4917
|
+
const sub = ctx.positionals[0] || "list";
|
|
4918
|
+
if (sub === "list" || sub === "ls") {
|
|
4919
|
+
log.step("Fetching Hetzner Cloud servers...");
|
|
4920
|
+
const servers = await client.listServers();
|
|
4921
|
+
if (!servers.length) {
|
|
4922
|
+
log.info("No servers found in this Hetzner Cloud project.");
|
|
4923
|
+
console.log(`
|
|
4924
|
+
Run ${c.cyan("epd hetzner create <name>")} to spin up a new server.
|
|
4925
|
+
`);
|
|
4926
|
+
return;
|
|
4927
|
+
}
|
|
4928
|
+
console.log(`
|
|
4929
|
+
${c.bold("HETZNER CLOUD SERVERS")} (${servers.length})
|
|
4930
|
+
`);
|
|
4931
|
+
const headers = ["ID", "NAME", "STATUS", "IPV4", "TYPE", "DATACENTER", "LABELS"];
|
|
4932
|
+
const rows = servers.map((s) => {
|
|
4933
|
+
let statusStr = s.status;
|
|
4934
|
+
if (s.status === "running")
|
|
4935
|
+
statusStr = c.green(s.status);
|
|
4936
|
+
else if (s.status === "initializing" || s.status === "starting")
|
|
4937
|
+
statusStr = c.yellow(s.status);
|
|
4938
|
+
else
|
|
4939
|
+
statusStr = c.gray(s.status);
|
|
4940
|
+
const labelsStr = Object.entries(s.labels).map(([k, v]) => `${k}=${v}`).join(",");
|
|
4941
|
+
return [
|
|
4942
|
+
String(s.id),
|
|
4943
|
+
s.name,
|
|
4944
|
+
statusStr,
|
|
4945
|
+
s.publicNet.ipv4.ip || c.gray("none"),
|
|
4946
|
+
s.serverType.name,
|
|
4947
|
+
s.datacenter.name,
|
|
4948
|
+
labelsStr ? c.gray(labelsStr) : "-"
|
|
4949
|
+
];
|
|
4950
|
+
});
|
|
4951
|
+
const colWidths = headers.map((h, i) => {
|
|
4952
|
+
const rowMax = rows.reduce((max, r) => Math.max(max, (r[i] || "").replace(/\x1b\[[0-9;]*m/g, "").length), 0);
|
|
4953
|
+
return Math.max(h.length, rowMax);
|
|
4954
|
+
});
|
|
4955
|
+
const headerLine = headers.map((h, i) => c.bold(h.padEnd(colWidths[i]))).join(" ");
|
|
4956
|
+
console.log(headerLine);
|
|
4957
|
+
console.log(c.gray("\u2014".repeat(headerLine.length)));
|
|
4958
|
+
for (const r of rows) {
|
|
4959
|
+
const line = r.map((cell, i) => {
|
|
4960
|
+
const rawLen = cell.replace(/\x1b\[[0-9;]*m/g, "").length;
|
|
4961
|
+
const pad = " ".repeat(Math.max(0, colWidths[i] - rawLen));
|
|
4962
|
+
return cell + pad;
|
|
4963
|
+
}).join(" ");
|
|
4964
|
+
console.log(line);
|
|
4965
|
+
}
|
|
4966
|
+
console.log("");
|
|
4967
|
+
return;
|
|
4968
|
+
}
|
|
4969
|
+
if (sub === "create") {
|
|
4970
|
+
const serverName = ctx.positionals[1];
|
|
4971
|
+
if (!serverName) {
|
|
4972
|
+
throw new EpdError("Server name is required", "Usage: epd hetzner create <name> [--type cx22] [--location fsn1] [--image ubuntu-24.04]");
|
|
4973
|
+
}
|
|
4974
|
+
const serverType = ctx.values.type || "cx22";
|
|
4975
|
+
const location = ctx.values.location || "fsn1";
|
|
4976
|
+
const image = ctx.values.image || "ubuntu-24.04";
|
|
4977
|
+
const labels = {
|
|
4978
|
+
managed_by: "epd"
|
|
4979
|
+
};
|
|
4980
|
+
if (projectName)
|
|
4981
|
+
labels.app = projectName;
|
|
4982
|
+
const userLabels = ctx.values.label ?? [];
|
|
4983
|
+
for (const l of userLabels) {
|
|
4984
|
+
const [k, v] = l.split("=");
|
|
4985
|
+
if (k && v !== undefined)
|
|
4986
|
+
labels[k] = v;
|
|
4987
|
+
}
|
|
4988
|
+
let sshKeys = undefined;
|
|
4989
|
+
const explicitKey = ctx.values["ssh-key"];
|
|
4990
|
+
if (explicitKey) {
|
|
4991
|
+
sshKeys = [explicitKey];
|
|
4992
|
+
} else {
|
|
4993
|
+
try {
|
|
4994
|
+
const keys = await client.listSshKeys();
|
|
4995
|
+
if (keys.length > 0) {
|
|
4996
|
+
sshKeys = keys.map((k) => k.id);
|
|
4997
|
+
log.info(`Attaching ${keys.length} Hetzner project SSH key(s): ${keys.map((k) => k.name).join(", ")}`);
|
|
4998
|
+
}
|
|
4999
|
+
} catch {}
|
|
5000
|
+
}
|
|
5001
|
+
log.step(`Creating Hetzner server ${c.bold(serverName)} (${serverType}, ${location}, ${image})...`);
|
|
5002
|
+
const res = await client.createServer({
|
|
5003
|
+
name: serverName,
|
|
5004
|
+
serverType,
|
|
5005
|
+
location,
|
|
5006
|
+
image,
|
|
5007
|
+
sshKeys,
|
|
5008
|
+
labels
|
|
5009
|
+
});
|
|
5010
|
+
log.step(`Waiting for server ${c.bold(serverName)} to become active...`);
|
|
5011
|
+
const readyServer = await client.waitForServerRunning(res.server.id);
|
|
5012
|
+
const ip = readyServer.publicNet.ipv4.ip;
|
|
5013
|
+
log.ok(`Server created successfully!`);
|
|
5014
|
+
console.log(`
|
|
5015
|
+
${c.bold("Name:")} ${readyServer.name}`);
|
|
5016
|
+
console.log(` ${c.bold("ID:")} ${readyServer.id}`);
|
|
5017
|
+
console.log(` ${c.bold("Public IPv4:")} ${c.green(c.bold(ip))}`);
|
|
5018
|
+
if (readyServer.publicNet.ipv6?.ip) {
|
|
5019
|
+
console.log(` ${c.bold("Public IPv6:")} ${readyServer.publicNet.ipv6.ip}`);
|
|
5020
|
+
}
|
|
5021
|
+
console.log(` ${c.bold("Location:")} ${readyServer.datacenter.location.city} (${readyServer.datacenter.name})`);
|
|
5022
|
+
if (res.rootPassword) {
|
|
5023
|
+
console.log(` ${c.bold("Root Password:")} ${c.yellow(res.rootPassword)}`);
|
|
5024
|
+
}
|
|
5025
|
+
console.log("");
|
|
5026
|
+
if (ctx.values.setup) {
|
|
5027
|
+
log.step(`Running "epd setup" on newly created server ${ip}...`);
|
|
5028
|
+
await setup.run({
|
|
5029
|
+
...ctx,
|
|
5030
|
+
values: {
|
|
5031
|
+
...ctx.values,
|
|
5032
|
+
host: [ip]
|
|
5033
|
+
}
|
|
5034
|
+
});
|
|
5035
|
+
} else {
|
|
5036
|
+
log.info(`To deploy to this server, add its IP to your epd.yml:`);
|
|
5037
|
+
console.log(` ${c.cyan(`servers: [${ip}]`)} or ${c.cyan(`servers: [hetzner:${readyServer.name}]`)}
|
|
5038
|
+
`);
|
|
5039
|
+
log.info(`Then run: ${c.cyan(`epd setup --host ${ip}`)}
|
|
5040
|
+
`);
|
|
5041
|
+
}
|
|
5042
|
+
return;
|
|
5043
|
+
}
|
|
5044
|
+
if (sub === "delete" || sub === "rm") {
|
|
5045
|
+
const target = ctx.positionals[1];
|
|
5046
|
+
if (!target) {
|
|
5047
|
+
throw new EpdError("Server name or ID is required", "Usage: epd hetzner delete <name|id>");
|
|
5048
|
+
}
|
|
5049
|
+
const server = await client.getServer(target);
|
|
5050
|
+
if (!server) {
|
|
5051
|
+
throw new EpdError(`Hetzner server "${target}" not found.`);
|
|
5052
|
+
}
|
|
5053
|
+
const confirm = Boolean(ctx.values.yes);
|
|
5054
|
+
if (!confirm) {
|
|
5055
|
+
process.stdout.write(`Are you sure you want to permanently delete server ${c.bold(server.name)} (${server.publicNet.ipv4.ip || server.id})? [y/N]: `);
|
|
5056
|
+
for await (const line of console) {
|
|
5057
|
+
if (!line.trim().toLowerCase().startsWith("y")) {
|
|
5058
|
+
log.info("Aborted.");
|
|
5059
|
+
return;
|
|
5060
|
+
}
|
|
5061
|
+
break;
|
|
5062
|
+
}
|
|
5063
|
+
}
|
|
5064
|
+
log.step(`Deleting server ${c.bold(server.name)} [ID: ${server.id}]...`);
|
|
5065
|
+
await client.deleteServer(server.id);
|
|
5066
|
+
log.ok(`Server ${server.name} deleted.`);
|
|
5067
|
+
return;
|
|
5068
|
+
}
|
|
5069
|
+
if (sub === "types") {
|
|
5070
|
+
log.step("Fetching available Hetzner server types...");
|
|
5071
|
+
const types = await client.listServerTypes();
|
|
5072
|
+
console.log(`
|
|
5073
|
+
${c.bold("AVAILABLE HETZNER SERVER TYPES")}
|
|
5074
|
+
`);
|
|
5075
|
+
const headers = ["NAME", "VCPU", "RAM (GB)", "DISK (GB)", "ARCH", "EUR/MO"];
|
|
5076
|
+
const rows = types.map((t) => {
|
|
5077
|
+
const price = t.prices?.[0]?.priceMonthly?.net ? `\u20AC${Number(t.prices[0].priceMonthly.net).toFixed(2)}` : "-";
|
|
5078
|
+
return [t.name, String(t.cores), String(t.memory), `${t.disk} GB`, t.architecture, price];
|
|
5079
|
+
});
|
|
5080
|
+
const colWidths = headers.map((h, i) => {
|
|
5081
|
+
const rowMax = rows.reduce((max, r) => Math.max(max, (r[i] || "").length), 0);
|
|
5082
|
+
return Math.max(h.length, rowMax);
|
|
5083
|
+
});
|
|
5084
|
+
const headerLine = headers.map((h, i) => c.bold(h.padEnd(colWidths[i]))).join(" ");
|
|
5085
|
+
console.log(headerLine);
|
|
5086
|
+
console.log(c.gray("\u2014".repeat(headerLine.length)));
|
|
5087
|
+
for (const r of rows) {
|
|
5088
|
+
console.log(r.map((cell, i) => cell.padEnd(colWidths[i])).join(" "));
|
|
5089
|
+
}
|
|
5090
|
+
console.log("");
|
|
5091
|
+
return;
|
|
5092
|
+
}
|
|
5093
|
+
if (sub === "locations") {
|
|
5094
|
+
log.step("Fetching Hetzner locations...");
|
|
5095
|
+
const locations = await client.listLocations();
|
|
5096
|
+
console.log(`
|
|
5097
|
+
${c.bold("HETZNER DATACENTER LOCATIONS")}
|
|
5098
|
+
`);
|
|
5099
|
+
const headers = ["CODE", "CITY", "COUNTRY", "ZONE"];
|
|
5100
|
+
const rows = locations.map((l) => [l.name, l.city, l.country, l.networkZone]);
|
|
5101
|
+
const colWidths = headers.map((h, i) => {
|
|
5102
|
+
const rowMax = rows.reduce((max, r) => Math.max(max, (r[i] || "").length), 0);
|
|
5103
|
+
return Math.max(h.length, rowMax);
|
|
5104
|
+
});
|
|
5105
|
+
const headerLine = headers.map((h, i) => c.bold(h.padEnd(colWidths[i]))).join(" ");
|
|
5106
|
+
console.log(headerLine);
|
|
5107
|
+
console.log(c.gray("\u2014".repeat(headerLine.length)));
|
|
5108
|
+
for (const r of rows) {
|
|
5109
|
+
console.log(r.map((cell, i) => cell.padEnd(colWidths[i])).join(" "));
|
|
5110
|
+
}
|
|
5111
|
+
console.log("");
|
|
5112
|
+
return;
|
|
5113
|
+
}
|
|
5114
|
+
throw new EpdError(`Unknown hetzner subcommand "${sub}"`, "Available subcommands: list, create, delete, types, locations");
|
|
5115
|
+
}
|
|
5116
|
+
};
|
|
5117
|
+
|
|
5118
|
+
// src/core/update.ts
|
|
5119
|
+
import { chmodSync, existsSync as existsSync5, mkdirSync as mkdirSync3, readFileSync as readFileSync3, renameSync, writeFileSync as writeFileSync2 } from "fs";
|
|
5120
|
+
import { homedir as homedir2 } from "os";
|
|
5121
|
+
import { dirname as dirname2, join as join6 } from "path";
|
|
5122
|
+
function parseSemver(v) {
|
|
5123
|
+
const clean = v.replace(/^v/, "").trim();
|
|
5124
|
+
const parts = clean.split("-")[0].split(".").map((n) => Number(n) || 0);
|
|
5125
|
+
return [parts[0] || 0, parts[1] || 0, parts[2] || 0];
|
|
5126
|
+
}
|
|
5127
|
+
function isNewer(current, latest) {
|
|
5128
|
+
const [cMaj, cMin, cPatch] = parseSemver(current);
|
|
5129
|
+
const [lMaj, lMin, lPatch] = parseSemver(latest);
|
|
5130
|
+
if (lMaj > cMaj)
|
|
5131
|
+
return true;
|
|
5132
|
+
if (lMaj < cMaj)
|
|
5133
|
+
return false;
|
|
5134
|
+
if (lMin > cMin)
|
|
5135
|
+
return true;
|
|
5136
|
+
if (lMin < cMin)
|
|
5137
|
+
return false;
|
|
5138
|
+
return lPatch > cPatch;
|
|
5139
|
+
}
|
|
5140
|
+
function getCachePath() {
|
|
5141
|
+
return join6(homedir2(), ".epd", "update-check.json");
|
|
5142
|
+
}
|
|
5143
|
+
function readCache() {
|
|
5144
|
+
try {
|
|
5145
|
+
const p = getCachePath();
|
|
5146
|
+
if (existsSync5(p)) {
|
|
5147
|
+
return JSON.parse(readFileSync3(p, "utf8"));
|
|
5148
|
+
}
|
|
5149
|
+
} catch {}
|
|
5150
|
+
return null;
|
|
5151
|
+
}
|
|
5152
|
+
function writeCache(latestVersion) {
|
|
5153
|
+
try {
|
|
5154
|
+
const p = getCachePath();
|
|
5155
|
+
mkdirSync3(dirname2(p), { recursive: true });
|
|
5156
|
+
const data = { lastChecked: Date.now(), latestVersion };
|
|
5157
|
+
writeFileSync2(p, JSON.stringify(data));
|
|
5158
|
+
} catch {}
|
|
5159
|
+
}
|
|
5160
|
+
async function fetchLatestNpmVersion() {
|
|
5161
|
+
try {
|
|
5162
|
+
const res = await fetch("https://registry.npmjs.org/@fabioplunser/epd/latest", {
|
|
5163
|
+
headers: { Accept: "application/json" },
|
|
5164
|
+
signal: AbortSignal.timeout(2500)
|
|
5165
|
+
});
|
|
5166
|
+
if (!res.ok)
|
|
5167
|
+
return null;
|
|
5168
|
+
const data = await res.json();
|
|
5169
|
+
return typeof data?.version === "string" ? data.version : null;
|
|
5170
|
+
} catch {
|
|
5171
|
+
return null;
|
|
5172
|
+
}
|
|
5173
|
+
}
|
|
5174
|
+
async function checkForUpdate(currentVersion, options = {}) {
|
|
5175
|
+
const cache = readCache();
|
|
5176
|
+
const cacheTtlMs = 4 * 60 * 60 * 1000;
|
|
5177
|
+
if (!options.force && cache && Date.now() - cache.lastChecked < cacheTtlMs) {
|
|
5178
|
+
const hasUpdate = isNewer(currentVersion, cache.latestVersion);
|
|
5179
|
+
return { hasUpdate, latestVersion: cache.latestVersion };
|
|
5180
|
+
}
|
|
5181
|
+
const remote = await fetchLatestNpmVersion();
|
|
5182
|
+
if (remote) {
|
|
5183
|
+
writeCache(remote);
|
|
5184
|
+
return {
|
|
5185
|
+
hasUpdate: isNewer(currentVersion, remote),
|
|
5186
|
+
latestVersion: remote
|
|
5187
|
+
};
|
|
5188
|
+
}
|
|
5189
|
+
if (cache) {
|
|
5190
|
+
return {
|
|
5191
|
+
hasUpdate: isNewer(currentVersion, cache.latestVersion),
|
|
5192
|
+
latestVersion: cache.latestVersion
|
|
5193
|
+
};
|
|
5194
|
+
}
|
|
5195
|
+
return { hasUpdate: false, latestVersion: currentVersion };
|
|
5196
|
+
}
|
|
5197
|
+
async function performUpdate(targetVersion) {
|
|
5198
|
+
const isBun = typeof process.isBun !== "undefined";
|
|
5199
|
+
const execPath = process.execPath || "";
|
|
5200
|
+
const isCompiledBinary = isBun && !execPath.endsWith("bun");
|
|
5201
|
+
if (isCompiledBinary) {
|
|
5202
|
+
try {
|
|
5203
|
+
const platform = process.platform;
|
|
5204
|
+
const arch = process.arch;
|
|
5205
|
+
let binaryName = "";
|
|
5206
|
+
if (platform === "linux" && arch === "x64")
|
|
5207
|
+
binaryName = "epd-linux-x64";
|
|
5208
|
+
else if (platform === "linux" && arch === "arm64")
|
|
5209
|
+
binaryName = "epd-linux-arm64";
|
|
5210
|
+
else if (platform === "darwin" && arch === "x64")
|
|
5211
|
+
binaryName = "epd-darwin-x64";
|
|
5212
|
+
else if (platform === "darwin" && arch === "arm64")
|
|
5213
|
+
binaryName = "epd-darwin-arm64";
|
|
5214
|
+
else if (platform === "win32" && arch === "x64")
|
|
5215
|
+
binaryName = "epd-windows-x64.exe";
|
|
5216
|
+
if (binaryName) {
|
|
5217
|
+
log.step(`Downloading ${binaryName} from GitHub Releases...`);
|
|
5218
|
+
const url = `https://github.com/FabioPlunser/epd/releases/latest/download/${binaryName}`;
|
|
5219
|
+
const res = await fetch(url);
|
|
5220
|
+
if (!res.ok)
|
|
5221
|
+
throw new Error(`HTTP ${res.status} ${res.statusText}`);
|
|
5222
|
+
const buf = await res.arrayBuffer();
|
|
5223
|
+
const tmpPath = `${execPath}.tmp.${Date.now()}`;
|
|
5224
|
+
writeFileSync2(tmpPath, Buffer.from(buf));
|
|
5225
|
+
chmodSync(tmpPath, 493);
|
|
5226
|
+
renameSync(tmpPath, execPath);
|
|
5227
|
+
return true;
|
|
5228
|
+
}
|
|
5229
|
+
} catch (e) {
|
|
5230
|
+
log.debug(`Binary self-update failed, falling back to package manager: ${e}`);
|
|
5231
|
+
}
|
|
5232
|
+
}
|
|
5233
|
+
const isBunGlobal = (process.argv[1] || "").includes(".bun");
|
|
5234
|
+
const pkgMgr = isBunGlobal ? "bun" : "npm";
|
|
5235
|
+
const pkgSpec = targetVersion ? `@fabioplunser/epd@${targetVersion}` : "@fabioplunser/epd@latest";
|
|
5236
|
+
try {
|
|
5237
|
+
log.step(`Updating via ${pkgMgr}...`);
|
|
5238
|
+
const res = await runShell(`${pkgMgr} install -g ${pkgSpec}`, { stream: true, allowFailure: true });
|
|
5239
|
+
return res.code === 0;
|
|
5240
|
+
} catch {
|
|
5241
|
+
const fallback = pkgMgr === "bun" ? "npm" : "bun";
|
|
5242
|
+
try {
|
|
5243
|
+
log.step(`Trying ${fallback}...`);
|
|
5244
|
+
const res = await runShell(`${fallback} install -g ${pkgSpec}`, { stream: true, allowFailure: true });
|
|
5245
|
+
return res.code === 0;
|
|
5246
|
+
} catch {
|
|
5247
|
+
return false;
|
|
5248
|
+
}
|
|
5249
|
+
}
|
|
5250
|
+
}
|
|
5251
|
+
async function promptAutoUpdate(currentVersion) {
|
|
5252
|
+
if (!interactive() || process.env.CI || process.env.EPD_NO_UPDATE_CHECK === "1" || process.env.EPD_NO_UPDATE_CHECK === "true") {
|
|
5253
|
+
return false;
|
|
5254
|
+
}
|
|
5255
|
+
const { hasUpdate, latestVersion } = await checkForUpdate(currentVersion);
|
|
5256
|
+
if (!hasUpdate)
|
|
5257
|
+
return false;
|
|
5258
|
+
console.log("");
|
|
5259
|
+
log.info(`A new version of ${c.bold("epd")} is available: ${c.yellow(currentVersion)} \u2192 ${c.green(c.bold(latestVersion))}`);
|
|
5260
|
+
const shouldUpdate = await confirm("Would you like to update now?", false);
|
|
5261
|
+
if (!shouldUpdate) {
|
|
5262
|
+
console.log("");
|
|
5263
|
+
return false;
|
|
5264
|
+
}
|
|
5265
|
+
log.step(`Updating epd to v${latestVersion}...`);
|
|
5266
|
+
const success = await performUpdate(latestVersion);
|
|
5267
|
+
if (success) {
|
|
5268
|
+
log.ok(`Successfully updated epd to ${c.bold(`v${latestVersion}`)}!`);
|
|
5269
|
+
console.log("");
|
|
5270
|
+
return true;
|
|
5271
|
+
} else {
|
|
5272
|
+
log.warn(`Auto-update failed. You can update manually with:
|
|
5273
|
+
${c.cyan(`npm install -g @fabioplunser/epd@latest`)}
|
|
5274
|
+
`);
|
|
5275
|
+
return false;
|
|
5276
|
+
}
|
|
5277
|
+
}
|
|
5278
|
+
|
|
5279
|
+
// src/version.ts
|
|
5280
|
+
var VERSION = "0.3.1";
|
|
5281
|
+
|
|
5282
|
+
// src/commands/update.ts
|
|
5283
|
+
var update = {
|
|
5284
|
+
name: "update",
|
|
5285
|
+
aliases: ["upgrade"],
|
|
5286
|
+
summary: "Check for updates and upgrade epd to the latest version",
|
|
5287
|
+
options: {
|
|
5288
|
+
check: { type: "boolean" },
|
|
5289
|
+
yes: { type: "boolean", short: "y" }
|
|
5290
|
+
},
|
|
5291
|
+
help: () => `${c.bold("epd update")} \u2014 update epd to the latest release
|
|
5292
|
+
|
|
5293
|
+
Options
|
|
5294
|
+
--check Check for updates without installing
|
|
5295
|
+
-y, --yes Install update without prompting`,
|
|
5296
|
+
async run(ctx) {
|
|
5297
|
+
const currentVersion = VERSION;
|
|
5298
|
+
log.step(`Checking for epd updates (current: v${currentVersion})...`);
|
|
5299
|
+
const { hasUpdate, latestVersion } = await checkForUpdate(currentVersion, { force: true });
|
|
5300
|
+
if (!hasUpdate) {
|
|
5301
|
+
log.ok(`epd is up to date (${c.green(`v${currentVersion}`)}).`);
|
|
5302
|
+
return;
|
|
5303
|
+
}
|
|
5304
|
+
log.info(`A newer version is available: ${c.yellow(`v${currentVersion}`)} \u2192 ${c.green(c.bold(`v${latestVersion}`))}`);
|
|
5305
|
+
if (ctx.values.check) {
|
|
5306
|
+
log.info(`Run ${c.cyan("epd update")} to upgrade.`);
|
|
5307
|
+
return;
|
|
5308
|
+
}
|
|
5309
|
+
log.step(`Upgrading epd to v${latestVersion}...`);
|
|
5310
|
+
const success = await performUpdate(latestVersion);
|
|
5311
|
+
if (success) {
|
|
5312
|
+
log.ok(`epd updated successfully to ${c.bold(`v${latestVersion}`)}!`);
|
|
5313
|
+
} else {
|
|
5314
|
+
log.error(`Update failed. You can update manually with:`);
|
|
5315
|
+
console.log(` ${c.cyan("npm install -g @fabioplunser/epd@latest")}
|
|
5316
|
+
`);
|
|
5317
|
+
}
|
|
5318
|
+
}
|
|
5319
|
+
};
|
|
5320
|
+
|
|
4085
5321
|
// src/commands/index.ts
|
|
4086
5322
|
var commands = [
|
|
4087
5323
|
init,
|
|
@@ -4098,11 +5334,13 @@ var commands = [
|
|
|
4098
5334
|
lock,
|
|
4099
5335
|
remove,
|
|
4100
5336
|
dockerCommand,
|
|
4101
|
-
cloudflare
|
|
5337
|
+
cloudflare,
|
|
5338
|
+
dns3,
|
|
5339
|
+
hetzner,
|
|
5340
|
+
update
|
|
4102
5341
|
];
|
|
4103
5342
|
|
|
4104
5343
|
// src/cli.ts
|
|
4105
|
-
var VERSION = "0.2.0";
|
|
4106
5344
|
var USAGE = `${c.bold("epd")} \u2014 Easy Project Deployer ${c.gray(`v${VERSION}`)}
|
|
4107
5345
|
|
|
4108
5346
|
${c.bold("Usage")}
|
|
@@ -4182,6 +5420,9 @@ ${command.help()}`);
|
|
|
4182
5420
|
loadOptions,
|
|
4183
5421
|
load: () => loadConfig(loadOptions)
|
|
4184
5422
|
};
|
|
5423
|
+
if (command.name !== "update") {
|
|
5424
|
+
await promptAutoUpdate(VERSION);
|
|
5425
|
+
}
|
|
4185
5426
|
await command.run(ctx);
|
|
4186
5427
|
return 0;
|
|
4187
5428
|
}
|