@sixb/deploy-ssh 0.2.6 → 0.2.7

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.
Files changed (64) hide show
  1. package/README.md +51 -44
  2. package/dist/check/index.d.ts +24 -0
  3. package/dist/check/index.d.ts.map +1 -0
  4. package/dist/check/judge.d.ts +23 -0
  5. package/dist/check/judge.d.ts.map +1 -0
  6. package/dist/index.js +599 -1527
  7. package/dist/index.js.map +10 -16
  8. package/dist/layout.d.ts +87 -30
  9. package/dist/layout.d.ts.map +1 -1
  10. package/dist/operations.d.ts +5 -3
  11. package/dist/operations.d.ts.map +1 -1
  12. package/dist/plan.d.ts +25 -0
  13. package/dist/plan.d.ts.map +1 -0
  14. package/dist/render.d.ts +15 -11
  15. package/dist/render.d.ts.map +1 -1
  16. package/dist/server/manifest.d.ts +10 -4
  17. package/dist/server/manifest.d.ts.map +1 -1
  18. package/dist/server/release-host.d.ts +4 -0
  19. package/dist/server/release-host.d.ts.map +1 -0
  20. package/dist/server/release.d.ts +46 -0
  21. package/dist/server/release.d.ts.map +1 -0
  22. package/dist/server/state.d.ts +0 -4
  23. package/dist/server/state.d.ts.map +1 -1
  24. package/dist/server/supervisor.d.ts +8 -8
  25. package/dist/server/supervisor.d.ts.map +1 -1
  26. package/dist/ssh-target.d.ts +3 -24
  27. package/dist/ssh-target.d.ts.map +1 -1
  28. package/dist/transport.d.ts.map +1 -1
  29. package/package.json +3 -3
  30. package/src/bootstrap.sh +93 -0
  31. package/src/check/index.ts +117 -0
  32. package/src/check/judge.ts +299 -0
  33. package/src/check/probe.sh +99 -0
  34. package/src/layout.ts +109 -61
  35. package/src/operations.ts +105 -65
  36. package/src/plan.ts +59 -0
  37. package/src/render.ts +54 -35
  38. package/src/server/cli.ts +16 -20
  39. package/src/server/manifest.ts +13 -6
  40. package/src/server/release-host.ts +81 -0
  41. package/src/server/release.ts +738 -0
  42. package/src/server/state.ts +1 -5
  43. package/src/server/supervisor.ts +45 -238
  44. package/src/sh.d.ts +4 -0
  45. package/src/ssh-target.ts +43 -285
  46. package/src/transport.ts +28 -12
  47. package/dist/access.d.ts +0 -11
  48. package/dist/access.d.ts.map +0 -1
  49. package/dist/check.d.ts +0 -31
  50. package/dist/check.d.ts.map +0 -1
  51. package/dist/ci.d.ts +0 -27
  52. package/dist/ci.d.ts.map +0 -1
  53. package/dist/keys.d.ts +0 -13
  54. package/dist/keys.d.ts.map +0 -1
  55. package/dist/scripts.d.ts +0 -48
  56. package/dist/scripts.d.ts.map +0 -1
  57. package/dist/setup.d.ts +0 -32
  58. package/dist/setup.d.ts.map +0 -1
  59. package/src/access.ts +0 -107
  60. package/src/check.ts +0 -257
  61. package/src/ci.ts +0 -88
  62. package/src/keys.ts +0 -57
  63. package/src/scripts.ts +0 -703
  64. package/src/setup.ts +0 -203
package/src/ssh-target.ts CHANGED
@@ -1,11 +1,7 @@
1
1
  import { isIPv6 } from "node:net"
2
2
  import type {
3
- DeployAccess,
4
- DeployAccessKey,
5
3
  DeployCheck,
6
4
  DeployCheckContext,
7
- DeployCi,
8
- DeployCiCredential,
9
5
  DeployContext,
10
6
  DeployControlAction,
11
7
  DeployHttpServiceName,
@@ -14,15 +10,12 @@ import type {
14
10
  DeployOperationContext,
15
11
  DeployRelease,
16
12
  DeployScript,
17
- DeploySetupContext,
18
13
  DeploySource,
19
14
  DeployStatus,
20
15
  DeployTarget,
21
16
  } from "@sixb/core/deploy"
22
- import { addKey, listKeys, removeKeys, removeKeysWhere } from "./access"
23
- import { checkDns, ENV_TOKEN_CHECK, runChecks } from "./check"
24
- import { generateCiKey, knownHostsLines, readHostKeys, renderCiInstall } from "./ci"
25
- import { ENV_TOKEN_FILE } from "./layout"
17
+ import { checkDns, checkHost } from "./check"
18
+ import { SLOT_PORTS } from "./layout"
26
19
  import {
27
20
  controlServices,
28
21
  deployRelease,
@@ -30,55 +23,37 @@ import {
30
23
  runDeployScript,
31
24
  streamLogs,
32
25
  } from "./operations"
33
- import { ensureEnvToken, pickPublicKey, renderAdminScript } from "./setup"
34
- import { shellQuote } from "./shell"
35
26
  import { resolveSshConfig } from "./ssh-config"
36
- import { RemoteScriptError, type RemoteShell, SshShell } from "./transport"
27
+ import { type RemoteShell, SshShell } from "./transport"
37
28
 
38
29
  export interface SshTargetOptions {
39
30
  /** The server: a hostname, an IP address, or a `Host` alias from your SSH config. */
40
31
  readonly host: string
41
- /**
42
- * The Linux user the deployment runs as. Projects under one user can read each other's files,
43
- * so give a project its own user to wall it off from the others on the server. Defaults to
44
- * `"sixb"`.
45
- */
32
+ /** The account the deployment logs in and runs as, never `root`. Defaults to `"sixb"`. */
46
33
  readonly user?: string
47
- /**
48
- * Local ports for the HTTP services, which Caddy on the server forwards to. Set them when
49
- * projects share a server, so that each has its own. Defaults: app 3001, api 3002.
50
- */
51
- readonly ports?: Readonly<Partial<Record<DeployHttpServiceName, number>>>
52
- /**
53
- * Second local port pair for blue-green cutovers while the active slot keeps serving. Defaults
54
- * to `ports` plus 10 (app 3011, api 3012).
55
- */
56
- readonly standbyPorts?: Readonly<Partial<Record<DeployHttpServiceName, number>>>
57
34
  }
58
35
 
59
- const OPTIONS = ["host", "user", "ports", "standbyPorts"] as const
60
-
61
36
  const DEFAULT_USER = "sixb"
62
37
 
63
- const DEFAULT_PORTS = {
64
- app: 3001,
65
- api: 3002,
66
- } as const satisfies Record<DeployHttpServiceName, number>
67
-
68
- /** Services listen on loopback only: Caddy on the same server is their one way in. */
69
- const LISTEN_HOST = "127.0.0.1"
38
+ /** Options earlier versions took, and why they went. */
39
+ const REMOVED_OPTIONS: Readonly<Record<string, string>> = {
40
+ ports: "a server runs one deployment, on fixed ports",
41
+ standbyPorts: "a server runs one deployment, on fixed ports",
42
+ }
70
43
 
71
44
  /** A Linux account name `useradd` accepts. */
72
45
  const USER_PATTERN = /^[a-z_][a-z0-9_-]{0,31}$/
73
46
 
47
+ /** Services listen on loopback only: Caddy on the same server is their one way in. */
48
+ const LISTEN_HOST = "127.0.0.1"
49
+
74
50
  /** A server reached over SSH, where Caddy routes each domain to its service. */
75
51
  export class SshTarget implements DeployTarget {
76
52
  readonly kind = "ssh"
77
53
  readonly host: string
54
+ /** The account the deployment logs in and runs as. */
78
55
  readonly user: string
79
56
  readonly location: string
80
- readonly #ports: Readonly<Record<DeployHttpServiceName, number>>
81
- readonly #standbyPorts: Readonly<Record<DeployHttpServiceName, number>>
82
57
 
83
58
  constructor(options: SshTargetOptions) {
84
59
  if (typeof options !== "object" || options === null) {
@@ -87,40 +62,24 @@ export class SshTarget implements DeployTarget {
87
62
  )
88
63
  }
89
64
  for (const key of Object.keys(options)) {
90
- if (!(OPTIONS as readonly string[]).includes(key)) {
91
- throw new Error(`[SshTarget] Unknown option '${key}'. Available: ${OPTIONS.join(", ")}.`)
65
+ const removed = REMOVED_OPTIONS[key]
66
+ if (removed) throw new Error(`[SshTarget] Remove \`${key}\`: ${removed}.`)
67
+ if (key !== "host" && key !== "user") {
68
+ throw new Error(`[SshTarget] Unknown option '${key}'. Available: host, user.`)
92
69
  }
93
70
  }
94
71
 
95
72
  this.host = validateHost(options.host)
96
73
  this.user = validateUser(options.user ?? DEFAULT_USER)
97
74
  this.location = `${this.user}@${this.host}`
98
- const primary = { ...DEFAULT_PORTS, ...validatePorts(options.ports, "ports") }
99
- const standbyDefaults: Record<DeployHttpServiceName, number> = {
100
- app: defaultStandbyPort(primary.app),
101
- api: defaultStandbyPort(primary.api),
102
- }
103
- const standby = { ...standbyDefaults, ...validatePorts(options.standbyPorts, "standbyPorts") }
104
- assertDistinctPorts(primary, standby)
105
- this.#ports = primary
106
- this.#standbyPorts = standby
107
75
  }
108
76
 
109
77
  listenAddress(service: DeployHttpServiceName): DeployListenAddress {
110
- return { host: LISTEN_HOST, port: this.#ports[service] }
111
- }
112
-
113
- standbyListenAddress(service: DeployHttpServiceName): DeployListenAddress {
114
- return { host: LISTEN_HOST, port: this.#standbyPorts[service] }
78
+ return { host: LISTEN_HOST, port: SLOT_PORTS.blue[service] }
115
79
  }
116
80
 
117
81
  deploy(release: DeployRelease, source: DeploySource, context: DeployContext): Promise<void> {
118
- return this.#connected((shell) =>
119
- deployRelease(shell, this.user, release, source, context, {
120
- blue: this.#ports,
121
- green: this.#standbyPorts,
122
- })
123
- )
82
+ return this.#connected((shell) => deployRelease(shell, release, source, context))
124
83
  }
125
84
 
126
85
  status(context: DeployOperationContext): Promise<DeployStatus> {
@@ -152,18 +111,17 @@ export class SshTarget implements DeployTarget {
152
111
  try {
153
112
  server = await this.#connected(async (shell) => [
154
113
  { id: "ssh", label: "SSH", status: "ok" as const, detail: this.location },
155
- ...(await runChecks(shell, {
114
+ ...(await checkHost(shell, {
156
115
  name: context.name,
157
116
  projectPath: context.projectPath,
158
- ports: release.services.flatMap((service) => {
159
- if (!service.http || (service.name !== "api" && service.name !== "app")) return []
160
- return [
161
- { service: service.name, port: this.#ports[service.name] },
162
- { service: `${service.name}-standby`, port: this.#standbyPorts[service.name] },
163
- ]
164
- }),
165
- envFromSource: release.steps.env !== undefined,
166
- location: this.location,
117
+ ports: [...Object.values(SLOT_PORTS.blue), ...Object.values(SLOT_PORTS.green)],
118
+ settings:
119
+ release.steps.env === undefined
120
+ ? "env-file"
121
+ : context.envToken
122
+ ? "env-token"
123
+ : "identity",
124
+ chromium: context.chromium,
167
125
  })),
168
126
  ])
169
127
  } catch (error) {
@@ -172,117 +130,6 @@ export class SshTarget implements DeployTarget {
172
130
  return [...server, ...(await dns)]
173
131
  }
174
132
 
175
- /**
176
- * Prepares the server as the admin login when the deploy user or the server is not set up
177
- * yet, then the project as the deploy user. Running it again changes nothing that is right.
178
- */
179
- async setup(release: DeployRelease, context: DeploySetupContext): Promise<void> {
180
- const before = await this.check(release, context)
181
- const serverFixes = before.filter(
182
- (check) =>
183
- (check.status === "fixable" &&
184
- check.id !== "project.env" &&
185
- check.id !== ENV_TOKEN_CHECK) ||
186
- (check.id === "ssh" && check.status !== "ok")
187
- )
188
- const unreachable = before.find((check) => check.id === "ssh" && check.status === "manual")
189
- if (unreachable) {
190
- throw new Error(`[SshTarget] ${unreachable.detail}`)
191
- }
192
-
193
- if (serverFixes.length > 0) {
194
- const admin = context.admin ?? "root"
195
- const { identityFiles } = await resolveSshConfig(this.location)
196
- const key = await pickPublicKey({ key: context.key, identityFiles })
197
- context.write(
198
- `Setting up ${this.host} as ${admin}, authorizing ${key.source} for ${this.user}.`
199
- )
200
- await runAsAdmin(
201
- `${admin}@${this.host}`,
202
- admin === "root",
203
- renderAdminScript({ user: this.user, publicKey: key.text, admin })
204
- )
205
- }
206
-
207
- context.write(`Preparing ${context.name} as ${this.user}.`)
208
- await this.#connected((shell) =>
209
- shell.run(
210
- [
211
- `root="$HOME"/${shellQuote(context.name)}`,
212
- `project="$HOME"/${shellQuote(`${context.name}/code/${context.projectPath}`)}`,
213
- 'mkdir -p "$root/shared"',
214
- 'if [ ! -L "$root/code" ]; then mkdir -p "$project"; fi',
215
- 'if [ -f "$root/shared/.env" ]; then chmod 600 "$root/shared/.env"; fi',
216
- 'if [ -f "$project/.env" ]; then chmod 600 "$project/.env"; fi',
217
- `token="$HOME"/${shellQuote(`${context.name}/${ENV_TOKEN_FILE}`)}`,
218
- 'if [ -f "$token" ]; then chmod 600 "$token"; fi',
219
- ].join("\n")
220
- )
221
- )
222
-
223
- const { createEnvToken } = context
224
- if (release.steps.env && createEnvToken) {
225
- const installed = await this.#connected((shell) =>
226
- ensureEnvToken(shell, context.name, createEnvToken)
227
- )
228
- if (installed) context.write(`Installed a read-only token for ${context.name}.`)
229
- }
230
- }
231
-
232
- readonly access: DeployAccess = {
233
- list: () => this.#connected(async (shell) => (await listKeys(shell)).map(withoutLine)),
234
- add: (key) => this.#connected((shell) => addKey(shell, key)).then(withoutLine),
235
- remove: (match) =>
236
- this.#connected(async (shell) => (await removeKeys(shell, match)).map(withoutLine)),
237
- }
238
-
239
- readonly ci: DeployCi = {
240
- create: (job, context) => this.#createCiKey(job, context.name),
241
- }
242
-
243
- /**
244
- * A key for one CI job, allowed to run commands and nothing else (no forwarding, no terminal),
245
- * with the server's host keys pinned so CI never trusts an address on first sight.
246
- */
247
- async #createCiKey(job: string, name: string): Promise<DeployCiCredential> {
248
- const ssh = await resolveSshConfig(this.location)
249
- if (ssh.proxyJump) {
250
- throw new Error(
251
- `[SshTarget] Your SSH config reaches ${this.host} through ${ssh.proxyJump}, and CI connects ` +
252
- "directly. Set `host` to an address CI can reach."
253
- )
254
- }
255
- // One comment per job and deployment: it is how a later run finds the keys it replaces.
256
- const comment = `sixb-ci:${name}@${job}`
257
- const pair = await generateCiKey(comment)
258
- const { key, hostKeys } = await this.#connected(async (shell) => ({
259
- hostKeys: await readHostKeys(shell),
260
- key: await addKey(shell, pair.publicKey, "restrict"),
261
- }))
262
-
263
- return {
264
- description: `${key.fingerprint} for ${this.location}, restricted to running commands`,
265
- secrets: {
266
- SIXB_DEPLOY_SSH_KEY: pair.privateKey,
267
- SIXB_DEPLOY_KNOWN_HOSTS: knownHostsLines(hostKeys, ssh.hostname, ssh.port).join("\n"),
268
- },
269
- install: renderCiInstall({ host: this.host, hostname: ssh.hostname, port: ssh.port }),
270
- retireOthers: () =>
271
- this.#connected(async (shell) =>
272
- (
273
- await removeKeysWhere(
274
- shell,
275
- (other) => other.comment === comment && other.fingerprint !== key.fingerprint
276
- )
277
- ).map(withoutLine)
278
- ),
279
- revoke: () =>
280
- this.#connected(async (shell) => {
281
- await removeKeysWhere(shell, (other) => other.fingerprint === key.fingerprint)
282
- }),
283
- }
284
- }
285
-
286
133
  async #connected<T>(work: (shell: RemoteShell) => Promise<T>): Promise<T> {
287
134
  const shell = await SshShell.open(this.location)
288
135
  try {
@@ -293,30 +140,17 @@ export class SshTarget implements DeployTarget {
293
140
  }
294
141
  }
295
142
 
296
- function defaultStandbyPort(port: number): number {
297
- return port + 10 <= 65_535 ? port + 10 : port - 10
298
- }
299
-
300
- function assertDistinctPorts(
301
- primary: Readonly<Record<DeployHttpServiceName, number>>,
302
- standby: Readonly<Record<DeployHttpServiceName, number>>
303
- ): void {
304
- const entries: readonly [string, number][] = [
305
- ["ports.app", primary.app],
306
- ["ports.api", primary.api],
307
- ["standbyPorts.app", standby.app],
308
- ["standbyPorts.api", standby.api],
309
- ]
310
- const seen = new Map<number, string>()
311
- for (const [label, port] of entries) {
312
- const previous = seen.get(port)
313
- if (previous) {
314
- throw new Error(
315
- `[SshTarget] ${label} (${port}) conflicts with ${previous}. Give each HTTP service and slot its own port.`
316
- )
317
- }
318
- seen.set(port, label)
143
+ function validateUser(value: unknown): string {
144
+ if (value === "root") {
145
+ throw new Error("[SshTarget] Deployments never run as root. Use an account without sudo.")
146
+ }
147
+ if (typeof value !== "string" || !USER_PATTERN.test(value)) {
148
+ throw new Error(
149
+ `[SshTarget] user ${JSON.stringify(value)} is not a Linux account name. Use lowercase ` +
150
+ "letters, digits, underscores and hyphens, starting with a letter or underscore."
151
+ )
319
152
  }
153
+ return value
320
154
  }
321
155
 
322
156
  function validateHost(value: unknown): string {
@@ -326,7 +160,7 @@ function validateHost(value: unknown): string {
326
160
  const host = value.trim()
327
161
  if (host.includes("@")) {
328
162
  throw new Error(
329
- `[SshTarget] host '${host}' includes a user. Set the host alone, and the user with \`user\`.`
163
+ `[SshTarget] host '${host}' includes a user. Set the host alone, and the account with \`user\`.`
330
164
  )
331
165
  }
332
166
  // `ssh` reads an argument that starts with `-` as an option, not a host.
@@ -342,89 +176,13 @@ function validateHost(value: unknown): string {
342
176
  return host
343
177
  }
344
178
 
345
- function validateUser(value: unknown): string {
346
- if (value === "root") {
347
- throw new Error(
348
- "[SshTarget] Deployments never run as root. Use a deploy user without sudo, such as the " +
349
- 'default "sixb".'
350
- )
351
- }
352
- if (typeof value !== "string" || !USER_PATTERN.test(value)) {
353
- throw new Error(
354
- `[SshTarget] user ${JSON.stringify(value)} is not a Linux user name. Use lowercase ` +
355
- "letters, digits, underscores, and hyphens, starting with a letter or underscore."
356
- )
357
- }
358
- return value
359
- }
360
-
361
- function validatePorts(
362
- value: unknown,
363
- field: "ports" | "standbyPorts"
364
- ): Partial<Record<DeployHttpServiceName, number>> {
365
- if (value === undefined) return {}
366
- if (typeof value !== "object" || value === null || Array.isArray(value)) {
367
- throw new Error(`[SshTarget] ${field} must be an object, such as \`{ api: 3012 }\`.`)
368
- }
369
-
370
- const ports: Partial<Record<DeployHttpServiceName, number>> = {}
371
- for (const [service, port] of Object.entries(value)) {
372
- if (!Object.hasOwn(DEFAULT_PORTS, service)) {
373
- throw new Error(
374
- `[SshTarget] ${field}.${service} is not an HTTP service. Available: api, app.`
375
- )
376
- }
377
- // A deploy user has no privileges, and ports below 1024 need them.
378
- if (!Number.isInteger(port) || port < 1024 || port > 65_535) {
379
- throw new Error(`[SshTarget] ${field}.${service} must be a port from 1024 to 65535.`)
380
- }
381
- ports[service as DeployHttpServiceName] = port
382
- }
383
- return ports
384
- }
385
-
386
- /** What a failed connection means for a deploy, and whether setup can fix it. */
179
+ /** A failed connection, as the check that stops a deploy. */
387
180
  function sshCheck(location: string, error: unknown): DeployCheck {
388
- const message =
389
- (error instanceof Error ? error.message : String(error))
390
- .split("\n")[0]
391
- ?.replace(/^\[SshTarget\] /, "") ?? ""
392
- if (error instanceof RemoteScriptError && /refused your SSH key/.test(message)) {
393
- return {
394
- id: "ssh",
395
- label: "SSH",
396
- status: "fixable",
397
- detail: message,
398
- remedy: `Run \`sixb deploy setup --admin <login>\` with a login that has sudo: it creates the deploy user and authorizes your key. Or have someone with access run \`sixb deploy access add\` with your key.`,
399
- }
400
- }
181
+ const [message = ""] = (error instanceof Error ? error.message : String(error)).split("\n")
401
182
  return {
402
183
  id: "ssh",
403
184
  label: "SSH",
404
- status: "manual",
405
- detail: message || `Cannot reach ${location}.`,
406
- }
407
- }
408
-
409
- function withoutLine({ type, fingerprint, comment, restricted }: DeployAccessKey): DeployAccessKey {
410
- return { type, fingerprint, comment, restricted }
411
- }
412
-
413
- /**
414
- * Runs the setup script as the admin login with the terminal attached, so sudo can ask for its
415
- * password and the person running setup sees each step.
416
- */
417
- async function runAsAdmin(destination: string, root: boolean, script: string): Promise<void> {
418
- const command = `${root ? "" : "sudo "}bash -c ${shellQuote(script)}`
419
- // LogLevel=ERROR drops the "Connection closed" line a terminal session ends with, not errors.
420
- const ssh = ["ssh", "-tt", "-o", "ConnectTimeout=15", "-o", "LogLevel=ERROR"]
421
- const child = Bun.spawn([...ssh, destination, command], {
422
- stdio: ["inherit", "inherit", "inherit"],
423
- })
424
- const exitCode = await child.exited
425
- if (exitCode !== 0) {
426
- throw new Error(
427
- `[SshTarget] Setting up the server as ${destination} failed (exit code ${exitCode}).`
428
- )
185
+ status: "fail",
186
+ detail: message.replace(/^\[SshTarget\] /, "") || `Cannot reach ${location}.`,
429
187
  }
430
188
  }
package/src/transport.ts CHANGED
@@ -199,16 +199,32 @@ export function sshError(destination: string, error: unknown): Error {
199
199
  }
200
200
  const output = error.message
201
201
  const host = destination.split("@").at(-1) ?? destination
202
- const reason = /REMOTE HOST IDENTIFICATION HAS CHANGED/.test(output)
203
- ? `${host} answered with a host key other than the one on record. If the server was rebuilt, remove the old key with \`ssh-keygen -R ${host}\` and connect once to accept the new one; for CI, run \`sixb deploy ci\` again. Otherwise, something else is answering at that address: do not deploy to it.`
204
- : /Host key verification failed/.test(output)
205
- ? `The host key for ${host} is not trusted yet. Connect once with \`ssh ${destination}\`, check the fingerprint, and accept it.`
206
- : /Permission denied/.test(output)
207
- ? `The server refused your SSH key for ${destination}. Load it into your SSH agent, or ask someone with access to authorize it.`
208
- : /Could not resolve hostname/.test(output)
209
- ? `${host} does not resolve. Check the target's host.`
210
- : /Connection refused|timed out|No route to host/.test(output)
211
- ? `Could not reach ${host} over SSH.`
212
- : `SSH to ${destination} failed.`
213
- return new RemoteScriptError(`[SshTarget] ${reason}\n${output}`, error.exitCode)
202
+ return new RemoteScriptError(
203
+ `[SshTarget] ${sshFailureReason(output, destination, host)}\n${output}`,
204
+ error.exitCode
205
+ )
206
+ }
207
+
208
+ function sshFailureReason(output: string, destination: string, host: string): string {
209
+ if (/Tailscale SSH requires an additional check/.test(output)) {
210
+ return `Tailscale SSH wants you to sign in again before reaching ${destination}: open the link below, then try again.`
211
+ }
212
+ if (/tailnet policy does not permit/.test(output)) {
213
+ return `The tailnet's SSH rules don't let you reach ${destination}. Ask a tailnet admin to allow it.`
214
+ }
215
+ if (/REMOTE HOST IDENTIFICATION HAS CHANGED/.test(output)) {
216
+ return `${host} answered with a host key other than the one on record. If the server was rebuilt, remove the old key with \`ssh-keygen -R ${host}\` and connect once to accept the new one. Otherwise, something else is answering at that address: do not deploy to it.`
217
+ }
218
+ if (/Host key verification failed/.test(output)) {
219
+ return `The host key for ${host} is not trusted yet. Connect once with \`ssh ${destination}\`, check the fingerprint, and accept it.`
220
+ }
221
+ if (/Permission denied/.test(output)) {
222
+ return `The server refused your SSH key for ${destination}. Load it into your SSH agent, or ask someone with access to the server to allow it.`
223
+ }
224
+ if (/Could not resolve hostname/.test(output))
225
+ return `${host} does not resolve. Check the target's host.`
226
+ if (/Connection refused|timed out|No route to host/.test(output)) {
227
+ return `Could not reach ${host} over SSH.`
228
+ }
229
+ return `SSH to ${destination} failed.`
214
230
  }
package/dist/access.d.ts DELETED
@@ -1,11 +0,0 @@
1
- import type { DeployAccessKey } from "@sixb/core/deploy";
2
- import { type AuthorizedKey } from "./keys";
3
- import type { RemoteShell } from "./transport";
4
- export declare function listKeys(shell: RemoteShell): Promise<AuthorizedKey[]>;
5
- /** Authorizes a public key once, with `options` (such as `restrict`) in front of it. */
6
- export declare function addKey(shell: RemoteShell, text: string, options?: string): Promise<AuthorizedKey>;
7
- /** Removes the keys whose fingerprint or comment is `match`. Never removes the last one. */
8
- export declare function removeKeys(shell: RemoteShell, match: string): Promise<DeployAccessKey[]>;
9
- /** Removes the keys `matches` picks, if any. Never removes the last one. */
10
- export declare function removeKeysWhere(shell: RemoteShell, matches: (key: AuthorizedKey) => boolean): Promise<AuthorizedKey[]>;
11
- //# sourceMappingURL=access.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"access.d.ts","sourceRoot":"","sources":["../src/access.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACxD,OAAO,EAAE,KAAK,aAAa,EAAsC,MAAM,QAAQ,CAAA;AAE/E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAQ9C,wBAAsB,QAAQ,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC,CAE3E;AAED,wFAAwF;AACxF,wBAAsB,MAAM,CAC1B,KAAK,EAAE,WAAW,EAClB,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,MAAM,GACf,OAAO,CAAC,aAAa,CAAC,CAOxB;AAED,4FAA4F;AAC5F,wBAAsB,UAAU,CAAC,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,EAAE,CAAC,CAS9F;AAED,4EAA4E;AAC5E,wBAAsB,eAAe,CACnC,KAAK,EAAE,WAAW,EAClB,OAAO,EAAE,CAAC,GAAG,EAAE,aAAa,KAAK,OAAO,GACvC,OAAO,CAAC,aAAa,EAAE,CAAC,CAiB1B"}
package/dist/check.d.ts DELETED
@@ -1,31 +0,0 @@
1
- import type { DeployCheck, DeployRelease } from "@sixb/core/deploy";
2
- import type { RemoteShell } from "./transport";
3
- export declare const CHECK_MARKER = "__SIXB_CHECK__";
4
- export declare const ENV_TOKEN_CHECK = "project.env-token";
5
- /**
6
- * Checks the server as the deploy user, changing nothing. Each check prints one
7
- * `__SIXB_CHECK__ id status detail` line; labels and remedies are added on this side.
8
- */
9
- export declare function renderCheckScript(input: {
10
- readonly name: string;
11
- readonly projectPath: string;
12
- readonly ports: readonly {
13
- readonly service: string;
14
- readonly port: number;
15
- }[];
16
- /** A deploy writes `.env` from the project's source, so what it needs is the token instead. */
17
- readonly envFromSource?: boolean;
18
- }): string;
19
- /** Reads the check script's output into checks, with labels and remedies. */
20
- export declare function parseCheckOutput(lines: readonly string[], context: {
21
- readonly location: string;
22
- readonly name: string;
23
- }): DeployCheck[];
24
- /** Where each HTTP domain resolves, against where the target is. */
25
- export declare function checkDns(release: DeployRelease, hostname: string): Promise<DeployCheck[]>;
26
- /** The checks that stop a deploy. */
27
- export declare function blocksDeploy(check: DeployCheck): boolean;
28
- export declare function runChecks(shell: RemoteShell, input: Parameters<typeof renderCheckScript>[0] & {
29
- readonly location: string;
30
- }): Promise<DeployCheck[]>;
31
- //# sourceMappingURL=check.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"check.d.ts","sourceRoot":"","sources":["../src/check.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAGnE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAE9C,eAAO,MAAM,YAAY,mBAAmB,CAAA;AAK5C,eAAO,MAAM,eAAe,sBAAsB,CAAA;AAIlD;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE;IACvC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;IAC5B,QAAQ,CAAC,KAAK,EAAE,SAAS;QAAE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;KAAE,EAAE,CAAA;IAC9E,+FAA+F;IAC/F,QAAQ,CAAC,aAAa,CAAC,EAAE,OAAO,CAAA;CACjC,GAAG,MAAM,CAwFT;AAED,6EAA6E;AAC7E,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,SAAS,MAAM,EAAE,EACxB,OAAO,EAAE;IAAE,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAC5D,WAAW,EAAE,CAMf;AAED,oEAAoE;AACpE,wBAAsB,QAAQ,CAAC,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC,CA6B/F;AAED,qCAAqC;AACrC,wBAAgB,YAAY,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAExD;AAED,wBAAsB,SAAS,CAC7B,KAAK,EAAE,WAAW,EAClB,KAAK,EAAE,UAAU,CAAC,OAAO,iBAAiB,CAAC,CAAC,CAAC,CAAC,GAAG;IAAE,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GAC7E,OAAO,CAAC,WAAW,EAAE,CAAC,CAQxB"}
package/dist/ci.d.ts DELETED
@@ -1,27 +0,0 @@
1
- import type { RemoteShell } from "./transport";
2
- /**
3
- * A new key pair for a CI job. It is made in a directory that is removed before this returns, so
4
- * the private key exists only in memory here and, afterwards, in the CI system's secrets.
5
- */
6
- export declare function generateCiKey(comment: string): Promise<{
7
- readonly privateKey: string;
8
- readonly publicKey: string;
9
- }>;
10
- /**
11
- * The server's host keys, read over a connection SSH has already checked against your own
12
- * `known_hosts`. CI trusts these instead of whatever answers at the address the first time.
13
- */
14
- export declare function readHostKeys(shell: RemoteShell): Promise<string[]>;
15
- /** `known_hosts` lines for the host keys, under the name and port CI connects to. */
16
- export declare function knownHostsLines(hostKeys: readonly string[], hostname: string, port: number): string[];
17
- /**
18
- * Shell lines that install the key on the CI runner, reading `SIXB_DEPLOY_SSH_KEY` and
19
- * `SIXB_DEPLOY_KNOWN_HOSTS` from the environment. `host` is what `sixb.deploy.ts` names, which may
20
- * be an alias from your SSH config; the runner gets the same alias.
21
- */
22
- export declare function renderCiInstall(input: {
23
- readonly host: string;
24
- readonly hostname: string;
25
- readonly port: number;
26
- }): string[];
27
- //# sourceMappingURL=ci.d.ts.map
package/dist/ci.d.ts.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"ci.d.ts","sourceRoot":"","sources":["../src/ci.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAE9C;;;GAGG;AACH,wBAAsB,aAAa,CACjC,OAAO,EAAE,MAAM,GACd,OAAO,CAAC;IAAE,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAAC,CAuBtE;AAED;;;GAGG;AACH,wBAAsB,YAAY,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAUxE;AAED,qFAAqF;AACrF,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,SAAS,MAAM,EAAE,EAC3B,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,GACX,MAAM,EAAE,CAGV;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE;IACrC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CACtB,GAAG,MAAM,EAAE,CAgBX"}
package/dist/keys.d.ts DELETED
@@ -1,13 +0,0 @@
1
- import type { DeployAccessKey } from "@sixb/core/deploy";
2
- export interface AuthorizedKey extends DeployAccessKey {
3
- /** The line as it appears in `authorized_keys`. */
4
- readonly line: string;
5
- }
6
- /**
7
- * One `authorized_keys` line: optional options, then type, key, and comment. Returns `null` for
8
- * blank lines, comments, and anything that is not a public key.
9
- */
10
- export declare function parseAuthorizedKey(line: string): AuthorizedKey | null;
11
- /** Parses a public key given as text, failing with what is wrong with it. */
12
- export declare function parsePublicKey(text: string): AuthorizedKey;
13
- //# sourceMappingURL=keys.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"keys.d.ts","sourceRoot":"","sources":["../src/keys.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAYxD,MAAM,WAAW,aAAc,SAAQ,eAAe;IACpD,mDAAmD;IACnD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CACtB;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,GAAG,IAAI,CAsBrE;AAED,6EAA6E;AAC7E,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,CAS1D"}
package/dist/scripts.d.ts DELETED
@@ -1,48 +0,0 @@
1
- import type { DeployRecord, DeployRelease } from "@sixb/core/deploy";
2
- import { type DeploymentLayout, type ReleaseLayout } from "./layout";
3
- import { type SlotPorts } from "./render";
4
- /** A line the deploy script prints around each step; the target turns it into progress. */
5
- export declare const STEP_MARKER = "__SIXB_STEP__";
6
- /** The server's home directory, and a fresh directory to upload the source into. */
7
- export declare function renderPrepareScript(name: string, commit: string): string;
8
- /** Extracts one uploaded archive from standard input. */
9
- export declare function renderReceiveScript(incoming: string, path: string): string;
10
- export interface DeployScriptInput {
11
- readonly release: DeployRelease;
12
- readonly layout: DeploymentLayout;
13
- readonly incoming: string;
14
- readonly record: DeployRecord;
15
- readonly releaseId?: string;
16
- readonly slotPorts?: SlotPorts;
17
- }
18
- export interface DeployScript {
19
- readonly labels: readonly string[];
20
- readonly script: string;
21
- }
22
- export declare function defaultSlotPorts(release: DeployRelease): SlotPorts;
23
- export declare function deriveReleaseId(record: DeployRecord): string;
24
- /**
25
- * Everything the server does once the source is uploaded, as one script that holds the
26
- * deployment's lock throughout. Every build, migration, provider check, and readiness check runs
27
- * against the new release directory before routes flip or the previous release retires.
28
- */
29
- export declare function renderDeployScript(input: DeployScriptInput): DeployScript;
30
- /**
31
- * Unpacks the upload into an immutable `releases/<id>` directory, migrating an in-place `code/`
32
- * directory on upgrade. The release's `.env` links to the server's `shared/.env`, so an edit to
33
- * that one file reaches the services on their next restart, and a committed `.env` never
34
- * replaces it.
35
- */
36
- export declare function renderPrepareRelease(layout: DeploymentLayout, targetRelease: ReleaseLayout, incoming: string): string;
37
- /**
38
- * Done means healthy, not just started: the API answers its readiness route, and no process has
39
- * exited in its first seconds. Those seconds count from "Start new release", so the time the API
40
- * takes to boot is part of them rather than added to them.
41
- */
42
- export declare function renderCheckServices(input: {
43
- readonly blueReadyUrl: string | null;
44
- readonly greenReadyUrl?: string | null;
45
- }): string;
46
- /** Keeps the active release, the previous release, and any release still draining in `state.json`. */
47
- export declare function renderPruneReleases(): string;
48
- //# sourceMappingURL=scripts.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"scripts.d.ts","sourceRoot":"","sources":["../src/scripts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,YAAY,EACZ,aAAa,EACd,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EAAE,KAAK,gBAAgB,EAAE,KAAK,aAAa,EAAiB,MAAM,UAAU,CAAA;AACnF,OAAO,EAML,KAAK,SAAS,EACf,MAAM,UAAU,CAAA;AAGjB,2FAA2F;AAC3F,eAAO,MAAM,WAAW,kBAAkB,CAAA;AAE1C,oFAAoF;AACpF,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAUxE;AAED,yDAAyD;AACzD,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAG1E;AAED,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,OAAO,EAAE,aAAa,CAAA;IAC/B,QAAQ,CAAC,MAAM,EAAE,gBAAgB,CAAA;IACjC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAA;IAC7B,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAA;IAC3B,QAAQ,CAAC,SAAS,CAAC,EAAE,SAAS,CAAA;CAC/B;AAED,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAA;IAClC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CACxB;AAOD,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,aAAa,GAAG,SAAS,CAYlE;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,YAAY,GAAG,MAAM,CAI5D;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,iBAAiB,GAAG,YAAY,CA6EzE;AAuHD;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,gBAAgB,EACxB,aAAa,EAAE,aAAa,EAC5B,QAAQ,EAAE,MAAM,GACf,MAAM,CAqCR;AAoND;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE;IACzC,QAAQ,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI,CAAA;IACpC,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CACvC,GAAG,MAAM,CAqCT;AA0GD,sGAAsG;AACtG,wBAAgB,mBAAmB,IAAI,MAAM,CAY5C"}