openship 0.4.7 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/README.md +1 -0
  2. package/dist/{bare-2HYDXQEH.js → bare-VRGE5MXH.js} +7 -7
  3. package/dist/{chunk-TGIINPVM.js → chunk-6LKHXB6T.js} +22 -7
  4. package/dist/{chunk-R5BHFFAV.js → chunk-6PIYRG5I.js} +56 -17
  5. package/dist/{chunk-IMBD5PZ5.js → chunk-BS2AXYZX.js} +430 -86
  6. package/dist/{chunk-SJIFLLX4.js → chunk-CUJXGK7R.js} +321 -85
  7. package/dist/{chunk-VFINNTUL.js → chunk-EAAGSQXN.js} +23 -8
  8. package/dist/{chunk-4Z5QO7N6.js → chunk-I6PSTQIR.js} +2 -2
  9. package/dist/{chunk-XFCDYZUQ.js → chunk-JLKKYUZA.js} +31 -49
  10. package/dist/{chunk-4TJC4JZQ.js → chunk-K2RPVGPN.js} +23 -4
  11. package/dist/{chunk-MZ2WEHHY.js → chunk-KNTJ7PSF.js} +1 -1
  12. package/dist/{chunk-L2VOGB2X.js → chunk-KZOBYJUW.js} +1 -1
  13. package/dist/{chunk-IPYPMI3S.js → chunk-NNPEG6HM.js} +1 -1
  14. package/dist/{chunk-UXWAVM4C.js → chunk-NXFIRK2Z.js} +398 -112
  15. package/dist/{chunk-FXTBHTWY.js → chunk-RB35YN3J.js} +271 -35
  16. package/dist/{chunk-6APULWSU.js → chunk-UMQP7SYT.js} +429 -66
  17. package/dist/{chunk-V6AN6XLZ.js → chunk-V7BZMGOT.js} +123 -45
  18. package/dist/{chunk-VDMQJHPI.js → chunk-YWMODKWL.js} +67 -4
  19. package/dist/{chunk-OXWDY22G.js → chunk-ZCOQJCZO.js} +1 -1
  20. package/dist/{cloud-2KXREXMO.js → cloud-3M2WZ624.js} +12 -12
  21. package/dist/{detect-2XSCFFTF.js → detect-BAJMY6KM.js} +7 -5
  22. package/dist/{docker-LODK5Y2S.js → docker-2NGBRJFJ.js} +9 -7
  23. package/dist/{docker-edge-executor-VHW3JPJS.js → docker-edge-executor-5I4M5QT7.js} +1 -1
  24. package/dist/{edge-import-ZQ4Y5HEA.js → edge-import-RIWNEIXQ.js} +21 -19
  25. package/dist/{ensure-container-edge-ED25XL3Z.js → ensure-container-edge-3NSYKHRX.js} +6 -6
  26. package/dist/{executor-YPT6RH6O.js → executor-LOYMPU67.js} +3 -3
  27. package/dist/index.js +309 -338
  28. package/dist/{nginx-XWJAOGS4.js → nginx-QE4DOM5J.js} +4 -4
  29. package/dist/{openresty-lua-4WLGDSER.js → openresty-lua-BTAKECCF.js} +2 -2
  30. package/dist/server/index.js +51705 -45369
  31. package/dist/server/migrations/0073_project_volumes_object_storage.sql +3 -0
  32. package/dist/server/migrations/0074_project_compose_path.sql +1 -0
  33. package/dist/server/migrations/0075_service_command_argv.sql +1 -0
  34. package/dist/server/migrations/0076_rollback_retention.sql +17 -0
  35. package/dist/server/migrations/0077_domain_redirect.sql +13 -0
  36. package/dist/server/migrations/0078_grant_source_scope.sql +30 -0
  37. package/dist/server/migrations/0079_project_readiness.sql +18 -0
  38. package/dist/server/migrations/0080_deployment_error_classification.sql +26 -0
  39. package/dist/server/migrations/0081_project_readiness_repair.sql +34 -0
  40. package/dist/server/migrations/meta/_journal.json +63 -0
  41. package/dist/{setup-2DMFIA74.js → setup-KELALK7H.js} +7 -7
  42. package/package.json +1 -1
package/README.md CHANGED
@@ -35,6 +35,7 @@
35
35
  <a href="docs/i18n/README.pt.md"><img src="https://img.shields.io/badge/lang-Português-555" alt="Português" /></a>
36
36
  <a href="docs/i18n/README.de.md"><img src="https://img.shields.io/badge/lang-Deutsch-555" alt="Deutsch" /></a>
37
37
  <a href="docs/i18n/README.tr.md"><img src="https://img.shields.io/badge/lang-Türkçe-555" alt="Türkçe" /></a>
38
+ <a href="docs/i18n/README.ko.md"><img src="https://img.shields.io/badge/lang-한국어-555" alt="한국어" /></a>
38
39
  </p>
39
40
 
40
41
  <p align="center">
@@ -5,17 +5,17 @@ const require = __ospCreateRequire(import.meta.url);
5
5
  import {
6
6
  BareRuntime,
7
7
  STATIC_RELEASE_BASE
8
- } from "./chunk-VDMQJHPI.js";
9
- import "./chunk-MZ2WEHHY.js";
10
- import "./chunk-L2VOGB2X.js";
11
- import "./chunk-4Z5QO7N6.js";
12
- import "./chunk-4TJC4JZQ.js";
13
- import "./chunk-OXWDY22G.js";
8
+ } from "./chunk-YWMODKWL.js";
9
+ import "./chunk-KNTJ7PSF.js";
10
+ import "./chunk-KZOBYJUW.js";
11
+ import "./chunk-I6PSTQIR.js";
12
+ import "./chunk-K2RPVGPN.js";
13
+ import "./chunk-ZCOQJCZO.js";
14
14
  import "./chunk-RPHRPFEH.js";
15
15
  import "./chunk-TYVME3XD.js";
16
16
  import "./chunk-FPRHYBY2.js";
17
17
  import "./chunk-ILFETZOM.js";
18
- import "./chunk-6APULWSU.js";
18
+ import "./chunk-UMQP7SYT.js";
19
19
  import "./chunk-KI2EY3WB.js";
20
20
  export {
21
21
  BareRuntime,
@@ -14,6 +14,15 @@ import {
14
14
  import Dockerode from "dockerode";
15
15
  import { PassThrough } from "stream";
16
16
  var DEFAULT_SOCKET = "/var/run/docker.sock";
17
+ function explainEdgeExecError(err, containerName) {
18
+ const msg = err?.message ?? String(err);
19
+ if (/is not running|not running|409/i.test(msg)) {
20
+ return new Error(
21
+ `edge container "${containerName}" is not running yet (still starting, or stopped) \u2014 wait for it to be up (docker start ${containerName}) and retry.`
22
+ );
23
+ }
24
+ return err instanceof Error ? err : new Error(msg);
25
+ }
17
26
  var WRITE_CHUNK = 6e4;
18
27
  var DockerEdgeExecutor = class {
19
28
  docker;
@@ -30,13 +39,19 @@ var DockerEdgeExecutor = class {
30
39
  /** Run one command inside the edge container, capturing stdout/stderr + exit. */
31
40
  async run(command) {
32
41
  const container = this.docker.getContainer(this.containerName);
33
- const exec = await container.exec({
34
- Cmd: ["/bin/sh", "-c", command],
35
- AttachStdout: true,
36
- AttachStderr: true,
37
- Tty: false
38
- });
39
- const stream = await exec.start({ stdin: false });
42
+ let exec;
43
+ let stream;
44
+ try {
45
+ exec = await container.exec({
46
+ Cmd: ["/bin/sh", "-c", command],
47
+ AttachStdout: true,
48
+ AttachStderr: true,
49
+ Tty: false
50
+ });
51
+ stream = await exec.start({ stdin: false });
52
+ } catch (err) {
53
+ throw explainEdgeExecError(err, this.containerName);
54
+ }
40
55
  const outStream = new PassThrough();
41
56
  const errStream = new PassThrough();
42
57
  let stdout = "";
@@ -8,10 +8,10 @@ import {
8
8
  } from "./chunk-ILFETZOM.js";
9
9
  import {
10
10
  OPENRESTY_LUA_DIR
11
- } from "./chunk-VFINNTUL.js";
11
+ } from "./chunk-EAAGSQXN.js";
12
12
  import {
13
13
  AppError
14
- } from "./chunk-6APULWSU.js";
14
+ } from "./chunk-UMQP7SYT.js";
15
15
 
16
16
  // ../../packages/adapters/src/system/proxy/detect.ts
17
17
  var EDGE_PORTS = [80, 443];
@@ -59,21 +59,59 @@ function sq(value) {
59
59
  function isOurEdgeContainer(name, image) {
60
60
  return /openship-edge/i.test(`${name ?? ""} ${image ?? ""}`);
61
61
  }
62
- async function edgeIsServing(executor, port = 80) {
63
- const running = await tryExec(
64
- executor,
65
- `docker inspect -f '{{.State.Running}}' ${sq(EDGE_CONTAINER_NAME)} 2>/dev/null`
66
- );
67
- if ((running ?? "").trim() !== "true") return false;
68
- const probe = await tryExec(
62
+ function vhostLog(message, level = "info") {
63
+ return { timestamp: (/* @__PURE__ */ new Date()).toISOString(), message, level };
64
+ }
65
+ async function sanitizeEdgeVhosts(executor, sitesDir, onLog) {
66
+ const script = [
67
+ `for f in ${sq(sitesDir)}/*.conf; do`,
68
+ // A host-side vhost may be a symlink into /etc/nginx/sites-available. That
69
+ // target is deliberately not mounted in the edge container, so leaving the
70
+ // link here makes nginx's include glob fail at startup. Materialize valid
71
+ // links before the container mounts this directory; remove dangling ones.
72
+ ` [ -e "$f" ] || [ -L "$f" ] || continue;`,
73
+ ` if [ -L "$f" ]; then`,
74
+ ` if [ ! -e "$f" ]; then`,
75
+ ` echo "dropped-dangling-link $f"; rm -f "$f"; continue;`,
76
+ ` fi;`,
77
+ ` if cat "$f" > "$f.osh-link"; then`,
78
+ ` rm -f "$f"; mv "$f.osh-link" "$f"; echo "materialized-link $f";`,
79
+ ` else`,
80
+ ` rm -f "$f.osh-link"; echo "dropped-unreadable-link $f"; rm -f "$f"; continue;`,
81
+ ` fi;`,
82
+ ` fi;`,
83
+ // A real server_name is anything that isn't the `_` wildcard.
84
+ ` if ! grep -qE '^[[:space:]]*server_name[[:space:]]+[^_;[:space:]]' "$f"; then`,
85
+ ` echo "dropped-catchall $f"; rm -f "$f"; continue;`,
86
+ ` fi;`,
87
+ ` if grep -qE '[[:space:]]default_server' "$f"; then`,
88
+ ` sed -E 's/([[:space:]]listen[^;]*)[[:space:]]+default_server/\\1/g' "$f" > "$f.osh" && mv "$f.osh" "$f" && echo "unset-default $f";`,
89
+ ` fi;`,
90
+ `done`
91
+ ].join(" ");
92
+ const out = await executor.exec(script).catch(() => "");
93
+ for (const line of out.split("\n").map((l) => l.trim()).filter(Boolean)) {
94
+ const [action, file] = [line.slice(0, line.indexOf(" ")), line.slice(line.indexOf(" ") + 1)];
95
+ if (action === "dropped-catchall") {
96
+ onLog(vhostLog(`Dropped catch-all vhost ${file} \u2014 the edge image provides it.`, "warn"));
97
+ } else if (action === "unset-default") {
98
+ onLog(vhostLog(`Removed default_server from ${file} \u2014 the edge image owns it.`, "warn"));
99
+ } else if (action === "materialized-link") {
100
+ onLog(vhostLog(`Materialized linked edge vhost ${file} for the container mount.`, "warn"));
101
+ } else if (action === "dropped-dangling-link") {
102
+ onLog(vhostLog(`Dropped dangling edge vhost link ${file}.`, "warn"));
103
+ } else if (action === "dropped-unreadable-link") {
104
+ onLog(vhostLog(`Dropped unreadable edge vhost link ${file}.`, "warn"));
105
+ }
106
+ }
107
+ }
108
+ async function edgeIsBroken(executor) {
109
+ const status = await tryExec(
69
110
  executor,
70
- containerShell(`wget -q -O /dev/null -T 3 http://127.0.0.1:${port}/ >/dev/null 2>&1; echo $?`)
111
+ `docker inspect -f '{{.State.Status}}' ${sq(EDGE_CONTAINER_NAME)} 2>/dev/null`
71
112
  );
72
- const code = (probe ?? "").trim().split("\n").pop() ?? "1";
73
- return code === "0" || code === "8";
74
- }
75
- function containerShell(command) {
76
- return `docker exec ${sq(EDGE_CONTAINER_NAME)} sh -c ${sq(command)}`;
113
+ const state = (status ?? "").trim();
114
+ return state === "restarting" || state === "exited" || state === "dead";
77
115
  }
78
116
  async function edgeCrashReason(executor) {
79
117
  const logs = await tryExec(
@@ -86,7 +124,7 @@ function edgeFailureReason(containerLog) {
86
124
  const lines = containerLog.split("\n").map((l) => l.trim()).filter(Boolean);
87
125
  const emerg = lines.find((l) => l.includes("[emerg]"));
88
126
  if (emerg) return emerg.replace(/^.*\[emerg\]\s*\d*#\d*:\s*/, "");
89
- return lines.at(-1) ?? null;
127
+ return null;
90
128
  }
91
129
  var EDGE_CONTAINER_NAME = "openship-edge";
92
130
  async function ourEdgeContainerRunning(executor) {
@@ -268,7 +306,8 @@ export {
268
306
  classifyProxy,
269
307
  sq,
270
308
  isOurEdgeContainer,
271
- edgeIsServing,
309
+ sanitizeEdgeVhosts,
310
+ edgeIsBroken,
272
311
  edgeCrashReason,
273
312
  edgeFailureReason,
274
313
  EDGE_CONTAINER_NAME,