@fabioplunser/epd 0.5.0 → 0.5.2
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 +3 -2
- package/dist/cli.js +181 -24
- package/docs/guide/installation.md +23 -0
- package/docs/reference/config.md +6 -0
- package/package.json +8 -3
package/README.md
CHANGED
|
@@ -139,14 +139,15 @@ build:
|
|
|
139
139
|
npm_token: NPM_TOKEN
|
|
140
140
|
|
|
141
141
|
ssh:
|
|
142
|
-
user: root
|
|
142
|
+
user: root # default login; a non-root user needs passwordless sudo
|
|
143
143
|
port: 22
|
|
144
144
|
key: ~/.ssh/id_ed25519
|
|
145
145
|
proxy_jump: bastion.example.com
|
|
146
146
|
|
|
147
147
|
servers:
|
|
148
148
|
web:
|
|
149
|
-
|
|
149
|
+
# "user@host" overrides ssh.user for that one server.
|
|
150
|
+
hosts: [203.0.113.10, deploy@203.0.113.11]
|
|
150
151
|
replicas: 2 # per host, load balanced by the proxy
|
|
151
152
|
port: 3000 # the port your app listens on
|
|
152
153
|
domains: [example.com, www.example.com]
|
package/dist/cli.js
CHANGED
|
@@ -205,6 +205,22 @@ function deepMerge(base, overlay) {
|
|
|
205
205
|
function fail(path, msg, hint) {
|
|
206
206
|
throw new EpdError(`${path}: ${msg}`, hint);
|
|
207
207
|
}
|
|
208
|
+
function takeHostUser(entry, path, users) {
|
|
209
|
+
const at = entry.lastIndexOf("@");
|
|
210
|
+
if (at < 0)
|
|
211
|
+
return entry;
|
|
212
|
+
const user = entry.slice(0, at);
|
|
213
|
+
const host = entry.slice(at + 1);
|
|
214
|
+
if (!user || !host) {
|
|
215
|
+
fail(path, `"${entry}" is not a valid host`, 'Write it as "user@host", e.g. "deploy@10.0.0.1".');
|
|
216
|
+
}
|
|
217
|
+
const seen = users[host];
|
|
218
|
+
if (seen && seen !== user) {
|
|
219
|
+
fail(path, `host ${host} is listed as both ${seen}@${host} and ${user}@${host}`, "Use one ssh user per host.");
|
|
220
|
+
}
|
|
221
|
+
users[host] = user;
|
|
222
|
+
return host;
|
|
223
|
+
}
|
|
208
224
|
function asString(v, path, dflt) {
|
|
209
225
|
if (v === undefined || v === null) {
|
|
210
226
|
if (dflt !== undefined)
|
|
@@ -523,6 +539,7 @@ function normalize(raw, configPath, root, destination) {
|
|
|
523
539
|
delay: 1
|
|
524
540
|
};
|
|
525
541
|
const rootHealth = parseHealth(raw.healthcheck ?? raw.health, "epd.yml.healthcheck", defaultHealth);
|
|
542
|
+
const hostUsers = {};
|
|
526
543
|
let servicesRaw = raw.services ?? raw.servers;
|
|
527
544
|
const inlineKeys = ["hosts", "host", "replicas", "port", "domain", "domains", "routes", "command", "labels", "volumes", "drain", "stop_timeout", "docker_options"];
|
|
528
545
|
const hasInline = inlineKeys.some((k) => raw[k] !== undefined);
|
|
@@ -590,7 +607,10 @@ function normalize(raw, configPath, root, destination) {
|
|
|
590
607
|
fail(`${p}.hetzner`, "expected a server name string or a mapping");
|
|
591
608
|
}
|
|
592
609
|
}
|
|
593
|
-
const hosts = [
|
|
610
|
+
const hosts = [
|
|
611
|
+
...asList(o.host, `${p}.host`).map((h) => takeHostUser(h, `${p}.host`, hostUsers)),
|
|
612
|
+
...asList(o.hosts, `${p}.hosts`).map((h) => takeHostUser(h, `${p}.hosts`, hostUsers))
|
|
613
|
+
];
|
|
594
614
|
if (!hosts.length && !svcHetzner)
|
|
595
615
|
fail(`${p}.hosts`, "at least one host is required");
|
|
596
616
|
const port = asNumber(o.port, `${p}.port`, asNumber(raw.port, "epd.yml.port", 3000));
|
|
@@ -638,7 +658,7 @@ function normalize(raw, configPath, root, destination) {
|
|
|
638
658
|
return {
|
|
639
659
|
name: accName,
|
|
640
660
|
image: asString(o.image, `${p}.image`),
|
|
641
|
-
host: asString(o.host, `${p}.host`),
|
|
661
|
+
host: takeHostUser(asString(o.host, `${p}.host`), `${p}.host`, hostUsers),
|
|
642
662
|
env: asDict(accEnvRaw?.clear ?? (accEnvRaw && !("clear" in accEnvRaw) && !("secret" in accEnvRaw) ? accEnvRaw : {}), `${p}.env`),
|
|
643
663
|
secrets: asList(accEnvRaw?.secret, `${p}.env.secret`),
|
|
644
664
|
volumes: asList(o.volumes, `${p}.volumes`),
|
|
@@ -665,7 +685,7 @@ function normalize(raw, configPath, root, destination) {
|
|
|
665
685
|
const buildRaw = raw.build ?? {};
|
|
666
686
|
checkKeys(buildRaw, ["dockerfile", "context", "platform", "target", "args", "secrets", "cache", "remote"], "epd.yml.build");
|
|
667
687
|
const sshRaw = raw.ssh ?? {};
|
|
668
|
-
checkKeys(sshRaw, ["user", "port", "key", "options", "proxy_jump", "control_persist"], "epd.yml.ssh");
|
|
688
|
+
checkKeys(sshRaw, ["user", "port", "key", "options", "proxy_jump", "control_persist", "sudo_password"], "epd.yml.ssh");
|
|
669
689
|
const procRaw = raw.process ?? {};
|
|
670
690
|
checkKeys(procRaw, ["exclude", "install", "build", "start", "path", "path_prepend", "source"], "epd.yml.process");
|
|
671
691
|
const processCfg = {
|
|
@@ -777,11 +797,13 @@ function normalize(raw, configPath, root, destination) {
|
|
|
777
797
|
},
|
|
778
798
|
ssh: {
|
|
779
799
|
user: asString(sshRaw.user, "epd.yml.ssh.user", "root"),
|
|
800
|
+
hostUsers,
|
|
780
801
|
port: asNumber(sshRaw.port, "epd.yml.ssh.port", 22),
|
|
781
802
|
key: sshRaw.key ? expandHome(asString(sshRaw.key, "epd.yml.ssh.key")) : undefined,
|
|
782
803
|
options: asList(sshRaw.options, "epd.yml.ssh.options"),
|
|
783
804
|
proxyJump: sshRaw.proxy_jump ? asString(sshRaw.proxy_jump, "epd.yml.ssh.proxy_jump") : undefined,
|
|
784
|
-
controlPersist: asString(sshRaw.control_persist, "epd.yml.ssh.control_persist", "60s")
|
|
805
|
+
controlPersist: asString(sshRaw.control_persist, "epd.yml.ssh.control_persist", "60s"),
|
|
806
|
+
sudoPassword: sshRaw.sudo_password ? asString(sshRaw.sudo_password, "epd.yml.ssh.sudo_password") : process.env.EPD_SUDO_PASSWORD || undefined
|
|
785
807
|
},
|
|
786
808
|
services,
|
|
787
809
|
proxy,
|
|
@@ -878,6 +900,28 @@ async function askSecret(question) {
|
|
|
878
900
|
const answer = (await readLine()).trim();
|
|
879
901
|
return answer;
|
|
880
902
|
}
|
|
903
|
+
async function askPassword(question) {
|
|
904
|
+
if (!isTTY)
|
|
905
|
+
return "";
|
|
906
|
+
process.stdout.write(`${c.cyan("?")} ${question} `);
|
|
907
|
+
const echo = await setEcho(false);
|
|
908
|
+
try {
|
|
909
|
+
return (await readLine()).trim();
|
|
910
|
+
} finally {
|
|
911
|
+
if (echo)
|
|
912
|
+
await setEcho(true);
|
|
913
|
+
process.stdout.write(`
|
|
914
|
+
`);
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
async function setEcho(on) {
|
|
918
|
+
try {
|
|
919
|
+
const proc = Bun.spawn(["stty", on ? "echo" : "-echo"], { stdin: "inherit", stdout: "inherit", stderr: "ignore" });
|
|
920
|
+
return await proc.exited === 0;
|
|
921
|
+
} catch {
|
|
922
|
+
return false;
|
|
923
|
+
}
|
|
924
|
+
}
|
|
881
925
|
async function pressEnter(message) {
|
|
882
926
|
if (!isTTY)
|
|
883
927
|
return;
|
|
@@ -957,6 +1001,25 @@ function saveGlobalAuth(updater) {
|
|
|
957
1001
|
chmodSync(file, 384);
|
|
958
1002
|
} catch {}
|
|
959
1003
|
}
|
|
1004
|
+
function isLinkDeclined(provider, root = process.cwd()) {
|
|
1005
|
+
return (getGlobalAuth().declined?.[provider] ?? []).includes(root);
|
|
1006
|
+
}
|
|
1007
|
+
function declineLink(provider, root = process.cwd()) {
|
|
1008
|
+
if (isLinkDeclined(provider, root))
|
|
1009
|
+
return;
|
|
1010
|
+
saveGlobalAuth((auth) => ({
|
|
1011
|
+
...auth,
|
|
1012
|
+
declined: { ...auth.declined, [provider]: [...auth.declined?.[provider] ?? [], root] }
|
|
1013
|
+
}));
|
|
1014
|
+
}
|
|
1015
|
+
function clearLinkDecline(provider, root = process.cwd()) {
|
|
1016
|
+
if (!isLinkDeclined(provider, root))
|
|
1017
|
+
return;
|
|
1018
|
+
saveGlobalAuth((auth) => ({
|
|
1019
|
+
...auth,
|
|
1020
|
+
declined: { ...auth.declined, [provider]: (auth.declined?.[provider] ?? []).filter((r) => r !== root) }
|
|
1021
|
+
}));
|
|
1022
|
+
}
|
|
960
1023
|
function saveProjectEnv(entries, root = process.cwd()) {
|
|
961
1024
|
const envPath = join2(root, ".env");
|
|
962
1025
|
let content = existsSync2(envPath) ? readFileSync2(envPath, "utf8") : "";
|
|
@@ -1085,6 +1148,7 @@ async function verifyHetznerToken(token) {
|
|
|
1085
1148
|
}
|
|
1086
1149
|
}
|
|
1087
1150
|
async function linkCloudflareInteractive(root = process.cwd()) {
|
|
1151
|
+
clearLinkDecline("cloudflare", root);
|
|
1088
1152
|
const url = "https://dash.cloudflare.com/profile/api-tokens";
|
|
1089
1153
|
console.log(`
|
|
1090
1154
|
${c.bold("Linking Cloudflare to EPD")}`);
|
|
@@ -1135,6 +1199,7 @@ ${c.bold("Linking Cloudflare to EPD")}`);
|
|
|
1135
1199
|
}
|
|
1136
1200
|
}
|
|
1137
1201
|
async function linkHetznerInteractive(root = process.cwd()) {
|
|
1202
|
+
clearLinkDecline("hetzner", root);
|
|
1138
1203
|
const url = "https://console.hetzner.cloud/";
|
|
1139
1204
|
console.log(`
|
|
1140
1205
|
${c.bold("Linking Hetzner Cloud to EPD")}`);
|
|
@@ -1568,6 +1633,15 @@ dns:
|
|
|
1568
1633
|
proxied: true
|
|
1569
1634
|
auto_sync: true
|
|
1570
1635
|
` : "";
|
|
1636
|
+
const sshBlock = `
|
|
1637
|
+
# How epd reaches your servers: plain ssh with your own key, no agent installed.
|
|
1638
|
+
# A non-root user needs passwordless sudo (epd escalates with "sudo -n").
|
|
1639
|
+
ssh:
|
|
1640
|
+
user: ${o.sshUser}
|
|
1641
|
+
# port: 22
|
|
1642
|
+
# key: ~/.ssh/id_ed25519
|
|
1643
|
+
# proxy_jump: bastion.example.com
|
|
1644
|
+
`;
|
|
1571
1645
|
const hetznerBlock = o.useHetzner ? `
|
|
1572
1646
|
# Hetzner Cloud integration (api_token resolved from ~/.config/epd/auth.json or HETZNER_API_TOKEN)
|
|
1573
1647
|
hetzner:
|
|
@@ -1588,8 +1662,9 @@ mode: ${o.mode}
|
|
|
1588
1662
|
${o.mode === "docker" ? `
|
|
1589
1663
|
# Image name. Tagged with the git sha of every deploy.
|
|
1590
1664
|
image: ${o.image ?? o.name}
|
|
1591
|
-
${registry}` : ""}${processBlock}${dnsBlock}${hetznerBlock}
|
|
1665
|
+
${registry}` : ""}${processBlock}${sshBlock}${dnsBlock}${hetznerBlock}
|
|
1592
1666
|
# One entry per group of processes. Add more (worker, cron, \u2026) as you need them.
|
|
1667
|
+
# A host may carry its own login \u2014 "deploy@203.0.113.10" overrides ssh.user.
|
|
1593
1668
|
servers:
|
|
1594
1669
|
web:
|
|
1595
1670
|
hosts: ${list(o.hosts)}
|
|
@@ -1709,6 +1784,7 @@ var init = {
|
|
|
1709
1784
|
domain: { type: "string", multiple: true },
|
|
1710
1785
|
port: { type: "string" },
|
|
1711
1786
|
email: { type: "string" },
|
|
1787
|
+
"ssh-user": { type: "string" },
|
|
1712
1788
|
replicas: { type: "string" },
|
|
1713
1789
|
force: { type: "boolean" },
|
|
1714
1790
|
dockerfile: { type: "boolean" },
|
|
@@ -1727,6 +1803,7 @@ Options
|
|
|
1727
1803
|
--domain <domain> Domain to serve (repeatable)
|
|
1728
1804
|
--port <port> Port your app listens on
|
|
1729
1805
|
--email <email> Contact address for Let's Encrypt
|
|
1806
|
+
--ssh-user <user> SSH login for the servers (default root)
|
|
1730
1807
|
--replicas <n> Replicas per host (default 1)
|
|
1731
1808
|
--dockerfile Also write a starter Dockerfile
|
|
1732
1809
|
--ci Also generate a GitHub Actions deploy workflow (.github/workflows/deploy.yml)
|
|
@@ -1835,6 +1912,7 @@ Options
|
|
|
1835
1912
|
const domains = (ctx.values.domain ?? []).length ? ctx.values.domain : (await ask("Domains to serve (comma separated)", defaultDomain)).split(",").map((s) => s.trim()).filter(Boolean);
|
|
1836
1913
|
const port = Number(ctx.values.port ?? await ask("Port your app listens on", String(detected.port)));
|
|
1837
1914
|
const email = ctx.values.email ?? await ask("Email for Let's Encrypt", "");
|
|
1915
|
+
const sshUser = ctx.values["ssh-user"] ?? await ask("SSH user for the server(s)", "root");
|
|
1838
1916
|
const replicas = Number(ctx.values.replicas ?? 1);
|
|
1839
1917
|
let registryUser;
|
|
1840
1918
|
let registryServer;
|
|
@@ -1847,6 +1925,7 @@ Options
|
|
|
1847
1925
|
writeFileSync2(target, template({
|
|
1848
1926
|
name,
|
|
1849
1927
|
mode,
|
|
1928
|
+
sshUser: sshUser || "root",
|
|
1850
1929
|
hosts,
|
|
1851
1930
|
domains,
|
|
1852
1931
|
port,
|
|
@@ -2193,15 +2272,58 @@ import { tmpdir } from "os";
|
|
|
2193
2272
|
import { join as join4 } from "path";
|
|
2194
2273
|
var controlDir = join4(tmpdir(), `epd-${process.getuid?.() ?? 0}`);
|
|
2195
2274
|
mkdirSync3(controlDir, { recursive: true, mode: 448 });
|
|
2275
|
+
var sudoPasswords = new Map;
|
|
2276
|
+
var promptQueue = Promise.resolve();
|
|
2277
|
+
function needsSudoPassword(res) {
|
|
2278
|
+
return /a password is required|no tty present|a terminal is required|incorrect password attempt|Sorry, try again/i.test(`${res.stderr}
|
|
2279
|
+
${res.stdout}`);
|
|
2280
|
+
}
|
|
2281
|
+
async function askSudoPassword(key, target) {
|
|
2282
|
+
const asked = promptQueue.then(async () => {
|
|
2283
|
+
const known = sudoPasswords.get(key);
|
|
2284
|
+
if (known !== undefined)
|
|
2285
|
+
return known;
|
|
2286
|
+
if (!interactive())
|
|
2287
|
+
return;
|
|
2288
|
+
const pw = await askPassword(`sudo password for ${target}:`);
|
|
2289
|
+
if (!pw)
|
|
2290
|
+
return;
|
|
2291
|
+
sudoPasswords.set(key, pw);
|
|
2292
|
+
return pw;
|
|
2293
|
+
});
|
|
2294
|
+
promptQueue = asked.catch(() => {
|
|
2295
|
+
return;
|
|
2296
|
+
});
|
|
2297
|
+
return asked;
|
|
2298
|
+
}
|
|
2299
|
+
function sshUserFor(name, cfg) {
|
|
2300
|
+
return cfg.hostUsers?.[name] ?? cfg.user;
|
|
2301
|
+
}
|
|
2196
2302
|
|
|
2197
2303
|
class Host {
|
|
2198
2304
|
name;
|
|
2305
|
+
user;
|
|
2199
2306
|
cfg;
|
|
2200
2307
|
sudo;
|
|
2201
2308
|
constructor(name, cfg) {
|
|
2202
2309
|
this.name = name;
|
|
2203
|
-
this.
|
|
2204
|
-
this.
|
|
2310
|
+
this.user = sshUserFor(name, cfg);
|
|
2311
|
+
this.cfg = this.user === cfg.user ? cfg : { ...cfg, user: this.user };
|
|
2312
|
+
this.sudo = this.user !== "root";
|
|
2313
|
+
const preset = cfg.sudoPassword || process.env.EPD_SUDO_PASSWORD;
|
|
2314
|
+
if (preset && !sudoPasswords.has(this.sudoKey))
|
|
2315
|
+
sudoPasswords.set(this.sudoKey, preset);
|
|
2316
|
+
}
|
|
2317
|
+
get sudoKey() {
|
|
2318
|
+
return `${this.user}@${this.name}:${this.cfg.port}`;
|
|
2319
|
+
}
|
|
2320
|
+
sudoHint() {
|
|
2321
|
+
return [
|
|
2322
|
+
`Give ${this.user} passwordless sudo on ${this.name}:`,
|
|
2323
|
+
` echo '${this.user} ALL=(ALL) NOPASSWD:ALL' | sudo tee /etc/sudoers.d/epd && sudo chmod 440 /etc/sudoers.d/epd`,
|
|
2324
|
+
"or set EPD_SUDO_PASSWORD (ssh.sudo_password in epd.yml), or deploy as root with ssh.user: root."
|
|
2325
|
+
].join(`
|
|
2326
|
+
`);
|
|
2205
2327
|
}
|
|
2206
2328
|
sshOptions() {
|
|
2207
2329
|
const socket = join4(controlDir, `${hash32(`${this.cfg.user}@${this.name}:${this.cfg.port}`).toString(36)}.sock`);
|
|
@@ -2248,14 +2370,22 @@ ${script}
|
|
|
2248
2370
|
log.debug(`${this.name}: ${script.split(`
|
|
2249
2371
|
`).filter(Boolean)[0] ?? ""}`);
|
|
2250
2372
|
const useSudo = opts.sudo ?? this.sudo;
|
|
2251
|
-
const
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2373
|
+
const label = opts.label ?? `${this.name}: ${script.split(`
|
|
2374
|
+
`).filter(Boolean)[0]}`;
|
|
2375
|
+
const known = sudoPasswords.get(this.sudoKey);
|
|
2376
|
+
let res = await this.ssh(body, useSudo, known, opts.stream, label);
|
|
2377
|
+
if (useSudo && res.code !== 0 && needsSudoPassword(res)) {
|
|
2378
|
+
if (known)
|
|
2379
|
+
sudoPasswords.delete(this.sudoKey);
|
|
2380
|
+
const pw = await askSudoPassword(this.sudoKey, this.target);
|
|
2381
|
+
if (pw)
|
|
2382
|
+
res = await this.ssh(body, true, pw, opts.stream, label);
|
|
2383
|
+
else if (!opts.allowFailure)
|
|
2384
|
+
throw new EpdError(`${this.name}: sudo needs a password for ${this.target}`, this.sudoHint());
|
|
2385
|
+
}
|
|
2386
|
+
if (useSudo && res.code !== 0 && needsSudoPassword(res) && !opts.allowFailure) {
|
|
2387
|
+
throw new EpdError(`${this.name}: sudo rejected the password for ${this.target}`, this.sudoHint());
|
|
2388
|
+
}
|
|
2259
2389
|
if (res.code !== 0 && !opts.allowFailure) {
|
|
2260
2390
|
const detail = [res.stdout, res.stderr].filter(Boolean).join(`
|
|
2261
2391
|
`).trim();
|
|
@@ -2263,6 +2393,16 @@ ${script}
|
|
|
2263
2393
|
}
|
|
2264
2394
|
return res;
|
|
2265
2395
|
}
|
|
2396
|
+
async ssh(body, useSudo, password, stream, label) {
|
|
2397
|
+
const remote = !useSudo ? ["bash", "-s"] : password ? ["sudo", "-S", "-p", "''", "bash", "-s"] : ["sudo", "-n", "bash", "-s"];
|
|
2398
|
+
return run(["ssh", ...this.sshOptions(), this.target, "--", ...remote], {
|
|
2399
|
+
input: useSudo && password ? `${password}
|
|
2400
|
+
${body}` : body,
|
|
2401
|
+
stream,
|
|
2402
|
+
allowFailure: true,
|
|
2403
|
+
label
|
|
2404
|
+
});
|
|
2405
|
+
}
|
|
2266
2406
|
async capture(script, opts = {}) {
|
|
2267
2407
|
return (await this.exec(script, opts)).stdout;
|
|
2268
2408
|
}
|
|
@@ -2270,7 +2410,7 @@ ${script}
|
|
|
2270
2410
|
return (await this.exec(script, { allowFailure: true })).code === 0;
|
|
2271
2411
|
}
|
|
2272
2412
|
async interactive(command, opts = {}) {
|
|
2273
|
-
const wrapped = opts.sudo ?? this.sudo ? `sudo
|
|
2413
|
+
const wrapped = opts.sudo ?? this.sudo ? `sudo bash -lc ${shq(command)}` : `bash -lc ${shq(command)}`;
|
|
2274
2414
|
const proc = Bun.spawn(["ssh", "-tt", ...this.sshOptions(), this.target, "--", wrapped], {
|
|
2275
2415
|
stdin: "inherit",
|
|
2276
2416
|
stdout: "inherit",
|
|
@@ -2293,14 +2433,24 @@ mv -f ${shq(path)}.tmp ${shq(path)}`, { label: `${this.name}: write ${path}` });
|
|
|
2293
2433
|
return res.stdout || null;
|
|
2294
2434
|
}
|
|
2295
2435
|
async pipeInto(remoteCommand, localCommand) {
|
|
2296
|
-
const
|
|
2436
|
+
const password = this.sudo ? sudoPasswords.get(this.sudoKey) : undefined;
|
|
2437
|
+
const remote = !this.sudo ? `bash -c ${shq(remoteCommand)}` : password ? `sudo -S -p '' bash -c ${shq(remoteCommand)}` : `sudo -n bash -c ${shq(remoteCommand)}`;
|
|
2297
2438
|
const sshArgs = ["ssh", ...this.sshOptions(), this.target, "--", remote];
|
|
2298
|
-
const
|
|
2299
|
-
|
|
2439
|
+
const local = localCommand.map((a) => shq(a)).join(" ");
|
|
2440
|
+
const source = password ? `{ printf '%s\\n' "$EPD_SUDO_PW"; ${local}; }` : local;
|
|
2441
|
+
const script = `set -euo pipefail; ${source} | ${sshArgs.map((a) => shq(a)).join(" ")}`;
|
|
2442
|
+
await run(["/bin/sh", "-c", script], {
|
|
2443
|
+
stream: true,
|
|
2444
|
+
label: `pipe \u2192 ${this.name}`,
|
|
2445
|
+
env: password ? { EPD_SUDO_PW: password } : undefined
|
|
2446
|
+
});
|
|
2300
2447
|
}
|
|
2301
2448
|
async ping() {
|
|
2302
2449
|
const res = await this.exec("echo epd-ok", { allowFailure: true });
|
|
2303
2450
|
if (res.code !== 0 || !res.stdout.includes("epd-ok")) {
|
|
2451
|
+
if (needsSudoPassword(res)) {
|
|
2452
|
+
throw new EpdError(`${this.name}: sudo needs a password for ${this.target}`, this.sudoHint());
|
|
2453
|
+
}
|
|
2304
2454
|
throw new EpdError(`cannot reach ${this.target}:${this.cfg.port}`, res.stderr || "Check that the host is up and your SSH key is authorized.");
|
|
2305
2455
|
}
|
|
2306
2456
|
}
|
|
@@ -2311,7 +2461,7 @@ function dirnameOf(p) {
|
|
|
2311
2461
|
}
|
|
2312
2462
|
var cache = new Map;
|
|
2313
2463
|
function host(name, cfg) {
|
|
2314
|
-
const key = `${cfg
|
|
2464
|
+
const key = `${sshUserFor(name, cfg)}@${name}:${cfg.port}`;
|
|
2315
2465
|
let h = cache.get(key);
|
|
2316
2466
|
if (!h) {
|
|
2317
2467
|
h = new Host(name, cfg);
|
|
@@ -4182,17 +4332,20 @@ Options
|
|
|
4182
4332
|
const loaded = ctx.load();
|
|
4183
4333
|
const cfg = loaded.config;
|
|
4184
4334
|
const needsHetzner = Boolean(cfg.hetzner) || cfg.services.some((s) => s.hosts.some((h) => h.startsWith("hetzner:")));
|
|
4185
|
-
if (needsHetzner && !cfg.hetzner?.apiToken && !getHetznerToken() && interactive()) {
|
|
4335
|
+
if (needsHetzner && !cfg.hetzner?.apiToken && !getHetznerToken() && interactive() && !isLinkDeclined("hetzner", cfg.root)) {
|
|
4186
4336
|
log.warn("Hetzner Cloud integration requires an API token.");
|
|
4187
4337
|
const link = await confirm("Would you like to link Hetzner Cloud now?", true);
|
|
4188
4338
|
if (link) {
|
|
4189
4339
|
const token = await linkHetznerInteractive();
|
|
4190
4340
|
if (token && cfg.hetzner)
|
|
4191
4341
|
cfg.hetzner.apiToken = token;
|
|
4342
|
+
} else {
|
|
4343
|
+
declineLink("hetzner", cfg.root);
|
|
4344
|
+
log.info(`not asking again \u2014 run ${c.cyan("epd auth hetzner")} to link it later`);
|
|
4192
4345
|
}
|
|
4193
4346
|
}
|
|
4194
4347
|
const needsCloudflare = cfg.dns?.provider === "cloudflare" || Boolean(cfg.cloudflare);
|
|
4195
|
-
if (needsCloudflare && !cfg.dns?.apiToken && !cfg.cloudflare?.apiToken && !getCloudflareToken() && interactive()) {
|
|
4348
|
+
if (needsCloudflare && !cfg.dns?.apiToken && !cfg.cloudflare?.apiToken && !getCloudflareToken() && interactive() && !isLinkDeclined("cloudflare", cfg.root)) {
|
|
4196
4349
|
log.warn("Cloudflare DNS integration requires an API token.");
|
|
4197
4350
|
const link = await confirm("Would you like to link Cloudflare now?", true);
|
|
4198
4351
|
if (link) {
|
|
@@ -4203,6 +4356,9 @@ Options
|
|
|
4203
4356
|
if (cfg.cloudflare)
|
|
4204
4357
|
cfg.cloudflare.apiToken = token;
|
|
4205
4358
|
}
|
|
4359
|
+
} else {
|
|
4360
|
+
declineLink("cloudflare", cfg.root);
|
|
4361
|
+
log.info(`not asking again \u2014 run ${c.cyan("epd auth cloudflare")} to link it later`);
|
|
4206
4362
|
}
|
|
4207
4363
|
}
|
|
4208
4364
|
await resolveDynamicHosts(cfg, loaded.env);
|
|
@@ -4863,7 +5019,8 @@ Options
|
|
|
4863
5019
|
else
|
|
4864
5020
|
log.plain(` start ${cfg.process.start}`);
|
|
4865
5021
|
log.plain(` hosts ${allHosts(cfg).join(", ")}`);
|
|
4866
|
-
|
|
5022
|
+
const sshOverrides = Object.entries(cfg.ssh.hostUsers).filter(([, u]) => u !== cfg.ssh.user).map(([h, u]) => `${u}@${h}`);
|
|
5023
|
+
log.plain(` ssh ${cfg.ssh.user}@\u2026:${cfg.ssh.port}${sshOverrides.length ? c.gray(` (${sshOverrides.join(", ")})`) : ""}`);
|
|
4867
5024
|
log.plain(` strategy ${cfg.strategy}`);
|
|
4868
5025
|
if (usesHostPorts(cfg)) {
|
|
4869
5026
|
const b = portBlock(cfg);
|
|
@@ -5766,7 +5923,7 @@ async function promptAutoUpdate(currentVersion) {
|
|
|
5766
5923
|
}
|
|
5767
5924
|
|
|
5768
5925
|
// src/version.ts
|
|
5769
|
-
var VERSION = "0.5.
|
|
5926
|
+
var VERSION = "0.5.2";
|
|
5770
5927
|
|
|
5771
5928
|
// src/commands/update.ts
|
|
5772
5929
|
var update = {
|
|
@@ -120,6 +120,29 @@ ssh:
|
|
|
120
120
|
proxy_jump: bastion.example.com
|
|
121
121
|
```
|
|
122
122
|
|
|
123
|
+
`ssh.user` is the login for every server. A non-root user needs `sudo`, because
|
|
124
|
+
epd escalates for docker, systemd and the files under `/var/lib/epd`. The
|
|
125
|
+
smoothest setup is a passwordless rule:
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
echo 'deploy ALL=(ALL) NOPASSWD:ALL' | sudo tee /etc/sudoers.d/epd
|
|
129
|
+
sudo chmod 440 /etc/sudoers.d/epd
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
Without it, epd asks for the sudo password once per run and reuses it for every
|
|
133
|
+
command on that host — nothing is written to disk. For CI, where nobody can
|
|
134
|
+
type, set `EPD_SUDO_PASSWORD` (or `ssh.sudo_password: ${EPD_SUDO_PASSWORD}` in
|
|
135
|
+
`epd.yml`) instead.
|
|
136
|
+
|
|
137
|
+
To use a different login on a single server, write it into the host entry —
|
|
138
|
+
that wins over `ssh.user`:
|
|
139
|
+
|
|
140
|
+
```yaml
|
|
141
|
+
servers:
|
|
142
|
+
web:
|
|
143
|
+
hosts: ["deploy@203.0.113.10", "ubuntu@203.0.113.11"]
|
|
144
|
+
```
|
|
145
|
+
|
|
123
146
|
---
|
|
124
147
|
|
|
125
148
|
## Next Step
|
package/docs/reference/config.md
CHANGED
|
@@ -50,8 +50,13 @@ process:
|
|
|
50
50
|
# ==============================================================================
|
|
51
51
|
ssh:
|
|
52
52
|
user: root # SSH username (default: root)
|
|
53
|
+
# Any non-root user needs passwordless sudo.
|
|
54
|
+
# Override it per server by writing the login
|
|
55
|
+
# into the host entry: "deploy@203.0.113.10".
|
|
53
56
|
port: 22 # SSH port (default: 22)
|
|
54
57
|
key: ~/.ssh/id_ed25519 # Path to explicit private key
|
|
58
|
+
sudo_password: ${EPD_SUDO_PASSWORD} # Only if the user has no NOPASSWD rule;
|
|
59
|
+
# interactive runs simply prompt for it instead
|
|
55
60
|
proxy_jump: bastion.net # Optional jump host / bastion
|
|
56
61
|
options: # Extra OpenSSH options
|
|
57
62
|
- ServerAliveInterval=30
|
|
@@ -63,6 +68,7 @@ servers:
|
|
|
63
68
|
web:
|
|
64
69
|
hosts: # Target servers (IPs or Hetzner selectors)
|
|
65
70
|
- 203.0.113.10
|
|
71
|
+
- deploy@203.0.113.11 # Per-host ssh login, overrides ssh.user
|
|
66
72
|
- hetzner:prod-web-1 # Dynamic Hetzner query by server name
|
|
67
73
|
- hetzner:label:app=web # Dynamic Hetzner query by label selector
|
|
68
74
|
replicas: 2 # Number of container replicas per host
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fabioplunser/epd",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.2",
|
|
4
4
|
"description": "Easy Project Deployer — deploy any project to one or many servers with Docker or PM2, fronted by Traefik.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "Fabio Plünser",
|
|
7
7
|
"license": "MIT",
|
|
8
|
-
"homepage": "https://
|
|
8
|
+
"homepage": "https://epd.peppi.dev",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
11
11
|
"url": "https://github.com/FabioPlunser/epd"
|
|
@@ -33,6 +33,9 @@
|
|
|
33
33
|
"LICENSE",
|
|
34
34
|
"docs"
|
|
35
35
|
],
|
|
36
|
+
"workspaces": [
|
|
37
|
+
"apps/*"
|
|
38
|
+
],
|
|
36
39
|
"publishConfig": {
|
|
37
40
|
"access": "public"
|
|
38
41
|
},
|
|
@@ -44,6 +47,8 @@
|
|
|
44
47
|
"build:binaries": "bun run scripts/build-all.ts",
|
|
45
48
|
"typecheck": "tsc --noEmit",
|
|
46
49
|
"test": "bun test",
|
|
50
|
+
"web:dev": "cd apps/web && bun run dev",
|
|
51
|
+
"web:build": "cd apps/web && bun run build",
|
|
47
52
|
"docs:dev": "vitepress dev docs",
|
|
48
53
|
"docs:build": "vitepress build docs",
|
|
49
54
|
"docs:preview": "vitepress preview docs",
|
|
@@ -53,7 +58,7 @@
|
|
|
53
58
|
"bun": ">=1.1.0"
|
|
54
59
|
},
|
|
55
60
|
"devDependencies": {
|
|
56
|
-
"@types/bun": "
|
|
61
|
+
"@types/bun": "^1.4.1",
|
|
57
62
|
"typescript": "^5.6.0",
|
|
58
63
|
"vitepress": "^1.6.4"
|
|
59
64
|
}
|