@fabioplunser/epd 0.5.1 → 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/dist/cli.js +133 -17
- package/docs/guide/installation.md +11 -5
- package/docs/reference/config.md +2 -0
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -685,7 +685,7 @@ function normalize(raw, configPath, root, destination) {
|
|
|
685
685
|
const buildRaw = raw.build ?? {};
|
|
686
686
|
checkKeys(buildRaw, ["dockerfile", "context", "platform", "target", "args", "secrets", "cache", "remote"], "epd.yml.build");
|
|
687
687
|
const sshRaw = raw.ssh ?? {};
|
|
688
|
-
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");
|
|
689
689
|
const procRaw = raw.process ?? {};
|
|
690
690
|
checkKeys(procRaw, ["exclude", "install", "build", "start", "path", "path_prepend", "source"], "epd.yml.process");
|
|
691
691
|
const processCfg = {
|
|
@@ -802,7 +802,8 @@ function normalize(raw, configPath, root, destination) {
|
|
|
802
802
|
key: sshRaw.key ? expandHome(asString(sshRaw.key, "epd.yml.ssh.key")) : undefined,
|
|
803
803
|
options: asList(sshRaw.options, "epd.yml.ssh.options"),
|
|
804
804
|
proxyJump: sshRaw.proxy_jump ? asString(sshRaw.proxy_jump, "epd.yml.ssh.proxy_jump") : undefined,
|
|
805
|
-
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
|
|
806
807
|
},
|
|
807
808
|
services,
|
|
808
809
|
proxy,
|
|
@@ -899,6 +900,28 @@ async function askSecret(question) {
|
|
|
899
900
|
const answer = (await readLine()).trim();
|
|
900
901
|
return answer;
|
|
901
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
|
+
}
|
|
902
925
|
async function pressEnter(message) {
|
|
903
926
|
if (!isTTY)
|
|
904
927
|
return;
|
|
@@ -978,6 +1001,25 @@ function saveGlobalAuth(updater) {
|
|
|
978
1001
|
chmodSync(file, 384);
|
|
979
1002
|
} catch {}
|
|
980
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
|
+
}
|
|
981
1023
|
function saveProjectEnv(entries, root = process.cwd()) {
|
|
982
1024
|
const envPath = join2(root, ".env");
|
|
983
1025
|
let content = existsSync2(envPath) ? readFileSync2(envPath, "utf8") : "";
|
|
@@ -1106,6 +1148,7 @@ async function verifyHetznerToken(token) {
|
|
|
1106
1148
|
}
|
|
1107
1149
|
}
|
|
1108
1150
|
async function linkCloudflareInteractive(root = process.cwd()) {
|
|
1151
|
+
clearLinkDecline("cloudflare", root);
|
|
1109
1152
|
const url = "https://dash.cloudflare.com/profile/api-tokens";
|
|
1110
1153
|
console.log(`
|
|
1111
1154
|
${c.bold("Linking Cloudflare to EPD")}`);
|
|
@@ -1156,6 +1199,7 @@ ${c.bold("Linking Cloudflare to EPD")}`);
|
|
|
1156
1199
|
}
|
|
1157
1200
|
}
|
|
1158
1201
|
async function linkHetznerInteractive(root = process.cwd()) {
|
|
1202
|
+
clearLinkDecline("hetzner", root);
|
|
1159
1203
|
const url = "https://console.hetzner.cloud/";
|
|
1160
1204
|
console.log(`
|
|
1161
1205
|
${c.bold("Linking Hetzner Cloud to EPD")}`);
|
|
@@ -2228,6 +2272,30 @@ import { tmpdir } from "os";
|
|
|
2228
2272
|
import { join as join4 } from "path";
|
|
2229
2273
|
var controlDir = join4(tmpdir(), `epd-${process.getuid?.() ?? 0}`);
|
|
2230
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
|
+
}
|
|
2231
2299
|
function sshUserFor(name, cfg) {
|
|
2232
2300
|
return cfg.hostUsers?.[name] ?? cfg.user;
|
|
2233
2301
|
}
|
|
@@ -2242,6 +2310,20 @@ class Host {
|
|
|
2242
2310
|
this.user = sshUserFor(name, cfg);
|
|
2243
2311
|
this.cfg = this.user === cfg.user ? cfg : { ...cfg, user: this.user };
|
|
2244
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
|
+
`);
|
|
2245
2327
|
}
|
|
2246
2328
|
sshOptions() {
|
|
2247
2329
|
const socket = join4(controlDir, `${hash32(`${this.cfg.user}@${this.name}:${this.cfg.port}`).toString(36)}.sock`);
|
|
@@ -2288,14 +2370,22 @@ ${script}
|
|
|
2288
2370
|
log.debug(`${this.name}: ${script.split(`
|
|
2289
2371
|
`).filter(Boolean)[0] ?? ""}`);
|
|
2290
2372
|
const useSudo = opts.sudo ?? this.sudo;
|
|
2291
|
-
const
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
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
|
+
}
|
|
2299
2389
|
if (res.code !== 0 && !opts.allowFailure) {
|
|
2300
2390
|
const detail = [res.stdout, res.stderr].filter(Boolean).join(`
|
|
2301
2391
|
`).trim();
|
|
@@ -2303,6 +2393,16 @@ ${script}
|
|
|
2303
2393
|
}
|
|
2304
2394
|
return res;
|
|
2305
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
|
+
}
|
|
2306
2406
|
async capture(script, opts = {}) {
|
|
2307
2407
|
return (await this.exec(script, opts)).stdout;
|
|
2308
2408
|
}
|
|
@@ -2310,7 +2410,7 @@ ${script}
|
|
|
2310
2410
|
return (await this.exec(script, { allowFailure: true })).code === 0;
|
|
2311
2411
|
}
|
|
2312
2412
|
async interactive(command, opts = {}) {
|
|
2313
|
-
const wrapped = opts.sudo ?? this.sudo ? `sudo
|
|
2413
|
+
const wrapped = opts.sudo ?? this.sudo ? `sudo bash -lc ${shq(command)}` : `bash -lc ${shq(command)}`;
|
|
2314
2414
|
const proc = Bun.spawn(["ssh", "-tt", ...this.sshOptions(), this.target, "--", wrapped], {
|
|
2315
2415
|
stdin: "inherit",
|
|
2316
2416
|
stdout: "inherit",
|
|
@@ -2333,14 +2433,24 @@ mv -f ${shq(path)}.tmp ${shq(path)}`, { label: `${this.name}: write ${path}` });
|
|
|
2333
2433
|
return res.stdout || null;
|
|
2334
2434
|
}
|
|
2335
2435
|
async pipeInto(remoteCommand, localCommand) {
|
|
2336
|
-
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)}`;
|
|
2337
2438
|
const sshArgs = ["ssh", ...this.sshOptions(), this.target, "--", remote];
|
|
2338
|
-
const
|
|
2339
|
-
|
|
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
|
+
});
|
|
2340
2447
|
}
|
|
2341
2448
|
async ping() {
|
|
2342
2449
|
const res = await this.exec("echo epd-ok", { allowFailure: true });
|
|
2343
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
|
+
}
|
|
2344
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.");
|
|
2345
2455
|
}
|
|
2346
2456
|
}
|
|
@@ -4222,17 +4332,20 @@ Options
|
|
|
4222
4332
|
const loaded = ctx.load();
|
|
4223
4333
|
const cfg = loaded.config;
|
|
4224
4334
|
const needsHetzner = Boolean(cfg.hetzner) || cfg.services.some((s) => s.hosts.some((h) => h.startsWith("hetzner:")));
|
|
4225
|
-
if (needsHetzner && !cfg.hetzner?.apiToken && !getHetznerToken() && interactive()) {
|
|
4335
|
+
if (needsHetzner && !cfg.hetzner?.apiToken && !getHetznerToken() && interactive() && !isLinkDeclined("hetzner", cfg.root)) {
|
|
4226
4336
|
log.warn("Hetzner Cloud integration requires an API token.");
|
|
4227
4337
|
const link = await confirm("Would you like to link Hetzner Cloud now?", true);
|
|
4228
4338
|
if (link) {
|
|
4229
4339
|
const token = await linkHetznerInteractive();
|
|
4230
4340
|
if (token && cfg.hetzner)
|
|
4231
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`);
|
|
4232
4345
|
}
|
|
4233
4346
|
}
|
|
4234
4347
|
const needsCloudflare = cfg.dns?.provider === "cloudflare" || Boolean(cfg.cloudflare);
|
|
4235
|
-
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)) {
|
|
4236
4349
|
log.warn("Cloudflare DNS integration requires an API token.");
|
|
4237
4350
|
const link = await confirm("Would you like to link Cloudflare now?", true);
|
|
4238
4351
|
if (link) {
|
|
@@ -4243,6 +4356,9 @@ Options
|
|
|
4243
4356
|
if (cfg.cloudflare)
|
|
4244
4357
|
cfg.cloudflare.apiToken = token;
|
|
4245
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`);
|
|
4246
4362
|
}
|
|
4247
4363
|
}
|
|
4248
4364
|
await resolveDynamicHosts(cfg, loaded.env);
|
|
@@ -5807,7 +5923,7 @@ async function promptAutoUpdate(currentVersion) {
|
|
|
5807
5923
|
}
|
|
5808
5924
|
|
|
5809
5925
|
// src/version.ts
|
|
5810
|
-
var VERSION = "0.5.
|
|
5926
|
+
var VERSION = "0.5.2";
|
|
5811
5927
|
|
|
5812
5928
|
// src/commands/update.ts
|
|
5813
5929
|
var update = {
|
|
@@ -120,13 +120,19 @@ 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
|
|
124
|
-
|
|
125
|
-
|
|
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
126
|
|
|
127
|
+
```bash
|
|
128
|
+
echo 'deploy ALL=(ALL) NOPASSWD:ALL' | sudo tee /etc/sudoers.d/epd
|
|
129
|
+
sudo chmod 440 /etc/sudoers.d/epd
|
|
127
130
|
```
|
|
128
|
-
|
|
129
|
-
|
|
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.
|
|
130
136
|
|
|
131
137
|
To use a different login on a single server, write it into the host entry —
|
|
132
138
|
that wins over `ssh.user`:
|
package/docs/reference/config.md
CHANGED
|
@@ -55,6 +55,8 @@ ssh:
|
|
|
55
55
|
# into the host entry: "deploy@203.0.113.10".
|
|
56
56
|
port: 22 # SSH port (default: 22)
|
|
57
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
|
|
58
60
|
proxy_jump: bastion.net # Optional jump host / bastion
|
|
59
61
|
options: # Extra OpenSSH options
|
|
60
62
|
- ServerAliveInterval=30
|
package/package.json
CHANGED