@caelo-cms/provisioning 0.10.49 → 0.10.51

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 (191) hide show
  1. package/caddy/Caddyfile.production +4 -0
  2. package/caddy/Caddyfile.staging +4 -0
  3. package/dist/adapter.d.ts +4 -6
  4. package/dist/adapter.d.ts.map +1 -1
  5. package/dist/admin-internal.d.ts +41 -0
  6. package/dist/admin-internal.d.ts.map +1 -0
  7. package/dist/admin-internal.js +169 -0
  8. package/dist/admin-internal.js.map +1 -0
  9. package/dist/agent-db.js +93 -20
  10. package/dist/aws-task-roles.d.ts +27 -0
  11. package/dist/aws-task-roles.d.ts.map +1 -0
  12. package/dist/aws-task-roles.js +35 -0
  13. package/dist/aws-task-roles.js.map +1 -0
  14. package/dist/caddy-redirects.d.ts +15 -0
  15. package/dist/caddy-redirects.d.ts.map +1 -0
  16. package/dist/caddy-redirects.js +65 -0
  17. package/dist/caddy-redirects.js.map +1 -0
  18. package/dist/caddy.d.ts +22 -2
  19. package/dist/caddy.d.ts.map +1 -1
  20. package/dist/caddy.js +66 -17
  21. package/dist/caddy.js.map +1 -1
  22. package/dist/cli-routing.d.ts.map +1 -1
  23. package/dist/cli-routing.js +7 -0
  24. package/dist/cli-routing.js.map +1 -1
  25. package/dist/cli.js +282 -255
  26. package/dist/cli.js.map +1 -1
  27. package/dist/compose.d.ts +54 -2
  28. package/dist/compose.d.ts.map +1 -1
  29. package/dist/compose.js +88 -34
  30. package/dist/compose.js.map +1 -1
  31. package/dist/deployed-release.d.ts +3 -2
  32. package/dist/deployed-release.d.ts.map +1 -1
  33. package/dist/deployed-release.js +12 -5
  34. package/dist/deployed-release.js.map +1 -1
  35. package/dist/gateway-credentials.d.ts.map +1 -1
  36. package/dist/gateway-credentials.js +6 -3
  37. package/dist/gateway-credentials.js.map +1 -1
  38. package/dist/gcloud.d.ts +2 -2
  39. package/dist/gcloud.d.ts.map +1 -1
  40. package/dist/gcloud.js +3 -3
  41. package/dist/gcloud.js.map +1 -1
  42. package/dist/gcp-names.d.ts +12 -0
  43. package/dist/gcp-names.d.ts.map +1 -1
  44. package/dist/gcp-names.js +21 -0
  45. package/dist/gcp-names.js.map +1 -1
  46. package/dist/gcp-url-map.d.ts +27 -0
  47. package/dist/gcp-url-map.d.ts.map +1 -0
  48. package/dist/gcp-url-map.js +62 -0
  49. package/dist/gcp-url-map.js.map +1 -0
  50. package/dist/index.d.ts +0 -1
  51. package/dist/index.d.ts.map +1 -1
  52. package/dist/index.js +0 -1
  53. package/dist/index.js.map +1 -1
  54. package/dist/infra-contract.d.ts +20 -1
  55. package/dist/infra-contract.d.ts.map +1 -1
  56. package/dist/infra-contract.js +44 -1
  57. package/dist/infra-contract.js.map +1 -1
  58. package/dist/owner-reset.d.ts +37 -0
  59. package/dist/owner-reset.d.ts.map +1 -0
  60. package/dist/owner-reset.js +80 -0
  61. package/dist/owner-reset.js.map +1 -0
  62. package/dist/public-role-isolation.d.ts +19 -0
  63. package/dist/public-role-isolation.d.ts.map +1 -0
  64. package/dist/public-role-isolation.js +69 -0
  65. package/dist/public-role-isolation.js.map +1 -0
  66. package/dist/release-contract.d.ts.map +1 -1
  67. package/dist/release-contract.js +3 -0
  68. package/dist/release-contract.js.map +1 -1
  69. package/dist/release-manifest.d.ts.map +1 -1
  70. package/dist/release-manifest.js +2 -1
  71. package/dist/release-manifest.js.map +1 -1
  72. package/dist/self-hosted-backup.d.ts +86 -0
  73. package/dist/self-hosted-backup.d.ts.map +1 -0
  74. package/dist/self-hosted-backup.js +350 -0
  75. package/dist/self-hosted-backup.js.map +1 -0
  76. package/dist/self-hosted-release.d.ts +12 -3
  77. package/dist/self-hosted-release.d.ts.map +1 -1
  78. package/dist/self-hosted-release.js +6 -4
  79. package/dist/self-hosted-release.js.map +1 -1
  80. package/dist/self-hosted-start.d.ts +50 -0
  81. package/dist/self-hosted-start.d.ts.map +1 -0
  82. package/dist/self-hosted-start.js +59 -0
  83. package/dist/self-hosted-start.js.map +1 -0
  84. package/dist/self-hosted-upgrade.d.ts +30 -0
  85. package/dist/self-hosted-upgrade.d.ts.map +1 -1
  86. package/dist/self-hosted-upgrade.js +29 -7
  87. package/dist/self-hosted-upgrade.js.map +1 -1
  88. package/dist/stack-contract.d.ts +9 -10
  89. package/dist/stack-contract.d.ts.map +1 -1
  90. package/dist/stack-contract.js +21 -10
  91. package/dist/stack-contract.js.map +1 -1
  92. package/dist/staging-admin.d.ts +12 -20
  93. package/dist/staging-admin.d.ts.map +1 -1
  94. package/dist/staging-admin.js +7 -159
  95. package/dist/staging-admin.js.map +1 -1
  96. package/dist/tar-entries.d.ts +14 -0
  97. package/dist/tar-entries.d.ts.map +1 -0
  98. package/dist/tar-entries.js +104 -0
  99. package/dist/tar-entries.js.map +1 -0
  100. package/dist/upgrade/converge.d.ts +2 -2
  101. package/dist/upgrade/converge.d.ts.map +1 -1
  102. package/dist/upgrade/converge.js +44 -2
  103. package/dist/upgrade/converge.js.map +1 -1
  104. package/dist/upgrader-assess.d.ts.map +1 -1
  105. package/dist/upgrader-assess.js +2 -1
  106. package/dist/upgrader-assess.js.map +1 -1
  107. package/dist/url-map-redirects-access.d.ts +15 -0
  108. package/dist/url-map-redirects-access.d.ts.map +1 -0
  109. package/dist/url-map-redirects-access.js +81 -0
  110. package/dist/url-map-redirects-access.js.map +1 -0
  111. package/dist/wizard.d.ts.map +1 -1
  112. package/dist/wizard.js +3 -1
  113. package/dist/wizard.js.map +1 -1
  114. package/dist/wizards/gcp-cost.js +1 -1
  115. package/dist/wizards/gcp.d.ts.map +1 -1
  116. package/dist/wizards/gcp.js +45 -0
  117. package/dist/wizards/gcp.js.map +1 -1
  118. package/package.json +2 -2
  119. package/src/adapter.ts +4 -6
  120. package/src/admin-internal.ts +212 -0
  121. package/src/admin-memory.test.ts +2 -2
  122. package/src/aws-task-roles.ts +58 -0
  123. package/src/caddy-redirects.docker.test.ts +255 -0
  124. package/src/caddy-redirects.test.ts +115 -0
  125. package/src/caddy-redirects.ts +68 -0
  126. package/src/caddy-validate.test.ts +119 -0
  127. package/src/caddy.test.ts +108 -0
  128. package/src/caddy.ts +89 -20
  129. package/src/checkpoint-secrets.test.ts +0 -1
  130. package/src/cli-routing.test.ts +12 -0
  131. package/src/cli-routing.ts +7 -0
  132. package/src/cli.ts +340 -288
  133. package/src/compose.ts +108 -36
  134. package/src/deployed-release.test.ts +22 -4
  135. package/src/deployed-release.ts +14 -7
  136. package/src/gateway-credentials.ts +6 -3
  137. package/src/gateway-env-isolation.test.ts +212 -0
  138. package/src/gcloud.ts +5 -3
  139. package/src/gcp-names.ts +23 -0
  140. package/src/gcp-url-map.test.ts +150 -0
  141. package/src/gcp-url-map.ts +81 -0
  142. package/src/index.test.ts +24 -152
  143. package/src/index.ts +0 -9
  144. package/src/infra-contract.test.ts +40 -0
  145. package/src/infra-contract.ts +47 -1
  146. package/src/owner-reset.test.ts +165 -0
  147. package/src/owner-reset.ts +106 -0
  148. package/src/public-role-isolation.test.ts +89 -0
  149. package/src/public-role-isolation.ts +83 -0
  150. package/src/release-contract.ts +3 -0
  151. package/src/release-manifest.test.ts +12 -0
  152. package/src/release-manifest.ts +2 -1
  153. package/src/runtime-secrets.test.ts +25 -8
  154. package/src/self-hosted-backup.test.ts +344 -0
  155. package/src/self-hosted-backup.ts +480 -0
  156. package/src/self-hosted-compose.test.ts +88 -4
  157. package/src/self-hosted-release.ts +22 -7
  158. package/src/self-hosted-start.test.ts +68 -0
  159. package/src/self-hosted-start.ts +123 -0
  160. package/src/self-hosted-upgrade.ts +35 -8
  161. package/src/stack-contract.test.ts +11 -20
  162. package/src/stack-contract.ts +25 -16
  163. package/src/stack-converge-secrets.test.ts +45 -10
  164. package/src/stack-converge.test.ts +19 -10
  165. package/src/staging-admin.ts +18 -181
  166. package/src/tar-entries.test.ts +52 -0
  167. package/src/tar-entries.ts +116 -0
  168. package/src/upgrade/converge.ts +51 -4
  169. package/src/upgrade/upgrade.test.ts +78 -1
  170. package/src/upgrader-assess.test.ts +22 -0
  171. package/src/upgrader-assess.ts +2 -1
  172. package/src/url-map-redirects-access.test.ts +88 -0
  173. package/src/url-map-redirects-access.ts +89 -0
  174. package/src/wizard.ts +3 -1
  175. package/src/wizards/gcp-cost.ts +1 -1
  176. package/src/wizards/gcp.ts +48 -0
  177. package/stacks/aws/README.md +1 -1
  178. package/stacks/aws/index.ts +89 -45
  179. package/stacks/azure/README.md +1 -1
  180. package/stacks/azure/index.ts +21 -14
  181. package/stacks/gcp/README.md +1 -1
  182. package/stacks/gcp/index.ts +26 -22
  183. package/stacks/gcp-firebase/index.ts +7 -3
  184. package/stacks/self-hosted/Pulumi.yaml +2 -2
  185. package/stacks/self-hosted/README.md +3 -3
  186. package/stacks/self-hosted/index.ts +45 -22
  187. package/dist/redirects-emit.d.ts +0 -52
  188. package/dist/redirects-emit.d.ts.map +0 -1
  189. package/dist/redirects-emit.js +0 -111
  190. package/dist/redirects-emit.js.map +0 -1
  191. package/src/redirects-emit.ts +0 -175
package/src/caddy.ts CHANGED
@@ -5,18 +5,32 @@
5
5
  *
6
6
  * Reads the `domains` table + the deploy targets and emits a
7
7
  * deterministic Caddyfile string. The CLI's `regenerate-caddy`
8
- * sub-command writes this to `/etc/caddy/Caddyfile` and runs
8
+ * sub-command writes this to `.caelo/Caddyfile` and runs
9
9
  * `caddy reload`.
10
10
  *
11
11
  * Per-vhost shape:
12
12
  * <hostname> {
13
- * # admin → reverse_proxy localhost:5173
14
- * # public → root + try_files (static), with /api/* → gateway
15
- * tls <ownerEmail>
13
+ * # admin → reverse_proxy <adminUpstream>
14
+ * # public → /api/* → <gatewayUpstream>; everything else is the
15
+ * # static site (try_files + file_server, 404 → /404.html)
16
16
  * }
17
17
  *
18
+ * Upstreams are `host:port` as seen FROM CADDY. In the Compose install
19
+ * Caddy runs in its own container, where `localhost` is Caddy itself, so
20
+ * the CLI passes the Compose service names (`caelo-admin:5173`,
21
+ * `caelo-gateway:8090`) — issue #707.
22
+ *
23
+ * Every directive here must be one Caddy accepts: the output is checked
24
+ * with `caddy validate` on the pinned Caddy image (caddy-validate.test.ts,
25
+ * run in CI) — issue #566 shipped a `try_files` nested inside
26
+ * `file_server { }`, which Caddy 2.11 refuses, so no vhost came up.
27
+ *
18
28
  * Staging vhosts force `X-Robots-Tag: noindex`.
19
29
  *
30
+ * Public vhosts import the redirect snippet of the build they serve
31
+ * (`_redirects.caddy`, #587); the Caddy container reloads itself when a
32
+ * deploy changes it (caddy-redirects.ts).
33
+ *
20
34
  * Public vhosts mark content-hashed build outputs (fonts, plugin
21
35
  * bundles — `CONTENT_HASHED_PATH_PATTERN` in @caelo-cms/shared)
22
36
  * `immutable` for a year. Everything else keeps Caddy's file_server
@@ -26,13 +40,22 @@
26
40
  * hashed URL (an old page requesting an asset the new build dropped)
27
41
  * is never cached for a year.
28
42
  *
43
+ * A path that matches no file is a real 404 serving the generator's
44
+ * `/404.html` — never the home page with a 200 (an SPA-style
45
+ * `/index.html` fallback would turn every dead URL into a soft 404).
46
+ * Same behaviour as the GCS / S3 / Blob adapters (CLAUDE.md §11.B).
47
+ *
29
48
  * `.ico` files (theme favicons) are served as `image/x-icon`, the one
30
49
  * icon MIME the media library stores and `<link rel="icon" type>`
31
50
  * declares. file_server only fills Content-Type when no earlier handler
32
51
  * set it, so the `header` line wins over the host's mime.types name.
33
52
  */
34
53
 
35
- import { CONTENT_HASHED_PATH_PATTERN, IMMUTABLE_CACHE_CONTROL } from "@caelo-cms/shared";
54
+ import {
55
+ CONTENT_HASHED_PATH_PATTERN,
56
+ caddyRedirectsImport,
57
+ IMMUTABLE_CACHE_CONTROL,
58
+ } from "@caelo-cms/shared";
36
59
 
37
60
  export interface CaddyDomainSpec {
38
61
  readonly hostname: string;
@@ -40,21 +63,64 @@ export interface CaddyDomainSpec {
40
63
  readonly env: "production" | "staging";
41
64
  }
42
65
 
66
+ /**
67
+ * How Caddy gets certificates: `acme` — publicly trusted ones from Let's
68
+ * Encrypt / ZeroSSL (needs public DNS + ports 80/443 reachable); `internal`
69
+ * — Caddy's own local CA, for a LAN or evaluation install without public
70
+ * DNS (browsers warn until the CA root is trusted).
71
+ */
72
+ export type CaddyTlsMode = "acme" | "internal";
73
+
43
74
  export interface CaddyfileSpec {
44
75
  readonly ownerEmail: string;
45
- readonly publicSiteRoot: string; // absolute path on disk
76
+ readonly tls: CaddyTlsMode;
77
+ readonly publicSiteRoot: string; // absolute path inside the Caddy container
46
78
  readonly stagingSiteRoot: string;
47
- readonly adminPort: number;
48
- readonly gatewayPort: number;
79
+ /** `host:port` of the admin as Caddy reaches it (Compose: `caelo-admin:5173`). */
80
+ readonly adminUpstream: string;
81
+ /** `host:port` of the API gateway as Caddy reaches it (Compose: `caelo-gateway:8090`). */
82
+ readonly gatewayUpstream: string;
49
83
  readonly domains: ReadonlyArray<CaddyDomainSpec>;
50
84
  }
51
85
 
86
+ /** The host the admin of a self-hosted install answers on (same convention as GCP). */
87
+ export function selfHostedAdminHost(domain: string): string {
88
+ return `admin.${domain}`;
89
+ }
90
+
91
+ /**
92
+ * The vhosts every self-hosted install serves before an Owner adds domains
93
+ * in the admin: the admin on `admin.<domain>`, the live site on `<domain>`,
94
+ * the staging site on its own host. The admin needs its own host — it
95
+ * routes from `/` (`/setup`, `/login`, …), so it cannot share one with the
96
+ * public site, and Caddy refuses two site blocks for the same address.
97
+ */
98
+ export function selfHostedSeedDomains(domain: string, stagingDomain: string): CaddyDomainSpec[] {
99
+ return [
100
+ { hostname: selfHostedAdminHost(domain), kind: "admin", env: "production" },
101
+ { hostname: domain, kind: "public", env: "production" },
102
+ { hostname: stagingDomain, kind: "public", env: "staging" },
103
+ ];
104
+ }
105
+
52
106
  export function generateCaddyfile(spec: CaddyfileSpec): string {
107
+ const hostnames = new Set<string>();
108
+ for (const d of spec.domains) {
109
+ if (hostnames.has(d.hostname)) {
110
+ // Caddy refuses a config with two site blocks for one address, so a
111
+ // duplicate would take every vhost down, not just this one.
112
+ throw new Error(
113
+ `Caddyfile: ${d.hostname} is listed twice — one host serves either the admin or a public site, not both.`,
114
+ );
115
+ }
116
+ hostnames.add(d.hostname);
117
+ }
118
+
53
119
  const blocks: string[] = [];
54
120
 
55
121
  // Global options.
56
122
  blocks.push(`{
57
- email ${spec.ownerEmail}
123
+ email ${spec.ownerEmail}${spec.tls === "internal" ? "\n local_certs" : ""}
58
124
  }
59
125
  `);
60
126
 
@@ -68,7 +134,7 @@ export function generateCaddyfile(spec: CaddyfileSpec): string {
68
134
  blocks.push(`# No domains configured yet — cms-provision regenerate-caddy
69
135
  # will overwrite this file when you add one at /settings/domains.
70
136
  :8081 {
71
- reverse_proxy localhost:${spec.adminPort}
137
+ reverse_proxy ${spec.adminUpstream}
72
138
  }
73
139
  `);
74
140
  }
@@ -80,15 +146,18 @@ function vhost(d: CaddyDomainSpec, spec: CaddyfileSpec): string {
80
146
  const noindex = d.env === "staging" ? `\n header X-Robots-Tag "noindex"` : "";
81
147
  if (d.kind === "admin") {
82
148
  return `${d.hostname} {${noindex}
83
- reverse_proxy localhost:${spec.adminPort}
149
+ reverse_proxy ${spec.adminUpstream}
84
150
  }
85
151
  `;
86
152
  }
87
- // public — API routes go to the gateway,
88
- // the rest serves static files. Locale variants serve from a
153
+ // public — API routes go to the gateway, the rest is the static site.
154
+ // `try_files` is its own directive (a rewrite), never a file_server
155
+ // subdirective (#566).
89
156
  const root = d.env === "staging" ? spec.stagingSiteRoot : spec.publicSiteRoot;
157
+ // #587 — the redirects table of the build this vhost serves.
90
158
  return `${d.hostname} {${noindex}
91
159
  root * ${root}
160
+ ${caddyRedirectsImport(root)}
92
161
  @content_hashed {
93
162
  path_regexp content_hashed ${CONTENT_HASHED_PATH_PATTERN}
94
163
  file
@@ -97,15 +166,15 @@ function vhost(d: CaddyDomainSpec, spec: CaddyfileSpec): string {
97
166
  @ico path *.ico
98
167
  header @ico Content-Type "image/x-icon"
99
168
  handle /api/* {
100
- reverse_proxy localhost:${spec.gatewayPort}
101
- }
102
- handle /admin/* {
103
- reverse_proxy localhost:${spec.adminPort}
169
+ reverse_proxy ${spec.gatewayUpstream}
104
170
  }
105
171
  handle {
106
- file_server {
107
- try_files {path} {path}/index.html /index.html
108
- }
172
+ try_files {path} {path}/index.html
173
+ file_server
174
+ }
175
+ handle_errors 404 {
176
+ rewrite * /404.html
177
+ file_server
109
178
  }
110
179
  }
111
180
  `;
@@ -40,7 +40,6 @@ const setupLink = "https://admin.acme.test/setup?token=fakeSetupToken0123456789"
40
40
  const stackOutputs = {
41
41
  adminDatabaseUrlOut: { value: databaseUrls("10.1.2.3").admin, secret: false },
42
42
  publicDatabaseUrlOut: { value: databaseUrls("10.1.2.3").public, secret: false },
43
- gatewayDatabaseUrlOut: { value: databaseUrls("10.1.2.3").gateway, secret: false },
44
43
  bootstrapUrlOut: { value: setupLink, secret: false },
45
44
  bootstrapTokenExpiresAtOut: { value: "2026-10-13T00:00:00.000Z", secret: false },
46
45
  providerOut: { value: "gcp", secret: false },
@@ -13,6 +13,18 @@ describe("resolveCliRoute", () => {
13
13
  ).toEqual({ kind: "wizard" });
14
14
  });
15
15
 
16
+ it("routes the self-hosted one-command install to init (#707)", () => {
17
+ expect(
18
+ resolveCliRoute(
19
+ argv("--provider", "self-hosted", "--domain", "example.com", "--owner-email", "o@x.y"),
20
+ HANDLERS,
21
+ ),
22
+ ).toEqual({ kind: "handler", name: "init" });
23
+ expect(resolveCliRoute(argv("--provider", "self-hosted", "--help"), HANDLERS)).toEqual({
24
+ kind: "usage",
25
+ });
26
+ });
27
+
16
28
  it("routes a bare invocation to the wizard", () => {
17
29
  expect(resolveCliRoute(argv(), HANDLERS)).toEqual({ kind: "wizard" });
18
30
  });
@@ -30,6 +30,13 @@ export function resolveCliRoute(argv: readonly string[], handlerNames: Iterable<
30
30
  if (argv.includes("--no-wizard") || argv.includes("--help") || argv.includes("-h")) {
31
31
  return { kind: "usage" };
32
32
  }
33
+ // #707 — `--provider self-hosted --domain … --owner-email …` is the
34
+ // self-hosted one-command install: `init` writes `.caelo/` and starts the
35
+ // stack. (The cloud wizard has nothing to provision for it.)
36
+ const provider = argv.indexOf("--provider");
37
+ if (provider !== -1 && argv[provider + 1] === "self-hosted") {
38
+ return { kind: "handler", name: "init" };
39
+ }
33
40
  return { kind: "wizard" };
34
41
  }
35
42