@sixb/deploy-ssh 0.2.5 → 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 -42
  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 -1102
  7. package/dist/index.js.map +10 -15
  8. package/dist/layout.d.ts +91 -18
  9. package/dist/layout.d.ts.map +1 -1
  10. package/dist/operations.d.ts +5 -2
  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 +20 -10
  15. package/dist/render.d.ts.map +1 -1
  16. package/dist/server/manifest.d.ts +15 -3
  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 +2 -0
  23. package/dist/server/state.d.ts.map +1 -1
  24. package/dist/server/supervisor.d.ts +12 -4
  25. package/dist/server/supervisor.d.ts.map +1 -1
  26. package/dist/ssh-target.d.ts +3 -18
  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 +117 -34
  35. package/src/operations.ts +104 -61
  36. package/src/plan.ts +59 -0
  37. package/src/render.ts +128 -31
  38. package/src/server/cli.ts +26 -9
  39. package/src/server/manifest.ts +42 -4
  40. package/src/server/release-host.ts +81 -0
  41. package/src/server/release.ts +738 -0
  42. package/src/server/state.ts +3 -1
  43. package/src/server/supervisor.ts +127 -55
  44. package/src/sh.d.ts +4 -0
  45. package/src/ssh-target.ts +46 -227
  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 -38
  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 -231
  61. package/src/ci.ts +0 -88
  62. package/src/keys.ts +0 -57
  63. package/src/scripts.ts +0 -323
  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,49 +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
34
  }
53
35
 
54
- const OPTIONS = ["host", "user", "ports"] as const
55
-
56
36
  const DEFAULT_USER = "sixb"
57
37
 
58
- const DEFAULT_PORTS = {
59
- app: 3001,
60
- api: 3002,
61
- } as const satisfies Record<DeployHttpServiceName, number>
62
-
63
- /** Services listen on loopback only: Caddy on the same server is their one way in. */
64
- 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
+ }
65
43
 
66
44
  /** A Linux account name `useradd` accepts. */
67
45
  const USER_PATTERN = /^[a-z_][a-z0-9_-]{0,31}$/
68
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
+
69
50
  /** A server reached over SSH, where Caddy routes each domain to its service. */
70
51
  export class SshTarget implements DeployTarget {
71
52
  readonly kind = "ssh"
72
53
  readonly host: string
54
+ /** The account the deployment logs in and runs as. */
73
55
  readonly user: string
74
56
  readonly location: string
75
- readonly #ports: Readonly<Record<DeployHttpServiceName, number>>
76
57
 
77
58
  constructor(options: SshTargetOptions) {
78
59
  if (typeof options !== "object" || options === null) {
@@ -81,23 +62,24 @@ export class SshTarget implements DeployTarget {
81
62
  )
82
63
  }
83
64
  for (const key of Object.keys(options)) {
84
- if (!(OPTIONS as readonly string[]).includes(key)) {
85
- 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.`)
86
69
  }
87
70
  }
88
71
 
89
72
  this.host = validateHost(options.host)
90
73
  this.user = validateUser(options.user ?? DEFAULT_USER)
91
74
  this.location = `${this.user}@${this.host}`
92
- this.#ports = { ...DEFAULT_PORTS, ...validatePorts(options.ports) }
93
75
  }
94
76
 
95
77
  listenAddress(service: DeployHttpServiceName): DeployListenAddress {
96
- return { host: LISTEN_HOST, port: this.#ports[service] }
78
+ return { host: LISTEN_HOST, port: SLOT_PORTS.blue[service] }
97
79
  }
98
80
 
99
81
  deploy(release: DeployRelease, source: DeploySource, context: DeployContext): Promise<void> {
100
- return this.#connected((shell) => deployRelease(shell, this.user, release, source, context))
82
+ return this.#connected((shell) => deployRelease(shell, release, source, context))
101
83
  }
102
84
 
103
85
  status(context: DeployOperationContext): Promise<DeployStatus> {
@@ -129,14 +111,17 @@ export class SshTarget implements DeployTarget {
129
111
  try {
130
112
  server = await this.#connected(async (shell) => [
131
113
  { id: "ssh", label: "SSH", status: "ok" as const, detail: this.location },
132
- ...(await runChecks(shell, {
114
+ ...(await checkHost(shell, {
133
115
  name: context.name,
134
116
  projectPath: context.projectPath,
135
- ports: release.services.flatMap((service) =>
136
- service.http ? [{ service: service.name, port: service.http.port }] : []
137
- ),
138
- envFromSource: release.steps.env !== undefined,
139
- 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,
140
125
  })),
141
126
  ])
142
127
  } catch (error) {
@@ -145,114 +130,6 @@ export class SshTarget implements DeployTarget {
145
130
  return [...server, ...(await dns)]
146
131
  }
147
132
 
148
- /**
149
- * Prepares the server as the admin login when the deploy user or the server is not set up
150
- * yet, then the project as the deploy user. Running it again changes nothing that is right.
151
- */
152
- async setup(release: DeployRelease, context: DeploySetupContext): Promise<void> {
153
- const before = await this.check(release, context)
154
- const serverFixes = before.filter(
155
- (check) =>
156
- (check.status === "fixable" &&
157
- check.id !== "project.env" &&
158
- check.id !== ENV_TOKEN_CHECK) ||
159
- (check.id === "ssh" && check.status !== "ok")
160
- )
161
- const unreachable = before.find((check) => check.id === "ssh" && check.status === "manual")
162
- if (unreachable) {
163
- throw new Error(`[SshTarget] ${unreachable.detail}`)
164
- }
165
-
166
- if (serverFixes.length > 0) {
167
- const admin = context.admin ?? "root"
168
- const { identityFiles } = await resolveSshConfig(this.location)
169
- const key = await pickPublicKey({ key: context.key, identityFiles })
170
- context.write(
171
- `Setting up ${this.host} as ${admin}, authorizing ${key.source} for ${this.user}.`
172
- )
173
- await runAsAdmin(
174
- `${admin}@${this.host}`,
175
- admin === "root",
176
- renderAdminScript({ user: this.user, publicKey: key.text, admin })
177
- )
178
- }
179
-
180
- context.write(`Preparing ${context.name} as ${this.user}.`)
181
- await this.#connected((shell) =>
182
- shell.run(
183
- [
184
- `project="$HOME"/${shellQuote(`${context.name}/code/${context.projectPath}`)}`,
185
- 'mkdir -p "$project"',
186
- 'if [ -f "$project/.env" ]; then chmod 600 "$project/.env"; fi',
187
- `token="$HOME"/${shellQuote(`${context.name}/${ENV_TOKEN_FILE}`)}`,
188
- 'if [ -f "$token" ]; then chmod 600 "$token"; fi',
189
- ].join("\n")
190
- )
191
- )
192
-
193
- const { createEnvToken } = context
194
- if (release.steps.env && createEnvToken) {
195
- const installed = await this.#connected((shell) =>
196
- ensureEnvToken(shell, context.name, createEnvToken)
197
- )
198
- if (installed) context.write(`Installed a read-only token for ${context.name}.`)
199
- }
200
- }
201
-
202
- readonly access: DeployAccess = {
203
- list: () => this.#connected(async (shell) => (await listKeys(shell)).map(withoutLine)),
204
- add: (key) => this.#connected((shell) => addKey(shell, key)).then(withoutLine),
205
- remove: (match) =>
206
- this.#connected(async (shell) => (await removeKeys(shell, match)).map(withoutLine)),
207
- }
208
-
209
- readonly ci: DeployCi = {
210
- create: (job, context) => this.#createCiKey(job, context.name),
211
- }
212
-
213
- /**
214
- * A key for one CI job, allowed to run commands and nothing else (no forwarding, no terminal),
215
- * with the server's host keys pinned so CI never trusts an address on first sight.
216
- */
217
- async #createCiKey(job: string, name: string): Promise<DeployCiCredential> {
218
- const ssh = await resolveSshConfig(this.location)
219
- if (ssh.proxyJump) {
220
- throw new Error(
221
- `[SshTarget] Your SSH config reaches ${this.host} through ${ssh.proxyJump}, and CI connects ` +
222
- "directly. Set `host` to an address CI can reach."
223
- )
224
- }
225
- // One comment per job and deployment: it is how a later run finds the keys it replaces.
226
- const comment = `sixb-ci:${name}@${job}`
227
- const pair = await generateCiKey(comment)
228
- const { key, hostKeys } = await this.#connected(async (shell) => ({
229
- hostKeys: await readHostKeys(shell),
230
- key: await addKey(shell, pair.publicKey, "restrict"),
231
- }))
232
-
233
- return {
234
- description: `${key.fingerprint} for ${this.location}, restricted to running commands`,
235
- secrets: {
236
- SIXB_DEPLOY_SSH_KEY: pair.privateKey,
237
- SIXB_DEPLOY_KNOWN_HOSTS: knownHostsLines(hostKeys, ssh.hostname, ssh.port).join("\n"),
238
- },
239
- install: renderCiInstall({ host: this.host, hostname: ssh.hostname, port: ssh.port }),
240
- retireOthers: () =>
241
- this.#connected(async (shell) =>
242
- (
243
- await removeKeysWhere(
244
- shell,
245
- (other) => other.comment === comment && other.fingerprint !== key.fingerprint
246
- )
247
- ).map(withoutLine)
248
- ),
249
- revoke: () =>
250
- this.#connected(async (shell) => {
251
- await removeKeysWhere(shell, (other) => other.fingerprint === key.fingerprint)
252
- }),
253
- }
254
- }
255
-
256
133
  async #connected<T>(work: (shell: RemoteShell) => Promise<T>): Promise<T> {
257
134
  const shell = await SshShell.open(this.location)
258
135
  try {
@@ -263,6 +140,19 @@ export class SshTarget implements DeployTarget {
263
140
  }
264
141
  }
265
142
 
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
+ )
152
+ }
153
+ return value
154
+ }
155
+
266
156
  function validateHost(value: unknown): string {
267
157
  if (typeof value !== "string" || value.trim() === "") {
268
158
  throw new Error("[SshTarget] host must be the server's hostname or IP address.")
@@ -270,7 +160,7 @@ function validateHost(value: unknown): string {
270
160
  const host = value.trim()
271
161
  if (host.includes("@")) {
272
162
  throw new Error(
273
- `[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\`.`
274
164
  )
275
165
  }
276
166
  // `ssh` reads an argument that starts with `-` as an option, not a host.
@@ -286,84 +176,13 @@ function validateHost(value: unknown): string {
286
176
  return host
287
177
  }
288
178
 
289
- function validateUser(value: unknown): string {
290
- if (value === "root") {
291
- throw new Error(
292
- "[SshTarget] Deployments never run as root. Use a deploy user without sudo, such as the " +
293
- 'default "sixb".'
294
- )
295
- }
296
- if (typeof value !== "string" || !USER_PATTERN.test(value)) {
297
- throw new Error(
298
- `[SshTarget] user ${JSON.stringify(value)} is not a Linux user name. Use lowercase ` +
299
- "letters, digits, underscores, and hyphens, starting with a letter or underscore."
300
- )
301
- }
302
- return value
303
- }
304
-
305
- function validatePorts(value: unknown): Partial<Record<DeployHttpServiceName, number>> {
306
- if (value === undefined) return {}
307
- if (typeof value !== "object" || value === null || Array.isArray(value)) {
308
- throw new Error("[SshTarget] ports must be an object, such as `{ api: 3012 }`.")
309
- }
310
-
311
- const ports: Partial<Record<DeployHttpServiceName, number>> = {}
312
- for (const [service, port] of Object.entries(value)) {
313
- if (!Object.hasOwn(DEFAULT_PORTS, service)) {
314
- throw new Error(`[SshTarget] ports.${service} is not an HTTP service. Available: api, app.`)
315
- }
316
- // A deploy user has no privileges, and ports below 1024 need them.
317
- if (!Number.isInteger(port) || port < 1024 || port > 65_535) {
318
- throw new Error(`[SshTarget] ports.${service} must be a port from 1024 to 65535.`)
319
- }
320
- ports[service as DeployHttpServiceName] = port
321
- }
322
- return ports
323
- }
324
-
325
- /** 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. */
326
180
  function sshCheck(location: string, error: unknown): DeployCheck {
327
- const message =
328
- (error instanceof Error ? error.message : String(error))
329
- .split("\n")[0]
330
- ?.replace(/^\[SshTarget\] /, "") ?? ""
331
- if (error instanceof RemoteScriptError && /refused your SSH key/.test(message)) {
332
- return {
333
- id: "ssh",
334
- label: "SSH",
335
- status: "fixable",
336
- detail: message,
337
- 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.`,
338
- }
339
- }
181
+ const [message = ""] = (error instanceof Error ? error.message : String(error)).split("\n")
340
182
  return {
341
183
  id: "ssh",
342
184
  label: "SSH",
343
- status: "manual",
344
- detail: message || `Cannot reach ${location}.`,
345
- }
346
- }
347
-
348
- function withoutLine({ type, fingerprint, comment, restricted }: DeployAccessKey): DeployAccessKey {
349
- return { type, fingerprint, comment, restricted }
350
- }
351
-
352
- /**
353
- * Runs the setup script as the admin login with the terminal attached, so sudo can ask for its
354
- * password and the person running setup sees each step.
355
- */
356
- async function runAsAdmin(destination: string, root: boolean, script: string): Promise<void> {
357
- const command = `${root ? "" : "sudo "}bash -c ${shellQuote(script)}`
358
- // LogLevel=ERROR drops the "Connection closed" line a terminal session ends with, not errors.
359
- const ssh = ["ssh", "-tt", "-o", "ConnectTimeout=15", "-o", "LogLevel=ERROR"]
360
- const child = Bun.spawn([...ssh, destination, command], {
361
- stdio: ["inherit", "inherit", "inherit"],
362
- })
363
- const exitCode = await child.exited
364
- if (exitCode !== 0) {
365
- throw new Error(
366
- `[SshTarget] Setting up the server as ${destination} failed (exit code ${exitCode}).`
367
- )
185
+ status: "fail",
186
+ detail: message.replace(/^\[SshTarget\] /, "") || `Cannot reach ${location}.`,
368
187
  }
369
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,CA0ET;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,38 +0,0 @@
1
- import type { DeployRecord, DeployRelease } from "@sixb/core/deploy";
2
- import type { DeploymentLayout } from "./layout";
3
- /** A line the deploy script prints around each step; the target turns it into progress. */
4
- export declare const STEP_MARKER = "__SIXB_STEP__";
5
- /** The server's home directory, and a fresh directory to upload the source into. */
6
- export declare function renderPrepareScript(name: string, commit: string): string;
7
- /** Extracts one uploaded archive from standard input. */
8
- export declare function renderReceiveScript(incoming: string, path: string): string;
9
- export interface DeployScriptInput {
10
- readonly release: DeployRelease;
11
- readonly layout: DeploymentLayout;
12
- readonly incoming: string;
13
- readonly record: DeployRecord;
14
- }
15
- export interface DeployScript {
16
- readonly labels: readonly string[];
17
- readonly script: string;
18
- }
19
- /**
20
- * Everything the server does once the source is uploaded, as one script that holds the
21
- * deployment's lock throughout. It runs with standard input closed: bash reads the whole `main`
22
- * function before running any of it, so no command can swallow the rest of the script.
23
- */
24
- export declare function renderDeployScript(input: DeployScriptInput): DeployScript;
25
- /**
26
- * Makes `code/` match the commit the way `git reset --hard` would: committed files replace what is
27
- * there, files the previous deploy brought and this one does not are removed, and everything else
28
- * — `.env`, `.sixb/`, `node_modules/` — stays. A committed `.env` is never copied over the
29
- * server's.
30
- */
31
- export declare function renderApplyFiles(layout: DeploymentLayout, incoming: string): string;
32
- /**
33
- * Done means healthy, not just started: the API answers its readiness route, and no process has
34
- * exited in its first seconds. Those seconds count from "Start services", so the time the API
35
- * takes to boot is part of them rather than added to them.
36
- */
37
- export declare function renderCheckServices(readinessUrl: string | null): string;
38
- //# 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,EAAiB,YAAY,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AACnF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAA;AAIhD,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;CAC9B;AAED,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAA;IAClC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CACxB;AAOD;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,iBAAiB,GAAG,YAAY,CA4CzE;AAwCD;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAuBnF;AAkID;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAyBvE"}
package/dist/setup.d.ts DELETED
@@ -1,32 +0,0 @@
1
- import { type RemoteShell } from "./transport";
2
- /**
3
- * Everything that needs root, run once per server and once per deploy user, safe to run again.
4
- * Afterwards the deploy user needs no sudo but reloading Caddy.
5
- *
6
- * Caddy's configuration is taken over only when it is still the one the package installed. A
7
- * server that already serves other sites keeps its configuration and gains one import line (the
8
- * old file is kept beside it), and its admin API stays where that configuration puts it.
9
- */
10
- export declare function renderAdminScript(input: {
11
- readonly user: string;
12
- readonly publicKey: string;
13
- readonly admin: string;
14
- }): string;
15
- /**
16
- * The public key to authorize for deploys: the one given, else the first key SSH would offer to
17
- * the server that has a `.pub` beside it, else the first key in the SSH agent.
18
- */
19
- export declare function pickPublicKey(input: {
20
- readonly key?: string;
21
- readonly identityFiles: readonly string[];
22
- }): Promise<{
23
- readonly text: string;
24
- readonly source: string;
25
- }>;
26
- /**
27
- * Creates the deploy's token when the server doesn't have one. This asks the server rather than
28
- * going by the checks setup started with: on a fresh server those stop at SSH, before they reach
29
- * the token. Returns whether it installed one.
30
- */
31
- export declare function ensureEnvToken(shell: RemoteShell, name: string, createToken: () => Promise<string>): Promise<boolean>;
32
- //# sourceMappingURL=setup.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../src/setup.ts"],"names":[],"mappings":"AAGA,OAAO,EAAqB,KAAK,WAAW,EAAE,MAAM,aAAa,CAAA;AAKjE;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE;IACvC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CACvB,GAAG,MAAM,CAoHT;AAED;;;GAGG;AACH,wBAAsB,aAAa,CAAC,KAAK,EAAE;IACzC,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,aAAa,EAAE,SAAS,MAAM,EAAE,CAAA;CAC1C,GAAG,OAAO,CAAC;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC,CAsB9D;AAED;;;;GAIG;AACH,wBAAsB,cAAc,CAClC,KAAK,EAAE,WAAW,EAClB,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,GACjC,OAAO,CAAC,OAAO,CAAC,CAwBlB"}