@sixb/deploy-ssh 0.1.4 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/check.d.ts +3 -0
- package/dist/check.d.ts.map +1 -1
- package/dist/index.js +136 -42
- package/dist/index.js.map +11 -11
- package/dist/layout.d.ts +3 -0
- package/dist/layout.d.ts.map +1 -1
- package/dist/operations.d.ts +8 -1
- package/dist/operations.d.ts.map +1 -1
- package/dist/render.d.ts.map +1 -1
- package/dist/scripts.d.ts.map +1 -1
- package/dist/server/manifest.d.ts +5 -0
- package/dist/server/manifest.d.ts.map +1 -1
- package/dist/server/run.d.ts +23 -0
- package/dist/server/run.d.ts.map +1 -0
- package/dist/setup.d.ts +7 -0
- package/dist/setup.d.ts.map +1 -1
- package/dist/ssh-target.d.ts +2 -1
- package/dist/ssh-target.d.ts.map +1 -1
- package/dist/transport.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/check.ts +19 -3
- package/src/layout.ts +5 -0
- package/src/operations.ts +52 -0
- package/src/render.ts +1 -0
- package/src/scripts.ts +9 -2
- package/src/server/cli.ts +13 -0
- package/src/server/manifest.ts +17 -7
- package/src/server/run.ts +246 -0
- package/src/setup.ts +37 -0
- package/src/ssh-target.ts +29 -4
- package/src/transport.ts +5 -2
package/dist/layout.d.ts
CHANGED
|
@@ -3,13 +3,16 @@
|
|
|
3
3
|
* sits in one directory in the deploy user's home, so projects under one user never share files.
|
|
4
4
|
*
|
|
5
5
|
* ~/<name>/code the deployed commit; the project is `code/<projectPath>`
|
|
6
|
+
* ~/<name>/env-token the read-only token a deploy pulls `.env` with, if it has a source
|
|
6
7
|
* ~/<name>/deploy lock, uploads, file list, release record, process manifest, ctl
|
|
7
8
|
* ~/<name>/run supervisor state, control requests, and logs
|
|
8
9
|
* ~/.sixb/bun/<v> Bun, shared by the user's projects that pin the same version
|
|
9
10
|
*/
|
|
11
|
+
export declare const ENV_TOKEN_FILE = "env-token";
|
|
10
12
|
export interface DeploymentLayout {
|
|
11
13
|
readonly root: string;
|
|
12
14
|
readonly code: string;
|
|
15
|
+
readonly envToken: string;
|
|
13
16
|
readonly project: string;
|
|
14
17
|
readonly deployDir: string;
|
|
15
18
|
readonly incomingDir: string;
|
package/dist/layout.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"layout.d.ts","sourceRoot":"","sources":["../src/layout.ts"],"names":[],"mappings":"AAEA
|
|
1
|
+
{"version":3,"file":"layout.d.ts","sourceRoot":"","sources":["../src/layout.ts"],"names":[],"mappings":"AAEA;;;;;;;;;GASG;AACH,eAAO,MAAM,cAAc,cAAc,CAAA;AAEzC,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IACxB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAA;IAC9B,gFAAgF;IAChF,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAA;CAC9B;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE;IACtC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;IAC5B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;CAC5B,GAAG,gBAAgB,CA8BnB"}
|
package/dist/operations.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { DeployContext, DeployControlAction, DeployLogsOptions, DeployRelease, DeploySource, DeployStatus } from "@sixb/core/deploy";
|
|
1
|
+
import type { DeployContext, DeployControlAction, DeployLogsOptions, DeployRelease, DeployScript, DeploySource, DeployStatus } from "@sixb/core/deploy";
|
|
2
2
|
import { type RemoteShell } from "./transport";
|
|
3
3
|
/** Uploads the source, then runs the release on the server as one locked script. */
|
|
4
4
|
export declare function deployRelease(shell: RemoteShell, user: string, release: DeployRelease, source: DeploySource, context: DeployContext): Promise<void>;
|
|
@@ -7,4 +7,11 @@ export declare function streamLogs(shell: RemoteShell, name: string, options: De
|
|
|
7
7
|
readonly terminal?: boolean;
|
|
8
8
|
}): Promise<void>;
|
|
9
9
|
export declare function controlServices(shell: RemoteShell, name: string, action: DeployControlAction, service: string | undefined): Promise<void>;
|
|
10
|
+
/**
|
|
11
|
+
* Uploads the script, then runs it through `ctl run` in a terminal on the server: Ctrl-C reaches
|
|
12
|
+
* the script there, and so does a dropped connection, as a hangup. Holding the deploy lock shared
|
|
13
|
+
* for the whole run keeps a deploy from replacing the code it imports or migrating its storage;
|
|
14
|
+
* runs share it with each other. Resolves with the script's exit code.
|
|
15
|
+
*/
|
|
16
|
+
export declare function runDeployScript(shell: RemoteShell, name: string, script: DeployScript): Promise<number>;
|
|
10
17
|
//# sourceMappingURL=operations.d.ts.map
|
package/dist/operations.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"operations.d.ts","sourceRoot":"","sources":["../src/operations.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"operations.d.ts","sourceRoot":"","sources":["../src/operations.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,aAAa,EACb,mBAAmB,EACnB,iBAAiB,EACjB,aAAa,EACb,YAAY,EACZ,YAAY,EACZ,YAAY,EACb,MAAM,mBAAmB,CAAA;AAU1B,OAAO,EAAqB,KAAK,WAAW,EAAE,MAAM,aAAa,CAAA;AAIjE,oFAAoF;AACpF,wBAAsB,aAAa,CACjC,KAAK,EAAE,WAAW,EAClB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,aAAa,EACtB,MAAM,EAAE,YAAY,EACpB,OAAO,EAAE,aAAa,GACrB,OAAO,CAAC,IAAI,CAAC,CAkCf;AAmCD,wBAAsB,UAAU,CAAC,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,CAOxF;AAED,wBAAsB,UAAU,CAC9B,KAAK,EAAE,WAAW,EAClB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,iBAAiB,GAAG;IAAE,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE,GAC3D,OAAO,CAAC,IAAI,CAAC,CAWf;AAED,wBAAsB,eAAe,CACnC,KAAK,EAAE,WAAW,EAClB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,mBAAmB,EAC3B,OAAO,EAAE,MAAM,GAAG,SAAS,GAC1B,OAAO,CAAC,IAAI,CAAC,CAEf;AAED;;;;;GAKG;AACH,wBAAsB,eAAe,CACnC,KAAK,EAAE,WAAW,EAClB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,YAAY,GACnB,OAAO,CAAC,MAAM,CAAC,CAsCjB"}
|
package/dist/render.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../src/render.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AACtD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAA;AAChD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAMxD,kFAAkF;AAClF,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,aAAa,EACtB,MAAM,EAAE,gBAAgB,GACvB,eAAe,
|
|
1
|
+
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../src/render.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AACtD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAA;AAChD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAMxD,kFAAkF;AAClF,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,aAAa,EACtB,MAAM,EAAE,gBAAgB,GACvB,eAAe,CAyBjB;AAED,8EAA8E;AAC9E,wBAAgB,SAAS,CAAC,MAAM,EAAE,gBAAgB,GAAG,MAAM,CAO1D;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,gBAAgB,GAAG,MAAM,CAyBnF;AAED,2EAA2E;AAC3E,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,aAAa,GAAG,MAAM,CAejE"}
|
package/dist/scripts.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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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,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"}
|
|
@@ -9,6 +9,11 @@ export interface ProcessManifest {
|
|
|
9
9
|
readonly logDir: string;
|
|
10
10
|
/** Written by the deploy; read back by `status`. */
|
|
11
11
|
readonly releasePath: string;
|
|
12
|
+
/**
|
|
13
|
+
* The environment every service starts from, before its own additions: what `ctl run` gives a
|
|
14
|
+
* script. Absent from deployments made before scripts could run.
|
|
15
|
+
*/
|
|
16
|
+
readonly env?: Readonly<Record<string, string>>;
|
|
12
17
|
readonly services: readonly ProcessServiceManifest[];
|
|
13
18
|
}
|
|
14
19
|
export interface ProcessServiceManifest {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manifest.d.ts","sourceRoot":"","sources":["../../src/server/manifest.ts"],"names":[],"mappings":"AAGA,4FAA4F;AAC5F,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAA;IACnB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,qDAAqD;IACrD,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;IACpB,8DAA8D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KAAK,EAAE,OAAO,EAAE,MAAM,SAAqB,GAAG,eAAe,CAmBjG"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { ProcessManifest } from "./manifest";
|
|
2
|
+
/**
|
|
3
|
+
* `ctl run <staged> <path> [args...]`: puts an uploaded script at `path` in the deployed project and
|
|
4
|
+
* runs `sixb run` on it there, so its imports resolve against the deployed code, with the
|
|
5
|
+
* environment the deployment's services start from. The caller holds the deploy lock shared for
|
|
6
|
+
* the whole run, so no deploy replaces that code or migrates its storage underneath. Resolves with
|
|
7
|
+
* the exit code to end with.
|
|
8
|
+
*
|
|
9
|
+
* absent write it, and delete it afterwards
|
|
10
|
+
* identical run the deployed file in place
|
|
11
|
+
* different refuse: the deployed file is someone's committed work
|
|
12
|
+
*
|
|
13
|
+
* One run per path at a time: a second run of the same new file would find the first one's copy,
|
|
14
|
+
* and the first one's cleanup would delete it underneath the second. Each run marks its path, and
|
|
15
|
+
* whether it wrote the file, so a later run removes what a killed one left in the deployed code.
|
|
16
|
+
*/
|
|
17
|
+
export declare function runScript(input: {
|
|
18
|
+
readonly manifest: ProcessManifest;
|
|
19
|
+
readonly staged: string;
|
|
20
|
+
readonly path: string;
|
|
21
|
+
readonly args: readonly string[];
|
|
22
|
+
}): Promise<number>;
|
|
23
|
+
//# sourceMappingURL=run.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../src/server/run.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAGjD;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,SAAS,CAAC,KAAK,EAAE;IACrC,QAAQ,CAAC,QAAQ,EAAE,eAAe,CAAA;IAClC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,CAAA;CACjC,GAAG,OAAO,CAAC,MAAM,CAAC,CA4BlB"}
|
package/dist/setup.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type RemoteShell } from "./transport";
|
|
1
2
|
/**
|
|
2
3
|
* Everything that needs root, run once per server and once per deploy user, safe to run again.
|
|
3
4
|
* Afterwards the deploy user needs no sudo but reloading Caddy.
|
|
@@ -22,4 +23,10 @@ export declare function pickPublicKey(input: {
|
|
|
22
23
|
readonly text: string;
|
|
23
24
|
readonly source: string;
|
|
24
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>;
|
|
25
32
|
//# sourceMappingURL=setup.d.ts.map
|
package/dist/setup.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../src/setup.ts"],"names":[],"mappings":"
|
|
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"}
|
package/dist/ssh-target.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { DeployAccess, DeployCheck, DeployCheckContext, DeployCi, DeployContext, DeployControlAction, DeployHttpServiceName, DeployListenAddress, DeployLogsOptions, DeployOperationContext, DeployRelease, DeploySetupContext, DeploySource, DeployStatus, DeployTarget } from "@sixb/core/deploy";
|
|
1
|
+
import type { DeployAccess, DeployCheck, DeployCheckContext, DeployCi, DeployContext, DeployControlAction, DeployHttpServiceName, DeployListenAddress, DeployLogsOptions, DeployOperationContext, DeployRelease, DeployScript, DeploySetupContext, DeploySource, DeployStatus, DeployTarget } from "@sixb/core/deploy";
|
|
2
2
|
export interface SshTargetOptions {
|
|
3
3
|
/** The server: a hostname, an IP address, or a `Host` alias from your SSH config. */
|
|
4
4
|
readonly host: string;
|
|
@@ -27,6 +27,7 @@ export declare class SshTarget implements DeployTarget {
|
|
|
27
27
|
status(context: DeployOperationContext): Promise<DeployStatus>;
|
|
28
28
|
logs(options: DeployLogsOptions, context: DeployOperationContext): Promise<void>;
|
|
29
29
|
control(action: DeployControlAction, service: string | undefined, context: DeployOperationContext): Promise<void>;
|
|
30
|
+
run(script: DeployScript, context: DeployOperationContext): Promise<number>;
|
|
30
31
|
check(release: DeployRelease, context: DeployCheckContext): Promise<DeployCheck[]>;
|
|
31
32
|
/**
|
|
32
33
|
* Prepares the server as the admin login when the deploy user or the server is not set up
|
package/dist/ssh-target.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ssh-target.d.ts","sourceRoot":"","sources":["../src/ssh-target.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,YAAY,EAEZ,WAAW,EACX,kBAAkB,EAClB,QAAQ,EAER,aAAa,EACb,mBAAmB,EACnB,qBAAqB,EACrB,mBAAmB,EACnB,iBAAiB,EACjB,sBAAsB,EACtB,aAAa,EACb,kBAAkB,EAClB,YAAY,EACZ,YAAY,EACZ,YAAY,EACb,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"ssh-target.d.ts","sourceRoot":"","sources":["../src/ssh-target.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,YAAY,EAEZ,WAAW,EACX,kBAAkB,EAClB,QAAQ,EAER,aAAa,EACb,mBAAmB,EACnB,qBAAqB,EACrB,mBAAmB,EACnB,iBAAiB,EACjB,sBAAsB,EACtB,aAAa,EACb,YAAY,EACZ,kBAAkB,EAClB,YAAY,EACZ,YAAY,EACZ,YAAY,EACb,MAAM,mBAAmB,CAAA;AAiB1B,MAAM,WAAW,gBAAgB;IAC/B,qFAAqF;IACrF,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB;;;;OAIG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAA;IACtB;;;OAGG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,qBAAqB,EAAE,MAAM,CAAC,CAAC,CAAC,CAAA;CAC1E;AAiBD,gFAAgF;AAChF,qBAAa,SAAU,YAAW,YAAY;;IAC5C,QAAQ,CAAC,IAAI,SAAQ;IACrB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;gBAGb,OAAO,EAAE,gBAAgB;IAkBrC,aAAa,CAAC,OAAO,EAAE,qBAAqB,GAAG,mBA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ACjF,wBAAgB,QAAQ,CAAC,WAAW,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,KAAK,CAkBnE"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sixb/deploy-ssh",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.5",
|
|
4
4
|
"description": "Deploy a Sixb project to your own server over SSH",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sixb",
|
|
@@ -38,10 +38,10 @@
|
|
|
38
38
|
"prepack": "bun run build"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
|
-
"@sixb/core": "^0.
|
|
41
|
+
"@sixb/core": "^0.2.5"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@sixb/core": "0.
|
|
44
|
+
"@sixb/core": "0.2.5",
|
|
45
45
|
"@types/bun": "latest",
|
|
46
46
|
"typescript": "^5.7.0"
|
|
47
47
|
},
|
package/src/check.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { resolve4, resolve6 } from "node:dns/promises"
|
|
|
2
2
|
import { isIP } from "node:net"
|
|
3
3
|
import { posix } from "node:path"
|
|
4
4
|
import type { DeployCheck, DeployRelease } from "@sixb/core/deploy"
|
|
5
|
+
import { ENV_TOKEN_FILE } from "./layout"
|
|
5
6
|
import { shellQuote } from "./shell"
|
|
6
7
|
import type { RemoteShell } from "./transport"
|
|
7
8
|
|
|
@@ -10,6 +11,8 @@ export const CHECK_MARKER = "__SIXB_CHECK__"
|
|
|
10
11
|
/** The tools a deploy runs on the server. */
|
|
11
12
|
const TOOLS = ["git", "curl", "unzip", "tar", "flock", "sha256sum", "caddy"]
|
|
12
13
|
|
|
14
|
+
export const ENV_TOKEN_CHECK = "project.env-token"
|
|
15
|
+
|
|
13
16
|
type Status = DeployCheck["status"]
|
|
14
17
|
|
|
15
18
|
/**
|
|
@@ -20,8 +23,11 @@ export function renderCheckScript(input: {
|
|
|
20
23
|
readonly name: string
|
|
21
24
|
readonly projectPath: string
|
|
22
25
|
readonly ports: readonly { readonly service: string; readonly port: number }[]
|
|
26
|
+
/** A deploy writes `.env` from the project's source, so what it needs is the token instead. */
|
|
27
|
+
readonly envFromSource?: boolean
|
|
23
28
|
}): string {
|
|
24
29
|
const project = posix.join(input.name, "code", input.projectPath)
|
|
30
|
+
const envToken = posix.join(input.name, ENV_TOKEN_FILE)
|
|
25
31
|
return [
|
|
26
32
|
`emit() { printf '${CHECK_MARKER}\\t%s\\t%s\\t%s\\n' "$1" "$2" "$(printf '%s' "$3" | tr '\\t\\n' ' ')"; }`,
|
|
27
33
|
`project="$HOME"/${shellQuote(project)}`,
|
|
@@ -62,9 +68,18 @@ export function renderCheckScript(input: {
|
|
|
62
68
|
' emit server.admin-api ok "not on localhost:2019"',
|
|
63
69
|
"fi",
|
|
64
70
|
"",
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
71
|
+
...(input.envFromSource
|
|
72
|
+
? [
|
|
73
|
+
`token="$HOME"/${shellQuote(envToken)}`,
|
|
74
|
+
`if [ ! -s "$token" ]; then emit ${ENV_TOKEN_CHECK} fixable "$token has no token"`,
|
|
75
|
+
`elif [ "$(stat -c %a "$token")" != 600 ]; then emit ${ENV_TOKEN_CHECK} fixable "$token is readable by others (mode $(stat -c %a "$token"))"`,
|
|
76
|
+
`else emit ${ENV_TOKEN_CHECK} ok "$token"; fi`,
|
|
77
|
+
]
|
|
78
|
+
: [
|
|
79
|
+
'if [ ! -f "$project/.env" ]; then emit project.env manual "$project/.env does not exist"',
|
|
80
|
+
'elif [ "$(stat -c %a "$project/.env")" != 600 ]; then emit project.env fixable "$project/.env is readable by others (mode $(stat -c %a "$project/.env"))"',
|
|
81
|
+
'else emit project.env ok "$project/.env"; fi',
|
|
82
|
+
]),
|
|
68
83
|
"",
|
|
69
84
|
...input.ports.flatMap(({ service, port }) => [
|
|
70
85
|
`if ss -ltnH "sport = :${port}" 2> /dev/null | grep -q .; then`,
|
|
@@ -157,6 +172,7 @@ const LABELS: Readonly<Record<string, string>> = {
|
|
|
157
172
|
"server.admin-api": "Caddy admin API",
|
|
158
173
|
"server.disk": "Disk space",
|
|
159
174
|
"project.env": ".env",
|
|
175
|
+
[ENV_TOKEN_CHECK]: "Source token",
|
|
160
176
|
}
|
|
161
177
|
|
|
162
178
|
function describe(
|
package/src/layout.ts
CHANGED
|
@@ -5,13 +5,17 @@ import { posix } from "node:path"
|
|
|
5
5
|
* sits in one directory in the deploy user's home, so projects under one user never share files.
|
|
6
6
|
*
|
|
7
7
|
* ~/<name>/code the deployed commit; the project is `code/<projectPath>`
|
|
8
|
+
* ~/<name>/env-token the read-only token a deploy pulls `.env` with, if it has a source
|
|
8
9
|
* ~/<name>/deploy lock, uploads, file list, release record, process manifest, ctl
|
|
9
10
|
* ~/<name>/run supervisor state, control requests, and logs
|
|
10
11
|
* ~/.sixb/bun/<v> Bun, shared by the user's projects that pin the same version
|
|
11
12
|
*/
|
|
13
|
+
export const ENV_TOKEN_FILE = "env-token"
|
|
14
|
+
|
|
12
15
|
export interface DeploymentLayout {
|
|
13
16
|
readonly root: string
|
|
14
17
|
readonly code: string
|
|
18
|
+
readonly envToken: string
|
|
15
19
|
readonly project: string
|
|
16
20
|
readonly deployDir: string
|
|
17
21
|
readonly incomingDir: string
|
|
@@ -49,6 +53,7 @@ export function deploymentLayout(input: {
|
|
|
49
53
|
return {
|
|
50
54
|
root,
|
|
51
55
|
code,
|
|
56
|
+
envToken: posix.join(root, ENV_TOKEN_FILE),
|
|
52
57
|
project: posix.join(code, input.projectPath),
|
|
53
58
|
deployDir,
|
|
54
59
|
incomingDir: posix.join(deployDir, "incoming"),
|
package/src/operations.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto"
|
|
1
2
|
import type {
|
|
2
3
|
DeployContext,
|
|
3
4
|
DeployControlAction,
|
|
4
5
|
DeployLogsOptions,
|
|
5
6
|
DeployRelease,
|
|
7
|
+
DeployScript,
|
|
6
8
|
DeploySource,
|
|
7
9
|
DeployStatus,
|
|
8
10
|
} from "@sixb/core/deploy"
|
|
@@ -130,6 +132,56 @@ export async function controlServices(
|
|
|
130
132
|
await shell.run(ctlScript(name, [action, ...(service ? [service] : [])]))
|
|
131
133
|
}
|
|
132
134
|
|
|
135
|
+
/**
|
|
136
|
+
* Uploads the script, then runs it through `ctl run` in a terminal on the server: Ctrl-C reaches
|
|
137
|
+
* the script there, and so does a dropped connection, as a hangup. Holding the deploy lock shared
|
|
138
|
+
* for the whole run keeps a deploy from replacing the code it imports or migrating its storage;
|
|
139
|
+
* runs share it with each other. Resolves with the script's exit code.
|
|
140
|
+
*/
|
|
141
|
+
export async function runDeployScript(
|
|
142
|
+
shell: RemoteShell,
|
|
143
|
+
name: string,
|
|
144
|
+
script: DeployScript
|
|
145
|
+
): Promise<number> {
|
|
146
|
+
const root = `"$HOME"/${shellQuote(name)}`
|
|
147
|
+
const staged = `${root}/deploy/runs/${randomUUID()}`
|
|
148
|
+
await shell.run(
|
|
149
|
+
[
|
|
150
|
+
`if [ ! -x ${root}/deploy/ctl ]; then`,
|
|
151
|
+
` echo "Nothing named ${name} is deployed on this server yet." >&2; exit 1`,
|
|
152
|
+
"fi",
|
|
153
|
+
"umask 077",
|
|
154
|
+
`mkdir -p ${root}/deploy/runs`,
|
|
155
|
+
// An upload whose run never started is left behind; a day later it goes.
|
|
156
|
+
`find ${root}/deploy/runs -type f -mmin +1440 -delete 2> /dev/null || true`,
|
|
157
|
+
`cat > ${staged}`,
|
|
158
|
+
].join("\n"),
|
|
159
|
+
{ stdin: new Blob([Uint8Array.from(script.source)]).stream() }
|
|
160
|
+
)
|
|
161
|
+
|
|
162
|
+
const run = [
|
|
163
|
+
`cd ${root}`,
|
|
164
|
+
`exec 9> ${root}/deploy/lock`,
|
|
165
|
+
"if ! flock -s -n 9; then",
|
|
166
|
+
` echo "Waiting for a deploy of ${name} to finish…" >&2`,
|
|
167
|
+
"fi",
|
|
168
|
+
"if ! flock -s -w 600 9; then",
|
|
169
|
+
` echo "A deploy of ${name} has held its lock for 10 minutes." >&2`,
|
|
170
|
+
` rm -f ${staged}`,
|
|
171
|
+
" exit 1",
|
|
172
|
+
"fi",
|
|
173
|
+
`exec ${root}/deploy/ctl run ${staged} ${[script.path, ...script.args].map(shellQuote).join(" ")}`,
|
|
174
|
+
].join("\n")
|
|
175
|
+
try {
|
|
176
|
+
await shell.run(run, { terminal: true })
|
|
177
|
+
return 0
|
|
178
|
+
} catch (error) {
|
|
179
|
+
// 255 is OpenSSH's own failure; any other code is the script's.
|
|
180
|
+
if (error instanceof RemoteScriptError && error.exitCode !== 255) return error.exitCode
|
|
181
|
+
throw error
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
133
185
|
/** Runs the deployment's `ctl` with arguments; fails plainly when nothing is deployed yet. */
|
|
134
186
|
function ctlScript(
|
|
135
187
|
name: string,
|
package/src/render.ts
CHANGED
|
@@ -19,6 +19,7 @@ export function renderProcessManifest(
|
|
|
19
19
|
runDir: layout.runDir,
|
|
20
20
|
logDir: layout.logDir,
|
|
21
21
|
releasePath: layout.releaseRecord,
|
|
22
|
+
env: release.env,
|
|
22
23
|
services: release.services.map((service) => ({
|
|
23
24
|
name: service.name,
|
|
24
25
|
processName: `${release.name}-${service.name}`,
|
package/src/scripts.ts
CHANGED
|
@@ -54,6 +54,7 @@ export function renderDeployScript(input: DeployScriptInput): DeployScript {
|
|
|
54
54
|
{ label: "Apply files", body: renderApplyFiles(layout, input.incoming) },
|
|
55
55
|
{ label: `Install Bun ${release.bunVersion}`, body: renderInstallBun(release.bunVersion) },
|
|
56
56
|
{ label: "Install dependencies", body: renderInstallDependencies() },
|
|
57
|
+
...(release.steps.env ? [envStep(release.steps.env, layout)] : []),
|
|
57
58
|
...release.steps.build.map((command) => runStep(command)),
|
|
58
59
|
// Everything that can be rejected happens while the previous release still serves: services
|
|
59
60
|
// are down only from here to "Start services".
|
|
@@ -121,10 +122,10 @@ function renderTakeLock(layout: DeploymentLayout): string {
|
|
|
121
122
|
return [
|
|
122
123
|
`exec 9>${shellQuote(layout.lock)}`,
|
|
123
124
|
"if ! flock -n 9; then",
|
|
124
|
-
' echo "Waiting for another deploy of this project to finish…"',
|
|
125
|
+
' echo "Waiting for another deploy or script run of this project to finish…"',
|
|
125
126
|
"fi",
|
|
126
127
|
"if ! flock -w 600 9; then",
|
|
127
|
-
' echo "Another deploy of this project has held its lock for 10 minutes." >&2',
|
|
128
|
+
' echo "Another deploy or script run of this project has held its lock for 10 minutes." >&2',
|
|
128
129
|
" exit 1",
|
|
129
130
|
"fi",
|
|
130
131
|
].join("\n")
|
|
@@ -214,6 +215,12 @@ function runStep(command: DeployCommand): Step {
|
|
|
214
215
|
}
|
|
215
216
|
}
|
|
216
217
|
|
|
218
|
+
/** Pulls `.env` with the token only this step reads, so no build or service ever holds it. */
|
|
219
|
+
function envStep(command: DeployCommand, layout: DeploymentLayout): Step {
|
|
220
|
+
const step = runStep(command)
|
|
221
|
+
return { ...step, body: `${step.body} --token-file ${shellQuote(layout.envToken)}` }
|
|
222
|
+
}
|
|
223
|
+
|
|
217
224
|
function renderStopServices(): string {
|
|
218
225
|
return [
|
|
219
226
|
'if systemctl --user is-active --quiet "$UNIT"; then',
|
package/src/server/cli.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { readFile } from "node:fs/promises"
|
|
|
3
3
|
import type { DeployRecord, DeployStatus } from "@sixb/core/deploy"
|
|
4
4
|
import { followLogFiles, type LogLine, readRecentLogLines, renderProcessLogLine } from "./logs"
|
|
5
5
|
import { loadProcessManifest, type ProcessManifest, statePath } from "./manifest"
|
|
6
|
+
import { runScript } from "./run"
|
|
6
7
|
import { isMissing, isPidRunning, readProcessState } from "./state"
|
|
7
8
|
import { runSupervisor, type SupervisorCommand, sendSupervisorCommand } from "./supervisor"
|
|
8
9
|
|
|
@@ -14,6 +15,7 @@ import { runSupervisor, type SupervisorCommand, sendSupervisorCommand } from "./
|
|
|
14
15
|
* status [--json] [--check] --check exits 1 unless every process is running
|
|
15
16
|
* logs [service] [--tail n] [--follow]
|
|
16
17
|
* restart|start|stop [service]
|
|
18
|
+
* run <staged> <path> [args...] run an uploaded script with `sixb run`; see ./run.ts
|
|
17
19
|
*/
|
|
18
20
|
const argv = process.argv.slice(2)
|
|
19
21
|
|
|
@@ -25,6 +27,17 @@ try {
|
|
|
25
27
|
}
|
|
26
28
|
|
|
27
29
|
async function main(): Promise<void> {
|
|
30
|
+
// A script's arguments are anything, `--manifest` included; `ctl` appends the real one last.
|
|
31
|
+
if (argv[0] === "run") {
|
|
32
|
+
const [, staged, path, ...args] = argv.slice(0, -2)
|
|
33
|
+
const manifestPath = argv.at(-1)
|
|
34
|
+
if (argv.at(-2) !== "--manifest" || !manifestPath || !staged || !path) {
|
|
35
|
+
throw new Error("[SshTarget] Usage: run <staged> <path> [args...] --manifest <path>")
|
|
36
|
+
}
|
|
37
|
+
const manifest = await loadProcessManifest(manifestPath)
|
|
38
|
+
return process.exit(await runScript({ manifest, staged, path, args }))
|
|
39
|
+
}
|
|
40
|
+
|
|
28
41
|
const manifestPath = option("--manifest")
|
|
29
42
|
if (!manifestPath) throw new Error("[SshTarget] --manifest is required.")
|
|
30
43
|
const [command, service] = positionals()
|
package/src/server/manifest.ts
CHANGED
|
@@ -12,6 +12,11 @@ export interface ProcessManifest {
|
|
|
12
12
|
readonly logDir: string
|
|
13
13
|
/** Written by the deploy; read back by `status`. */
|
|
14
14
|
readonly releasePath: string
|
|
15
|
+
/**
|
|
16
|
+
* The environment every service starts from, before its own additions: what `ctl run` gives a
|
|
17
|
+
* script. Absent from deployments made before scripts could run.
|
|
18
|
+
*/
|
|
19
|
+
readonly env?: Readonly<Record<string, string>>
|
|
15
20
|
readonly services: readonly ProcessServiceManifest[]
|
|
16
21
|
}
|
|
17
22
|
|
|
@@ -57,6 +62,7 @@ export function parseProcessManifest(value: unknown, source = "process manifest"
|
|
|
57
62
|
runDir: string(manifest.runDir, `${source}.runDir`),
|
|
58
63
|
logDir: string(manifest.logDir, `${source}.logDir`),
|
|
59
64
|
releasePath: string(manifest.releasePath, `${source}.releasePath`),
|
|
65
|
+
...(manifest.env === undefined ? {} : { env: environment(manifest.env, `${source}.env`) }),
|
|
60
66
|
services: manifest.services.map((service, index) =>
|
|
61
67
|
parseService(service, `${source}.services[${index}]`)
|
|
62
68
|
),
|
|
@@ -68,19 +74,14 @@ function parseService(value: unknown, source: string): ProcessServiceManifest {
|
|
|
68
74
|
if (!Array.isArray(service.args) || service.args.some((arg) => typeof arg !== "string")) {
|
|
69
75
|
throw new Error(`[SshTarget] ${source}.args must be an array of strings`)
|
|
70
76
|
}
|
|
71
|
-
const env =
|
|
72
|
-
for (const [key, variable] of Object.entries(env)) {
|
|
73
|
-
if (typeof variable !== "string") {
|
|
74
|
-
throw new Error(`[SshTarget] ${source}.env.${key} must be a string`)
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
+
const env = environment(service.env, `${source}.env`)
|
|
77
78
|
|
|
78
79
|
return {
|
|
79
80
|
name: string(service.name, `${source}.name`),
|
|
80
81
|
processName: string(service.processName, `${source}.processName`),
|
|
81
82
|
command: string(service.command, `${source}.command`),
|
|
82
83
|
args: service.args,
|
|
83
|
-
env
|
|
84
|
+
env,
|
|
84
85
|
instances: positiveInteger(service.instances, `${source}.instances`),
|
|
85
86
|
killTimeoutMs: positiveInteger(service.killTimeoutMs, `${source}.killTimeoutMs`),
|
|
86
87
|
restartDelayMs: positiveInteger(service.restartDelayMs, `${source}.restartDelayMs`),
|
|
@@ -90,6 +91,15 @@ function parseService(value: unknown, source: string): ProcessServiceManifest {
|
|
|
90
91
|
}
|
|
91
92
|
}
|
|
92
93
|
|
|
94
|
+
function environment(value: unknown, source: string): Record<string, string> {
|
|
95
|
+
const env = record(value, source)
|
|
96
|
+
for (const [key, variable] of Object.entries(env)) {
|
|
97
|
+
if (typeof variable !== "string")
|
|
98
|
+
throw new Error(`[SshTarget] ${source}.${key} must be a string`)
|
|
99
|
+
}
|
|
100
|
+
return env as Record<string, string>
|
|
101
|
+
}
|
|
102
|
+
|
|
93
103
|
function record(value: unknown, source: string): Record<string, unknown> {
|
|
94
104
|
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
95
105
|
throw new Error(`[SshTarget] ${source} must be an object`)
|