@caelo-cms/provisioning 0.1.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/caddy/Caddyfile.production +18 -0
- package/caddy/Caddyfile.staging +21 -0
- package/package.json +27 -0
- package/src/adapter.ts +103 -0
- package/src/bootstrap-token.ts +20 -0
- package/src/caddy.ts +93 -0
- package/src/cdn-copy.ts +84 -0
- package/src/cli.ts +674 -0
- package/src/compose.ts +123 -0
- package/src/index.test.ts +246 -0
- package/src/index.ts +52 -0
- package/src/redirects-emit.ts +166 -0
- package/stacks/aws/Pulumi.yaml +39 -0
- package/stacks/aws/README.md +80 -0
- package/stacks/aws/build-edge.ts +80 -0
- package/stacks/aws/edge-handler-bundle.js +21 -0
- package/stacks/aws/edge-handler.ts +87 -0
- package/stacks/aws/index.ts +412 -0
- package/stacks/azure/Pulumi.yaml +37 -0
- package/stacks/azure/README.md +69 -0
- package/stacks/azure/edge-handler.ts +88 -0
- package/stacks/azure/index.ts +309 -0
- package/stacks/gcp/Pulumi.yaml +36 -0
- package/stacks/gcp/README.md +78 -0
- package/stacks/gcp/edge-handler.ts +106 -0
- package/stacks/gcp/index.ts +483 -0
- package/stacks/self-hosted/Pulumi.yaml +27 -0
- package/stacks/self-hosted/README.md +43 -0
- package/stacks/self-hosted/index.ts +117 -0
- package/tsconfig.json +16 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# SPDX-License-Identifier: MPL-2.0
|
|
2
|
+
#
|
|
3
|
+
# Production vhost. No noindex header — the bot-indexing behavior comes
|
|
4
|
+
# straight from each page's emitted robots.txt (CMS_REQUIREMENTS §8.3).
|
|
5
|
+
#
|
|
6
|
+
# P6.2 — root is /srv/current, a symlink the deploy.trigger /
|
|
7
|
+
# deploy.promote / deploy.rollback ops atomically re-target. The
|
|
8
|
+
# routing manifest (/srv/current/routing-manifest.json) lists every
|
|
9
|
+
# emitted page + its output path; P9 will swap this Caddyfile for one
|
|
10
|
+
# that consults the manifest to handle locale URL strategies, and P13
|
|
11
|
+
# will use the same indirection for A/B variant edge selection.
|
|
12
|
+
|
|
13
|
+
:80 {
|
|
14
|
+
root * /srv/current
|
|
15
|
+
encode gzip
|
|
16
|
+
try_files {path} {path}/index.html
|
|
17
|
+
file_server
|
|
18
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# SPDX-License-Identifier: MPL-2.0
|
|
2
|
+
#
|
|
3
|
+
# Staging vhost. Per CMS_REQUIREMENTS §16.5 staging is always noindexed at
|
|
4
|
+
# the serving layer (not just via robots.txt body) — `X-Robots-Tag:
|
|
5
|
+
# noindex, nofollow` is enforced here so a misconfigured robots.txt can
|
|
6
|
+
# never accidentally let a bot index a staging page.
|
|
7
|
+
#
|
|
8
|
+
# `try_files` falls back to <slug>/index.html so the page-output paths
|
|
9
|
+
# the static generator emits ("about/index.html") work as clean URLs.
|
|
10
|
+
#
|
|
11
|
+
# P6.2 — root is /srv/current, a symlink the deploy.trigger op atomically
|
|
12
|
+
# re-targets to the most recent build. Caddy follows the symlink at
|
|
13
|
+
# request time so a deploy is invisible to in-flight requests.
|
|
14
|
+
|
|
15
|
+
:80 {
|
|
16
|
+
root * /srv/current
|
|
17
|
+
encode gzip
|
|
18
|
+
header X-Robots-Tag "noindex, nofollow"
|
|
19
|
+
try_files {path} {path}/index.html
|
|
20
|
+
file_server
|
|
21
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@caelo-cms/provisioning",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"license": "MPL-2.0",
|
|
6
|
+
"description": "Pulumi-driven provisioning for Caelo CMS — `bunx @caelo-cms/provisioning --provider <self-hosted|gcp|aws|azure>` brings up a TLS-served install with Postgres + storage + secrets manager + the admin + the API gateway.",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "./src/index.ts",
|
|
9
|
+
"types": "./src/index.ts",
|
|
10
|
+
"bin": {
|
|
11
|
+
"cms-provision": "./src/cli.ts"
|
|
12
|
+
},
|
|
13
|
+
"exports": {
|
|
14
|
+
".": "./src/index.ts"
|
|
15
|
+
},
|
|
16
|
+
"scripts": {
|
|
17
|
+
"typecheck": "tsc -b"
|
|
18
|
+
},
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@pulumi/aws": "^7",
|
|
21
|
+
"@pulumi/awsx": "^3",
|
|
22
|
+
"@pulumi/azure-native": "^3",
|
|
23
|
+
"@pulumi/command": "^1",
|
|
24
|
+
"@pulumi/gcp": "^9",
|
|
25
|
+
"@pulumi/pulumi": "^3"
|
|
26
|
+
}
|
|
27
|
+
}
|
package/src/adapter.ts
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* P15 — shared cloud-provider adapter contract.
|
|
5
|
+
*
|
|
6
|
+
* Every per-provider Pulumi stack at `packages/provisioning/stacks/<provider>/`
|
|
7
|
+
* exports a `provision(inputs: CloudAdapterInputs): CloudAdapterOutputs`
|
|
8
|
+
* function. The Caelo runtime never knows which provider it's running
|
|
9
|
+
* on — it just consumes the connection strings + URLs the adapter
|
|
10
|
+
* publishes via `CloudAdapterOutputs`. This keeps the per-provider
|
|
11
|
+
* surface small (~6 capabilities, see master plan) and the runtime
|
|
12
|
+
* provider-agnostic.
|
|
13
|
+
*
|
|
14
|
+
* Pulumi types are intentionally NOT imported here so that callers
|
|
15
|
+
* outside the Pulumi runtime (e.g. the cms-provision CLI, the admin
|
|
16
|
+
* app's DNS-guidance page) can consume the *plain* shape without
|
|
17
|
+
* dragging in the @pulumi/pulumi peer dep. Per-stack `index.ts` files
|
|
18
|
+
* narrow the output type to `pulumi.Output<T>` at their boundary.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
export type Environment = "dev" | "staging" | "production";
|
|
22
|
+
export type LocaleStrategy = "subdirectory" | "subdomain" | "domain";
|
|
23
|
+
|
|
24
|
+
export interface LocaleConfig {
|
|
25
|
+
/** ISO code, e.g. "en", "de", "fr-CA". */
|
|
26
|
+
readonly code: string;
|
|
27
|
+
/** URL strategy. Mixed strategies in one install are explicitly supported. */
|
|
28
|
+
readonly strategy: LocaleStrategy;
|
|
29
|
+
/** Required when strategy is "subdomain" or "domain"; ignored for "subdirectory". */
|
|
30
|
+
readonly host?: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface CloudAdapterInputs {
|
|
34
|
+
/** Primary domain (e.g. example.com). Admin + production public both bind here. */
|
|
35
|
+
readonly domain: string;
|
|
36
|
+
/** Operator email used for ACME / cert provisioning + Pulumi notifications. */
|
|
37
|
+
readonly ownerEmail: string;
|
|
38
|
+
/** Three-env model (CMS_REQUIREMENTS §16.5). Cloud installs always provision all three. */
|
|
39
|
+
readonly environments: ReadonlyArray<Environment>;
|
|
40
|
+
/** Per-locale routing config — drives per-domain cert + DNS guidance + edge routing. */
|
|
41
|
+
readonly locales: ReadonlyArray<LocaleConfig>;
|
|
42
|
+
/** Optional pre-existing secret references (e.g. from a CI secrets manager). */
|
|
43
|
+
readonly preProvisionedSecrets?: {
|
|
44
|
+
readonly anthropicApiKey?: string;
|
|
45
|
+
readonly resendApiKey?: string;
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* DNS records the operator must create at their registrar to make the
|
|
51
|
+
* install reachable. Surfaced in the admin's /security/dns page with
|
|
52
|
+
* live resolver status badges.
|
|
53
|
+
*/
|
|
54
|
+
export interface DnsRecord {
|
|
55
|
+
readonly hostname: string; // e.g. "de.example.com"
|
|
56
|
+
readonly type: "A" | "AAAA" | "CNAME" | "TXT";
|
|
57
|
+
readonly value: string; // the value the operator's registrar must hold
|
|
58
|
+
readonly purpose: string; // human-readable description
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Plain-data adapter outputs. Per-stack code wraps each field in
|
|
63
|
+
* `pulumi.Output<…>` at the Pulumi boundary, but the *shape* is shared
|
|
64
|
+
* across providers so the cms-provision CLI + the DNS UI can consume
|
|
65
|
+
* any provider's outputs uniformly.
|
|
66
|
+
*/
|
|
67
|
+
export interface CloudAdapterOutputs {
|
|
68
|
+
/** DSN for cms_admin role (encrypted in Pulumi state). */
|
|
69
|
+
readonly adminDatabaseUrl: string;
|
|
70
|
+
/** DSN for cms_public role (encrypted in Pulumi state). */
|
|
71
|
+
readonly publicDatabaseUrl: string;
|
|
72
|
+
/** Provider-native blob URL (s3://, gs://, https://<account>.blob.core.windows.net/<container>). */
|
|
73
|
+
readonly mediaStorageUrl: string;
|
|
74
|
+
/** Public-facing URL the admin reaches for media reads. */
|
|
75
|
+
readonly mediaCdnBaseUrl: string;
|
|
76
|
+
/** Bootstrap-token URL — operator opens this once after `pulumi up`. */
|
|
77
|
+
readonly bootstrapUrl: string;
|
|
78
|
+
/** DNS records consumed by the admin's DNS-guidance page. */
|
|
79
|
+
readonly dnsRecordsRequired: ReadonlyArray<DnsRecord>;
|
|
80
|
+
/**
|
|
81
|
+
* Where edge-A/B assignment logs land — read by the P12A analytics plugin's
|
|
82
|
+
* provider-specific log adapter. Provider-native sink URL (BigQuery dataset,
|
|
83
|
+
* Athena database, Log Analytics workspace).
|
|
84
|
+
*/
|
|
85
|
+
readonly edgeLogSinkUrl: string;
|
|
86
|
+
/** Which provider produced these outputs — drives the analytics plugin's adapter dispatch. */
|
|
87
|
+
readonly provider: SupportedProvider;
|
|
88
|
+
/** Which environment this output snapshot represents. */
|
|
89
|
+
readonly environment: Environment;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export type SupportedProvider = "self-hosted" | "gcp" | "aws" | "azure";
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Convenience: the shape persisted in `cms_admin.provisioning_outputs.outputs_json`.
|
|
96
|
+
* Pulumi runs the adapter, the CLI's `pulumi-output-sync` subcommand reads
|
|
97
|
+
* `pulumi stack output --json`, hashes the result, and writes a row keyed on
|
|
98
|
+
* (provider, environment) so the admin UI can read without provider creds.
|
|
99
|
+
*/
|
|
100
|
+
export interface ProvisioningOutputsJson {
|
|
101
|
+
readonly outputs: CloudAdapterOutputs;
|
|
102
|
+
readonly syncedAt: string; // ISO timestamp
|
|
103
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* P14 — owner bootstrap token. cms-provision generates one at first
|
|
5
|
+
* `up`; the operator visits /setup?token=<…> to create the first
|
|
6
|
+
* Owner. Single-use, 24h TTL.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export interface BootstrapToken {
|
|
10
|
+
readonly token: string;
|
|
11
|
+
readonly expiresAt: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function generateBootstrapToken(): BootstrapToken {
|
|
15
|
+
const bytes = new Uint8Array(32);
|
|
16
|
+
crypto.getRandomValues(bytes);
|
|
17
|
+
const token = [...bytes].map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
18
|
+
const expiresAt = new Date(Date.now() + 24 * 60 * 60 * 1000).toISOString();
|
|
19
|
+
return { token, expiresAt };
|
|
20
|
+
}
|
package/src/caddy.ts
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* P14 — Caddyfile generator.
|
|
5
|
+
*
|
|
6
|
+
* Reads the `domains` table + the deploy targets and emits a
|
|
7
|
+
* deterministic Caddyfile string. The CLI's `regenerate-caddy`
|
|
8
|
+
* sub-command writes this to `/etc/caddy/Caddyfile` and runs
|
|
9
|
+
* `caddy reload`.
|
|
10
|
+
*
|
|
11
|
+
* Per-vhost shape:
|
|
12
|
+
* <hostname> {
|
|
13
|
+
* # admin → reverse_proxy localhost:5173
|
|
14
|
+
* # public → root + try_files (static), with /api/* → gateway
|
|
15
|
+
* # locale → same as public, scoped to a per-locale dist dir
|
|
16
|
+
* tls <ownerEmail>
|
|
17
|
+
* }
|
|
18
|
+
*
|
|
19
|
+
* Staging vhosts force `X-Robots-Tag: noindex`.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
export interface CaddyDomainSpec {
|
|
23
|
+
readonly hostname: string;
|
|
24
|
+
readonly kind: "admin" | "public" | "locale-public";
|
|
25
|
+
readonly localeCode?: string;
|
|
26
|
+
readonly env: "production" | "staging";
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface CaddyfileSpec {
|
|
30
|
+
readonly ownerEmail: string;
|
|
31
|
+
readonly publicSiteRoot: string; // absolute path on disk
|
|
32
|
+
readonly stagingSiteRoot: string;
|
|
33
|
+
readonly adminPort: number;
|
|
34
|
+
readonly gatewayPort: number;
|
|
35
|
+
readonly domains: ReadonlyArray<CaddyDomainSpec>;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function generateCaddyfile(spec: CaddyfileSpec): string {
|
|
39
|
+
const blocks: string[] = [];
|
|
40
|
+
|
|
41
|
+
// Global options.
|
|
42
|
+
blocks.push(`{
|
|
43
|
+
email ${spec.ownerEmail}
|
|
44
|
+
}
|
|
45
|
+
`);
|
|
46
|
+
|
|
47
|
+
for (const d of spec.domains) {
|
|
48
|
+
blocks.push(vhost(d, spec));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Localhost dev fallback when no domains are configured (so a fresh
|
|
52
|
+
// `cms-provision` produces a working Caddyfile even pre-DNS).
|
|
53
|
+
if (spec.domains.length === 0) {
|
|
54
|
+
blocks.push(`# No domains configured yet — cms-provision regenerate-caddy
|
|
55
|
+
# will overwrite this file when you add one at /security/domains.
|
|
56
|
+
:8081 {
|
|
57
|
+
reverse_proxy localhost:${spec.adminPort}
|
|
58
|
+
}
|
|
59
|
+
`);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return blocks.join("\n");
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function vhost(d: CaddyDomainSpec, spec: CaddyfileSpec): string {
|
|
66
|
+
const noindex = d.env === "staging" ? `\n header X-Robots-Tag "noindex"` : "";
|
|
67
|
+
if (d.kind === "admin") {
|
|
68
|
+
return `${d.hostname} {${noindex}
|
|
69
|
+
reverse_proxy localhost:${spec.adminPort}
|
|
70
|
+
}
|
|
71
|
+
`;
|
|
72
|
+
}
|
|
73
|
+
// public / locale-public — same shape: API routes go to the gateway,
|
|
74
|
+
// the rest serves static files. Locale variants serve from a
|
|
75
|
+
// per-locale subdirectory.
|
|
76
|
+
const root = d.env === "staging" ? spec.stagingSiteRoot : spec.publicSiteRoot;
|
|
77
|
+
const localeSubdir = d.kind === "locale-public" && d.localeCode ? `/${d.localeCode}` : "";
|
|
78
|
+
return `${d.hostname} {${noindex}
|
|
79
|
+
root * ${root}${localeSubdir}
|
|
80
|
+
handle /api/* {
|
|
81
|
+
reverse_proxy localhost:${spec.gatewayPort}
|
|
82
|
+
}
|
|
83
|
+
handle /admin/* {
|
|
84
|
+
reverse_proxy localhost:${spec.adminPort}
|
|
85
|
+
}
|
|
86
|
+
handle {
|
|
87
|
+
file_server {
|
|
88
|
+
try_files {path} {path}/index.html /index.html
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
`;
|
|
93
|
+
}
|
package/src/cdn-copy.ts
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* P15 — per-provider CDN-copy adapter contract.
|
|
5
|
+
*
|
|
6
|
+
* P7 ships the `media_assets.usage_count` threshold + the `media.set_cdn`
|
|
7
|
+
* op that flips a per-asset boolean. P15 wires the actual edge-pin
|
|
8
|
+
* operation per provider:
|
|
9
|
+
* - AWS → CloudFront cache invalidation + warmer request.
|
|
10
|
+
* - GCP → set Cache-Control metadata on the GCS object so Cloud CDN
|
|
11
|
+
* respects the long TTL.
|
|
12
|
+
* - Azure → Front Door purge + warm endpoint.
|
|
13
|
+
*
|
|
14
|
+
* The redeploy-orchestrator's `cdnCopyTick()` (currently a no-op for
|
|
15
|
+
* cloud installs) drains the per-asset CDN-pin queue using the adapter
|
|
16
|
+
* registered for the active provider.
|
|
17
|
+
*
|
|
18
|
+
* Each provider's stack publishes a `CdnCopyAdapter` instance via its
|
|
19
|
+
* Pulumi outputs (the actual implementation is dynamically imported by
|
|
20
|
+
* the orchestrator at runtime so `@caelo-cms/provisioning` doesn't pull in
|
|
21
|
+
* `@aws-sdk/...`/`@google-cloud/...`/`@azure/...` as static deps). The
|
|
22
|
+
* interface defined here is the only thing both sides agree on.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
export interface CdnCopyAdapter {
|
|
26
|
+
/**
|
|
27
|
+
* Mark the asset at `assetKey` (object key in primary storage) as
|
|
28
|
+
* CDN-cached. Returns the public CDN URL — admin uses this as the
|
|
29
|
+
* canonical URL for the asset thereafter.
|
|
30
|
+
*/
|
|
31
|
+
pin(assetKey: string): Promise<string>;
|
|
32
|
+
/** Reverse — drop from CDN edge cache. */
|
|
33
|
+
unpin(assetKey: string): Promise<void>;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* No-op adapter for self-hosted installs (Caddy serves directly from
|
|
38
|
+
* disk; no separate CDN tier). Returns the input asset key as a relative
|
|
39
|
+
* URL so callers don't have to special-case the no-CDN case.
|
|
40
|
+
*/
|
|
41
|
+
export const selfHostedCdnCopy: CdnCopyAdapter = {
|
|
42
|
+
async pin(assetKey) {
|
|
43
|
+
return `/media/${assetKey}`;
|
|
44
|
+
},
|
|
45
|
+
async unpin() {
|
|
46
|
+
// no-op
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Resolves the right adapter per `process.env.CAELO_PROVIDER`. Lazy
|
|
52
|
+
* dynamic-imports the per-provider implementation so a self-hosted
|
|
53
|
+
* install never loads the cloud SDKs.
|
|
54
|
+
*
|
|
55
|
+
* Returns `selfHostedCdnCopy` ONLY for `provider==='self-hosted'` or an
|
|
56
|
+
* unset env (treated as self-hosted). For `gcp`/`aws`/`azure`, the
|
|
57
|
+
* matching `cdn-copy-<gcs|aws|azure>.ts` file MUST exist in this
|
|
58
|
+
* directory — those land with the per-provider PRs. Per CLAUDE.md §2
|
|
59
|
+
* "no fallbacks pre-1.0" we deliberately do NOT silently degrade to
|
|
60
|
+
* the self-hosted no-op when the file is missing: a missing module is
|
|
61
|
+
* a deploy bug + the orchestrator tick should crash loudly so the
|
|
62
|
+
* operator notices instead of silently dropping CDN-pin requests.
|
|
63
|
+
*/
|
|
64
|
+
export async function loadCdnCopyAdapter(provider?: string): Promise<CdnCopyAdapter> {
|
|
65
|
+
switch (provider) {
|
|
66
|
+
case "gcp":
|
|
67
|
+
// biome-ignore lint/suspicious/noExplicitAny: opt-in dynamic import
|
|
68
|
+
return ((await import("./cdn-copy-gcs.js" as string)) as any).gcsCloudCdnPin;
|
|
69
|
+
case "aws":
|
|
70
|
+
// biome-ignore lint/suspicious/noExplicitAny: opt-in dynamic import
|
|
71
|
+
return ((await import("./cdn-copy-aws.js" as string)) as any).s3CloudfrontPrewarm;
|
|
72
|
+
case "azure":
|
|
73
|
+
// biome-ignore lint/suspicious/noExplicitAny: opt-in dynamic import
|
|
74
|
+
return ((await import("./cdn-copy-azure.js" as string)) as any).azureBlobCdnPrefetch;
|
|
75
|
+
case undefined:
|
|
76
|
+
case "":
|
|
77
|
+
case "self-hosted":
|
|
78
|
+
return selfHostedCdnCopy;
|
|
79
|
+
default:
|
|
80
|
+
throw new Error(
|
|
81
|
+
`loadCdnCopyAdapter: unknown CAELO_PROVIDER='${provider}'. Expected one of: self-hosted | gcp | aws | azure.`,
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
}
|