@sixb/deploy-ssh 0.2.5 → 0.2.6
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 +7 -5
- package/dist/check.d.ts.map +1 -1
- package/dist/index.js +543 -118
- package/dist/index.js.map +11 -10
- package/dist/layout.d.ts +21 -5
- package/dist/layout.d.ts.map +1 -1
- package/dist/operations.d.ts +2 -1
- package/dist/operations.d.ts.map +1 -1
- package/dist/render.d.ts +10 -4
- package/dist/render.d.ts.map +1 -1
- package/dist/scripts.d.ts +20 -10
- package/dist/scripts.d.ts.map +1 -1
- package/dist/server/manifest.d.ts +6 -0
- package/dist/server/manifest.d.ts.map +1 -1
- package/dist/server/state.d.ts +6 -0
- package/dist/server/state.d.ts.map +1 -1
- package/dist/server/supervisor.d.ts +11 -3
- package/dist/server/supervisor.d.ts.map +1 -1
- package/dist/ssh-target.d.ts +6 -0
- package/dist/ssh-target.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/check.ts +32 -6
- package/src/layout.ts +40 -5
- package/src/operations.ts +4 -1
- package/src/render.ts +88 -10
- package/src/scripts.ts +492 -112
- package/src/server/cli.ts +30 -9
- package/src/server/manifest.ts +32 -1
- package/src/server/state.ts +8 -2
- package/src/server/supervisor.ts +329 -64
- package/src/ssh-target.ts +72 -11
package/dist/layout.d.ts
CHANGED
|
@@ -2,23 +2,33 @@
|
|
|
2
2
|
* Where a deployment lives on its server. Everything but the Bun binaries and the Caddy route
|
|
3
3
|
* sits in one directory in the deploy user's home, so projects under one user never share files.
|
|
4
4
|
*
|
|
5
|
-
* ~/<name>/
|
|
6
|
-
* ~/<name>/
|
|
7
|
-
* ~/<name>/
|
|
8
|
-
* ~/<name>/
|
|
9
|
-
*
|
|
5
|
+
* ~/<name>/releases/<id> immutable release directories (code, node_modules, .sixb/dist)
|
|
6
|
+
* ~/<name>/current symlink to the active release directory
|
|
7
|
+
* ~/<name>/code symlink to `current` (migrated in place from single-folder deploys)
|
|
8
|
+
* ~/<name>/shared/.env shared project `.env`, linked from each release
|
|
9
|
+
* ~/<name>/env-token the read-only token a deploy pulls `.env` with, if it has a source
|
|
10
|
+
* ~/<name>/deploy lock, uploads, manifests, release record, ctl
|
|
11
|
+
* ~/<name>/run supervisor state, control requests, and logs
|
|
12
|
+
* ~/.sixb/bun/<v> Bun, shared by the user's projects that pin the same version
|
|
10
13
|
*/
|
|
11
14
|
export declare const ENV_TOKEN_FILE = "env-token";
|
|
15
|
+
export type DeploySlot = "blue" | "green";
|
|
12
16
|
export interface DeploymentLayout {
|
|
13
17
|
readonly root: string;
|
|
18
|
+
readonly releasesDir: string;
|
|
19
|
+
readonly currentLink: string;
|
|
14
20
|
readonly code: string;
|
|
21
|
+
readonly sharedDir: string;
|
|
22
|
+
readonly sharedEnv: string;
|
|
15
23
|
readonly envToken: string;
|
|
16
24
|
readonly project: string;
|
|
25
|
+
readonly projectPath: string;
|
|
17
26
|
readonly deployDir: string;
|
|
18
27
|
readonly incomingDir: string;
|
|
19
28
|
readonly lock: string;
|
|
20
29
|
readonly fileList: string;
|
|
21
30
|
readonly manifest: string;
|
|
31
|
+
readonly candidateManifest: string;
|
|
22
32
|
readonly releaseRecord: string;
|
|
23
33
|
/** Runs the server half of this package with the project's Bun and manifest. */
|
|
24
34
|
readonly ctl: string;
|
|
@@ -31,6 +41,11 @@ export interface DeploymentLayout {
|
|
|
31
41
|
readonly caddyDir: string;
|
|
32
42
|
readonly caddySnippet: string;
|
|
33
43
|
}
|
|
44
|
+
export interface ReleaseLayout {
|
|
45
|
+
readonly id: string;
|
|
46
|
+
readonly root: string;
|
|
47
|
+
readonly project: string;
|
|
48
|
+
}
|
|
34
49
|
export declare function deploymentLayout(input: {
|
|
35
50
|
readonly home: string;
|
|
36
51
|
readonly user: string;
|
|
@@ -38,4 +53,5 @@ export declare function deploymentLayout(input: {
|
|
|
38
53
|
readonly projectPath: string;
|
|
39
54
|
readonly bunVersion: string;
|
|
40
55
|
}): DeploymentLayout;
|
|
56
|
+
export declare function releaseLayout(layout: DeploymentLayout, releaseId: string): ReleaseLayout;
|
|
41
57
|
//# sourceMappingURL=layout.d.ts.map
|
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;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,cAAc,cAAc,CAAA;AAEzC,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,OAAO,CAAA;AAEzC,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;IAC5B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IACxB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;IAC5B,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,iBAAiB,EAAE,MAAM,CAAA;IAClC,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,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;IACnB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;CACzB;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,CAuCnB;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,GAAG,aAAa,CAOxF"}
|
package/dist/operations.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { DeployContext, DeployControlAction, DeployLogsOptions, DeployRelease, DeployScript, DeploySource, DeployStatus } from "@sixb/core/deploy";
|
|
2
|
+
import type { SlotPorts } from "./render";
|
|
2
3
|
import { type RemoteShell } from "./transport";
|
|
3
4
|
/** Uploads the source, then runs the release on the server as one locked script. */
|
|
4
|
-
export declare function deployRelease(shell: RemoteShell, user: string, release: DeployRelease, source: DeploySource, context: DeployContext): Promise<void>;
|
|
5
|
+
export declare function deployRelease(shell: RemoteShell, user: string, release: DeployRelease, source: DeploySource, context: DeployContext, slotPorts?: SlotPorts): Promise<void>;
|
|
5
6
|
export declare function readStatus(shell: RemoteShell, name: string): Promise<DeployStatus>;
|
|
6
7
|
export declare function streamLogs(shell: RemoteShell, name: string, options: DeployLogsOptions & {
|
|
7
8
|
readonly terminal?: boolean;
|
package/dist/operations.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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;
|
|
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;AAE1B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AASzC,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,EACtB,SAAS,CAAC,EAAE,SAAS,GACpB,OAAO,CAAC,IAAI,CAAC,CAmCf;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
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
|
-
import type { DeployRelease } from "@sixb/core/deploy";
|
|
2
|
-
import type { DeploymentLayout } from "./layout";
|
|
1
|
+
import type { DeployHttpServiceName, DeployRelease } from "@sixb/core/deploy";
|
|
2
|
+
import type { DeploymentLayout, DeploySlot } from "./layout";
|
|
3
3
|
import type { ProcessManifest } from "./server/manifest";
|
|
4
|
+
export type SlotPorts = Readonly<Record<DeploySlot, Readonly<Record<DeployHttpServiceName, number>>>>;
|
|
5
|
+
/** Rewrites a release's HTTP services to listen on the given slot's loopback ports. */
|
|
6
|
+
export declare function releaseForSlot(release: DeployRelease, ports: Readonly<Record<DeployHttpServiceName, number>>): DeployRelease;
|
|
4
7
|
/** The supervisor's view of the release: absolute commands, full environments. */
|
|
5
|
-
export declare function renderProcessManifest(release: DeployRelease, layout: DeploymentLayout
|
|
8
|
+
export declare function renderProcessManifest(release: DeployRelease, layout: DeploymentLayout, options?: {
|
|
9
|
+
readonly projectDir?: string;
|
|
10
|
+
readonly slot?: DeploySlot;
|
|
11
|
+
}): ProcessManifest;
|
|
6
12
|
/** Pins the server half of this package to the project's Bun and manifest. */
|
|
7
13
|
export declare function renderCtl(layout: DeploymentLayout): string;
|
|
8
14
|
/**
|
|
@@ -10,6 +16,6 @@ export declare function renderCtl(layout: DeploymentLayout): string;
|
|
|
10
16
|
* unit comes back after a reboot without anyone logged in.
|
|
11
17
|
*/
|
|
12
18
|
export declare function renderUnit(release: DeployRelease, layout: DeploymentLayout): string;
|
|
13
|
-
/** One site per HTTP service, forwarded to the
|
|
19
|
+
/** One site per HTTP service, forwarded to the active slot's loopback port. */
|
|
14
20
|
export declare function renderCaddySnippet(release: DeployRelease): string;
|
|
15
21
|
//# sourceMappingURL=render.d.ts.map
|
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,
|
|
1
|
+
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../src/render.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,aAAa,EAAwB,MAAM,mBAAmB,CAAA;AACnG,OAAO,KAAK,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAC5D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAOxD,MAAM,MAAM,SAAS,GAAG,QAAQ,CAC9B,MAAM,CAAC,UAAU,EAAE,QAAQ,CAAC,MAAM,CAAC,qBAAqB,EAAE,MAAM,CAAC,CAAC,CAAC,CACpE,CAAA;AAED,uFAAuF;AACvF,wBAAgB,cAAc,CAC5B,OAAO,EAAE,aAAa,EACtB,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,qBAAqB,EAAE,MAAM,CAAC,CAAC,GACrD,aAAa,CAqBf;AAWD,kFAAkF;AAClF,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,aAAa,EACtB,MAAM,EAAE,gBAAgB,EACxB,OAAO,GAAE;IAAE,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,UAAU,CAAA;CAAO,GACzE,eAAe,CA4BjB;AAqBD,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,+EAA+E;AAC/E,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,aAAa,GAAG,MAAM,CAkBjE"}
|
package/dist/scripts.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { DeployRecord, DeployRelease } from "@sixb/core/deploy";
|
|
2
|
-
import type
|
|
2
|
+
import { type DeploymentLayout, type ReleaseLayout } from "./layout";
|
|
3
|
+
import { type SlotPorts } from "./render";
|
|
3
4
|
/** A line the deploy script prints around each step; the target turns it into progress. */
|
|
4
5
|
export declare const STEP_MARKER = "__SIXB_STEP__";
|
|
5
6
|
/** The server's home directory, and a fresh directory to upload the source into. */
|
|
@@ -11,28 +12,37 @@ export interface DeployScriptInput {
|
|
|
11
12
|
readonly layout: DeploymentLayout;
|
|
12
13
|
readonly incoming: string;
|
|
13
14
|
readonly record: DeployRecord;
|
|
15
|
+
readonly releaseId?: string;
|
|
16
|
+
readonly slotPorts?: SlotPorts;
|
|
14
17
|
}
|
|
15
18
|
export interface DeployScript {
|
|
16
19
|
readonly labels: readonly string[];
|
|
17
20
|
readonly script: string;
|
|
18
21
|
}
|
|
22
|
+
export declare function defaultSlotPorts(release: DeployRelease): SlotPorts;
|
|
23
|
+
export declare function deriveReleaseId(record: DeployRecord): string;
|
|
19
24
|
/**
|
|
20
25
|
* Everything the server does once the source is uploaded, as one script that holds the
|
|
21
|
-
* deployment's lock throughout.
|
|
22
|
-
*
|
|
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.
|
|
23
28
|
*/
|
|
24
29
|
export declare function renderDeployScript(input: DeployScriptInput): DeployScript;
|
|
25
30
|
/**
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
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.
|
|
30
35
|
*/
|
|
31
|
-
export declare function
|
|
36
|
+
export declare function renderPrepareRelease(layout: DeploymentLayout, targetRelease: ReleaseLayout, incoming: string): string;
|
|
32
37
|
/**
|
|
33
38
|
* 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
|
|
39
|
+
* exited in its first seconds. Those seconds count from "Start new release", so the time the API
|
|
35
40
|
* takes to boot is part of them rather than added to them.
|
|
36
41
|
*/
|
|
37
|
-
export declare function renderCheckServices(
|
|
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;
|
|
38
48
|
//# sourceMappingURL=scripts.d.ts.map
|
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,
|
|
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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wBAAgB,mBAAmB,IAAI,MAAM,CAY5C"}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
import type { DeploySlot } from "../layout";
|
|
2
|
+
export type ProcessServiceKind = "http" | "singleton" | "workers" | "script";
|
|
1
3
|
/** What the supervisor runs for one deployment, written by `sixb deploy` on each deploy. */
|
|
2
4
|
export interface ProcessManifest {
|
|
3
5
|
readonly version: 1;
|
|
4
6
|
readonly name: string;
|
|
7
|
+
/** Which port pair (`blue` or `green`) this release's HTTP services bind. */
|
|
8
|
+
readonly slot?: DeploySlot;
|
|
5
9
|
/** The project directory every process starts in. */
|
|
6
10
|
readonly cwd: string;
|
|
7
11
|
/** Supervisor state, control requests, and logs live here. */
|
|
@@ -18,6 +22,7 @@ export interface ProcessManifest {
|
|
|
18
22
|
}
|
|
19
23
|
export interface ProcessServiceManifest {
|
|
20
24
|
readonly name: string;
|
|
25
|
+
readonly kind?: ProcessServiceKind;
|
|
21
26
|
readonly processName: string;
|
|
22
27
|
readonly command: string;
|
|
23
28
|
readonly args: readonly string[];
|
|
@@ -27,6 +32,7 @@ export interface ProcessServiceManifest {
|
|
|
27
32
|
readonly restartDelayMs: number;
|
|
28
33
|
readonly maxMemory?: string;
|
|
29
34
|
}
|
|
35
|
+
export declare function isOverlapSafeService(service: ProcessServiceManifest): boolean;
|
|
30
36
|
export declare function loadProcessManifest(path: string): Promise<ProcessManifest>;
|
|
31
37
|
export declare function statePath(manifest: ProcessManifest): string;
|
|
32
38
|
export declare function controlDir(manifest: ProcessManifest): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manifest.d.ts","sourceRoot":"","sources":["../../src/server/manifest.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"manifest.d.ts","sourceRoot":"","sources":["../../src/server/manifest.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAE3C,MAAM,MAAM,kBAAkB,GAAG,MAAM,GAAG,W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AO,CAG7E;AAED,wBAAsB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC,CAEhF;AAED,wBAAgB,SAAS,CAAC,QAAQ,EAAE,eAAe,GAAG,MAAM,CAE3D;AAED,wBAAgB,UAAU,CAAC,QAAQ,EAAE,eAAe,GAAG,MAAM,CAE5D;AAED,wBAAgB,WAAW,CAAC,QAAQ,EAAE,eAAe,GAAG,MAAM,CAE7D;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,SAAqB,GAAG,eAAe,CAqBjG"}
|
package/dist/server/state.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { DeploySlot } from "../layout";
|
|
1
2
|
export type ProcessInstanceStatus = "starting" | "running" | "stopping" | "stopped" | "exited";
|
|
2
3
|
/** What the supervisor last knew about every process, rewritten on each change. */
|
|
3
4
|
export interface ProcessState {
|
|
@@ -5,7 +6,12 @@ export interface ProcessState {
|
|
|
5
6
|
readonly name: string;
|
|
6
7
|
readonly supervisorPid: number;
|
|
7
8
|
readonly updatedAt: string;
|
|
9
|
+
readonly slot?: DeploySlot;
|
|
8
10
|
readonly instances: readonly ProcessInstanceState[];
|
|
11
|
+
/** Overlap-safe instances of a candidate release waiting to cut over. */
|
|
12
|
+
readonly staged?: readonly ProcessInstanceState[];
|
|
13
|
+
/** Release `cwd`s still held by background-draining processes after a cutover. */
|
|
14
|
+
readonly retiringCwds?: readonly string[];
|
|
9
15
|
}
|
|
10
16
|
export interface ProcessInstanceState {
|
|
11
17
|
readonly service: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../src/server/state.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../src/server/state.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAE3C,MAAM,M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CAAA;IAC3B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;CACzB;AAUD,wBAAsB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CASjF;AAED,wBAAsB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAExF;AAED;;;GAGG;AACH,wBAAsB,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAItF;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,SAAkB,GAAG,YAAY,CAWxF;AAED,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAOjD;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAEjD"}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { type ProcessManifest } from "./manifest";
|
|
2
|
-
export type SupervisorCommand = "restart" | "start" | "stop";
|
|
2
|
+
export type SupervisorCommand = "restart" | "start" | "stop" | "stage" | "activate" | "discard";
|
|
3
|
+
/** SIGINT comes this long before SIGKILL, so a draining role can still record its partial work. */
|
|
4
|
+
export declare const INTERRUPT_LEAD_MS = 10000;
|
|
5
|
+
/** A retiring process gets the cutover's drain window, or its own kill timeout when longer. */
|
|
6
|
+
export declare function retiringKillTimeoutMs(killTimeoutMs: number): number;
|
|
3
7
|
/**
|
|
4
8
|
* Runs every process a deployment's manifest lists, restarting any that exit, and answers
|
|
5
9
|
* control requests. One per deployment, started by the deployment's `systemd --user` unit.
|
|
@@ -9,8 +13,12 @@ export type SupervisorCommand = "restart" | "start" | "stop";
|
|
|
9
13
|
* `run/responses`.
|
|
10
14
|
*/
|
|
11
15
|
export declare function runSupervisor(manifestPath: string): Promise<void>;
|
|
12
|
-
/** Asks the running supervisor to
|
|
13
|
-
export declare function sendSupervisorCommand(manifest: ProcessManifest, type: SupervisorCommand,
|
|
16
|
+
/** Asks the running supervisor to control services or cut over a staged release. */
|
|
17
|
+
export declare function sendSupervisorCommand(manifest: ProcessManifest, type: SupervisorCommand, options?: {
|
|
18
|
+
readonly service?: string;
|
|
19
|
+
readonly manifestPath?: string;
|
|
20
|
+
readonly timeoutMs?: number;
|
|
21
|
+
}): Promise<string>;
|
|
14
22
|
export declare function parseMemoryLimit(value: string): number | null;
|
|
15
23
|
export declare function formatBytes(bytes: number): string;
|
|
16
24
|
//# sourceMappingURL=supervisor.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"supervisor.d.ts","sourceRoot":"","sources":["../../src/server/supervisor.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"supervisor.d.ts","sourceRoot":"","sources":["../../src/server/supervisor.ts"],"names":[],"mappings":"AAOA,OAAO,EAIL,KAAK,eAAe,EAIrB,MAAM,YAAY,CAAA;AAYnB,MAAM,MAAM,iBAAiB,GAAG,SAAS,GAAG,OAAO,GAAG,MAAM,GAAG,OAAO,GAAG,UAAU,GAAG,SAAS,CAAA;AAQ/F,mGAAmG;AACnG,eAAO,MAAM,iBAAiB,QAAS,CAAA;AAEvC,+FAA+F;AAC/F,wBAAgB,qBAAqB,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,CAEnE;AAkDD;;;;;;;GAOG;AACH,wBAAsB,aAAa,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAGvE;AAED,oFAAoF;AACpF,wBAAsB,qBAAqB,CACzC,QAAQ,EAAE,eAAe,EACzB,IAAI,EAAE,iBAAiB,EACvB,OAAO,GAAE;IACP,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAA;IAC9B,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CACvB,GACL,OAAO,CAAC,MAAM,CAAC,CAyBjB;AAgnBD,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAM7D;AAoCD,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAKjD"}
|
package/dist/ssh-target.d.ts
CHANGED
|
@@ -13,6 +13,11 @@ export interface SshTargetOptions {
|
|
|
13
13
|
* projects share a server, so that each has its own. Defaults: app 3001, api 3002.
|
|
14
14
|
*/
|
|
15
15
|
readonly ports?: Readonly<Partial<Record<DeployHttpServiceName, number>>>;
|
|
16
|
+
/**
|
|
17
|
+
* Second local port pair for blue-green cutovers while the active slot keeps serving. Defaults
|
|
18
|
+
* to `ports` plus 10 (app 3011, api 3012).
|
|
19
|
+
*/
|
|
20
|
+
readonly standbyPorts?: Readonly<Partial<Record<DeployHttpServiceName, number>>>;
|
|
16
21
|
}
|
|
17
22
|
/** A server reached over SSH, where Caddy routes each domain to its service. */
|
|
18
23
|
export declare class SshTarget implements DeployTarget {
|
|
@@ -23,6 +28,7 @@ export declare class SshTarget implements DeployTarget {
|
|
|
23
28
|
readonly location: string;
|
|
24
29
|
constructor(options: SshTargetOptions);
|
|
25
30
|
listenAddress(service: DeployHttpServiceName): DeployListenAddress;
|
|
31
|
+
standbyListenAddress(service: DeployHttpServiceName): DeployListenAddress;
|
|
26
32
|
deploy(release: DeployRelease, source: DeploySource, context: DeployContext): Promise<void>;
|
|
27
33
|
status(context: DeployOperationContext): Promise<DeployStatus>;
|
|
28
34
|
logs(options: DeployLogsOptions, context: DeployOperationContext): Promise<void>;
|
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,E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|
3
|
+
"version": "0.2.6",
|
|
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.2.
|
|
41
|
+
"@sixb/core": "^0.2.6"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@sixb/core": "0.2.
|
|
44
|
+
"@sixb/core": "0.2.6",
|
|
45
45
|
"@types/bun": "latest",
|
|
46
46
|
"typescript": "^5.7.0"
|
|
47
47
|
},
|
package/src/check.ts
CHANGED
|
@@ -27,11 +27,14 @@ export function renderCheckScript(input: {
|
|
|
27
27
|
readonly envFromSource?: boolean
|
|
28
28
|
}): string {
|
|
29
29
|
const project = posix.join(input.name, "code", input.projectPath)
|
|
30
|
+
const sharedEnv = posix.join(input.name, "shared", ".env")
|
|
30
31
|
const envToken = posix.join(input.name, ENV_TOKEN_FILE)
|
|
31
32
|
return [
|
|
32
33
|
`emit() { printf '${CHECK_MARKER}\\t%s\\t%s\\t%s\\n' "$1" "$2" "$(printf '%s' "$3" | tr '\\t\\n' ' ')"; }`,
|
|
33
34
|
`project="$HOME"/${shellQuote(project)}`,
|
|
35
|
+
`shared_env="$HOME"/${shellQuote(sharedEnv)}`,
|
|
34
36
|
`manifest="$HOME"/${shellQuote(input.name)}/deploy/processes.json`,
|
|
37
|
+
`ports_file="$HOME"/${shellQuote(input.name)}/deploy/ports.txt`,
|
|
35
38
|
'routes_dir="/etc/caddy/sixb.d/$USER"',
|
|
36
39
|
`snippet="$routes_dir"/${shellQuote(`${input.name}.caddy`)}`,
|
|
37
40
|
"",
|
|
@@ -46,6 +49,13 @@ export function renderCheckScript(input: {
|
|
|
46
49
|
'if [ -n "$missing" ]; then emit server.tools fixable "missing:$missing"',
|
|
47
50
|
'else emit server.tools ok "Caddy $(caddy version 2>/dev/null | cut -d" " -f1), git, curl, unzip"; fi',
|
|
48
51
|
"",
|
|
52
|
+
// The routes keep WebSockets open through a reload with `stream_close_delay`, new in Caddy 2.7.
|
|
53
|
+
"if command -v caddy > /dev/null; then",
|
|
54
|
+
' caddy_version="$(caddy version 2>/dev/null | cut -d" " -f1 | sed "s/^v//")"',
|
|
55
|
+
' if [ "$(printf "%s\\n" 2.7.0 "$caddy_version" | sort -V | head -n 1)" = 2.7.0 ]; then emit server.caddy ok "$caddy_version"',
|
|
56
|
+
' else emit server.caddy manual "$caddy_version is older than 2.7"; fi',
|
|
57
|
+
"fi",
|
|
58
|
+
"",
|
|
49
59
|
'if [ -e "/var/lib/systemd/linger/$USER" ]; then emit server.linger ok "on for $USER"',
|
|
50
60
|
'else emit server.linger fixable "off for $USER: services would stop when you log out"; fi',
|
|
51
61
|
"",
|
|
@@ -76,20 +86,24 @@ export function renderCheckScript(input: {
|
|
|
76
86
|
`else emit ${ENV_TOKEN_CHECK} ok "$token"; fi`,
|
|
77
87
|
]
|
|
78
88
|
: [
|
|
79
|
-
'
|
|
80
|
-
'
|
|
81
|
-
'
|
|
89
|
+
'env_file="$project/.env"',
|
|
90
|
+
'if [ -f "$shared_env" ]; then env_file="$shared_env"; fi',
|
|
91
|
+
'if [ ! -f "$env_file" ]; then emit project.env manual "$env_file does not exist"',
|
|
92
|
+
'elif [ "$(stat -c %a "$env_file")" != 600 ]; then emit project.env fixable "$env_file is readable by others (mode $(stat -c %a "$env_file"))"',
|
|
93
|
+
'else emit project.env ok "$env_file"; fi',
|
|
82
94
|
]),
|
|
83
95
|
"",
|
|
84
96
|
...input.ports.flatMap(({ service, port }) => [
|
|
85
97
|
`if ss -ltnH "sport = :${port}" 2> /dev/null | grep -q .; then`,
|
|
86
|
-
` if grep -qs '"--port",' "$manifest" && grep -A1 -s '"--port",' "$manifest" | grep -q '"${port}"'; then`,
|
|
98
|
+
` if grep -qx '${port}' "$ports_file" 2> /dev/null || { grep -qs '"--port",' "$manifest" && grep -A1 -s '"--port",' "$manifest" | grep -q '"${port}"'; }; then`,
|
|
87
99
|
` emit project.port.${service} ok "${port}, used by this deployment"`,
|
|
88
100
|
" else",
|
|
89
101
|
` emit project.port.${service} manual "${port} is in use by another program"`,
|
|
90
102
|
" fi",
|
|
91
103
|
`elif grep -ls '127.0.0.1:${port}\\b' /etc/caddy/sixb.d/*/*.caddy 2> /dev/null | grep -qv "^$snippet$"; then`,
|
|
92
104
|
` emit project.port.${service} manual "${port} is routed to another deployment"`,
|
|
105
|
+
`elif grep -lxs '${port}' "$HOME"/*/deploy/ports.txt 2> /dev/null | grep -qv "^$ports_file$"; then`,
|
|
106
|
+
` emit project.port.${service} manual "${port} is reserved by another deployment"`,
|
|
93
107
|
"else",
|
|
94
108
|
` emit project.port.${service} ok "${port}"`,
|
|
95
109
|
"fi",
|
|
@@ -167,6 +181,7 @@ const LABELS: Readonly<Record<string, string>> = {
|
|
|
167
181
|
"server.os": "Server",
|
|
168
182
|
"server.tools": "Server tools",
|
|
169
183
|
"server.linger": "Services at boot",
|
|
184
|
+
"server.caddy": "Caddy version",
|
|
170
185
|
"server.reload": "Caddy reload",
|
|
171
186
|
"server.routes": "Caddy routes",
|
|
172
187
|
"server.admin-api": "Caddy admin API",
|
|
@@ -181,7 +196,8 @@ function describe(
|
|
|
181
196
|
detail: string,
|
|
182
197
|
context: { readonly location: string; readonly name: string }
|
|
183
198
|
): DeployCheck {
|
|
184
|
-
const label =
|
|
199
|
+
const label =
|
|
200
|
+
LABELS[id] ?? (id.startsWith("project.port.") ? `${id.slice(13).replace(/-/g, " ")} port` : id)
|
|
185
201
|
const check = { id, label, status, detail }
|
|
186
202
|
if (status === "ok") return check
|
|
187
203
|
if (status === "fixable") return { ...check, remedy: "Run `sixb deploy setup`." }
|
|
@@ -194,7 +210,17 @@ function describe(
|
|
|
194
210
|
}
|
|
195
211
|
}
|
|
196
212
|
if (id.startsWith("project.port.")) {
|
|
197
|
-
return {
|
|
213
|
+
return {
|
|
214
|
+
...check,
|
|
215
|
+
remedy: "Give this service another port in the target's `ports` or `standbyPorts`.",
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
if (id === "server.caddy") {
|
|
219
|
+
return {
|
|
220
|
+
...check,
|
|
221
|
+
remedy:
|
|
222
|
+
"Upgrade Caddy from its own apt repository: https://caddyserver.com/docs/install#debian-ubuntu-raspbian",
|
|
223
|
+
}
|
|
198
224
|
}
|
|
199
225
|
if (id === "server.admin-api") {
|
|
200
226
|
return {
|
package/src/layout.ts
CHANGED
|
@@ -4,24 +4,35 @@ import { posix } from "node:path"
|
|
|
4
4
|
* Where a deployment lives on its server. Everything but the Bun binaries and the Caddy route
|
|
5
5
|
* sits in one directory in the deploy user's home, so projects under one user never share files.
|
|
6
6
|
*
|
|
7
|
-
* ~/<name>/
|
|
8
|
-
* ~/<name>/
|
|
9
|
-
* ~/<name>/
|
|
10
|
-
* ~/<name>/
|
|
11
|
-
*
|
|
7
|
+
* ~/<name>/releases/<id> immutable release directories (code, node_modules, .sixb/dist)
|
|
8
|
+
* ~/<name>/current symlink to the active release directory
|
|
9
|
+
* ~/<name>/code symlink to `current` (migrated in place from single-folder deploys)
|
|
10
|
+
* ~/<name>/shared/.env shared project `.env`, linked from each release
|
|
11
|
+
* ~/<name>/env-token the read-only token a deploy pulls `.env` with, if it has a source
|
|
12
|
+
* ~/<name>/deploy lock, uploads, manifests, release record, ctl
|
|
13
|
+
* ~/<name>/run supervisor state, control requests, and logs
|
|
14
|
+
* ~/.sixb/bun/<v> Bun, shared by the user's projects that pin the same version
|
|
12
15
|
*/
|
|
13
16
|
export const ENV_TOKEN_FILE = "env-token"
|
|
14
17
|
|
|
18
|
+
export type DeploySlot = "blue" | "green"
|
|
19
|
+
|
|
15
20
|
export interface DeploymentLayout {
|
|
16
21
|
readonly root: string
|
|
22
|
+
readonly releasesDir: string
|
|
23
|
+
readonly currentLink: string
|
|
17
24
|
readonly code: string
|
|
25
|
+
readonly sharedDir: string
|
|
26
|
+
readonly sharedEnv: string
|
|
18
27
|
readonly envToken: string
|
|
19
28
|
readonly project: string
|
|
29
|
+
readonly projectPath: string
|
|
20
30
|
readonly deployDir: string
|
|
21
31
|
readonly incomingDir: string
|
|
22
32
|
readonly lock: string
|
|
23
33
|
readonly fileList: string
|
|
24
34
|
readonly manifest: string
|
|
35
|
+
readonly candidateManifest: string
|
|
25
36
|
readonly releaseRecord: string
|
|
26
37
|
/** Runs the server half of this package with the project's Bun and manifest. */
|
|
27
38
|
readonly ctl: string
|
|
@@ -35,6 +46,12 @@ export interface DeploymentLayout {
|
|
|
35
46
|
readonly caddySnippet: string
|
|
36
47
|
}
|
|
37
48
|
|
|
49
|
+
export interface ReleaseLayout {
|
|
50
|
+
readonly id: string
|
|
51
|
+
readonly root: string
|
|
52
|
+
readonly project: string
|
|
53
|
+
}
|
|
54
|
+
|
|
38
55
|
export function deploymentLayout(input: {
|
|
39
56
|
readonly home: string
|
|
40
57
|
readonly user: string
|
|
@@ -43,7 +60,10 @@ export function deploymentLayout(input: {
|
|
|
43
60
|
readonly bunVersion: string
|
|
44
61
|
}): DeploymentLayout {
|
|
45
62
|
const root = posix.join(input.home, input.name)
|
|
63
|
+
const releasesDir = posix.join(root, "releases")
|
|
64
|
+
const currentLink = posix.join(root, "current")
|
|
46
65
|
const code = posix.join(root, "code")
|
|
66
|
+
const sharedDir = posix.join(root, "shared")
|
|
47
67
|
const deployDir = posix.join(root, "deploy")
|
|
48
68
|
const runDir = posix.join(root, "run")
|
|
49
69
|
const bunDir = posix.join(input.home, ".sixb", "bun", input.bunVersion)
|
|
@@ -52,14 +72,20 @@ export function deploymentLayout(input: {
|
|
|
52
72
|
|
|
53
73
|
return {
|
|
54
74
|
root,
|
|
75
|
+
releasesDir,
|
|
76
|
+
currentLink,
|
|
55
77
|
code,
|
|
78
|
+
sharedDir,
|
|
79
|
+
sharedEnv: posix.join(sharedDir, ".env"),
|
|
56
80
|
envToken: posix.join(root, ENV_TOKEN_FILE),
|
|
57
81
|
project: posix.join(code, input.projectPath),
|
|
82
|
+
projectPath: input.projectPath,
|
|
58
83
|
deployDir,
|
|
59
84
|
incomingDir: posix.join(deployDir, "incoming"),
|
|
60
85
|
lock: posix.join(deployDir, "lock"),
|
|
61
86
|
fileList: posix.join(deployDir, "files.txt"),
|
|
62
87
|
manifest: posix.join(deployDir, "processes.json"),
|
|
88
|
+
candidateManifest: posix.join(deployDir, "candidate.json"),
|
|
63
89
|
releaseRecord: posix.join(deployDir, "release.json"),
|
|
64
90
|
ctl: posix.join(deployDir, "ctl"),
|
|
65
91
|
runDir,
|
|
@@ -72,3 +98,12 @@ export function deploymentLayout(input: {
|
|
|
72
98
|
caddySnippet: posix.join(caddyDir, `${input.name}.caddy`),
|
|
73
99
|
}
|
|
74
100
|
}
|
|
101
|
+
|
|
102
|
+
export function releaseLayout(layout: DeploymentLayout, releaseId: string): ReleaseLayout {
|
|
103
|
+
const root = posix.join(layout.releasesDir, releaseId)
|
|
104
|
+
return {
|
|
105
|
+
id: releaseId,
|
|
106
|
+
root,
|
|
107
|
+
project: posix.join(root, layout.projectPath),
|
|
108
|
+
}
|
|
109
|
+
}
|
package/src/operations.ts
CHANGED
|
@@ -9,6 +9,7 @@ import type {
|
|
|
9
9
|
DeployStatus,
|
|
10
10
|
} from "@sixb/core/deploy"
|
|
11
11
|
import { deploymentLayout } from "./layout"
|
|
12
|
+
import type { SlotPorts } from "./render"
|
|
12
13
|
import {
|
|
13
14
|
renderDeployScript,
|
|
14
15
|
renderPrepareScript,
|
|
@@ -27,7 +28,8 @@ export async function deployRelease(
|
|
|
27
28
|
user: string,
|
|
28
29
|
release: DeployRelease,
|
|
29
30
|
source: DeploySource,
|
|
30
|
-
context: DeployContext
|
|
31
|
+
context: DeployContext,
|
|
32
|
+
slotPorts?: SlotPorts
|
|
31
33
|
): Promise<void> {
|
|
32
34
|
const prepared = await capture(shell, renderPrepareScript(release.name, source.commit))
|
|
33
35
|
const [home, incoming] = prepared
|
|
@@ -46,6 +48,7 @@ export async function deployRelease(
|
|
|
46
48
|
release,
|
|
47
49
|
layout,
|
|
48
50
|
incoming,
|
|
51
|
+
...(slotPorts ? { slotPorts } : {}),
|
|
49
52
|
record: {
|
|
50
53
|
commit: source.commit,
|
|
51
54
|
ref: source.ref,
|