@sixb/deploy-ssh 0.1.0

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 (66) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +74 -0
  3. package/dist/access.d.ts +11 -0
  4. package/dist/access.d.ts.map +1 -0
  5. package/dist/check.d.ts +28 -0
  6. package/dist/check.d.ts.map +1 -0
  7. package/dist/ci.d.ts +27 -0
  8. package/dist/ci.d.ts.map +1 -0
  9. package/dist/index.d.ts +3 -0
  10. package/dist/index.d.ts.map +1 -0
  11. package/dist/index.js +1415 -0
  12. package/dist/index.js.map +24 -0
  13. package/dist/keys.d.ts +13 -0
  14. package/dist/keys.d.ts.map +1 -0
  15. package/dist/layout.d.ts +38 -0
  16. package/dist/layout.d.ts.map +1 -0
  17. package/dist/operations.d.ts +10 -0
  18. package/dist/operations.d.ts.map +1 -0
  19. package/dist/render.d.ts +15 -0
  20. package/dist/render.d.ts.map +1 -0
  21. package/dist/scripts.d.ts +37 -0
  22. package/dist/scripts.d.ts.map +1 -0
  23. package/dist/server/cli.d.ts +3 -0
  24. package/dist/server/cli.d.ts.map +1 -0
  25. package/dist/server/logs.d.ts +25 -0
  26. package/dist/server/logs.d.ts.map +1 -0
  27. package/dist/server/manifest.d.ts +30 -0
  28. package/dist/server/manifest.d.ts.map +1 -0
  29. package/dist/server/state.d.ts +32 -0
  30. package/dist/server/state.d.ts.map +1 -0
  31. package/dist/server/supervisor.d.ts +16 -0
  32. package/dist/server/supervisor.d.ts.map +1 -0
  33. package/dist/setup.d.ts +25 -0
  34. package/dist/setup.d.ts.map +1 -0
  35. package/dist/shell.d.ts +5 -0
  36. package/dist/shell.d.ts.map +1 -0
  37. package/dist/ssh-config.d.ts +12 -0
  38. package/dist/ssh-config.d.ts.map +1 -0
  39. package/dist/ssh-target.d.ts +39 -0
  40. package/dist/ssh-target.d.ts.map +1 -0
  41. package/dist/transport.d.ts +45 -0
  42. package/dist/transport.d.ts.map +1 -0
  43. package/dist/tsconfig.json +5 -0
  44. package/dist/update-page.d.ts +6 -0
  45. package/dist/update-page.d.ts.map +1 -0
  46. package/package.json +61 -0
  47. package/src/access.ts +107 -0
  48. package/src/check.ts +215 -0
  49. package/src/ci.ts +88 -0
  50. package/src/index.ts +2 -0
  51. package/src/keys.ts +57 -0
  52. package/src/layout.ts +69 -0
  53. package/src/operations.ts +158 -0
  54. package/src/render.ts +129 -0
  55. package/src/scripts.ts +305 -0
  56. package/src/server/cli.ts +157 -0
  57. package/src/server/logs.ts +180 -0
  58. package/src/server/manifest.ts +112 -0
  59. package/src/server/state.ts +81 -0
  60. package/src/server/supervisor.ts +542 -0
  61. package/src/setup.ts +166 -0
  62. package/src/shell.ts +10 -0
  63. package/src/ssh-config.ts +35 -0
  64. package/src/ssh-target.ts +347 -0
  65. package/src/transport.ts +211 -0
  66. package/src/update-page.ts +44 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Sixb contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,74 @@
1
+ # @sixb/deploy-ssh
2
+
3
+ The SSH target for `sixb deploy`. It runs a Sixb project on a Linux server you reach over SSH, under
4
+ an account without root access, with Caddy serving each domain over HTTPS.
5
+
6
+ ```ts
7
+ // sixb.deploy.ts
8
+ import { defineDeploy } from "@sixb/core/deploy"
9
+ import { SshTarget } from "@sixb/deploy-ssh"
10
+
11
+ export default defineDeploy({
12
+ name: "northline",
13
+ domain: "example.com",
14
+ target: new SshTarget({ host: "203.0.113.10" }),
15
+ })
16
+ ```
17
+
18
+ - [Deploy to a server](https://docs.sixb.ai/deployment/servers): the options, setup, and commands.
19
+ - [Deploy from GitHub Actions](https://docs.sixb.ai/deployment/github-actions).
20
+ - [Server accounts and access](https://docs.sixb.ai/deployment/server-access): who can do what, and
21
+ several projects on one server.
22
+
23
+ ## How it works
24
+
25
+ The rest of this file is for working on the package.
26
+
27
+ ### On the server
28
+
29
+ Each deployment lives in its deploy user's home:
30
+
31
+ ```
32
+ ~/<name>/code the deployed commit, with the project's .env
33
+ ~/<name>/deploy the lock, uploads, file list, release record, process manifest, and ctl
34
+ ~/<name>/run process state and logs
35
+ ~/.sixb/bun/<v> Bun, shared by the user's projects on the same version
36
+ ```
37
+
38
+ - **Processes.** The user unit `~/.config/systemd/user/sixb-<name>.service` runs the supervisor
39
+ (`src/server/`, this package's `sixb-deploy-ssh` bin) over `deploy/processes.json`. The
40
+ supervisor restarts a process that exits, waiting `restartDelayMs` times its restart count up to
41
+ a cap, restarts one past `maxMemory`, and rotates logs at 20 MB. Linger starts the unit at boot.
42
+ `deploy/ctl` is what `status`, `logs`, and `restart` call.
43
+ - **Routes.** Each deployment writes `/etc/caddy/sixb.d/<user>/<name>.caddy`. Caddy loads it through
44
+ the root-owned `/etc/caddy/sixb.d/<user>.caddy`, which imports `/etc/caddy/sixb.d/<user>/*.caddy`,
45
+ and the root Caddyfile imports `/etc/caddy/sixb.d/*.caddy`: Caddy allows one `*` per import
46
+ pattern. A deploy runs `caddy validate` on the whole configuration before
47
+ `sudo systemctl reload caddy`, the one command the `sixb-deploy` group may run as root, and puts
48
+ the previous snippet back when Caddy rejects the new one. Atlas and the app answer 502, 503, and
49
+ 504 with the update page in `src/update-page.ts`.
50
+ - **The deploy.** `src/scripts.ts` renders one script that holds `deploy/lock` throughout and prints
51
+ a marker around each step, which the CLI turns into progress. `code/` is updated like
52
+ `git reset --hard`, using the previous deploy's `deploy/files.txt` to find removed files.
53
+
54
+ ### From your machine
55
+
56
+ - Each command uses one SSH connection, multiplexed, in batch mode: it never prompts.
57
+ `src/transport.ts` rewords OpenSSH's own failures as what to do about them.
58
+ - The source is a `git archive` of the repository and of each submodule at its recorded commit,
59
+ streamed into `deploy/incoming/`.
60
+ - `setup` runs `src/setup.ts`'s script as the admin login with a terminal attached, so `sudo` can
61
+ ask for a password. `check` runs `src/check.ts`'s script as the deploy user; it prints one
62
+ `__SIXB_CHECK__` line per check.
63
+ - `access` rewrites `authorized_keys` through a rename, and refuses when the file changed since it
64
+ was read. `ci` makes its key in `src/ci.ts`.
65
+
66
+ ### Testing
67
+
68
+ `bun test deploy/ssh/tests` runs the unit tests. `tests/server.e2e.ts` deploys Northline to a
69
+ server that `sixb deploy setup` prepared, and drives it through the CLI:
70
+
71
+ ```bash
72
+ SIXB_DEPLOY_TEST_HOST=203.0.113.10 SIXB_DEPLOY_TEST_DOMAIN=example.com \
73
+ bun test ./deploy/ssh/tests/server.e2e.ts
74
+ ```
@@ -0,0 +1,11 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,28 @@
1
+ import type { DeployCheck, DeployRelease } from "@sixb/core/deploy";
2
+ import type { RemoteShell } from "./transport";
3
+ export declare const CHECK_MARKER = "__SIXB_CHECK__";
4
+ /**
5
+ * Checks the server as the deploy user, changing nothing. Each check prints one
6
+ * `__SIXB_CHECK__ id status detail` line; labels and remedies are added on this side.
7
+ */
8
+ export declare function renderCheckScript(input: {
9
+ readonly name: string;
10
+ readonly projectPath: string;
11
+ readonly ports: readonly {
12
+ readonly service: string;
13
+ readonly port: number;
14
+ }[];
15
+ }): string;
16
+ /** Reads the check script's output into checks, with labels and remedies. */
17
+ export declare function parseCheckOutput(lines: readonly string[], context: {
18
+ readonly location: string;
19
+ readonly name: string;
20
+ }): DeployCheck[];
21
+ /** Where each HTTP domain resolves, against where the target is. */
22
+ export declare function checkDns(release: DeployRelease, hostname: string): Promise<DeployCheck[]>;
23
+ /** The checks that stop a deploy. */
24
+ export declare function blocksDeploy(check: DeployCheck): boolean;
25
+ export declare function runChecks(shell: RemoteShell, input: Parameters<typeof renderCheckScript>[0] & {
26
+ readonly location: string;
27
+ }): Promise<DeployCheck[]>;
28
+ //# sourceMappingURL=check.d.ts.map
@@ -0,0 +1 @@
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;AAEnE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAE9C,eAAO,MAAM,YAAY,mBAAmB,CAAA;AAO5C;;;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;CAC/E,GAAG,MAAM,CAgET;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 ADDED
@@ -0,0 +1,27 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,3 @@
1
+ export type { SshTargetOptions } from "./ssh-target";
2
+ export { SshTarget } from "./ssh-target";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA"}