@usine/server 0.3.0 → 0.4.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.
- package/LICENSE +661 -21
- package/README.md +22 -4
- package/dist/backend.d.ts +3 -1
- package/dist/backend.d.ts.map +1 -1
- package/dist/backend.js +5 -1
- package/dist/backend.js.map +1 -1
- package/dist/backup.d.ts +3 -3
- package/dist/backup.d.ts.map +1 -1
- package/dist/backup.js +3 -5
- package/dist/backup.js.map +1 -1
- package/dist/cli.d.ts +58 -5
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +216 -17
- package/dist/cli.js.map +1 -1
- package/dist/command.d.ts +22 -0
- package/dist/command.d.ts.map +1 -0
- package/dist/command.js +51 -0
- package/dist/command.js.map +1 -0
- package/dist/detach.d.ts +83 -0
- package/dist/detach.d.ts.map +1 -0
- package/dist/detach.js +320 -0
- package/dist/detach.js.map +1 -0
- package/dist/failure-message.d.ts +7 -1
- package/dist/failure-message.d.ts.map +1 -1
- package/dist/failure-message.js +71 -2
- package/dist/failure-message.js.map +1 -1
- package/dist/http.d.ts +14 -5
- package/dist/http.d.ts.map +1 -1
- package/dist/http.js +25 -13
- package/dist/http.js.map +1 -1
- package/dist/instance/environment.d.ts +17 -0
- package/dist/instance/environment.d.ts.map +1 -0
- package/dist/instance/environment.js +51 -0
- package/dist/instance/environment.js.map +1 -0
- package/dist/instance/id.d.ts +17 -0
- package/dist/instance/id.d.ts.map +1 -0
- package/dist/instance/id.js +35 -0
- package/dist/instance/id.js.map +1 -0
- package/dist/{instance-lock.d.ts → instance/lock.d.ts} +9 -5
- package/dist/instance/lock.d.ts.map +1 -0
- package/dist/instance/lock.js +127 -0
- package/dist/instance/lock.js.map +1 -0
- package/dist/instance/manifest.d.ts +52 -0
- package/dist/instance/manifest.d.ts.map +1 -0
- package/dist/instance/manifest.js +131 -0
- package/dist/instance/manifest.js.map +1 -0
- package/dist/instance/operator-api.d.ts +30 -0
- package/dist/instance/operator-api.d.ts.map +1 -0
- package/dist/instance/operator-api.js +47 -0
- package/dist/instance/operator-api.js.map +1 -0
- package/dist/instance/ports.d.ts +23 -0
- package/dist/instance/ports.d.ts.map +1 -0
- package/dist/instance/ports.js +81 -0
- package/dist/instance/ports.js.map +1 -0
- package/dist/instance/record.d.ts +82 -0
- package/dist/instance/record.d.ts.map +1 -0
- package/dist/instance/record.js +116 -0
- package/dist/instance/record.js.map +1 -0
- package/dist/instance/state.d.ts +45 -0
- package/dist/instance/state.d.ts.map +1 -0
- package/dist/instance/state.js +79 -0
- package/dist/instance/state.js.map +1 -0
- package/dist/instance/systemd.d.ts +36 -0
- package/dist/instance/systemd.d.ts.map +1 -0
- package/dist/instance/systemd.js +61 -0
- package/dist/instance/systemd.js.map +1 -0
- package/dist/logger.d.ts +3 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +27 -0
- package/dist/logger.js.map +1 -0
- package/dist/main.js +35 -9
- package/dist/main.js.map +1 -1
- package/dist/registry.d.ts +20 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +37 -0
- package/dist/registry.js.map +1 -0
- package/dist/restart.d.ts +19 -0
- package/dist/restart.d.ts.map +1 -0
- package/dist/restart.js +105 -0
- package/dist/restart.js.map +1 -0
- package/dist/status.d.ts +12 -0
- package/dist/status.d.ts.map +1 -0
- package/dist/status.js +99 -0
- package/dist/status.js.map +1 -0
- package/dist/stop.d.ts +81 -0
- package/dist/stop.d.ts.map +1 -0
- package/dist/stop.js +195 -0
- package/dist/stop.js.map +1 -0
- package/dist/system-sleep.d.ts +9 -0
- package/dist/system-sleep.d.ts.map +1 -0
- package/dist/system-sleep.js +42 -0
- package/dist/system-sleep.js.map +1 -0
- package/dist/tracing.d.ts +22 -0
- package/dist/tracing.d.ts.map +1 -0
- package/dist/tracing.js +61 -0
- package/dist/tracing.js.map +1 -0
- package/dist/up.d.ts +2 -2
- package/dist/up.d.ts.map +1 -1
- package/dist/up.js +41 -16
- package/dist/up.js.map +1 -1
- package/dist/upgrade.d.ts +58 -0
- package/dist/upgrade.d.ts.map +1 -0
- package/dist/upgrade.js +237 -0
- package/dist/upgrade.js.map +1 -0
- package/dist/web/assets/CompositeItem-DU6IyNMY.js +1 -0
- package/dist/web/assets/ToolbarRootContext-Cytu6o2e.js +1 -0
- package/dist/web/assets/X.es-B7iqdxa_.js +1 -0
- package/dist/web/assets/_agent-BVKD5odk.js +1 -0
- package/dist/web/assets/_loop-BFLzamuo.js +1 -0
- package/dist/web/assets/_name-Bh4AQ9sR.js +6 -0
- package/dist/web/assets/_name-CMVsmWzq.js +1 -0
- package/dist/web/assets/_name-DCkgEma_.js +1 -0
- package/dist/web/assets/_name-Ds_pWi15.js +1 -0
- package/dist/web/assets/_number-B9aYwvcQ.js +1 -0
- package/dist/web/assets/_run-BZWt47QS.js +8 -0
- package/dist/web/assets/_worker-Dgfufm5p.js +1 -0
- package/dist/web/assets/action-rCd1FeAz.js +1 -0
- package/dist/web/assets/agents-Drbg6qpH.js +1 -0
- package/dist/web/assets/agents-_6-dEjrY.js +1 -0
- package/dist/web/assets/button-DVWXde__.js +1 -0
- package/dist/web/assets/collapsible-IOhZV1qg.js +1 -0
- package/dist/web/assets/{core-BUmsKffF.js → core-wi-Hu_JV.js} +1 -1
- package/dist/web/assets/drawer-BiqnR_8i.js +1 -0
- package/dist/web/assets/dropdown-menu-C9D1kRkO.js +1 -0
- package/dist/web/assets/edit-and-retry-BgOR6mvP.js +1 -0
- package/dist/web/assets/error-alert-9tKpTE3v.js +1 -0
- package/dist/web/assets/file-error-SjG2jLJ9.js +1 -0
- package/dist/web/assets/fill-cell-ClM88KFD.js +1 -0
- package/dist/web/assets/heading-lX1a1LNN.js +1 -0
- package/dist/web/assets/index-BymNZU1Q.js +10 -0
- package/dist/web/assets/index-Dyjfp3ET.css +2 -0
- package/dist/web/assets/label-badge-aIGT1Bry.js +1 -0
- package/dist/web/assets/list-v8WJp2Eq.js +1 -0
- package/dist/web/assets/loops-BFoFf_og.js +1 -0
- package/dist/web/assets/mark-CC3RwMy_.js +1 -0
- package/dist/web/assets/{markdown-D07-JkYB.js → markdown-BnyfnuCL.js} +4 -4
- package/dist/web/assets/matchContext-BquevSJS.js +2 -0
- package/dist/web/assets/model-BerBT6R0.js +1 -0
- package/dist/web/assets/moves-Dg9sshX5.js +1 -0
- package/dist/web/assets/overview-C_tFKGZ8.js +1 -0
- package/dist/web/assets/page-DWnGi6wA.js +301 -0
- package/dist/web/assets/project-not-found-CodaBVdu.js +1 -0
- package/dist/web/assets/pull-request-marks-DE00nqGW.js +1 -0
- package/dist/web/assets/queries-B1SHA_r4.js +1 -0
- package/dist/web/assets/reload-Dsl0zjJ7.js +1 -0
- package/dist/web/assets/repositories-BdxmD192.js +1 -0
- package/dist/web/assets/repositories-D4wYJfa_.js +1 -0
- package/dist/web/assets/route-B_gphTYG.js +1 -0
- package/dist/web/assets/route-Cc7dKnn5.js +1 -0
- package/dist/web/assets/routes-BLy5TGH_.js +65 -0
- package/dist/web/assets/run-again-BTKagSXR.js +1 -0
- package/dist/web/assets/section-B3pWIIBa.js +1 -0
- package/dist/web/assets/section-CD-MB5r3.js +1 -0
- package/dist/web/assets/section-Id99HktI.js +1 -0
- package/dist/web/assets/settings-YrDysQXW.js +1 -0
- package/dist/web/assets/slots-BraHmbNr.js +1 -0
- package/dist/web/assets/status-badge-DnvNo1tG.js +1 -0
- package/dist/web/assets/strings-CW2XaR5f.js +1 -0
- package/dist/web/assets/table-BjyI4fVI.js +1 -0
- package/dist/web/assets/tasks-DCL8kLmD.js +1 -0
- package/dist/web/assets/transcript-sxRJzx6t.js +5 -0
- package/dist/web/assets/usage-CLQJdX9-.js +1 -0
- package/dist/web/assets/use-now-0P8TUXeg.js +1 -0
- package/dist/web/assets/useAnchoredPopupScrollLock-CQ83Wy-r.js +1 -0
- package/dist/web/assets/useNavigate-BW1WdocJ.js +1 -0
- package/dist/web/assets/usePositioner-rNCxnHO-.js +1 -0
- package/dist/web/assets/useTimeout-_TcdZXP6.js +1 -0
- package/dist/web/assets/with-selector-DoElmmtd.js +1 -0
- package/dist/web/assets/workers-BH5CBOR3.js +1 -0
- package/dist/web/index.html +15 -12
- package/package.json +16 -15
- package/dist/instance-lock.d.ts.map +0 -1
- package/dist/instance-lock.js +0 -58
- package/dist/instance-lock.js.map +0 -1
- package/dist/web/assets/DialogTitle-DrHlwOSg.js +0 -1
- package/dist/web/assets/_agent-cBqm12lE.js +0 -1
- package/dist/web/assets/_loop-kf1h3qkS.js +0 -1
- package/dist/web/assets/_name-CKWcxUh0.js +0 -2
- package/dist/web/assets/_name-DCEDRHnF.js +0 -1
- package/dist/web/assets/_name-sJkGyn7O.js +0 -1
- package/dist/web/assets/_number-DbgcVg1N.js +0 -1
- package/dist/web/assets/_run-DqslP0y6.js +0 -8
- package/dist/web/assets/_worker-CH4UoJT_.js +0 -1
- package/dist/web/assets/action-DYT048Jm.js +0 -1
- package/dist/web/assets/agents-DIZolb0U.js +0 -1
- package/dist/web/assets/agents-DMhSMb9O.js +0 -1
- package/dist/web/assets/button-C4yvcSko.js +0 -2
- package/dist/web/assets/copy-BM1l6IGB.js +0 -1
- package/dist/web/assets/error-alert-BrI00JbQ.js +0 -1
- package/dist/web/assets/file-error-C--_cWuj.js +0 -1
- package/dist/web/assets/index-BljdfRBm.js +0 -10
- package/dist/web/assets/index-YKcAk3No.css +0 -2
- package/dist/web/assets/item-rBBCTV8x.js +0 -1
- package/dist/web/assets/label-badge-ohqvZnY7.js +0 -1
- package/dist/web/assets/loops-CXM3f90o.js +0 -1
- package/dist/web/assets/loops-DWLXyUPN.js +0 -1
- package/dist/web/assets/moves-RiWgdCxQ.js +0 -5
- package/dist/web/assets/operator-copy-DsM7LJx6.js +0 -301
- package/dist/web/assets/outcome-YiIf6xbJ.js +0 -5
- package/dist/web/assets/project-not-found-CQVclgb0.js +0 -1
- package/dist/web/assets/query-DWN8IHdt.js +0 -1
- package/dist/web/assets/repositories-CoTEmYmS.js +0 -1
- package/dist/web/assets/repositories-Cq7zGzNb.js +0 -1
- package/dist/web/assets/rolldown-runtime-XKyaHtl9.js +0 -1
- package/dist/web/assets/route-CE9U74a9.js +0 -1
- package/dist/web/assets/route-DNH2EwHP.js +0 -1
- package/dist/web/assets/routes-XAUJJqfj.js +0 -1
- package/dist/web/assets/run-again-DxjFCuNu.js +0 -1
- package/dist/web/assets/run-drawer-CyjxH5mf.js +0 -1
- package/dist/web/assets/section-BBnBOk-U.js +0 -1
- package/dist/web/assets/section-Cm-j3zHs.js +0 -1
- package/dist/web/assets/section-DkBCDv4D.js +0 -1
- package/dist/web/assets/settings-iZf872O5.js +0 -1
- package/dist/web/assets/status-badge-CNlyvwWL.js +0 -1
- package/dist/web/assets/table-B6NH8hTW.js +0 -1
- package/dist/web/assets/tasks-DhLW-1gg.js +0 -1
- package/dist/web/assets/usage-DPUTTLGs.js +0 -1
- package/dist/web/assets/use-now-CcFZyFvf.js +0 -1
- package/dist/web/assets/useNavigate-lXd3v3E0.js +0 -1
- package/dist/web/assets/usePositioner-WErrA3Ah.js +0 -1
- package/dist/web/assets/useScrollLock-BOb01sL8.js +0 -1
- package/dist/web/assets/useTriggerFocusGuards-B0FItfLc.js +0 -1
- package/dist/web/assets/utils-BEQKLGgi.js +0 -1
- package/dist/web/assets/with-selector-NsM_5qXG.js +0 -1
- package/dist/web/assets/workers-BgocBXT9.js +0 -1
- package/dist/web/assets/workers-Dw2uHY0Y.js +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"system-sleep.d.ts","sourceRoot":"","sources":["../src/system-sleep.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,MAAM,EAAkB,MAAM,QAAQ,CAAC;AAC1D,OAAO,EAAgB,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AA8BnE;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,2EAyB7B,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Duration, Effect, Option, Schema } from "effect";
|
|
2
|
+
import { ChildProcess, ChildProcessSpawner } from "effect/process";
|
|
3
|
+
const PMSET_TIMEOUT = Duration.seconds(5);
|
|
4
|
+
/** Matches a line such as ` sleep 1 (sleep prevented by caffeinate, powerd)`. */
|
|
5
|
+
const SLEEP_LINE = /^\s*sleep\s+(\d+)(?:\s+\(sleep prevented by ([^)]*)\))?/mu;
|
|
6
|
+
const Minutes = Schema.NumberFromString.pipe(Schema.decodeTo(Schema.Int));
|
|
7
|
+
/** Returns the `sleep` setting in `pmset -g` output, or `None` if it has no `sleep` line. */
|
|
8
|
+
const systemSleepOf = (output) => {
|
|
9
|
+
const line = SLEEP_LINE.exec(output);
|
|
10
|
+
if (line === null)
|
|
11
|
+
return Option.none();
|
|
12
|
+
return Option.map(Schema.decodeUnknownOption(Minutes)(line[1]), (minutes) => ({
|
|
13
|
+
minutes,
|
|
14
|
+
preventedBy: (line[2] ?? "")
|
|
15
|
+
.split(",")
|
|
16
|
+
.map((name) => name.trim())
|
|
17
|
+
.filter((name) => name.length > 0),
|
|
18
|
+
}));
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Logs a warning if this Mac can sleep while `usine up` runs: system sleep is on, and `caffeinate`
|
|
22
|
+
* doesn't prevent it. A sleep closes the SSH connections to Workers and to the Gateway, and the
|
|
23
|
+
* orchestrator does nothing until the Mac wakes.
|
|
24
|
+
*/
|
|
25
|
+
export const warnIfSystemSleeps = Effect.fn("Server.warnIfSystemSleeps")(function* () {
|
|
26
|
+
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
|
|
27
|
+
const sleep = yield* spawner
|
|
28
|
+
.string(ChildProcess.make("pmset", ["-g"], { stdin: "ignore", stderr: "ignore" }))
|
|
29
|
+
.pipe(Effect.timeout(PMSET_TIMEOUT), Effect.map(systemSleepOf), Effect.tapError((cause) => Effect.logWarning("Could not read the system sleep setting with pmset", { cause })), Effect.orElseSucceed(() => Option.none()));
|
|
30
|
+
if (Option.isNone(sleep))
|
|
31
|
+
return yield* Effect.logDebug("pmset reported no system sleep setting; skipping the check");
|
|
32
|
+
const { minutes, preventedBy } = sleep.value;
|
|
33
|
+
if (minutes === 0)
|
|
34
|
+
return yield* Effect.logDebug("System sleep is off");
|
|
35
|
+
if (preventedBy.includes("caffeinate"))
|
|
36
|
+
return yield* Effect.logInfo("System sleep is on, and caffeinate prevents it", {
|
|
37
|
+
minutes,
|
|
38
|
+
preventedBy,
|
|
39
|
+
});
|
|
40
|
+
yield* Effect.logWarning("This Mac can sleep while runs are open. A sleep drops the SSH connections to workers and the gateway, and remote children must resume. Run `caffeinate -s` while runs are open, turn off sleep on AC power with `sudo pmset -c sleep 0`, or run the orchestrator on an always-on server: https://docs.usine.dev/guides/run-the-orchestrator-on-a-server/", { minutes, preventedBy });
|
|
41
|
+
});
|
|
42
|
+
//# sourceMappingURL=system-sleep.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"system-sleep.js","sourceRoot":"","sources":["../src/system-sleep.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAEnE,MAAM,aAAa,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;AAU1C,kFAAkF;AAClF,MAAM,UAAU,GAAG,2DAA2D,CAAC;AAE/E,MAAM,OAAO,GAAG,MAAM,CAAC,gBAAgB,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;AAE1E,6FAA6F;AAC7F,MAAM,aAAa,GAAG,CAAC,MAAc,EAA8B,EAAE;IACnE,MAAM,IAAI,GAAG,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACrC,IAAI,IAAI,KAAK,IAAI;QAAE,OAAO,MAAM,CAAC,IAAI,EAAE,CAAC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AAC,MAAM,CAAC,QAAQ,CAAC,4DAA4D,CAAC,CAAC;IAC9F,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,GAAG,KAAK,CAAC,KAAK,CAAC;IAC7C,IAAI,OAAO,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,qBAAqB,CAAC,CAAC;IACxE,IAAI,WAAW,CAAC,QAAQ,CAAC,YAAY,CAAC;QACpC,OAAO,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,gDAAgD,EAAE;YAC7E,OAAO;YACP,WAAW;SACZ,CAAC,CAAC;IACL,KAAK,CAAC,CAAC,MAAM,CAAC,UAAU,CACtB,0VAA0V,EAC1V,EAAE,OAAO,EAAE,WAAW,EAAE,CACzB,CAAC;AACJ,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Tracing } from "@usine/config/factory";
|
|
2
|
+
import { type FileSystem, Layer, Option, Schema } from "effect";
|
|
3
|
+
import { type CliVersionError } from "./cli.ts";
|
|
4
|
+
declare const ResourceAttributesError_base: Schema.Class<ResourceAttributesError, Schema.TaggedStruct<"ResourceAttributesError", {
|
|
5
|
+
readonly variable: Schema.Literal<"OTEL_RESOURCE_ATTRIBUTES">;
|
|
6
|
+
/** The parse problem, with the key at fault. */
|
|
7
|
+
readonly message: Schema.String;
|
|
8
|
+
}>, import("effect/Cause").YieldableError>;
|
|
9
|
+
/** `OTEL_RESOURCE_ATTRIBUTES` has a key or value that isn't valid percent-encoding. */
|
|
10
|
+
export declare class ResourceAttributesError extends ResourceAttributesError_base {
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Exports every ended span to `tracing.otlpUrl` as OTLP/HTTP protobuf, or keeps Effect's default
|
|
14
|
+
* tracer, which exports nothing, if `tracing` is `None`. Logs which of the two applies, and a
|
|
15
|
+
* warning for each failed export request, with the URL's origin and path only. A failed export,
|
|
16
|
+
* after up to 3 retries, drops the buffered spans and pauses export for 60 seconds. Closing the
|
|
17
|
+
* layer's scope flushes buffered spans for at most 3 seconds. Fails with
|
|
18
|
+
* `ResourceAttributesError` if `tracing` is set and `OTEL_RESOURCE_ATTRIBUTES` is malformed.
|
|
19
|
+
*/
|
|
20
|
+
export declare const tracingLayer: (tracing: Option.Option<Tracing>) => Layer.Layer<never, CliVersionError | ResourceAttributesError, FileSystem.FileSystem>;
|
|
21
|
+
export {};
|
|
22
|
+
//# sourceMappingURL=tracing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tracing.d.ts","sourceRoot":"","sources":["../src/tracing.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAIL,KAAK,UAAU,EACf,KAAK,EACL,MAAM,EACN,MAAM,EAEP,MAAM,QAAQ,CAAC;AAGhB,OAAO,EAAE,KAAK,eAAe,EAAkB,MAAM,UAAU,CAAC;;;IAS9D,gDAAgD;;;AALlD,uFAAuF;AACvF,qBAAa,uBAAwB,SAAQ,4BAM3C;CAAG;AA+CL;;;;;;;GAOG;AACH,eAAO,MAAM,YAAY,YACd,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,KAC9B,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE,eAAe,GAAG,uBAAuB,EAAE,UAAU,CAAC,UAAU,CAgClF,CAAC"}
|
package/dist/tracing.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { Config, ConfigProvider, Effect, Layer, Option, Schema, SchemaTransformation, } from "effect";
|
|
2
|
+
import { FetchHttpClient, HttpClient } from "effect/http";
|
|
3
|
+
import { OtlpSerialization, OtlpTracer } from "effect/observability";
|
|
4
|
+
import { packageVersion } from "./cli.js";
|
|
5
|
+
const RESOURCE_ATTRIBUTES = "OTEL_RESOURCE_ATTRIBUTES";
|
|
6
|
+
/** `OTEL_RESOURCE_ATTRIBUTES` has a key or value that isn't valid percent-encoding. */
|
|
7
|
+
export class ResourceAttributesError extends Schema.TaggedError("@usine/server/ResourceAttributesError")("ResourceAttributesError", {
|
|
8
|
+
variable: Schema.Literal(RESOURCE_ATTRIBUTES),
|
|
9
|
+
/** The parse problem, with the key at fault. */
|
|
10
|
+
message: Schema.String,
|
|
11
|
+
}) {
|
|
12
|
+
}
|
|
13
|
+
/** Comma-separated `key=value` pairs with percent-encoded keys and values. */
|
|
14
|
+
const ResourceAttributes = Schema.String.pipe(Schema.decodeTo(Schema.Record(Schema.StringFromUriComponent, Schema.StringFromUriComponent), SchemaTransformation.splitKeyValue()));
|
|
15
|
+
/** Returns the attributes in `OTEL_RESOURCE_ATTRIBUTES`, or none if it's unset. */
|
|
16
|
+
const resourceAttributes = Effect.fn("Tracing.resourceAttributes")(function* () {
|
|
17
|
+
const refuse = (error) => new ResourceAttributesError({ variable: RESOURCE_ATTRIBUTES, message: error.message });
|
|
18
|
+
const value = yield* Config.option(Config.String(RESOURCE_ATTRIBUTES)).pipe(Effect.mapError(refuse));
|
|
19
|
+
return yield* Option.match(value, {
|
|
20
|
+
onNone: () => Effect.succeed({}),
|
|
21
|
+
onSome: (attributes) => Schema.decodeUnknownEffect(ResourceAttributes)(attributes).pipe(Effect.mapError(refuse)),
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
/** Returns the URL's origin and path, without credentials, query string, or fragment. */
|
|
25
|
+
const loggedUrl = (url) => `${url.origin}${url.pathname}`;
|
|
26
|
+
const EXPORT_FAILED = "Span export to the OTLP collector failed";
|
|
27
|
+
// The error message is left out because it repeats the request URL.
|
|
28
|
+
const exportClientLayer = (collector) => Layer.effect(HttpClient.HttpClient, Effect.map(HttpClient.HttpClient, (client) => client.pipe(HttpClient.filterStatusOk, HttpClient.tapError((error) => {
|
|
29
|
+
const failure = { otlpUrl: collector, reason: error.reason._tag };
|
|
30
|
+
return Option.match(Option.fromUndefinedOr(error.response), {
|
|
31
|
+
onNone: () => Effect.logWarning(EXPORT_FAILED, failure),
|
|
32
|
+
onSome: ({ status }) => Effect.logWarning(EXPORT_FAILED, { ...failure, status }),
|
|
33
|
+
});
|
|
34
|
+
})))).pipe(Layer.provide(FetchHttpClient.layer));
|
|
35
|
+
/**
|
|
36
|
+
* Exports every ended span to `tracing.otlpUrl` as OTLP/HTTP protobuf, or keeps Effect's default
|
|
37
|
+
* tracer, which exports nothing, if `tracing` is `None`. Logs which of the two applies, and a
|
|
38
|
+
* warning for each failed export request, with the URL's origin and path only. A failed export,
|
|
39
|
+
* after up to 3 retries, drops the buffered spans and pauses export for 60 seconds. Closing the
|
|
40
|
+
* layer's scope flushes buffered spans for at most 3 seconds. Fails with
|
|
41
|
+
* `ResourceAttributesError` if `tracing` is set and `OTEL_RESOURCE_ATTRIBUTES` is malformed.
|
|
42
|
+
*/
|
|
43
|
+
export const tracingLayer = (tracing) => Option.match(tracing, {
|
|
44
|
+
onNone: () => Layer.effectDiscard(Effect.logInfo("Span export is off; set tracing.otlp_url in usine.yaml to turn it on")),
|
|
45
|
+
onSome: ({ otlpUrl, serviceName }) => Layer.unwrap(Effect.gen(function* () {
|
|
46
|
+
const serviceVersion = yield* packageVersion();
|
|
47
|
+
const attributes = yield* resourceAttributes();
|
|
48
|
+
return OtlpTracer.layer({
|
|
49
|
+
url: otlpUrl.href,
|
|
50
|
+
resource: { serviceName, serviceVersion, attributes },
|
|
51
|
+
}).pipe(
|
|
52
|
+
// `attributes` replaces the resource's own read of OTEL_RESOURCE_ATTRIBUTES, which dies on
|
|
53
|
+
// a malformed value.
|
|
54
|
+
Layer.provide(ConfigProvider.layer(ConfigProvider.fromUnknown({}))), Layer.provide(OtlpSerialization.layerProtobuf), Layer.provide(exportClientLayer(loggedUrl(otlpUrl))), Layer.merge(Layer.effectDiscard(Effect.logInfo("Exporting spans over OTLP", {
|
|
55
|
+
otlpUrl: loggedUrl(otlpUrl),
|
|
56
|
+
serviceName,
|
|
57
|
+
serviceVersion,
|
|
58
|
+
}))));
|
|
59
|
+
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KAAK,CAAC,aAAa,CACjB,MAAM,CAAC,OAAO,CAAC,2BAA2B,EAAE;YAC1C,OAAO,EAAE,SAAS,CAAC,OAAO,CAAC;YAC3B,WAAW;YACX,cAAc;SACf,CAAC,CACH,CACF,CACF,CAAC;IACJ,CAAC,CAAC,CACH;CACJ,CAAC,CAAC"}
|
package/dist/up.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
|
-
import { type
|
|
3
|
-
export declare const up: (
|
|
2
|
+
import { type UpCommand, VolatileInstanceDirectoryError } from "./cli.ts";
|
|
3
|
+
export declare const up: (command: UpCommand) => Effect.Effect<never, import("@usine/github/github-app").AppAuthenticationError | import("@usine/engine/engine").AttemptCancellationError | import("./cli.ts").CliVersionError | import("@usine/executor").CredentialUnavailableError | import("@usine/durable/harness").DurableHarnessError | import("@usine/engine/engine").EnginePersistenceError | import("@usine/executor").ExecutorOperationError | import("@usine/config/file").FactoryConfigError | import("./instance/id.ts").InstanceIdError | import("./instance/lock.ts").InstanceInUseError | import("./instance/lock.ts").InstanceLockError | import("./cli.ts").PortInUseError | import("./tracing.ts").ResourceAttributesError | import("@usine/engine/engine").RunInterventionRejectedError | import("@usine/engine/engine").RunNotFoundError | import("@usine/engine/engine").RunOperationRejectedError | import("@usine/engine/engine").RunRetryBlockedError | import("./cli.ts").ServerStartError | import("@usine/orchestrator/scheduler").UnsupportedWorkerError | VolatileInstanceDirectoryError | import("@usine/executor").WorkerCapabilityError, import("effect/process/ChildProcessSpawner").ChildProcessSpawner>;
|
|
4
4
|
//# sourceMappingURL=up.d.ts.map
|
package/dist/up.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"up.d.ts","sourceRoot":"","sources":["../src/up.ts"],"names":[],"mappings":"AAcA,OAAO,
|
|
1
|
+
{"version":3,"file":"up.d.ts","sourceRoot":"","sources":["../src/up.ts"],"names":[],"mappings":"AAcA,OAAO,EAQL,MAAM,EAMP,MAAM,QAAQ,CAAC;AAEhB,OAAO,EAGL,KAAK,SAAS,EACd,8BAA8B,EAQ/B,MAAM,UAAU,CAAC;AAsKlB,eAAO,MAAM,EAAE,YAAa,SAAS,goCAiCwC,CAAC"}
|
package/dist/up.js
CHANGED
|
@@ -12,13 +12,18 @@ import { CurrentInstance } from "@usine/orchestrator/current-instance";
|
|
|
12
12
|
import { Operator, OperatorConfiguration, OperatorObservation } from "@usine/orchestrator/operator";
|
|
13
13
|
import { Orchestrator } from "@usine/orchestrator/orchestrator";
|
|
14
14
|
import { operatorObservationLayer, runtimeLayer } from "@usine/orchestrator/runtime";
|
|
15
|
-
import { Cause, Console, Context, Duration, Deferred, Effect, FileSystem, Layer, Option, Result, } from "effect";
|
|
15
|
+
import { Cause, Config, Console, Context, DateTime, Duration, Deferred, Effect, FileSystem, Layer, Option, References, Result, } from "effect";
|
|
16
16
|
import { liveBackendLayer, needsSetupBackendLayer } from "./backend.js";
|
|
17
|
-
import { VolatileInstanceDirectoryError, openBrowser, portInUse, refuseTakenPort, serverStartError, volatileRoot, volatileRoots, } from "./cli.js";
|
|
17
|
+
import { VolatileInstanceDirectoryError, openBrowser, packageVersion, portInUse, refuseTakenPort, serverStartError, volatileRoot, volatileRoots, } from "./cli.js";
|
|
18
18
|
import { serverLayer } from "./http.js";
|
|
19
|
-
import {
|
|
19
|
+
import { instanceIdOf } from "./instance/id.js";
|
|
20
|
+
import { holdInstance } from "./instance/lock.js";
|
|
21
|
+
import { InstanceRecord, ProcessId, currentLaunch, instanceFiles } from "./instance/record.js";
|
|
22
|
+
import { currentSystemService } from "./instance/systemd.js";
|
|
20
23
|
import { reloadOnHangup } from "./reload-signal.js";
|
|
21
24
|
import { withGracefulShutdown } from "./shutdown.js";
|
|
25
|
+
import { warnIfSystemSleeps } from "./system-sleep.js";
|
|
26
|
+
import { tracingLayer } from "./tracing.js";
|
|
22
27
|
const instanceFolderLayer = InstanceFolder.layer.pipe(Layer.provide(ConfigParser.layer.pipe(Layer.provide(MarcbachmannCelLayer))), Layer.provide(NodeServices.layer));
|
|
23
28
|
/** Loads the instance folder and keeps it reloadable. Fails if `usine.yaml` is invalid. */
|
|
24
29
|
const loadInstance = Effect.fn("Server.loadInstance")(function* (directory) {
|
|
@@ -27,8 +32,9 @@ const loadInstance = Effect.fn("Server.loadInstance")(function* (directory) {
|
|
|
27
32
|
const current = yield* Layer.build(CurrentInstance.layer(directory, initial).pipe(Layer.provide(Layer.succeedContext(context))));
|
|
28
33
|
return Context.get(current, CurrentInstance);
|
|
29
34
|
});
|
|
30
|
-
|
|
31
|
-
|
|
35
|
+
// Untraced: a span around a server that never returns would parent every request span.
|
|
36
|
+
const serve = Effect.fnUntraced(function* (options) {
|
|
37
|
+
yield* Layer.build(serverLayer(options.backend, options.webRoot, options.port, options.origin)).pipe(Effect.mapError((error) => serverStartError(options.port, error)), Effect.catchTag("PortInUseError", ({ port }) => portInUse(port)));
|
|
32
38
|
yield* Console.log(options.openSetupPage
|
|
33
39
|
? `usine is running in setup mode at ${options.url}`
|
|
34
40
|
: `usine is running at ${options.url}`);
|
|
@@ -43,7 +49,7 @@ const serve = Effect.fn("Server.serve")(function* (options) {
|
|
|
43
49
|
});
|
|
44
50
|
const refuseVolatileInstance = Effect.fn("Server.refuseVolatileInstance")(function* (directory, allowVolatileInstance) {
|
|
45
51
|
const realDirectory = yield* Effect.flatMap(FileSystem.FileSystem, (fileSystem) => fileSystem.realPath(directory)).pipe(Effect.orElseSucceed(() => directory));
|
|
46
|
-
const roots = volatileRoots(
|
|
52
|
+
const roots = volatileRoots(yield* Effect.orDie(Config.option(Config.String("TMPDIR"))));
|
|
47
53
|
const root = Option.orElse(volatileRoot(directory, roots), () => volatileRoot(realDirectory, roots));
|
|
48
54
|
if (Option.isNone(root))
|
|
49
55
|
return;
|
|
@@ -52,13 +58,8 @@ const refuseVolatileInstance = Effect.fn("Server.refuseVolatileInstance")(functi
|
|
|
52
58
|
}
|
|
53
59
|
yield* Effect.logWarning("Instance folder sits under a volatile path; its runtime store is the only copy of run history", { instanceDirectory: directory, root: root.value });
|
|
54
60
|
});
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
yield* refuseVolatileInstance(directory, allowVolatileInstance).pipe(Effect.provide(NodeServices.layer));
|
|
58
|
-
// Acquired before any store opens and released after every store closes.
|
|
59
|
-
yield* holdInstance(directory).pipe(Effect.provide(NodeServices.layer));
|
|
60
|
-
yield* refuseTakenPort(port).pipe(Effect.provide(NodeServices.layer));
|
|
61
|
-
const instances = yield* loadInstance(directory);
|
|
61
|
+
/** Serves setup mode if the GitHub App credentials are absent, otherwise runs the factory. */
|
|
62
|
+
const start = Effect.fnUntraced(function* (directory, instanceId, instances, port, origin) {
|
|
62
63
|
yield* reloadOnHangup(instances);
|
|
63
64
|
const credentials = yield* loadLocalCredentials(directory).pipe(Effect.provide(NodeServices.layer), Effect.result);
|
|
64
65
|
const webRoot = resolve(dirname(fileURLToPath(import.meta.url)), "web");
|
|
@@ -72,11 +73,11 @@ export const up = (port, allowVolatileInstance) => Effect.scoped(Effect.gen(func
|
|
|
72
73
|
});
|
|
73
74
|
const observationContext = yield* Layer.build(operatorObservationLayer(directory));
|
|
74
75
|
const backend = needsSetupBackendLayer(instances, error._tag, Context.get(observationContext, OperatorObservation), Context.get(observationContext, OperatorConfiguration));
|
|
75
|
-
return yield* serve({ backend, webRoot, port, url, openSetupPage: true });
|
|
76
|
+
return yield* serve({ backend, webRoot, port, origin, url, openSetupPage: true });
|
|
76
77
|
}
|
|
77
78
|
const shutdown = yield* Deferred.make();
|
|
78
79
|
const startup = Effect.gen(function* () {
|
|
79
|
-
const runtime = runtimeLayer(directory).pipe(Layer.provide(Layer.succeed(GitHubCredentials, credentials.success)), Layer.provide(Layer.succeed(CurrentInstance, instances)));
|
|
80
|
+
const runtime = runtimeLayer(directory, instanceId).pipe(Layer.provide(Layer.succeed(GitHubCredentials, credentials.success)), Layer.provide(Layer.succeed(CurrentInstance, instances)));
|
|
80
81
|
const context = yield* Layer.build(runtime).pipe(Effect.provideService(RunEngineShutdown, shutdown));
|
|
81
82
|
const operator = Context.get(context, Operator);
|
|
82
83
|
const orchestrator = Context.get(context, Orchestrator);
|
|
@@ -87,6 +88,7 @@ export const up = (port, allowVolatileInstance) => Effect.scoped(Effect.gen(func
|
|
|
87
88
|
backend: liveBackendLayer(instances, operator, Context.get(context, OperatorConfiguration)),
|
|
88
89
|
webRoot,
|
|
89
90
|
port,
|
|
91
|
+
origin,
|
|
90
92
|
url,
|
|
91
93
|
openSetupPage: false,
|
|
92
94
|
}), orchestrator.run.pipe(Effect.tapCause((cause) => Cause.hasInterruptsOnly(cause)
|
|
@@ -100,5 +102,28 @@ export const up = (port, allowVolatileInstance) => Effect.scoped(Effect.gen(func
|
|
|
100
102
|
onNone: () => Duration.infinity,
|
|
101
103
|
onSome: Duration.minutes,
|
|
102
104
|
})));
|
|
103
|
-
})
|
|
105
|
+
});
|
|
106
|
+
export const up = (command) => Effect.scoped(Effect.gen(function* () {
|
|
107
|
+
const { port, origin } = command;
|
|
108
|
+
const directory = InstanceDirectory.make(process.cwd());
|
|
109
|
+
yield* refuseVolatileInstance(directory, command.allowVolatileInstance).pipe(Effect.provide(NodeServices.layer));
|
|
110
|
+
const record = new InstanceRecord({
|
|
111
|
+
pid: ProcessId.make(process.pid),
|
|
112
|
+
version: yield* packageVersion().pipe(Effect.provide(NodeServices.layer)),
|
|
113
|
+
startedAt: yield* DateTime.now,
|
|
114
|
+
launch: yield* currentLaunch(command),
|
|
115
|
+
systemdUnit: yield* currentSystemService().pipe(Effect.provide(NodeServices.layer)),
|
|
116
|
+
});
|
|
117
|
+
// Acquired before any store opens and released after every store closes.
|
|
118
|
+
yield* holdInstance(directory, record).pipe(Effect.provide(NodeServices.layer));
|
|
119
|
+
const instanceId = yield* instanceIdOf(instanceFiles(directory)).pipe(Effect.provide(NodeServices.layer));
|
|
120
|
+
yield* refuseTakenPort(port).pipe(Effect.provide(NodeServices.layer));
|
|
121
|
+
if (process.platform === "darwin")
|
|
122
|
+
yield* warnIfSystemSleeps().pipe(Effect.provide(NodeServices.layer));
|
|
123
|
+
const instances = yield* loadInstance(directory);
|
|
124
|
+
const { config } = yield* instances.get;
|
|
125
|
+
// Built before the runtime, so the exporter flushes the runtime's last spans when it closes.
|
|
126
|
+
const tracer = yield* Layer.build(tracingLayer(config.tracing)).pipe(Effect.provide(NodeServices.layer));
|
|
127
|
+
return yield* start(directory, instanceId, instances, port, origin).pipe(Effect.provideContext(tracer));
|
|
128
|
+
})).pipe(Effect.provideService(References.MinimumLogLevel, command.logLevel));
|
|
104
129
|
//# sourceMappingURL=up.js.map
|
package/dist/up.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"up.js","sourceRoot":"","sources":["../src/up.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,iBAAiB,
|
|
1
|
+
{"version":3,"file":"up.js","sourceRoot":"","sources":["../src/up.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,iBAAiB,EAAmB,MAAM,sBAAsB,CAAC;AAC1E,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,sB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C,IAAI,CACnE,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC,CACnC,CAAC;IACF,KAAK,CAAC,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC;IACtE,IAAI,OAAO,CAAC,QAAQ,KAAK,QAAQ;QAC/B,KAAK,CAAC,CAAC,kBAAkB,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC;IACvE,MAAM,SAAS,GAAG,KAAK,CAAC,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC;IACjD,MAAM,EAAE,MAAM,EAAE,GAAG,KAAK,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC;IACxC,6FAA6F;IAC7F,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,YAAY,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAClE,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC,CACnC,CAAC;IACF,OAAO,KAAK,CAAC,CAAC,KAAK,CAAC,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,IAAI,CACtE,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,CAC9B,CAAC;AACJ,CAAC,CAAC,CACH,CAAC,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,UAAU,CAAC,eAAe,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { Effect, FileSystem, Schema } from "effect";
|
|
2
|
+
import type { UpgradeCommand } from "./cli.ts";
|
|
3
|
+
import { UnrecordedInstanceError } from "./stop.ts";
|
|
4
|
+
declare const EngineOutsideInstanceError_base: Schema.Class<EngineOutsideInstanceError, Schema.TaggedStruct<"EngineOutsideInstanceError", {
|
|
5
|
+
readonly script: Schema.String;
|
|
6
|
+
readonly version: Schema.String;
|
|
7
|
+
/** Whether the entry point is in a `node_modules` folder, as with a global install. */
|
|
8
|
+
readonly packaged: Schema.Boolean;
|
|
9
|
+
}>, import("effect/Cause").YieldableError>;
|
|
10
|
+
/** The running engine isn't installed in the instance's `node_modules`, so no pin selects it. */
|
|
11
|
+
export declare class EngineOutsideInstanceError extends EngineOutsideInstanceError_base {
|
|
12
|
+
}
|
|
13
|
+
declare const EnginePinError_base: Schema.Class<EnginePinError, Schema.TaggedStruct<"EnginePinError", {
|
|
14
|
+
readonly path: Schema.String;
|
|
15
|
+
readonly missing: Schema.Boolean;
|
|
16
|
+
/** The local spec, such as `link:../usine/apps/server`, if `@usine/server` has one. */
|
|
17
|
+
readonly linked: Schema.Option<Schema.String>;
|
|
18
|
+
}>, import("effect/Cause").YieldableError>;
|
|
19
|
+
/** The instance's `package.json` is absent or doesn't pin `@usine/server` to a registry version. */
|
|
20
|
+
export declare class EnginePinError extends EnginePinError_base {
|
|
21
|
+
}
|
|
22
|
+
declare const UpgradeFileError_base: Schema.Class<UpgradeFileError, Schema.TaggedStruct<"UpgradeFileError", {
|
|
23
|
+
readonly path: Schema.String;
|
|
24
|
+
readonly reason: Schema.String;
|
|
25
|
+
}>, import("effect/Cause").YieldableError>;
|
|
26
|
+
/** A file that `usine upgrade` reads or writes couldn't be accessed. */
|
|
27
|
+
export declare class UpgradeFileError extends UpgradeFileError_base {
|
|
28
|
+
}
|
|
29
|
+
declare const UpgradeFailedError_base: Schema.Class<UpgradeFailedError, Schema.TaggedStruct<"UpgradeFailedError", {
|
|
30
|
+
readonly stage: Schema.Literals<readonly ["install", "start", "listen"]>;
|
|
31
|
+
readonly reason: Schema.String;
|
|
32
|
+
readonly previous: Schema.String;
|
|
33
|
+
readonly target: Schema.String;
|
|
34
|
+
readonly packageManager: Schema.Literals<readonly ["pnpm", "npm", "yarn", "bun"]>;
|
|
35
|
+
/** The runtime store copy, if the instance had a runtime store. The durable copy is next to it. */
|
|
36
|
+
readonly backup: Schema.Option<Schema.String>;
|
|
37
|
+
/** The commit of the pin change, if `usine upgrade` made one. */
|
|
38
|
+
readonly commit: Schema.Option<Schema.String>;
|
|
39
|
+
/** The last lines of `.usine/usine.log`, for a failed start. */
|
|
40
|
+
readonly tail: Schema.String;
|
|
41
|
+
/** The systemd service that runs the instance, whose journal has its output. */
|
|
42
|
+
readonly unit: Schema.Option<Schema.brand<Schema.String, "SystemdUnit">>;
|
|
43
|
+
}>, import("effect/Cause").YieldableError>;
|
|
44
|
+
/**
|
|
45
|
+
* `usine upgrade` failed after it changed the pin. `install` restored the pin, `start` left the
|
|
46
|
+
* instance stopped, and `listen` left a new process that doesn't answer.
|
|
47
|
+
*/
|
|
48
|
+
export declare class UpgradeFailedError extends UpgradeFailedError_base {
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Moves the instance's `@usine/*` pins to `command.version`, or to `latest`. Refuses while
|
|
52
|
+
* Attempts are live, unless `--force`. Backs up the stores to `.usine/backups/`, stops the
|
|
53
|
+
* instance, installs with the instance's package manager, commits the pin change, and starts the
|
|
54
|
+
* instance again if it was running.
|
|
55
|
+
*/
|
|
56
|
+
export declare const upgrade: (directory: string & import("effect/Brand").Brand<"InstanceDirectory">, command: UpgradeCommand) => Effect.Effect<void, import("./detach.ts").DetachedSpawnError | import("@usine/durable/backup").DurableStorageBackupError | EngineOutsideInstanceError | EnginePinError | import("./instance/lock.ts").InstanceLockError | import("./instance/manifest.ts").InstanceManifestError | import("./stop.ts").KillTimeoutError | import("./stop.ts").LiveAttemptsError | import("./stop.ts").MissingEnvironmentError | import("./registry.ts").PackageLookupError | import("@usine/engine/local-sqlite").RuntimeStoreBackupError | import("./instance/state.ts").SignalError | import("./stop.ts").StopTimeoutError | import("./instance/systemd.ts").SystemctlError | UnrecordedInstanceError | UpgradeFailedError | UpgradeFileError, import("effect/process/ChildProcessSpawner").ChildProcessSpawner | FileSystem.FileSystem | import("effect/http/HttpClient").HttpClient | import("effect/Path").Path>;
|
|
57
|
+
export {};
|
|
58
|
+
//# sourceMappingURL=upgrade.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upgrade.d.ts","sourceRoot":"","sources":["../src/upgrade.ts"],"names":[],"mappings":"AAEA,OAAO,EAA+B,MAAM,EAAE,UAAU,EAAU,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEzF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAmB/C,OAAO,EACL,uBAAuB,EAIxB,MAAM,WAAW,CAAC;;;;IAUjB,uFAAuF;;;AANzF,iGAAiG;AACjG,qBAAa,0BAA2B,SAAQ,+BAO9C;CAAG;;;;IAQH,uFAAuF;;;AANzF,oGAAoG;AACpG,qBAAa,cAAe,SAAQ,mBAOlC;CAAG;;;;;AAEL,wEAAwE;AACxE,qBAAa,gBAAiB,SAAQ,qBAE+B;CAAG;;;;;;;IActE,mGAAmG;;IAEnG,iEAAiE;;IAEjE,gEAAgE;;IAEhE,gFAAgF;;;AAlBlF;;;GAGG;AACH,qBAAa,kBAAmB,SAAQ,uBAgBtC;CAAG;AAuDL;;;;;GAKG;AACH,eAAO,MAAM,OAAO,28BA0OlB,CAAC"}
|
package/dist/upgrade.js
ADDED
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import { join, sep } from "node:path";
|
|
2
|
+
import { Console, DateTime, Duration, Effect, FileSystem, Option, Schema } from "effect";
|
|
3
|
+
import { backup } from "./backup.js";
|
|
4
|
+
import { runCommand, runInTerminal } from "./command.js";
|
|
5
|
+
import { startAgain, startedMessage } from "./detach.js";
|
|
6
|
+
import { PackageManager, SERVER_PACKAGE, bumpPins, compareVersions, installedInInstance, parseManifest, readManifest, realPathOrSelf, serverPin, } from "./instance/manifest.js";
|
|
7
|
+
import { instanceFiles } from "./instance/record.js";
|
|
8
|
+
import { probeInstance } from "./instance/state.js";
|
|
9
|
+
import { SystemdUnit, supervisingUnit } from "./instance/systemd.js";
|
|
10
|
+
import { dependenciesOf, resolveVersion } from "./registry.js";
|
|
11
|
+
import { UnrecordedInstanceError, refuseLiveAttempts, refuseMissingEnvironment, stopProcess, } from "./stop.js";
|
|
12
|
+
const GIT_TIMEOUT = "30 seconds";
|
|
13
|
+
/** The running engine isn't installed in the instance's `node_modules`, so no pin selects it. */
|
|
14
|
+
export class EngineOutsideInstanceError extends Schema.TaggedError("@usine/server/EngineOutsideInstanceError")("EngineOutsideInstanceError", {
|
|
15
|
+
script: Schema.String,
|
|
16
|
+
version: Schema.String,
|
|
17
|
+
/** Whether the entry point is in a `node_modules` folder, as with a global install. */
|
|
18
|
+
packaged: Schema.Boolean,
|
|
19
|
+
}) {
|
|
20
|
+
}
|
|
21
|
+
/** The instance's `package.json` is absent or doesn't pin `@usine/server` to a registry version. */
|
|
22
|
+
export class EnginePinError extends Schema.TaggedError("@usine/server/EnginePinError")("EnginePinError", {
|
|
23
|
+
path: Schema.String,
|
|
24
|
+
missing: Schema.Boolean,
|
|
25
|
+
/** The local spec, such as `link:../usine/apps/server`, if `@usine/server` has one. */
|
|
26
|
+
linked: Schema.Option(Schema.String),
|
|
27
|
+
}) {
|
|
28
|
+
}
|
|
29
|
+
/** A file that `usine upgrade` reads or writes couldn't be accessed. */
|
|
30
|
+
export class UpgradeFileError extends Schema.TaggedError("@usine/server/UpgradeFileError")("UpgradeFileError", { path: Schema.String, reason: Schema.String }) {
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* `usine upgrade` failed after it changed the pin. `install` restored the pin, `start` left the
|
|
34
|
+
* instance stopped, and `listen` left a new process that doesn't answer.
|
|
35
|
+
*/
|
|
36
|
+
export class UpgradeFailedError extends Schema.TaggedError("@usine/server/UpgradeFailedError")("UpgradeFailedError", {
|
|
37
|
+
stage: Schema.Literals(["install", "start", "listen"]),
|
|
38
|
+
reason: Schema.String,
|
|
39
|
+
previous: Schema.String,
|
|
40
|
+
target: Schema.String,
|
|
41
|
+
packageManager: PackageManager,
|
|
42
|
+
/** The runtime store copy, if the instance had a runtime store. The durable copy is next to it. */
|
|
43
|
+
backup: Schema.Option(Schema.String),
|
|
44
|
+
/** The commit of the pin change, if `usine upgrade` made one. */
|
|
45
|
+
commit: Schema.Option(Schema.String),
|
|
46
|
+
/** The last lines of `.usine/usine.log`, for a failed start. */
|
|
47
|
+
tail: Schema.String,
|
|
48
|
+
/** The systemd service that runs the instance, whose journal has its output. */
|
|
49
|
+
unit: Schema.Option(SystemdUnit),
|
|
50
|
+
}) {
|
|
51
|
+
}
|
|
52
|
+
const backupStamp = (now) => DateTime.formatIso(now)
|
|
53
|
+
.replace(/[-:]/gu, "")
|
|
54
|
+
.replace(/\.\d+Z$/u, "Z");
|
|
55
|
+
/** Returns the versions for the pins: the server's dependency spec for each, or else `latest`. */
|
|
56
|
+
const targetVersions = Effect.fn("Cli.upgradeTargets")(function* (directory, manifest, target) {
|
|
57
|
+
const serverDependencies = yield* dependenciesOf(directory, SERVER_PACKAGE, target);
|
|
58
|
+
const versions = new Map([[SERVER_PACKAGE, target]]);
|
|
59
|
+
for (const { name } of manifest.pins) {
|
|
60
|
+
if (name === SERVER_PACKAGE)
|
|
61
|
+
continue;
|
|
62
|
+
const spec = Option.getOrElse(Option.fromUndefinedOr(serverDependencies[name]), () => "latest");
|
|
63
|
+
versions.set(name, yield* resolveVersion(directory, name, spec));
|
|
64
|
+
}
|
|
65
|
+
return versions;
|
|
66
|
+
});
|
|
67
|
+
/** Commits `paths` alone and returns the short commit hash. */
|
|
68
|
+
const commitPin = Effect.fn("Cli.commitPin")(function* (directory, paths, message) {
|
|
69
|
+
yield* runCommand("git", ["add", "--", ...paths], directory, GIT_TIMEOUT);
|
|
70
|
+
yield* runCommand("git", ["commit", "--quiet", "-m", message, "--", ...paths], directory, GIT_TIMEOUT);
|
|
71
|
+
const { stdout } = yield* runCommand("git", ["rev-parse", "--short", "HEAD"], directory, GIT_TIMEOUT);
|
|
72
|
+
return stdout.trim();
|
|
73
|
+
});
|
|
74
|
+
/** Prints the lines of `--check`. */
|
|
75
|
+
const printLines = (lines) => Effect.forEach(lines, (line) => Console.log(line), { discard: true });
|
|
76
|
+
const targetLabel = (command) => Option.isSome(command.version) ? "requested " : "latest ";
|
|
77
|
+
const runningLine = (record, from) => `running ${SERVER_PACKAGE} ${record.version}${from}`;
|
|
78
|
+
/**
|
|
79
|
+
* Moves the instance's `@usine/*` pins to `command.version`, or to `latest`. Refuses while
|
|
80
|
+
* Attempts are live, unless `--force`. Backs up the stores to `.usine/backups/`, stops the
|
|
81
|
+
* instance, installs with the instance's package manager, commits the pin change, and starts the
|
|
82
|
+
* instance again if it was running.
|
|
83
|
+
*/
|
|
84
|
+
export const upgrade = Effect.fn("Cli.upgrade")(function* (directory, command) {
|
|
85
|
+
const fileSystem = yield* FileSystem.FileSystem;
|
|
86
|
+
const files = instanceFiles(directory);
|
|
87
|
+
const fileError = (path) => (error) => new UpgradeFileError({ path, reason: error.message });
|
|
88
|
+
const state = yield* probeInstance(directory);
|
|
89
|
+
if (state._tag === "Unrecorded") {
|
|
90
|
+
return yield* new UnrecordedInstanceError({ command: "upgrade", directory, pid: state.pid });
|
|
91
|
+
}
|
|
92
|
+
const running = state._tag === "Running" ? Option.some(state.record) : Option.none();
|
|
93
|
+
const spec = Option.getOrElse(command.version, () => "latest");
|
|
94
|
+
yield* Effect.annotateCurrentSpan({ instanceDirectory: directory, spec });
|
|
95
|
+
// Only a running engine shows where it runs from. A stopped one is whatever the pin installs.
|
|
96
|
+
if (Option.isSome(running)) {
|
|
97
|
+
const script = running.value.launch.script;
|
|
98
|
+
if (!installedInInstance(yield* realPathOrSelf(directory), yield* realPathOrSelf(script))) {
|
|
99
|
+
if (!command.check) {
|
|
100
|
+
return yield* new EngineOutsideInstanceError({
|
|
101
|
+
script,
|
|
102
|
+
version: running.value.version,
|
|
103
|
+
packaged: script.includes(`${sep}node_modules${sep}`),
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
return yield* printLines([
|
|
107
|
+
runningLine(running.value, ` from ${script}`),
|
|
108
|
+
`${targetLabel(command)}${yield* resolveVersion(directory, SERVER_PACKAGE, spec)}`,
|
|
109
|
+
"The engine runs from outside the instance's node_modules, so usine upgrade doesn't change it.",
|
|
110
|
+
]);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
const manifestPath = join(directory, "package.json");
|
|
114
|
+
const manifest = yield* readManifest(directory);
|
|
115
|
+
if (Option.isNone(manifest)) {
|
|
116
|
+
return yield* new EnginePinError({ path: manifestPath, missing: true, linked: Option.none() });
|
|
117
|
+
}
|
|
118
|
+
const pin = serverPin(manifest.value);
|
|
119
|
+
if (Option.isNone(pin)) {
|
|
120
|
+
return yield* new EnginePinError({
|
|
121
|
+
path: manifestPath,
|
|
122
|
+
missing: false,
|
|
123
|
+
linked: manifest.value.linkedServer,
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
const previous = pin.value.spec;
|
|
127
|
+
const target = yield* resolveVersion(directory, SERVER_PACKAGE, spec);
|
|
128
|
+
if (command.check) {
|
|
129
|
+
return yield* printLines([
|
|
130
|
+
...Option.toArray(Option.map(running, (record) => runningLine(record, ""))),
|
|
131
|
+
`pinned ${previous} in package.json`,
|
|
132
|
+
`${targetLabel(command)}${target}`,
|
|
133
|
+
previous === target
|
|
134
|
+
? "The pin is up to date."
|
|
135
|
+
: `Run usine upgrade${Option.isSome(command.version) ? ` ${spec}` : ""} to move the pin to ${target}.`,
|
|
136
|
+
]);
|
|
137
|
+
}
|
|
138
|
+
if (previous === target) {
|
|
139
|
+
yield* Console.log(`${SERVER_PACKAGE} is already pinned to ${target}.`);
|
|
140
|
+
if (Option.isSome(running) && running.value.version !== target) {
|
|
141
|
+
yield* Console.log(`The running engine is ${running.value.version}. Run usine restart to start ${target}.`);
|
|
142
|
+
}
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
if (Option.isNone(command.version) && compareVersions(target, previous) < 0) {
|
|
146
|
+
yield* Console.log(`The latest release, ${target}, is older than the pinned ${previous}. To change the pin, run usine upgrade <version>.`);
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
const versions = yield* targetVersions(directory, manifest.value, target);
|
|
150
|
+
const lockfiles = yield* Effect.forEach(manifest.value.lockfiles, (file) => {
|
|
151
|
+
const path = join(directory, file);
|
|
152
|
+
return fileSystem.readFileString(path).pipe(Effect.map((text) => [path, text]), Effect.mapError(fileError(path)));
|
|
153
|
+
});
|
|
154
|
+
const restore = Effect.forEach([[manifest.value.path, manifest.value.text], ...lockfiles], ([path, text]) => fileSystem.writeFileString(path, text).pipe(Effect.tapError((error) => Effect.logError("Could not restore a file after a failed install", {
|
|
155
|
+
path,
|
|
156
|
+
message: error.message,
|
|
157
|
+
})), Effect.ignore), { discard: true });
|
|
158
|
+
const bumped = bumpPins(manifest.value.text, manifest.value.pins, versions);
|
|
159
|
+
const rewritten = yield* parseManifest(manifest.value.path, bumped, manifest.value.lockfiles);
|
|
160
|
+
if (!Option.exists(serverPin(rewritten), ({ spec: pinned }) => pinned === target)) {
|
|
161
|
+
return yield* Effect.die(new Error(`Could not rewrite the ${SERVER_PACKAGE} pin`));
|
|
162
|
+
}
|
|
163
|
+
if (Option.isSome(running)) {
|
|
164
|
+
yield* refuseMissingEnvironment("upgrade", running.value.launch.port);
|
|
165
|
+
yield* refuseLiveAttempts("upgrade", running.value.launch.port, command.options.force);
|
|
166
|
+
}
|
|
167
|
+
const unit = Option.isSome(running)
|
|
168
|
+
? yield* supervisingUnit(running.value.pid, running.value.systemdUnit)
|
|
169
|
+
: Option.none();
|
|
170
|
+
yield* Effect.logInfo("Upgrading the engine pin of the instance", {
|
|
171
|
+
from: previous,
|
|
172
|
+
to: target,
|
|
173
|
+
packageManager: manifest.value.packageManager,
|
|
174
|
+
});
|
|
175
|
+
yield* Console.log(`Upgrading ${SERVER_PACKAGE} from ${previous} to ${target}.`);
|
|
176
|
+
const runtimeStore = join(files.folder, "runtime.sqlite");
|
|
177
|
+
const hasStore = yield* fileSystem
|
|
178
|
+
.exists(runtimeStore)
|
|
179
|
+
.pipe(Effect.mapError(fileError(runtimeStore)));
|
|
180
|
+
// Named after the engine that wrote the store, which its migrations match.
|
|
181
|
+
const writer = Option.match(running, {
|
|
182
|
+
onNone: () => previous,
|
|
183
|
+
onSome: ({ version }) => version,
|
|
184
|
+
});
|
|
185
|
+
const backupPath = hasStore
|
|
186
|
+
? Option.some(join(files.backups, `runtime-${backupStamp(yield* DateTime.now)}-${writer}.sqlite`))
|
|
187
|
+
: Option.none();
|
|
188
|
+
if (Option.isSome(backupPath)) {
|
|
189
|
+
yield* fileSystem
|
|
190
|
+
.makeDirectory(files.backups, { recursive: true, mode: 0o700 })
|
|
191
|
+
.pipe(Effect.mapError(fileError(files.backups)));
|
|
192
|
+
yield* backup(directory, backupPath.value);
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
yield* Console.log("No runtime store to back up: .usine/runtime.sqlite does not exist.");
|
|
196
|
+
}
|
|
197
|
+
if (Option.isSome(running)) {
|
|
198
|
+
yield* stopProcess("upgrade", running.value.pid, running, unit, command.options);
|
|
199
|
+
}
|
|
200
|
+
const failure = (stage, reason, commit, tail) => new UpgradeFailedError({
|
|
201
|
+
stage,
|
|
202
|
+
reason,
|
|
203
|
+
previous,
|
|
204
|
+
target,
|
|
205
|
+
packageManager: manifest.value.packageManager,
|
|
206
|
+
backup: backupPath,
|
|
207
|
+
commit,
|
|
208
|
+
tail,
|
|
209
|
+
unit,
|
|
210
|
+
});
|
|
211
|
+
yield* fileSystem
|
|
212
|
+
.writeFileString(manifest.value.path, bumped)
|
|
213
|
+
.pipe(Effect.mapError(fileError(manifest.value.path)));
|
|
214
|
+
yield* runInTerminal(manifest.value.packageManager, ["install"], directory).pipe(Effect.catchTag("CommandError", (error) => restore.pipe(Effect.andThen(Effect.fail(failure("install", `${error.command} ${error.reason}`, Option.none(), ""))))));
|
|
215
|
+
const installed = yield* readManifest(directory);
|
|
216
|
+
const paths = [
|
|
217
|
+
"package.json",
|
|
218
|
+
...Option.match(installed, { onNone: () => [], onSome: ({ lockfiles: present }) => present }),
|
|
219
|
+
];
|
|
220
|
+
const commit = yield* commitPin(directory, paths, `Pin ${SERVER_PACKAGE} to ${target}`).pipe(Effect.map(Option.some), Effect.catchTag("CommandError", (error) => Console.log(`Could not commit the pin change (${error.command} ${error.reason}). Commit ${paths.join(", ")} yourself.`).pipe(Effect.as(Option.none()))));
|
|
221
|
+
if (Option.isSome(commit))
|
|
222
|
+
yield* Console.log(`Committed the pin change as ${commit.value}.`);
|
|
223
|
+
if (Option.isNone(running)) {
|
|
224
|
+
yield* Console.log(`${SERVER_PACKAGE} is now ${target}. usine wasn't running, so start it with usine up --detach.`);
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
const started = yield* startAgain(directory, running.value.launch, unit, running.value.pid, command.options.timeout).pipe(Effect.catchTags({
|
|
228
|
+
DetachedStartError: (error) => Effect.fail(error.outcome === "exited"
|
|
229
|
+
? failure("start", `it exited (${Option.getOrElse(error.exit, () => "unknown")}) before it listened`, commit, error.tail)
|
|
230
|
+
: failure("listen", `it didn't answer on port ${error.port}, and wrote nothing to its log for ${Duration.format(error.timeout)}`, commit, error.tail)),
|
|
231
|
+
SystemdStartError: (error) => Effect.fail(error.outcome === "failed"
|
|
232
|
+
? failure("start", `${error.unit} was ${error.state} before it listened`, commit, "")
|
|
233
|
+
: failure("listen", `it didn't answer within ${Duration.format(error.timeout)}`, commit, "")),
|
|
234
|
+
}));
|
|
235
|
+
yield* Console.log(startedMessage(started));
|
|
236
|
+
});
|
|
237
|
+
//# sourceMappingURL=upgrade.js.map
|