@geekmidas/cli 10.0.0-alpha.5 → 10.0.0-alpha.50
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +196 -257
- package/bin/adjacent-tsconfig.mjs +97 -0
- package/bin/gkm.mjs +16 -2
- package/bin/owning-tsconfig-jsx-register.mjs +18 -0
- package/bin/owning-tsconfig-jsx.mjs +108 -0
- package/dist/{HostingerProvider-h3EbEp-Z.cjs → HostingerProvider-BZFGYYVA.cjs} +21 -22
- package/dist/HostingerProvider-BZFGYYVA.cjs.map +1 -0
- package/dist/{HostingerProvider-Cft7lEYr.mjs → HostingerProvider-GF6NAZAK.mjs} +20 -21
- package/dist/HostingerProvider-GF6NAZAK.mjs.map +1 -0
- package/dist/{LocalStateProvider-Db9SEjyH.cjs → LocalStateProvider-7HR6SS2t.cjs} +11 -6
- package/dist/LocalStateProvider-7HR6SS2t.cjs.map +1 -0
- package/dist/{LocalStateProvider-Bn6tS-oL.mjs → LocalStateProvider-D7QyJoLM.mjs} +10 -4
- package/dist/LocalStateProvider-D7QyJoLM.mjs.map +1 -0
- package/dist/{openapi-CA0yJUTN.cjs → OpenApiTsGenerator-BN0PIZxd.cjs} +157 -372
- package/dist/OpenApiTsGenerator-BN0PIZxd.cjs.map +1 -0
- package/dist/{openapi-kkQbsRVj.mjs → OpenApiTsGenerator-BzIGy8KE.mjs} +128 -324
- package/dist/OpenApiTsGenerator-BzIGy8KE.mjs.map +1 -0
- package/dist/{Route53Provider-RdpUDJQk.mjs → Route53Provider-Cvj40A8I.mjs} +12 -12
- package/dist/Route53Provider-Cvj40A8I.mjs.map +1 -0
- package/dist/{Route53Provider-di2fMM5N.cjs → Route53Provider-DVILBsvV.cjs} +20 -21
- package/dist/Route53Provider-DVILBsvV.cjs.map +1 -0
- package/dist/{SSMStateProvider-BRt2py-A.mjs → SSMStateProvider-B0Hu1MKZ.mjs} +13 -4
- package/dist/SSMStateProvider-B0Hu1MKZ.mjs.map +1 -0
- package/dist/{SSMStateProvider-DyX8s9HI.cjs → SSMStateProvider-VrQ-yeqd.cjs} +17 -9
- package/dist/SSMStateProvider-VrQ-yeqd.cjs.map +1 -0
- package/dist/aws-DkHdTV-p.cjs +61 -0
- package/dist/aws-DkHdTV-p.cjs.map +1 -0
- package/dist/aws-DojzQnLd.mjs +61 -0
- package/dist/aws-DojzQnLd.mjs.map +1 -0
- package/dist/backends-B9V2XD2M.cjs +82 -0
- package/dist/backends-B9V2XD2M.cjs.map +1 -0
- package/dist/backends-CSuLl0YP.mjs +59 -0
- package/dist/backends-CSuLl0YP.mjs.map +1 -0
- package/dist/{backup-provisioner-BrsHwYG0.cjs → backup-provisioner-BmhIO_Yr.cjs} +21 -19
- package/dist/backup-provisioner-BmhIO_Yr.cjs.map +1 -0
- package/dist/{backup-provisioner-Bgj5Vi_L.mjs → backup-provisioner-DIVCbfee.mjs} +10 -7
- package/dist/backup-provisioner-DIVCbfee.mjs.map +1 -0
- package/dist/{bundler-Be8Zg4Wd.mjs → bundler--fyybf1N.mjs} +19 -30
- package/dist/bundler--fyybf1N.mjs.map +1 -0
- package/dist/{bundler-BY1OmV1e.cjs → bundler-By6_sXiL.cjs} +20 -32
- package/dist/bundler-By6_sXiL.cjs.map +1 -0
- package/dist/{config-C21ocYNd.cjs → config-CsYSyUya.cjs} +209 -210
- package/dist/config-CsYSyUya.cjs.map +1 -0
- package/dist/{config-WRdsQYZK.mjs → config-D8J5rrTb.mjs} +142 -154
- package/dist/config-D8J5rrTb.mjs.map +1 -0
- package/dist/config.cjs +9 -6
- package/dist/config.d.cts +62 -33
- package/dist/config.d.cts.map +1 -1
- package/dist/config.d.mts +62 -33
- package/dist/config.d.mts.map +1 -1
- package/dist/config.mjs +3 -5
- package/dist/deploy/sniffer-envkit-patch.cjs +18 -10
- package/dist/deploy/sniffer-envkit-patch.cjs.map +1 -1
- package/dist/deploy/sniffer-envkit-patch.d.cts +0 -2
- package/dist/deploy/sniffer-envkit-patch.d.cts.map +1 -1
- package/dist/deploy/sniffer-envkit-patch.d.mts +0 -2
- package/dist/deploy/sniffer-envkit-patch.d.mts.map +1 -1
- package/dist/deploy/sniffer-envkit-patch.mjs +10 -2
- package/dist/deploy/sniffer-envkit-patch.mjs.map +1 -1
- package/dist/deploy/sniffer-hooks.cjs +13 -7
- package/dist/deploy/sniffer-hooks.cjs.map +1 -1
- package/dist/deploy/sniffer-hooks.d.cts +1 -2
- package/dist/deploy/sniffer-hooks.d.cts.map +1 -1
- package/dist/deploy/sniffer-hooks.d.mts +1 -2
- package/dist/deploy/sniffer-hooks.d.mts.map +1 -1
- package/dist/deploy/sniffer-hooks.mjs +9 -2
- package/dist/deploy/sniffer-hooks.mjs.map +1 -1
- package/dist/deploy/sniffer-loader.cjs +16 -7
- package/dist/deploy/sniffer-loader.cjs.map +1 -1
- package/dist/deploy/sniffer-loader.d.cts +1 -1
- package/dist/deploy/sniffer-loader.d.mts +1 -1
- package/dist/deploy/sniffer-loader.mjs +13 -2
- package/dist/deploy/sniffer-loader.mjs.map +1 -1
- package/dist/deploy/sniffer-routes-worker.cjs +11 -11
- package/dist/deploy/sniffer-routes-worker.cjs.map +1 -1
- package/dist/deploy/sniffer-routes-worker.d.cts +1 -1
- package/dist/deploy/sniffer-routes-worker.d.mts +1 -1
- package/dist/deploy/sniffer-routes-worker.mjs +3 -3
- package/dist/deploy/sniffer-routes-worker.mjs.map +1 -1
- package/dist/deploy/sniffer-worker.cjs +15 -6
- package/dist/deploy/sniffer-worker.cjs.map +1 -1
- package/dist/deploy/sniffer-worker.d.cts +1 -3
- package/dist/deploy/sniffer-worker.d.cts.map +1 -1
- package/dist/deploy/sniffer-worker.d.mts +1 -3
- package/dist/deploy/sniffer-worker.d.mts.map +1 -1
- package/dist/deploy/sniffer-worker.mjs +15 -4
- package/dist/deploy/sniffer-worker.mjs.map +1 -1
- package/dist/{discover-CAlFgYec.mjs → discover-Cf2jAcgF.mjs} +56 -63
- package/dist/discover-Cf2jAcgF.mjs.map +1 -0
- package/dist/{discover-DTmFeloL.cjs → discover-DXNviAh-.cjs} +86 -110
- package/dist/discover-DXNviAh-.cjs.map +1 -0
- package/dist/{emit-CiZS_5Ub.mjs → emit-C1e8qD08.mjs} +13 -26
- package/dist/emit-C1e8qD08.mjs.map +1 -0
- package/dist/{emit-CbcRolsa.cjs → emit-Dmc1nvdS.cjs} +31 -57
- package/dist/emit-Dmc1nvdS.cjs.map +1 -0
- package/dist/encryption-C7OGMve_.cjs +91 -0
- package/dist/encryption-C7OGMve_.cjs.map +1 -0
- package/dist/encryption-DyQnPsZN.mjs +90 -0
- package/dist/encryption-DyQnPsZN.mjs.map +1 -0
- package/dist/github-BfpadQWQ.mjs +213 -0
- package/dist/github-BfpadQWQ.mjs.map +1 -0
- package/dist/github-BrI1tv6u.cjs +213 -0
- package/dist/github-BrI1tv6u.cjs.map +1 -0
- package/dist/{index-CHB4tSzX.d.cts → index-BQhJXpaQ.d.mts} +4 -23
- package/dist/index-BQhJXpaQ.d.mts.map +1 -0
- package/dist/{index-BThUzEIp.d.mts → index-DHJePE0y.d.cts} +4 -23
- package/dist/index-DHJePE0y.d.cts.map +1 -0
- package/dist/index.cjs +9531 -7200
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +9412 -7108
- package/dist/index.mjs.map +1 -1
- package/dist/migrate-B00XpVaO.mjs +736 -0
- package/dist/migrate-B00XpVaO.mjs.map +1 -0
- package/dist/migrate-CNlew9Ek.cjs +743 -0
- package/dist/migrate-CNlew9Ek.cjs.map +1 -0
- package/dist/openapi.cjs +198 -8
- package/dist/openapi.cjs.map +1 -0
- package/dist/openapi.d.cts +53 -15
- package/dist/openapi.d.cts.map +1 -1
- package/dist/openapi.d.mts +53 -15
- package/dist/openapi.d.mts.map +1 -1
- package/dist/openapi.mjs +193 -5
- package/dist/openapi.mjs.map +1 -0
- package/dist/ready-WfT-eWlm.mjs +861 -0
- package/dist/ready-WfT-eWlm.mjs.map +1 -0
- package/dist/ready-lr2Fm-ep.cjs +932 -0
- package/dist/ready-lr2Fm-ep.cjs.map +1 -0
- package/dist/reconcile/public.cjs +3 -5
- package/dist/reconcile/public.d.cts +30 -33
- package/dist/reconcile/public.d.cts.map +1 -1
- package/dist/reconcile/public.d.mts +30 -33
- package/dist/reconcile/public.d.mts.map +1 -1
- package/dist/reconcile/public.mjs +3 -4
- package/dist/{reconcile-CFs8C_1a.mjs → reconcile--I7V4Klj.mjs} +4 -7
- package/dist/reconcile--I7V4Klj.mjs.map +1 -0
- package/dist/{reconcile-D0pimNiy.cjs → reconcile-CuCQBa5-.cjs} +5 -8
- package/dist/reconcile-CuCQBa5-.cjs.map +1 -0
- package/dist/rolldown-runtime-BhDjJH2R.mjs +15 -0
- package/dist/{chunk-CUT6urMc.cjs → rolldown-runtime-C0BPl7ul.cjs} +23 -10
- package/dist/storage-BzaUxmqe.mjs +124 -0
- package/dist/storage-BzaUxmqe.mjs.map +1 -0
- package/dist/storage-CSGoC3bK.cjs +152 -0
- package/dist/storage-CSGoC3bK.cjs.map +1 -0
- package/dist/store-DQgxT_WR.cjs +211 -0
- package/dist/store-DQgxT_WR.cjs.map +1 -0
- package/dist/store-DeGATCS-.mjs +182 -0
- package/dist/store-DeGATCS-.mjs.map +1 -0
- package/dist/types-BbrNu83u.d.mts +6229 -0
- package/dist/types-BbrNu83u.d.mts.map +1 -0
- package/dist/types-DNqEsctD.d.cts +6230 -0
- package/dist/types-DNqEsctD.d.cts.map +1 -0
- package/dist/vitest.cjs +65 -0
- package/dist/vitest.cjs.map +1 -0
- package/dist/vitest.d.cts +29 -0
- package/dist/vitest.d.cts.map +1 -0
- package/dist/vitest.d.mts +29 -0
- package/dist/vitest.d.mts.map +1 -0
- package/dist/vitest.mjs +65 -0
- package/dist/vitest.mjs.map +1 -0
- package/dist/workspace/index.cjs +3 -4
- package/dist/workspace/index.d.cts +3 -3
- package/dist/workspace/index.d.mts +3 -3
- package/dist/workspace/index.mjs +2 -3
- package/dist/{credentials-BBIRJVp4.mjs → workspace-BsbxbqV-.mjs} +2201 -1732
- package/dist/workspace-BsbxbqV-.mjs.map +1 -0
- package/dist/{workspace-BcucjwvA.cjs → workspace-DEibcoBe.cjs} +1038 -1118
- package/dist/workspace-DEibcoBe.cjs.map +1 -0
- package/dist/{workspace-BFMrAKqI.mjs → workspace-DNzWgM1J.mjs} +869 -972
- package/dist/workspace-DNzWgM1J.mjs.map +1 -0
- package/dist/{credentials-G1JwBoXH.cjs → workspace-j6ZxvJqq.cjs} +2337 -1849
- package/dist/workspace-j6ZxvJqq.cjs.map +1 -0
- package/package.json +29 -20
- package/dist/CachedStateProvider-BLo7zv7S.cjs +0 -3
- package/dist/CachedStateProvider-BxoAm-B2.mjs +0 -3
- package/dist/CachedStateProvider-CqPdW7CB.cjs +0 -60
- package/dist/CachedStateProvider-CqPdW7CB.cjs.map +0 -1
- package/dist/CachedStateProvider-DTniehMP.mjs +0 -54
- package/dist/CachedStateProvider-DTniehMP.mjs.map +0 -1
- package/dist/HostingerProvider-Cft7lEYr.mjs.map +0 -1
- package/dist/HostingerProvider-h3EbEp-Z.cjs.map +0 -1
- package/dist/LocalStateProvider-Bn6tS-oL.mjs.map +0 -1
- package/dist/LocalStateProvider-Db9SEjyH.cjs.map +0 -1
- package/dist/Route53Provider-RdpUDJQk.mjs.map +0 -1
- package/dist/Route53Provider-di2fMM5N.cjs.map +0 -1
- package/dist/SSMStateProvider-BRt2py-A.mjs.map +0 -1
- package/dist/SSMStateProvider-DyX8s9HI.cjs.map +0 -1
- package/dist/backup-provisioner-Bgj5Vi_L.mjs.map +0 -1
- package/dist/backup-provisioner-BrsHwYG0.cjs.map +0 -1
- package/dist/bundler-BY1OmV1e.cjs.map +0 -1
- package/dist/bundler-Be8Zg4Wd.mjs.map +0 -1
- package/dist/chunk-Duj1WY3L.mjs +0 -7
- package/dist/config-C21ocYNd.cjs.map +0 -1
- package/dist/config-WRdsQYZK.mjs.map +0 -1
- package/dist/credentials-B5zRHdAl.mjs +0 -141
- package/dist/credentials-B5zRHdAl.mjs.map +0 -1
- package/dist/credentials-BBIRJVp4.mjs.map +0 -1
- package/dist/credentials-BapzjyV5.cjs +0 -195
- package/dist/credentials-BapzjyV5.cjs.map +0 -1
- package/dist/credentials-G1JwBoXH.cjs.map +0 -1
- package/dist/discover-CAlFgYec.mjs.map +0 -1
- package/dist/discover-DTmFeloL.cjs.map +0 -1
- package/dist/dokploy-api-BS2xnJLZ.mjs +0 -3
- package/dist/dokploy-api-BsVH0y_s.cjs +0 -718
- package/dist/dokploy-api-BsVH0y_s.cjs.map +0 -1
- package/dist/dokploy-api-BuxDRo3l.cjs +0 -3
- package/dist/dokploy-api-aTFPz7_4.mjs +0 -706
- package/dist/dokploy-api-aTFPz7_4.mjs.map +0 -1
- package/dist/emit-CbcRolsa.cjs.map +0 -1
- package/dist/emit-CiZS_5Ub.mjs.map +0 -1
- package/dist/encryption-C6jaU0hE.cjs +0 -54
- package/dist/encryption-C6jaU0hE.cjs.map +0 -1
- package/dist/encryption-CHzzeR8a.cjs +0 -4
- package/dist/encryption-CQUncu7v.mjs +0 -3
- package/dist/encryption-D-abyhZx.mjs +0 -42
- package/dist/encryption-D-abyhZx.mjs.map +0 -1
- package/dist/fullstack-secrets-C-GGohke.cjs +0 -111
- package/dist/fullstack-secrets-C-GGohke.cjs.map +0 -1
- package/dist/fullstack-secrets-D1o9-G5l.mjs +0 -87
- package/dist/fullstack-secrets-D1o9-G5l.mjs.map +0 -1
- package/dist/generator-CNzBw7g5.cjs +0 -289
- package/dist/generator-CNzBw7g5.cjs.map +0 -1
- package/dist/generator-VE2JrFlY.mjs +0 -253
- package/dist/generator-VE2JrFlY.mjs.map +0 -1
- package/dist/index-BThUzEIp.d.mts.map +0 -1
- package/dist/index-CHB4tSzX.d.cts.map +0 -1
- package/dist/openapi-CA0yJUTN.cjs.map +0 -1
- package/dist/openapi-kkQbsRVj.mjs.map +0 -1
- package/dist/openapi-react-query-Byltvm_7.mjs +0 -167
- package/dist/openapi-react-query-Byltvm_7.mjs.map +0 -1
- package/dist/openapi-react-query-CmJ1xDbn.cjs +0 -173
- package/dist/openapi-react-query-CmJ1xDbn.cjs.map +0 -1
- package/dist/openapi-react-query.cjs +0 -4
- package/dist/openapi-react-query.d.cts +0 -11
- package/dist/openapi-react-query.d.cts.map +0 -1
- package/dist/openapi-react-query.d.mts +0 -11
- package/dist/openapi-react-query.d.mts.map +0 -1
- package/dist/openapi-react-query.mjs +0 -4
- package/dist/reconcile-CFs8C_1a.mjs.map +0 -1
- package/dist/reconcile-D0pimNiy.cjs.map +0 -1
- package/dist/setup-B5_oHHUj.cjs +0 -11
- package/dist/setup-Cm2UnAdh.cjs +0 -473
- package/dist/setup-Cm2UnAdh.cjs.map +0 -1
- package/dist/setup-DXvRLTZN.mjs +0 -443
- package/dist/setup-DXvRLTZN.mjs.map +0 -1
- package/dist/setup-ZijS4qeC.mjs +0 -11
- package/dist/storage-BJmzYxt8.cjs +0 -363
- package/dist/storage-BJmzYxt8.cjs.map +0 -1
- package/dist/storage-BM9hGpgv.cjs +0 -7
- package/dist/storage-Bi24WfoW.mjs +0 -297
- package/dist/storage-Bi24WfoW.mjs.map +0 -1
- package/dist/storage-CYlGwWTj.mjs +0 -3
- package/dist/sync-CmEuNZsB.mjs +0 -76
- package/dist/sync-CmEuNZsB.mjs.map +0 -1
- package/dist/sync-D306yOWu.cjs +0 -4
- package/dist/sync-SizaChmC.cjs +0 -93
- package/dist/sync-SizaChmC.cjs.map +0 -1
- package/dist/sync-hOqAWHR6.mjs +0 -3
- package/dist/types-C-arnQ1r.d.mts +0 -2184
- package/dist/types-C-arnQ1r.d.mts.map +0 -1
- package/dist/types-abJQuk7m.d.cts +0 -2184
- package/dist/types-abJQuk7m.d.cts.map +0 -1
- package/dist/workspace-BFMrAKqI.mjs.map +0 -1
- package/dist/workspace-BcucjwvA.cjs.map +0 -1
- package/dist/workspace-DdJss8I6.cjs +0 -9
- package/dist/workspace-k4l3rsFh.mjs +0 -8
|
@@ -1,322 +1,268 @@
|
|
|
1
|
-
const
|
|
2
|
-
const require_discover = require(
|
|
3
|
-
const require_config = require(
|
|
4
|
-
const require_workspace = require(
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const STORAGE_BACKENDS = [
|
|
34
|
-
"minio",
|
|
35
|
-
"s3",
|
|
36
|
-
"r2"
|
|
37
|
-
];
|
|
38
|
-
/**
|
|
39
|
-
* The cache backend a workspace selected, or the one its target implies.
|
|
40
|
-
*
|
|
41
|
-
* Defaulted here rather than by every caller, so "what happens when nobody
|
|
42
|
-
* said" is answered once and the answer is greppable — and now answered by
|
|
43
|
-
* *where it deploys*, because there is no single right answer for both a
|
|
44
|
-
* Lambda and a box running its own Postgres.
|
|
45
|
-
*
|
|
46
|
-
* `on` is the deploy target, not where this code happens to be running. A
|
|
47
|
-
* local `gkm dev` for an AWS app still defaults to Upstash, because a backend
|
|
48
|
-
* that differed between local and deployed would be worse than a slower one —
|
|
49
|
-
* which is the property the type's own documentation asks for.
|
|
50
|
-
*/
|
|
51
|
-
function cacheBackendOf(value, on = "aws") {
|
|
52
|
-
return isBackend(value, CACHE_BACKENDS) ? value : require_discover.DEFAULT_CACHE[on];
|
|
53
|
-
}
|
|
54
|
-
/** The email backend a workspace selected, defaulting to SES on every target. */
|
|
55
|
-
function emailBackendOf(value) {
|
|
56
|
-
return isBackend(value, EMAIL_BACKENDS) ? value : require_discover.DEFAULT_EMAIL;
|
|
57
|
-
}
|
|
58
|
-
/** The storage backend a workspace selected, or the one its target implies. */
|
|
59
|
-
function storageBackendOf(value, on = "aws") {
|
|
60
|
-
return isBackend(value, STORAGE_BACKENDS) ? value : require_discover.DEFAULT_STORAGE[on];
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Which family of defaults a workspace's deploy target belongs to.
|
|
64
|
-
*
|
|
65
|
-
* One question, asked once: **does this target run containers the project
|
|
66
|
-
* controls?** Dokploy and a bare server do, so a bucket or a cache can live
|
|
67
|
-
* beside the app; AWS, Vercel and Cloudflare do not, so the default has to be
|
|
68
|
-
* something managed. That is the whole of the distinction, and it is why
|
|
69
|
-
* `MainProvider` is the right axis rather than the deploy target's own name —
|
|
70
|
-
* three targets share one answer.
|
|
71
|
-
*
|
|
72
|
-
* An AWS deploy names no `deploy.default` at all, because it goes through SST,
|
|
73
|
-
* which is why the absence is what selects `aws`.
|
|
74
|
-
*/
|
|
75
|
-
function providerOf(workspace) {
|
|
76
|
-
const target = workspace.deploy?.default;
|
|
77
|
-
return target === "dokploy" || target === "server" ? "server" : "aws";
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Whether a string names a backend, as opposed to being one of the other things
|
|
81
|
-
* a `services:` value can be.
|
|
82
|
-
*
|
|
83
|
-
* A misspelling falls through to the default rather than throwing, which is the
|
|
84
|
-
* wrong trade for something with a cost attached — so callers that can report it
|
|
85
|
-
* should use {@link unknownBackend} to say so.
|
|
86
|
-
*/
|
|
87
|
-
function isBackend(value, backends) {
|
|
88
|
-
return typeof value === "string" && backends.includes(value);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
//#endregion
|
|
92
|
-
//#region src/reconcile/caddyfile.ts
|
|
93
|
-
/**
|
|
94
|
-
* The kinds the edge serves.
|
|
95
|
-
*
|
|
96
|
-
* Everything that owns a *public address*. Deployed, each of these has a real
|
|
97
|
-
* hostname and a certificate, so this is what makes the local shape the same
|
|
98
|
-
* one rather than a near-enough one — and the application is indifferent
|
|
99
|
-
* either way, because it reads whichever address was injected and never
|
|
100
|
-
* composes one.
|
|
101
|
-
*
|
|
102
|
-
* Adding a kind here is the whole of adding it to the edge.
|
|
103
|
-
*/
|
|
104
|
-
const EDGE_KINDS = {
|
|
105
|
-
"file-server": true,
|
|
106
|
-
"rest-api": true,
|
|
107
|
-
site: true
|
|
108
|
-
};
|
|
1
|
+
const require_rolldown_runtime = require("./rolldown-runtime-C0BPl7ul.cjs");
|
|
2
|
+
const require_discover = require("./discover-DXNviAh-.cjs");
|
|
3
|
+
const require_config = require("./config-CsYSyUya.cjs");
|
|
4
|
+
const require_workspace = require("./workspace-DEibcoBe.cjs");
|
|
5
|
+
const require_storage = require("./storage-CSGoC3bK.cjs");
|
|
6
|
+
const require_store = require("./store-DQgxT_WR.cjs");
|
|
7
|
+
const require_ready = require("./ready-lr2Fm-ep.cjs");
|
|
8
|
+
const require_backends = require("./backends-B9V2XD2M.cjs");
|
|
9
|
+
let node_fs = require("node:fs");
|
|
10
|
+
let node_fs_promises = require("node:fs/promises");
|
|
11
|
+
let node_os = require("node:os");
|
|
12
|
+
let node_path = require("node:path");
|
|
13
|
+
let node_child_process = require("node:child_process");
|
|
14
|
+
let _geekmidas_manifest = require("@geekmidas/manifest");
|
|
15
|
+
let node_net = require("node:net");
|
|
16
|
+
let dotenv = require("dotenv");
|
|
17
|
+
let node_crypto = require("node:crypto");
|
|
18
|
+
let _geekmidas_constructs_encryption = require("@geekmidas/constructs/encryption");
|
|
19
|
+
let _geekmidas_db_pg_roles = require("@geekmidas/db/pg/roles");
|
|
20
|
+
let _geekmidas_events_sns_url = require("@geekmidas/events/sns/url");
|
|
21
|
+
_geekmidas_events_sns_url = require_rolldown_runtime.__toESM(_geekmidas_events_sns_url, 1);
|
|
22
|
+
let _geekmidas_events_sqs_url = require("@geekmidas/events/sqs/url");
|
|
23
|
+
_geekmidas_events_sqs_url = require_rolldown_runtime.__toESM(_geekmidas_events_sqs_url, 1);
|
|
24
|
+
let _aws_sdk_client_s3 = require("@aws-sdk/client-s3");
|
|
25
|
+
let _aws_sdk_client_sns = require("@aws-sdk/client-sns");
|
|
26
|
+
let _aws_sdk_client_sqs = require("@aws-sdk/client-sqs");
|
|
27
|
+
let pg = require("pg");
|
|
28
|
+
let yaml = require("yaml");
|
|
29
|
+
let node_util = require("node:util");
|
|
30
|
+
let _geekmidas_cache_postgres = require("@geekmidas/cache/postgres");
|
|
31
|
+
//#region src/credentials/index.ts
|
|
32
|
+
const logger = console;
|
|
109
33
|
/**
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
* A surface and a site are served by processes `gkm dev` starts on the host,
|
|
113
|
-
* not by containers — so the edge has to leave Docker's network to reach them.
|
|
114
|
-
* Docker Desktop resolves this name already; on Linux the compose definition
|
|
115
|
-
* maps it to the host gateway.
|
|
34
|
+
* Load environment files
|
|
35
|
+
* @internal Exported for testing
|
|
116
36
|
*/
|
|
117
|
-
|
|
37
|
+
function loadEnvFiles(envConfig, cwd = process.cwd()) {
|
|
38
|
+
const loaded = [];
|
|
39
|
+
const missing = [];
|
|
40
|
+
const envFiles = envConfig ? Array.isArray(envConfig) ? envConfig : [envConfig] : [".env"];
|
|
41
|
+
for (const envFile of envFiles) {
|
|
42
|
+
const envPath = (0, node_path.resolve)(cwd, envFile);
|
|
43
|
+
if ((0, node_fs.existsSync)(envPath)) {
|
|
44
|
+
(0, dotenv.config)({
|
|
45
|
+
path: envPath,
|
|
46
|
+
override: true,
|
|
47
|
+
quiet: true
|
|
48
|
+
});
|
|
49
|
+
loaded.push(envFile);
|
|
50
|
+
} else if (envConfig) missing.push(envFile);
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
loaded,
|
|
54
|
+
missing
|
|
55
|
+
};
|
|
56
|
+
}
|
|
118
57
|
/**
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
* `.localhost` rather than a made-up TLD because it resolves to loopback
|
|
122
|
-
* without touching `/etc/hosts` — macOS and systemd-resolved both answer for
|
|
123
|
-
* subdomains of it, and Caddy issues internal certificates for it by default.
|
|
58
|
+
* Check if a port is available
|
|
59
|
+
* @internal Exported for testing
|
|
124
60
|
*/
|
|
125
|
-
|
|
61
|
+
async function isPortAvailable(port) {
|
|
62
|
+
return new Promise((resolve) => {
|
|
63
|
+
const server = (0, node_net.createServer)();
|
|
64
|
+
server.once("error", (err) => {
|
|
65
|
+
if (err.code === "EADDRINUSE") resolve(false);
|
|
66
|
+
else resolve(false);
|
|
67
|
+
});
|
|
68
|
+
server.once("listening", () => {
|
|
69
|
+
server.close();
|
|
70
|
+
resolve(true);
|
|
71
|
+
});
|
|
72
|
+
server.listen(port);
|
|
73
|
+
});
|
|
74
|
+
}
|
|
126
75
|
/**
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
* The leading label is the *server's* stage-scoped name rather than the
|
|
130
|
-
* bucket's, which is the difference that matters: two servers over one bucket
|
|
131
|
-
* are a legitimate arrangement — two cache behaviours, one origin — and naming
|
|
132
|
-
* the host after the bucket would make them collide.
|
|
76
|
+
* Find an available port starting from the preferred port
|
|
77
|
+
* @internal Exported for testing
|
|
133
78
|
*/
|
|
134
|
-
function
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
const host = hostFor(resource, project);
|
|
140
|
-
if (resource.kind === "file-server") {
|
|
141
|
-
const origin = resource.of ? byId.get(resource.of) : void 0;
|
|
142
|
-
if (!origin) continue;
|
|
143
|
-
sites.push({
|
|
144
|
-
host,
|
|
145
|
-
upstream: "http://minio:9000",
|
|
146
|
-
rewrite: `/${origin.name}{uri}`
|
|
147
|
-
});
|
|
148
|
-
continue;
|
|
149
|
-
}
|
|
150
|
-
const address = addresses[resource.id];
|
|
151
|
-
if (!address) continue;
|
|
152
|
-
const port = portOf(address);
|
|
153
|
-
if (!port) continue;
|
|
154
|
-
sites.push({
|
|
155
|
-
host,
|
|
156
|
-
upstream: `http://${HOST_GATEWAY}:${port}`
|
|
157
|
-
});
|
|
79
|
+
async function findAvailablePort(preferredPort, maxAttempts = 10) {
|
|
80
|
+
for (let i = 0; i < maxAttempts; i++) {
|
|
81
|
+
const port = preferredPort + i;
|
|
82
|
+
if (await isPortAvailable(port)) return port;
|
|
83
|
+
logger.log(`⚠️ Port ${port} is in use, trying ${port + 1}...`);
|
|
158
84
|
}
|
|
159
|
-
|
|
85
|
+
throw new Error(`Could not find an available port after trying ${maxAttempts} ports starting from ${preferredPort}`);
|
|
160
86
|
}
|
|
161
|
-
|
|
162
|
-
|
|
87
|
+
const PORT_STATE_PATH = ".gkm/ports.json";
|
|
88
|
+
/**
|
|
89
|
+
* Load saved port state from .gkm/ports.json.
|
|
90
|
+
* @internal Exported for testing
|
|
91
|
+
*/
|
|
92
|
+
async function loadPortState(workspaceRoot) {
|
|
163
93
|
try {
|
|
164
|
-
const
|
|
165
|
-
return
|
|
94
|
+
const raw = await (0, node_fs_promises.readFile)((0, node_path.join)(workspaceRoot, PORT_STATE_PATH), "utf-8");
|
|
95
|
+
return JSON.parse(raw);
|
|
166
96
|
} catch {
|
|
167
|
-
return
|
|
97
|
+
return {};
|
|
168
98
|
}
|
|
169
99
|
}
|
|
170
100
|
/**
|
|
171
|
-
*
|
|
172
|
-
*
|
|
173
|
-
* The project is a label rather than a decoration: it is what keeps two
|
|
174
|
-
* checkouts from answering on one address. Omitted when there is no project to
|
|
175
|
-
* name, because an empty label makes `uploads..localhost` — a host nothing
|
|
176
|
-
* resolves and no certificate can be issued for.
|
|
101
|
+
* Save port state to .gkm/ports.json.
|
|
102
|
+
* @internal Exported for testing
|
|
177
103
|
*/
|
|
178
|
-
function
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
LOCAL_TLD
|
|
183
|
-
].filter(Boolean).join(".");
|
|
104
|
+
async function savePortState(workspaceRoot, ports) {
|
|
105
|
+
const dir = (0, node_path.join)(workspaceRoot, ".gkm");
|
|
106
|
+
await (0, node_fs_promises.mkdir)(dir, { recursive: true });
|
|
107
|
+
await (0, node_fs_promises.writeFile)((0, node_path.join)(workspaceRoot, PORT_STATE_PATH), `${JSON.stringify(ports, null, 2)}\n`);
|
|
184
108
|
}
|
|
185
109
|
/**
|
|
186
|
-
*
|
|
187
|
-
*
|
|
188
|
-
*
|
|
189
|
-
* differ and they live in their own files. That split is not tidiness: one
|
|
190
|
-
* container serves every stage — the same way one Postgres holds `orders` and
|
|
191
|
-
* `orders_test` — so a single Caddyfile would mean `gkm test` deleting the
|
|
192
|
-
* routes `gkm dev` is serving, and each command silently breaking the other.
|
|
110
|
+
* Load and flatten secrets for an app from encrypted storage.
|
|
111
|
+
* For workspace app: maps {APP}_DATABASE_URL → DATABASE_URL.
|
|
112
|
+
* @internal Exported for testing
|
|
193
113
|
*/
|
|
194
|
-
function
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
114
|
+
async function loadSecretsForApp(store, stage, appName) {
|
|
115
|
+
let secrets = {};
|
|
116
|
+
const stageSecrets = await store.read(stage);
|
|
117
|
+
if (stageSecrets) {
|
|
118
|
+
logger.log(`🔐 Loading secrets from stage: ${stage}`);
|
|
119
|
+
secrets = require_storage.toEmbeddableSecrets(stageSecrets);
|
|
120
|
+
}
|
|
121
|
+
if (Object.keys(secrets).length === 0) return {};
|
|
122
|
+
if (!appName) return secrets;
|
|
123
|
+
const prefix = appName.toUpperCase();
|
|
124
|
+
const mapped = { ...secrets };
|
|
125
|
+
const appDbUrl = secrets[`${prefix}_DATABASE_URL`];
|
|
126
|
+
if (appDbUrl) mapped.DATABASE_URL = appDbUrl;
|
|
127
|
+
return mapped;
|
|
200
128
|
}
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
129
|
+
/**
|
|
130
|
+
* Walk up the directory tree to find the root containing .gkm/secrets/.
|
|
131
|
+
* @internal Exported for testing
|
|
132
|
+
*/
|
|
133
|
+
function findSecretsRoot(startDir) {
|
|
134
|
+
let dir = startDir;
|
|
135
|
+
while (dir !== "/") {
|
|
136
|
+
if ((0, node_fs.existsSync)((0, node_path.join)(dir, ".gkm", "secrets"))) return dir;
|
|
137
|
+
const parent = (0, node_path.dirname)(dir);
|
|
138
|
+
if (parent === dir) break;
|
|
139
|
+
dir = parent;
|
|
140
|
+
}
|
|
141
|
+
return startDir;
|
|
206
142
|
}
|
|
207
143
|
/**
|
|
208
|
-
*
|
|
209
|
-
*
|
|
210
|
-
*
|
|
211
|
-
* origin's business, and the client asks for the key it stored.
|
|
212
|
-
*
|
|
213
|
-
* `header_up Host {upstream_hostport}` matters more than it looks. MinIO routes
|
|
214
|
-
* and signs on the Host header, so forwarding the requested hostname would make
|
|
215
|
-
* it look for a bucket named after the domain.
|
|
144
|
+
* Generate the credentials injection code snippet.
|
|
145
|
+
* This is the common logic used by both entry wrapper and exec preload.
|
|
146
|
+
* @internal
|
|
216
147
|
*/
|
|
217
|
-
function
|
|
218
|
-
|
|
219
|
-
# No file server is declared in this stage, so it routes nothing.
|
|
220
|
-
`;
|
|
221
|
-
const blocks = sites.map(({ host, upstream, rewrite }) => `
|
|
222
|
-
https://${host} {
|
|
223
|
-
tls internal
|
|
148
|
+
function generateCredentialsInjection(secretsJsonPath) {
|
|
149
|
+
return `import { existsSync, readFileSync } from 'node:fs';
|
|
224
150
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
header_up Host {host}
|
|
234
|
-
header_up X-Forwarded-Proto {scheme}`}
|
|
235
|
-
}
|
|
236
|
-
}`);
|
|
237
|
-
return `${GENERATED}${blocks.join("\n")}\n`;
|
|
151
|
+
// Inject dev secrets via globalThis and process.env
|
|
152
|
+
// Using globalThis.__gkm_credentials__ avoids CJS/ESM interop issues where
|
|
153
|
+
// Object.assign on the Credentials export only mutates one module copy.
|
|
154
|
+
const secretsPath = '${secretsJsonPath}';
|
|
155
|
+
if (existsSync(secretsPath)) {
|
|
156
|
+
const secrets = JSON.parse(readFileSync(secretsPath, 'utf-8'));
|
|
157
|
+
globalThis.__gkm_credentials__ = secrets;
|
|
158
|
+
Object.assign(process.env, secrets);
|
|
238
159
|
}
|
|
239
|
-
const GENERATED = `# Generated by gkm from the construct manifest — do not edit.
|
|
240
|
-
#
|
|
241
|
-
# One host per declared file server, in front of the object store that holds its
|
|
242
|
-
# objects. This is the shape a file server has deployed — a domain serving a
|
|
243
|
-
# bucket — which MinIO alone cannot produce: its virtual-host mode reads the
|
|
244
|
-
# leading label as the bucket name.
|
|
245
|
-
#
|
|
246
|
-
# Certificates come from Caddy's own CA. "gkm dev" and "gkm test" export its
|
|
247
|
-
# root and point Node at it, so nothing has to be installed to use these URLs
|
|
248
|
-
# from code; a browser needs the root trusted once.
|
|
249
160
|
`;
|
|
250
|
-
|
|
251
|
-
//#endregion
|
|
252
|
-
//#region src/reconcile/clients.ts
|
|
253
|
-
/** The credential local containers are brought up with. */
|
|
254
|
-
const LOCAL_USER$2 = "geekmidas";
|
|
161
|
+
}
|
|
255
162
|
/**
|
|
256
|
-
*
|
|
257
|
-
*
|
|
258
|
-
*
|
|
259
|
-
* and a schema must be created from inside its own database — so the database is
|
|
260
|
-
* part of each query rather than fixed when the client is built.
|
|
163
|
+
* Create a preload script that injects secrets into Credentials.
|
|
164
|
+
* Used by `gkm exec` to inject secrets before running any command.
|
|
165
|
+
* @internal Exported for testing
|
|
261
166
|
*/
|
|
262
|
-
function
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
database: database ?? LOCAL_USER$2
|
|
270
|
-
});
|
|
271
|
-
await client.connect();
|
|
272
|
-
try {
|
|
273
|
-
const result = await client.query(sql, values);
|
|
274
|
-
return result.rows;
|
|
275
|
-
} finally {
|
|
276
|
-
await client.end();
|
|
277
|
-
}
|
|
278
|
-
} };
|
|
167
|
+
async function createCredentialsPreload(preloadPath, secretsJsonPath) {
|
|
168
|
+
const content = `/**
|
|
169
|
+
* Credentials preload generated by 'gkm exec'
|
|
170
|
+
* This file is loaded via NODE_OPTIONS="--import <path>"
|
|
171
|
+
*/
|
|
172
|
+
${generateCredentialsInjection(secretsJsonPath)}`;
|
|
173
|
+
await (0, node_fs_promises.writeFile)(preloadPath, content);
|
|
279
174
|
}
|
|
280
|
-
/**
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
175
|
+
/**
|
|
176
|
+
* Create a wrapper script that injects secrets before importing the entry file.
|
|
177
|
+
* @internal Exported for testing
|
|
178
|
+
*/
|
|
179
|
+
async function createEntryWrapper(wrapperPath, entryPath, secretsJsonPath) {
|
|
180
|
+
const content = `#!/usr/bin/env node
|
|
181
|
+
/**
|
|
182
|
+
* Entry wrapper generated by 'gkm dev --entry'
|
|
183
|
+
*/
|
|
184
|
+
${secretsJsonPath ? `${generateCredentialsInjection(secretsJsonPath)}
|
|
185
|
+
` : ""}// Import and run the user's entry file (dynamic import ensures secrets load first)
|
|
186
|
+
await import('${entryPath}');
|
|
187
|
+
`;
|
|
188
|
+
await (0, node_fs_promises.writeFile)(wrapperPath, content);
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Prepare credentials for dev/exec/test modes.
|
|
192
|
+
* Loads workspace config, secrets, resolves Docker ports, rewrites URLs,
|
|
193
|
+
* injects PORT, dependency URLs, and writes credentials JSON.
|
|
194
|
+
*
|
|
195
|
+
* @param options.stage - The stage whose secrets to load. Default: the project's `stages.local`.
|
|
196
|
+
* @param options.startDocker - Start Docker Compose services after port resolution. Default: false.
|
|
197
|
+
* @param options.secretsFileName - Custom secrets JSON filename. Default: 'dev-secrets-{appName}.json' or 'dev-secrets.json'.
|
|
198
|
+
* @internal Exported for testing
|
|
199
|
+
*/
|
|
200
|
+
async function prepareEntryCredentials(options) {
|
|
201
|
+
const cwd = options.cwd ?? process.cwd();
|
|
202
|
+
let workspaceAppPort;
|
|
203
|
+
let secretsRoot = cwd;
|
|
204
|
+
let appName;
|
|
205
|
+
let appInfo;
|
|
206
|
+
let workspace;
|
|
207
|
+
try {
|
|
208
|
+
appInfo = await require_config.loadWorkspaceAppInfo(cwd);
|
|
209
|
+
workspace = appInfo.workspace;
|
|
210
|
+
workspaceAppPort = appInfo.app.port;
|
|
211
|
+
secretsRoot = appInfo.workspaceRoot;
|
|
212
|
+
appName = appInfo.appName;
|
|
213
|
+
} catch (error) {
|
|
214
|
+
if (!(error instanceof require_config.NotInAnApp || error instanceof require_config.ConfigNotFound)) throw error;
|
|
215
|
+
workspace = await require_config.loadWorkspaceConfig(cwd).then((loaded) => loaded.workspace).catch(() => void 0);
|
|
216
|
+
secretsRoot = workspace?.root ?? findSecretsRoot(cwd);
|
|
217
|
+
}
|
|
218
|
+
if (appName && workspace && options.explicitPort === void 0) {
|
|
219
|
+
const { assignAppPorts, describeHolder, holderOf, withAppPorts } = await Promise.resolve().then(() => require("./index.cjs")).then((n) => n.appPorts_exports);
|
|
220
|
+
const assigned = await assignAppPorts(workspace, [appName], {
|
|
221
|
+
free: isPortAvailable,
|
|
222
|
+
holder: holderOf
|
|
223
|
+
});
|
|
224
|
+
for (const { app, from, to, holder } of assigned.moved) logger.log(`↪️ ${app}: ${from} is held by ${describeHolder(holder)}, which is not this workspace's — using ${to}`);
|
|
225
|
+
workspace = withAppPorts(workspace, assigned.ports);
|
|
226
|
+
workspaceAppPort = assigned.ports[appName] ?? workspaceAppPort;
|
|
227
|
+
}
|
|
228
|
+
if (appName) {
|
|
229
|
+
const { APP_TAG_ENV, appTag } = await Promise.resolve().then(() => require("./index.cjs")).then((n) => n.appPorts_exports);
|
|
230
|
+
process.env[APP_TAG_ENV] = appTag(secretsRoot, appName);
|
|
231
|
+
}
|
|
232
|
+
const resolvedPort = options.explicitPort ?? workspaceAppPort ?? 3e3;
|
|
233
|
+
const stage = options.stage ?? workspace?.stages.local;
|
|
234
|
+
const store = stage ? workspace ? await require_store.secretsStoreFor(workspace, stage) : new require_store.FileSecretsStore(secretsRoot) : void 0;
|
|
235
|
+
const credentials = store && stage ? await loadSecretsForApp(store, stage, appName) : {};
|
|
236
|
+
credentials.PORT = String(resolvedPort);
|
|
237
|
+
if (appInfo?.app.type === "mobile") credentials.RCT_METRO_PORT = String(resolvedPort);
|
|
238
|
+
const declaredKeys = [];
|
|
239
|
+
let reconciled;
|
|
240
|
+
if (workspace) {
|
|
241
|
+
const { reconcileWorkspace } = await Promise.resolve().then(() => workspace_exports);
|
|
242
|
+
reconciled = await reconcileWorkspace(workspace, {
|
|
243
|
+
stage: options.reconcileStage ?? workspace.stages.local,
|
|
244
|
+
start: options.startDocker ?? false
|
|
245
|
+
});
|
|
246
|
+
Object.assign(credentials, reconciled.env);
|
|
247
|
+
declaredKeys.push(...Object.keys(reconciled.env));
|
|
248
|
+
if (Object.keys(reconciled.env).length > 0) logger.log(`🔌 Resolved ${Object.keys(reconciled.env).length} declared URL(s)`);
|
|
249
|
+
}
|
|
250
|
+
const secretsDir = (0, node_path.join)(secretsRoot, ".gkm");
|
|
251
|
+
await (0, node_fs_promises.mkdir)(secretsDir, { recursive: true });
|
|
252
|
+
const secretsFileName = options.secretsFileName ?? (appName ? `dev-secrets-${appName}.json` : "dev-secrets.json");
|
|
253
|
+
const secretsJsonPath = (0, node_path.join)(secretsDir, secretsFileName);
|
|
254
|
+
await (0, node_fs_promises.writeFile)(secretsJsonPath, JSON.stringify(credentials, null, 2));
|
|
291
255
|
return {
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
}
|
|
300
|
-
async create(bucket) {
|
|
301
|
-
await s3.send(new __aws_sdk_client_s3.CreateBucketCommand({ Bucket: bucket }));
|
|
302
|
-
},
|
|
303
|
-
async policy(bucket) {
|
|
304
|
-
try {
|
|
305
|
-
const result = await s3.send(new __aws_sdk_client_s3.GetBucketPolicyCommand({ Bucket: bucket }));
|
|
306
|
-
return result.Policy;
|
|
307
|
-
} catch {
|
|
308
|
-
return void 0;
|
|
309
|
-
}
|
|
310
|
-
},
|
|
311
|
-
async setPolicy(bucket, policy) {
|
|
312
|
-
await s3.send(new __aws_sdk_client_s3.PutBucketPolicyCommand({
|
|
313
|
-
Bucket: bucket,
|
|
314
|
-
Policy: policy
|
|
315
|
-
}));
|
|
316
|
-
}
|
|
256
|
+
credentials,
|
|
257
|
+
resolvedPort,
|
|
258
|
+
secretsJsonPath,
|
|
259
|
+
appName,
|
|
260
|
+
secretsRoot,
|
|
261
|
+
appInfo,
|
|
262
|
+
declaredKeys,
|
|
263
|
+
...reconciled ? { reconciled } : {}
|
|
317
264
|
};
|
|
318
265
|
}
|
|
319
|
-
|
|
320
266
|
//#endregion
|
|
321
267
|
//#region src/reconcile/containers.ts
|
|
322
268
|
/**
|
|
@@ -348,8 +294,8 @@ function postgresImage(version) {
|
|
|
348
294
|
* per project: a project needing `postgis/postgis` says so in config.
|
|
349
295
|
*/
|
|
350
296
|
const DEFAULT_IMAGES = {
|
|
351
|
-
postgres: postgresImage(
|
|
352
|
-
minio: "
|
|
297
|
+
postgres: postgresImage(_geekmidas_manifest.DEFAULT_POSTGRES_VERSION),
|
|
298
|
+
minio: "pgsty/minio:RELEASE.2026-08-04T00-00-00Z",
|
|
353
299
|
mailpit: "axllent/mailpit:latest",
|
|
354
300
|
redis: "redis:8-alpine",
|
|
355
301
|
"redis-http": "hiett/serverless-redis-http:latest",
|
|
@@ -377,7 +323,8 @@ const PORTS = {
|
|
|
377
323
|
}, {
|
|
378
324
|
key: "minio-console",
|
|
379
325
|
inside: 9001,
|
|
380
|
-
label: "minio console"
|
|
326
|
+
label: "minio console",
|
|
327
|
+
web: true
|
|
381
328
|
}],
|
|
382
329
|
mailpit: [{
|
|
383
330
|
key: "mailpit",
|
|
@@ -386,7 +333,8 @@ const PORTS = {
|
|
|
386
333
|
}, {
|
|
387
334
|
key: "mailpit-web",
|
|
388
335
|
inside: 8025,
|
|
389
|
-
label: "mailpit inbox"
|
|
336
|
+
label: "mailpit inbox",
|
|
337
|
+
web: true
|
|
390
338
|
}],
|
|
391
339
|
redis: [{
|
|
392
340
|
key: "redis",
|
|
@@ -405,7 +353,8 @@ const PORTS = {
|
|
|
405
353
|
}, {
|
|
406
354
|
key: "rabbitmq-management",
|
|
407
355
|
inside: 15672,
|
|
408
|
-
label: "rabbitmq console"
|
|
356
|
+
label: "rabbitmq console",
|
|
357
|
+
web: true
|
|
409
358
|
}],
|
|
410
359
|
localstack: [{
|
|
411
360
|
key: "localstack",
|
|
@@ -418,10 +367,48 @@ const PORTS = {
|
|
|
418
367
|
label: "https edge"
|
|
419
368
|
}]
|
|
420
369
|
};
|
|
421
|
-
/** The
|
|
422
|
-
function
|
|
370
|
+
/** The port key — and container name, for an image — of an API's fake. */
|
|
371
|
+
function fakeKey(id) {
|
|
372
|
+
return `${(0, _geekmidas_manifest.kebabCase)(id)}-fake`;
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* The ports a container needs published. Empty for one gkm does not know.
|
|
376
|
+
*
|
|
377
|
+
* `fakes` answers for the containers no table can: an external API's fake
|
|
378
|
+
* listens wherever its declaration says.
|
|
379
|
+
*/
|
|
380
|
+
function portsOf(container, fakes = {}) {
|
|
381
|
+
const fake = fakes[container];
|
|
382
|
+
if (fake?.port !== void 0) return [{
|
|
383
|
+
key: container,
|
|
384
|
+
inside: fake.port,
|
|
385
|
+
label: `${fake.id} fake`
|
|
386
|
+
}];
|
|
423
387
|
return PORTS[container] ?? [];
|
|
424
388
|
}
|
|
389
|
+
/**
|
|
390
|
+
* Every port the containers publish — not only the one an app connects to.
|
|
391
|
+
*
|
|
392
|
+
* The consoles and the inbox are most of why these are real containers, and an
|
|
393
|
+
* inbox nobody can find is an inbox nobody opens: a sign-in link gets fished
|
|
394
|
+
* out of `docker ps` instead.
|
|
395
|
+
*/
|
|
396
|
+
function serviceAddresses(containers, ports, fakes = {}) {
|
|
397
|
+
return containers.flatMap((container) => portsOf(container, fakes).flatMap((port) => {
|
|
398
|
+
const assigned = ports[port.key];
|
|
399
|
+
if (assigned === void 0) return [];
|
|
400
|
+
return [{
|
|
401
|
+
container,
|
|
402
|
+
label: port.label,
|
|
403
|
+
address: port.web ? `http://localhost:${assigned}` : `localhost:${assigned}`
|
|
404
|
+
}];
|
|
405
|
+
}));
|
|
406
|
+
}
|
|
407
|
+
/** The lines `gkm dev` and `gkm setup` print under the services heading. */
|
|
408
|
+
function describeServices(services) {
|
|
409
|
+
const width = Math.max(0, ...services.map(({ label }) => label.length));
|
|
410
|
+
return services.map(({ label, address }) => ` ${label.padEnd(width)} ${address}`);
|
|
411
|
+
}
|
|
425
412
|
/** The key a container's primary port is allocated under. */
|
|
426
413
|
function primaryPortKey(container) {
|
|
427
414
|
return portsOf(container)[0]?.key ?? container;
|
|
@@ -432,8 +419,9 @@ function primaryPortKey(container) {
|
|
|
432
419
|
* What allocation is handed: it assigns ports to names and knows nothing about
|
|
433
420
|
* what listens on them.
|
|
434
421
|
*/
|
|
435
|
-
function portKeys(containers) {
|
|
436
|
-
|
|
422
|
+
function portKeys(containers, fakes = {}) {
|
|
423
|
+
const keys = [...containers].sort().flatMap((container) => portsOf(container, fakes).map((port) => port.key));
|
|
424
|
+
return [.../* @__PURE__ */ new Set([...keys, ...Object.keys(fakes).sort()])];
|
|
437
425
|
}
|
|
438
426
|
/**
|
|
439
427
|
* The named volume a container's data lives in.
|
|
@@ -442,945 +430,1705 @@ function portKeys(containers) {
|
|
|
442
430
|
* survives days of dev is noise rather than state.
|
|
443
431
|
*/
|
|
444
432
|
function volumeOf(container) {
|
|
445
|
-
|
|
433
|
+
return {
|
|
446
434
|
postgres: "postgres-data",
|
|
447
435
|
minio: "minio-data",
|
|
448
436
|
redis: "redis-data",
|
|
449
437
|
rabbitmq: "rabbitmq-data",
|
|
450
438
|
localstack: "localstack-data",
|
|
451
439
|
caddy: "caddy-data"
|
|
452
|
-
};
|
|
453
|
-
return volumes[container];
|
|
440
|
+
}[container];
|
|
454
441
|
}
|
|
455
|
-
|
|
456
442
|
//#endregion
|
|
457
|
-
//#region src/reconcile/
|
|
458
|
-
/** The credential every derived container is brought up with locally. */
|
|
459
|
-
const LOCAL_USER$1 = "geekmidas";
|
|
443
|
+
//#region src/reconcile/caddyfile.ts
|
|
460
444
|
/**
|
|
461
|
-
* The
|
|
445
|
+
* The kinds the edge serves.
|
|
462
446
|
*
|
|
463
|
-
*
|
|
464
|
-
*
|
|
465
|
-
*
|
|
447
|
+
* Everything that owns a *public address*. Deployed, each of these has a real
|
|
448
|
+
* hostname and a certificate, so this is what makes the local shape the same
|
|
449
|
+
* one rather than a near-enough one — and the application is indifferent
|
|
450
|
+
* either way, because it reads whichever address was injected and never
|
|
451
|
+
* composes one.
|
|
452
|
+
*
|
|
453
|
+
* Adding a kind here is the whole of adding it to the edge.
|
|
466
454
|
*/
|
|
467
|
-
const
|
|
455
|
+
const EDGE_KINDS = {
|
|
456
|
+
"file-server": true,
|
|
457
|
+
"rest-api": true,
|
|
458
|
+
site: true
|
|
459
|
+
};
|
|
468
460
|
/**
|
|
469
|
-
*
|
|
461
|
+
* How the edge reaches the host, from inside its container.
|
|
470
462
|
*
|
|
471
|
-
*
|
|
472
|
-
*
|
|
473
|
-
*
|
|
463
|
+
* A surface and a site are served by processes `gkm dev` starts on the host,
|
|
464
|
+
* not by containers — so the edge has to leave Docker's network to reach them.
|
|
465
|
+
* Docker Desktop resolves this name already; on Linux the compose definition
|
|
466
|
+
* maps it to the host gateway.
|
|
474
467
|
*/
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
468
|
+
const HOST_GATEWAY = "host.docker.internal";
|
|
469
|
+
/**
|
|
470
|
+
* The suffix every local host shares.
|
|
471
|
+
*
|
|
472
|
+
* `.localhost` rather than a made-up TLD because it resolves to loopback
|
|
473
|
+
* without touching `/etc/hosts` — macOS and systemd-resolved both answer for
|
|
474
|
+
* subdomains of it, and Caddy issues internal certificates for it by default.
|
|
475
|
+
*/
|
|
476
|
+
const LOCAL_TLD = "localhost";
|
|
477
|
+
/**
|
|
478
|
+
* The sites a plan implies, one per file server.
|
|
479
|
+
*
|
|
480
|
+
* The leading label is the *server's* stage-scoped name rather than the
|
|
481
|
+
* bucket's, which is the difference that matters: two servers over one bucket
|
|
482
|
+
* are a legitimate arrangement — two cache behaviours, one origin — and naming
|
|
483
|
+
* the host after the bucket would make them collide.
|
|
484
|
+
*/
|
|
485
|
+
function sitesFor(plan, project, addresses = {}) {
|
|
486
|
+
const byId = new Map(plan.resources.map((r) => [r.id, r]));
|
|
487
|
+
const sites = [];
|
|
488
|
+
for (const resource of plan.resources) {
|
|
489
|
+
if (!EDGE_KINDS[resource.kind]) continue;
|
|
490
|
+
const host = hostFor(resource, project);
|
|
491
|
+
if (resource.kind === "file-server") {
|
|
492
|
+
const origin = resource.of ? byId.get(resource.of) : void 0;
|
|
493
|
+
if (!origin) continue;
|
|
494
|
+
sites.push({
|
|
495
|
+
host,
|
|
496
|
+
upstream: "http://minio:9000",
|
|
497
|
+
rewrite: `/${origin.name}{uri}`
|
|
498
|
+
});
|
|
499
|
+
continue;
|
|
500
|
+
}
|
|
501
|
+
const address = addresses[resource.id];
|
|
502
|
+
if (!address) continue;
|
|
503
|
+
const port = portOf(address);
|
|
504
|
+
if (!port) continue;
|
|
505
|
+
sites.push({
|
|
506
|
+
host,
|
|
507
|
+
upstream: `http://${HOST_GATEWAY}:${port}`
|
|
508
|
+
});
|
|
485
509
|
}
|
|
486
|
-
return
|
|
487
|
-
name: options.project,
|
|
488
|
-
services,
|
|
489
|
-
...Object.keys(volumes).length ? { volumes } : {}
|
|
490
|
-
};
|
|
491
|
-
}
|
|
492
|
-
/** Render a compose document as the file it becomes. */
|
|
493
|
-
function toYaml(file) {
|
|
494
|
-
return `# Generated by gkm from the construct manifest — do not edit.
|
|
495
|
-
# Containers are derived from what the app declares; images and anything no
|
|
496
|
-
# construct implies are yours, in gkm.config.ts.
|
|
497
|
-
#
|
|
498
|
-
# Use "gkm dev" or "gkm test" to start these. Running "docker compose up"
|
|
499
|
-
# directly will not inject secrets.
|
|
500
|
-
${(0, yaml.stringify)(file, { lineWidth: 0 })}`;
|
|
510
|
+
return sites;
|
|
501
511
|
}
|
|
502
|
-
/**
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
super("No image is known for this container; pin one in config");
|
|
510
|
-
this.name = "UnknownContainer";
|
|
511
|
-
this.container = container;
|
|
512
|
+
/** The port a local address answers on, defaulting by scheme. */
|
|
513
|
+
function portOf(address) {
|
|
514
|
+
try {
|
|
515
|
+
const { port, protocol } = new URL(address);
|
|
516
|
+
return port || (protocol === "https:" ? "443" : "80");
|
|
517
|
+
} catch {
|
|
518
|
+
return;
|
|
512
519
|
}
|
|
513
|
-
}
|
|
514
|
-
/**
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
520
|
+
}
|
|
521
|
+
/**
|
|
522
|
+
* Where one file server answers, including the stage its name carries.
|
|
523
|
+
*
|
|
524
|
+
* The project is a label rather than a decoration: it is what keeps two
|
|
525
|
+
* checkouts from answering on one address. Omitted when there is no project to
|
|
526
|
+
* name, because an empty label makes `uploads..localhost` — a host nothing
|
|
527
|
+
* resolves and no certificate can be issued for.
|
|
528
|
+
*/
|
|
529
|
+
function hostFor(resource, project) {
|
|
530
|
+
return [
|
|
531
|
+
resource.root && project ? stageOf(resource) : resource.name,
|
|
532
|
+
project,
|
|
533
|
+
LOCAL_TLD
|
|
534
|
+
].filter(Boolean).join(".");
|
|
535
|
+
}
|
|
536
|
+
/** The stage a resource's name carries, or nothing for the local stage's. */
|
|
537
|
+
function stageOf(resource) {
|
|
538
|
+
const base = resource.id.toLowerCase();
|
|
539
|
+
return resource.name === base ? void 0 : resource.name.slice(base.length + 1);
|
|
540
|
+
}
|
|
541
|
+
/**
|
|
542
|
+
* The static root config, which only ever imports.
|
|
543
|
+
*
|
|
544
|
+
* Written once and identical for every stage, because the *sites* are what
|
|
545
|
+
* differ and they live in their own files. That split is not tidiness: one
|
|
546
|
+
* container serves every stage — the same way one Postgres holds `orders` and
|
|
547
|
+
* `orders_test` — so a single Caddyfile would mean `gkm test` deleting the
|
|
548
|
+
* routes `gkm dev` is serving, and each command silently breaking the other.
|
|
549
|
+
*/
|
|
550
|
+
function caddyfileRoot() {
|
|
551
|
+
return `${GENERATED}
|
|
552
|
+
{
|
|
553
|
+
# No ACME, no public DNS: the CA is local and so are the names.
|
|
554
|
+
local_certs
|
|
555
|
+
auto_https disable_redirects
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
# One file per stage, so two stages share this edge the way they already share
|
|
559
|
+
# one Postgres and one MinIO.
|
|
560
|
+
import /etc/caddy/sites/*.caddy
|
|
561
|
+
`;
|
|
562
|
+
}
|
|
563
|
+
/**
|
|
564
|
+
* One stage's sites, as the file imported above.
|
|
565
|
+
*
|
|
566
|
+
* `rewrite` rather than a path prefix on the address: the bucket is the
|
|
567
|
+
* origin's business, and the client asks for the key it stored.
|
|
568
|
+
*
|
|
569
|
+
* `header_up Host {upstream_hostport}` matters more than it looks. MinIO routes
|
|
570
|
+
* and signs on the Host header, so forwarding the requested hostname would make
|
|
571
|
+
* it look for a bucket named after the domain.
|
|
572
|
+
*/
|
|
573
|
+
function toCaddyfile(sites) {
|
|
574
|
+
if (sites.length === 0) return `${GENERATED}
|
|
575
|
+
# No file server is declared in this stage, so it routes nothing.
|
|
576
|
+
`;
|
|
577
|
+
const blocks = sites.map(({ host, upstream, rewrite }) => `
|
|
578
|
+
https://${host} {
|
|
579
|
+
tls internal
|
|
580
|
+
|
|
581
|
+
reverse_proxy ${upstream} {${rewrite ? `
|
|
582
|
+
rewrite ${rewrite}
|
|
583
|
+
# MinIO routes and signs on the Host header, so forwarding the requested
|
|
584
|
+
# hostname would make it look for a bucket named after the domain.
|
|
585
|
+
header_up Host {upstream_hostport}` : `
|
|
586
|
+
# The application reads whatever address was injected, so it has to see
|
|
587
|
+
# the one a caller used — that is what makes a redirect, a cookie domain
|
|
588
|
+
# and a generated link point back here rather than at the upstream.
|
|
589
|
+
header_up Host {host}
|
|
590
|
+
header_up X-Forwarded-Proto {scheme}`}
|
|
591
|
+
}
|
|
592
|
+
}`);
|
|
593
|
+
return `${GENERATED}${blocks.join("\n")}\n`;
|
|
594
|
+
}
|
|
595
|
+
const GENERATED = `# Generated by gkm from the construct manifest — do not edit.
|
|
596
|
+
#
|
|
597
|
+
# One host per declared file server, in front of the object store that holds its
|
|
598
|
+
# objects. This is the shape a file server has deployed — a domain serving a
|
|
599
|
+
# bucket — which MinIO alone cannot produce: its virtual-host mode reads the
|
|
600
|
+
# leading label as the bucket name.
|
|
601
|
+
#
|
|
602
|
+
# Certificates come from Caddy's own CA. "gkm dev" and "gkm test" export its
|
|
603
|
+
# root and point Node at it, so nothing has to be installed to use these URLs
|
|
604
|
+
# from code; a browser needs the root trusted once.
|
|
605
|
+
`;
|
|
606
|
+
//#endregion
|
|
607
|
+
//#region src/reconcile/emulator.ts
|
|
608
|
+
/**
|
|
609
|
+
* The AWS emulator (floci, LocalStack-compatible) the `sns` backend runs on
|
|
610
|
+
* locally — the facts the compose file, the env writer and the applier must
|
|
611
|
+
* agree on.
|
|
612
|
+
*
|
|
613
|
+
* The emulator has one account and answers with deterministic ARNs and queue
|
|
614
|
+
* URLs, which is what lets a connection string be composed before the topic
|
|
615
|
+
* or queue it names has been created.
|
|
616
|
+
*/
|
|
617
|
+
/** The emulator's single account. */
|
|
618
|
+
const EMULATOR_ACCOUNT = "000000000000";
|
|
619
|
+
const EMULATOR_REGION = "us-east-1";
|
|
620
|
+
/**
|
|
621
|
+
* The emulator's credential. The `LSIA` prefix is what LocalStack required on
|
|
622
|
+
* issued keys; floci does not care, and keeping it means a project that pins
|
|
623
|
+
* the old image still works.
|
|
624
|
+
*/
|
|
625
|
+
const EMULATOR_CREDENTIALS = {
|
|
626
|
+
accessKeyId: "LSIAQAAAAAAVNCBMPNSG",
|
|
627
|
+
secretAccessKey: "geekmidas"
|
|
628
|
+
};
|
|
629
|
+
/** The emulator's address from the host, on the port it was published on. */
|
|
630
|
+
function emulatorEndpoint(port) {
|
|
631
|
+
return `http://localhost:${port}`;
|
|
632
|
+
}
|
|
633
|
+
function emulatorTopicArn(name) {
|
|
634
|
+
return `arn:aws:sns:${EMULATOR_REGION}:${EMULATOR_ACCOUNT}:${name}`;
|
|
635
|
+
}
|
|
636
|
+
function emulatorQueueUrl(name, port) {
|
|
637
|
+
return `${emulatorEndpoint(port)}/${EMULATOR_ACCOUNT}/${name}`;
|
|
638
|
+
}
|
|
639
|
+
//#endregion
|
|
640
|
+
//#region src/workspace/rootSite.ts
|
|
641
|
+
/**
|
|
642
|
+
* Which site the base domain points at — deployed and locally alike.
|
|
643
|
+
*
|
|
644
|
+
* Three rules, in order, and the last one is the point:
|
|
645
|
+
*
|
|
646
|
+
* 1. **One site** — it is the root. Unambiguous, so nothing has to be said.
|
|
647
|
+
* 2. **Named `web`** — the convention wins, because people already rely on it.
|
|
648
|
+
* 3. **Declared `root: true`** — the site says so itself.
|
|
649
|
+
*
|
|
650
|
+
* Anything else throws. It used to take the *first* site it iterated, and that
|
|
651
|
+
* order came from the manifest, which is built in glob traversal order — so two
|
|
652
|
+
* sites with neither named `web` meant renaming a file could move the root
|
|
653
|
+
* domain, silently.
|
|
654
|
+
*
|
|
655
|
+
* One rule for both targets: deployed the root site gets the base domain, and
|
|
656
|
+
* locally it gets the project's bare host behind the edge. Before this was
|
|
657
|
+
* shared, the local edge put every site on a subdomain, so what a developer
|
|
658
|
+
* browsed was not the shape production served.
|
|
659
|
+
*
|
|
660
|
+
* @returns the root site's name, or `undefined` when there are no sites
|
|
661
|
+
* @throws {AmbiguousRootSite} when several sites could be the root and none says it is
|
|
662
|
+
*/
|
|
663
|
+
function rootSite(sites) {
|
|
664
|
+
if (sites.length === 0) return void 0;
|
|
665
|
+
if (sites.length === 1) return sites[0].name;
|
|
666
|
+
if (sites.some(({ name }) => name === "web")) return "web";
|
|
667
|
+
const declared = sites.filter(({ root }) => root === true);
|
|
668
|
+
if (declared.length === 1) return declared[0].name;
|
|
669
|
+
throw new AmbiguousRootSite(sites.map(({ name }) => name), declared.length > 1);
|
|
670
|
+
}
|
|
671
|
+
/** Several sites could hold the base domain, and none of them says it does. */
|
|
672
|
+
var AmbiguousRootSite = class extends Error {
|
|
673
|
+
sites;
|
|
674
|
+
tooMany;
|
|
675
|
+
constructor(sites, tooMany = false) {
|
|
676
|
+
super(tooMany ? `More than one site declares \`root: true\` — ${sites.join(", ")}. The base domain points at one of them.` : `${sites.length} sites and nothing says which holds the base domain: ${sites.join(", ")}. Name one of them \`web\`, or declare \`root: true\` on the one the base domain points at. It used to be whichever the glob reached first, which is not a thing to decide a hostname.`);
|
|
677
|
+
this.sites = sites;
|
|
678
|
+
this.tooMany = tooMany;
|
|
679
|
+
this.name = "AmbiguousRootSite";
|
|
680
|
+
}
|
|
681
|
+
};
|
|
682
|
+
//#endregion
|
|
683
|
+
//#region src/reconcile/plan.ts
|
|
684
|
+
/**
|
|
685
|
+
* The reconcile plan — what a manifest wants to exist, for one stage.
|
|
686
|
+
*
|
|
687
|
+
* Pure. Turning the plan into running containers and provisioned resources is
|
|
688
|
+
* the applier's job; deciding *what* should exist is this, so the decisions can
|
|
689
|
+
* be asserted as data rather than by starting Docker.
|
|
690
|
+
*
|
|
691
|
+
* One plan serves every stage. `gkm dev` reconciles `development` and `gkm test`
|
|
692
|
+
* reconciles `test`; they differ only in what the resources are called, never in
|
|
693
|
+
* what infrastructure exists. Roles are cluster-scoped in Postgres while grants
|
|
694
|
+
* are per-object, so one container and one role pair serve both.
|
|
695
|
+
*/
|
|
696
|
+
/**
|
|
697
|
+
* Which container serves a kind.
|
|
698
|
+
*
|
|
699
|
+
* Derived kinds map to the same container as their parent — a schema tenant
|
|
700
|
+
* lives in its parent's Postgres — so the set is deduplicated rather than
|
|
701
|
+
* counted.
|
|
702
|
+
*/
|
|
703
|
+
const CONTAINERS = {
|
|
704
|
+
database: "postgres",
|
|
705
|
+
"database-reader": "postgres",
|
|
706
|
+
"database-schema": "postgres",
|
|
707
|
+
objects: "minio",
|
|
708
|
+
"file-server": "caddy",
|
|
709
|
+
email: "mailpit"
|
|
710
|
+
};
|
|
711
|
+
/**
|
|
712
|
+
* The container a cache backend needs locally.
|
|
713
|
+
*
|
|
714
|
+
* Each one matches the protocol its deployed form speaks, which is the property
|
|
715
|
+
* worth having: a cache that behaves differently in the two places is worse than
|
|
716
|
+
* a slower one.
|
|
717
|
+
*
|
|
718
|
+
* `db` is deliberately absent, the same way `pgboss` is absent from
|
|
719
|
+
* `EVENT_CONTAINERS`: the cache is a table in a database the manifest already
|
|
720
|
+
* declares, so mapping it here would start a container for a project that needs
|
|
721
|
+
* none.
|
|
722
|
+
*/
|
|
723
|
+
const CACHE_CONTAINERS = {
|
|
724
|
+
upstash: "redis-http",
|
|
725
|
+
elasticache: "redis"
|
|
726
|
+
};
|
|
727
|
+
/**
|
|
728
|
+
* Kinds that resolve a value without anything running.
|
|
729
|
+
*
|
|
730
|
+
* A secret is the case: it has no address, so there is nothing to start and
|
|
731
|
+
* nothing to connect to — but it still appears in the plan, because the target
|
|
732
|
+
* still has to resolve it.
|
|
733
|
+
*/
|
|
734
|
+
const CONTAINERLESS = {
|
|
735
|
+
secret: true,
|
|
736
|
+
credential: true,
|
|
737
|
+
encryption: true,
|
|
738
|
+
"rest-api": true,
|
|
739
|
+
site: true,
|
|
740
|
+
"mobile-app": true,
|
|
741
|
+
"external-api": true
|
|
742
|
+
};
|
|
743
|
+
/**
|
|
744
|
+
* Containers that cannot run alone.
|
|
745
|
+
*
|
|
746
|
+
* The one case is the cache: `serverless-redis-http` is a proxy and needs the
|
|
747
|
+
* Redis it proxies. Kept here rather than in the compose definition so the plan
|
|
748
|
+
* -- which is what decides what must be running -- still names everything.
|
|
749
|
+
*/
|
|
750
|
+
const REQUIRES = { "redis-http": ["redis"] };
|
|
751
|
+
/**
|
|
752
|
+
* The role each kind's one key plays, where it is not a URL.
|
|
753
|
+
*
|
|
754
|
+
* The twin of `ProvidesByKind` in `@geekmidas/manifest`: that is what a
|
|
755
|
+
* construct declares, this is what the local target resolves, and both derive
|
|
756
|
+
* the key from the same `provideKey` so they cannot disagree.
|
|
757
|
+
*/
|
|
758
|
+
const ROLES = {
|
|
759
|
+
queue: "publisherConnectionString",
|
|
760
|
+
topic: "publisherConnectionString",
|
|
761
|
+
credential: "credentials",
|
|
762
|
+
"mobile-app": "scheme"
|
|
763
|
+
};
|
|
764
|
+
/** The kinds whose container is the events backend's rather than their own. */
|
|
765
|
+
const EVENT_KINDS = {
|
|
766
|
+
queue: true,
|
|
767
|
+
topic: true
|
|
768
|
+
};
|
|
769
|
+
/**
|
|
770
|
+
* Which kinds provision something *inside* their container.
|
|
771
|
+
*
|
|
772
|
+
* A database creates a database, a bucket creates a bucket; mail creates
|
|
773
|
+
* nothing — Mailpit accepts whatever is sent to it and has no per-stage object
|
|
774
|
+
* to name. Both still appear in the plan, because both still resolve a URL; the
|
|
775
|
+
* flag is the difference between "must be running" and "must be created".
|
|
776
|
+
*/
|
|
777
|
+
const PROVISIONS = {
|
|
778
|
+
database: true,
|
|
779
|
+
"database-reader": true,
|
|
780
|
+
"database-schema": true,
|
|
781
|
+
objects: true,
|
|
782
|
+
cache: true,
|
|
783
|
+
"file-server": true
|
|
784
|
+
};
|
|
785
|
+
/**
|
|
786
|
+
* The container each events backend needs, where it needs one of its own.
|
|
787
|
+
*
|
|
788
|
+
* `pgboss` is deliberately absent rather than mapped to `postgres`: it is a
|
|
789
|
+
* schema tenant in a database the manifest already declares, so mapping it here
|
|
790
|
+
* would start a Postgres for a project that declared no database at all.
|
|
791
|
+
*
|
|
792
|
+
* This one comes from config rather than from a declaration because there are
|
|
793
|
+
* no `topic` or `queue` kinds yet. When they land the mapping moves to
|
|
794
|
+
* {@link CONTAINERS} keyed by kind, and this constant goes with them.
|
|
795
|
+
*/
|
|
796
|
+
const EVENT_CONTAINERS = {
|
|
797
|
+
sns: "localstack",
|
|
798
|
+
rabbitmq: "rabbitmq"
|
|
799
|
+
};
|
|
800
|
+
/** The backend a project gets when it declares queues or topics and says nothing. */
|
|
801
|
+
const DEFAULT_EVENTS = "pgboss";
|
|
802
|
+
/**
|
|
803
|
+
* How a resource of each kind separates its stage suffix.
|
|
804
|
+
*
|
|
805
|
+
* Postgres identifiers are snake_case and a hyphen would need quoting
|
|
806
|
+
* everywhere; buckets and queues are kebab and disallow underscores in some
|
|
807
|
+
* providers. The suffix is the same word either way.
|
|
808
|
+
*/
|
|
809
|
+
const SEPARATORS = {
|
|
810
|
+
database: "_",
|
|
811
|
+
"database-reader": "_",
|
|
812
|
+
"database-schema": "_",
|
|
813
|
+
objects: "-"
|
|
814
|
+
};
|
|
815
|
+
/**
|
|
816
|
+
* The stage-scoped name for a resource.
|
|
817
|
+
*
|
|
818
|
+
* The local stage carries no suffix, so `gkm dev` keeps using `orders` and a
|
|
819
|
+
* developer's psql history, saved connections, and muscle memory survive a
|
|
820
|
+
* change of stage name. Every other stage is suffixed.
|
|
821
|
+
*/
|
|
822
|
+
function resourceName(id, kind, stage, localStage) {
|
|
823
|
+
const base = id.toLowerCase();
|
|
824
|
+
if (stage === localStage) return base;
|
|
825
|
+
return `${base}${SEPARATORS[kind] ?? "-"}${stage}`;
|
|
826
|
+
}
|
|
827
|
+
/**
|
|
828
|
+
* The container a kind needs, or `undefined` if it needs none.
|
|
829
|
+
*
|
|
830
|
+
* Queues and topics have no container of their own — they live in whichever
|
|
831
|
+
* broker the project selected, which is why the backend is an argument here
|
|
832
|
+
* rather than a second pass that adds containers after the fact.
|
|
833
|
+
*/
|
|
834
|
+
function containerFor(kind, events = DEFAULT_EVENTS, cache = require_ready.DEFAULT_CACHE.aws, derived = false, edge = true) {
|
|
835
|
+
if (EVENT_KINDS[kind]) return EVENT_CONTAINERS[events] ?? CONTAINERS.database;
|
|
836
|
+
if (kind === "file-server") return edge ? "caddy" : CONTAINERS.objects;
|
|
837
|
+
if (kind === "cache") {
|
|
838
|
+
if (derived) return CONTAINERS.database;
|
|
839
|
+
return CACHE_CONTAINERS[cache] ?? CONTAINERS.database;
|
|
840
|
+
}
|
|
841
|
+
return CONTAINERS[kind];
|
|
842
|
+
}
|
|
843
|
+
/**
|
|
844
|
+
* Build the plan for a manifest and stage.
|
|
845
|
+
*
|
|
846
|
+
* `order` is the caller's provisioning order — parents before children — which
|
|
847
|
+
* `provisionOrder` produces from the manifest. Passing it in keeps this
|
|
848
|
+
* function free of the traversal and makes the ordering assertable on its own.
|
|
849
|
+
*/
|
|
850
|
+
function planFor(manifest, stage, order, options = {}) {
|
|
851
|
+
const containers = /* @__PURE__ */ new Set();
|
|
852
|
+
const resources = [];
|
|
853
|
+
const fakes = {};
|
|
854
|
+
const events = options.events ?? "pgboss";
|
|
855
|
+
const cache = options.cache ?? require_ready.DEFAULT_CACHE.aws;
|
|
856
|
+
for (const id of order) {
|
|
857
|
+
const declaration = manifest[id];
|
|
858
|
+
if (!declaration) continue;
|
|
859
|
+
const local = declaration.kind === "external-api" ? options.fakes?.[id] : void 0;
|
|
860
|
+
const fake = local && {
|
|
861
|
+
key: fakeKey(id),
|
|
862
|
+
...local
|
|
660
863
|
};
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
AWS_ACCESS_KEY_ID: "LSIAQAAAAAAVNCBMPNSG",
|
|
668
|
-
AWS_SECRET_ACCESS_KEY: LOCAL_USER$1
|
|
669
|
-
},
|
|
670
|
-
volumes: ["localstack-data:/var/lib/localstack"],
|
|
671
|
-
healthcheck: {
|
|
672
|
-
test: [
|
|
673
|
-
"CMD",
|
|
674
|
-
"curl",
|
|
675
|
-
"-f",
|
|
676
|
-
"http://localhost:4566/_localstack/health"
|
|
677
|
-
],
|
|
678
|
-
interval: "10s",
|
|
679
|
-
timeout: "5s",
|
|
680
|
-
retries: 5,
|
|
681
|
-
start_period: "10s"
|
|
682
|
-
}
|
|
864
|
+
if (fake) fakes[fake.key] = {
|
|
865
|
+
id,
|
|
866
|
+
...fake.image ? {
|
|
867
|
+
image: fake.image,
|
|
868
|
+
port: fake.port
|
|
869
|
+
} : {}
|
|
683
870
|
};
|
|
684
|
-
|
|
871
|
+
const container = fake?.image ? fake.key : containerFor(declaration.kind, events, cache, "of" in declaration && typeof declaration.of === "string", options.edge !== false);
|
|
872
|
+
if (!container && !CONTAINERLESS[declaration.kind]) continue;
|
|
873
|
+
if (container) {
|
|
874
|
+
containers.add(container);
|
|
875
|
+
for (const required of REQUIRES[container] ?? []) containers.add(required);
|
|
876
|
+
}
|
|
877
|
+
resources.push({
|
|
878
|
+
id,
|
|
879
|
+
kind: declaration.kind,
|
|
880
|
+
...container ? { container } : {},
|
|
881
|
+
name: resourceName(id, declaration.kind, stage, options.localStage),
|
|
882
|
+
envKey: (0, _geekmidas_manifest.providedKeyFor)(id, declaration.kind, ROLES[declaration.kind] ?? "url"),
|
|
883
|
+
provisions: PROVISIONS[declaration.kind] === true,
|
|
884
|
+
...declaration.kind === "rest-api" ? { callers: (0, _geekmidas_manifest.dependentsOf)(manifest, id) } : {},
|
|
885
|
+
...declaration.kind === "site" ? { publicEnv: (0, _geekmidas_manifest.publicEnvFor)(declaration, manifest) } : {},
|
|
886
|
+
...declaration.kind === "mobile-app" ? {
|
|
887
|
+
publicEnv: (0, _geekmidas_manifest.publicEnvFor)(declaration, manifest),
|
|
888
|
+
...declaration.scheme ? { scheme: declaration.scheme } : {}
|
|
889
|
+
} : {},
|
|
890
|
+
...declaration.kind === "file-server" && declaration.open?.length ? { open: declaration.open } : {},
|
|
891
|
+
...fake ? { fake: {
|
|
892
|
+
key: fake.key,
|
|
893
|
+
credentials: fake.credentials
|
|
894
|
+
} } : {},
|
|
895
|
+
...declaration.kind === "external-api" && !fake ? { url: declaration.url } : {},
|
|
896
|
+
..."of" in declaration ? { of: declaration.of } : {},
|
|
897
|
+
..."schema" in declaration && declaration.schema ? { schema: declaration.schema } : {},
|
|
898
|
+
..."version" in declaration && declaration.version ? { version: declaration.version } : {},
|
|
899
|
+
..."roles" in declaration && declaration.roles === false ? { roles: false } : {},
|
|
900
|
+
..."table" in declaration && declaration.table ? { table: declaration.table } : {}
|
|
901
|
+
});
|
|
902
|
+
}
|
|
903
|
+
if (options.edge !== false && resources.some((r) => EDGE_KINDS[r.kind] === true)) containers.add("caddy");
|
|
904
|
+
for (const extra of options.extraContainers ?? []) containers.add(extra);
|
|
905
|
+
if (events === "pgboss" && resources.some((r) => EVENT_KINDS[r.kind]) && !resources.some((r) => r.kind === "database")) throw new PgBossNeedsDatabase(resources.filter((r) => EVENT_KINDS[r.kind]).map((r) => r.id));
|
|
906
|
+
if (cache === "db") {
|
|
907
|
+
const placeless = resources.filter((r) => r.kind === "cache" && !r.of);
|
|
908
|
+
if (placeless.length > 0) {
|
|
909
|
+
const databases = resources.filter((r) => r.kind === "database");
|
|
910
|
+
const [only] = databases;
|
|
911
|
+
if (!only) throw new CacheNeedsDatabase(resources.filter((r) => r.kind === "cache").map((r) => r.id));
|
|
912
|
+
if (databases.length > 1) throw new CacheIsAmbiguous(placeless.map((r) => r.id), databases.map((r) => r.id));
|
|
913
|
+
for (const resource of placeless) resource.of = only.id;
|
|
914
|
+
}
|
|
685
915
|
}
|
|
916
|
+
const sites = resources.filter((r) => r.kind === "site");
|
|
917
|
+
const root = rootSite(sites.map((r) => {
|
|
918
|
+
const declared = manifest[r.id];
|
|
919
|
+
return {
|
|
920
|
+
name: require_config.appKey(r.id),
|
|
921
|
+
...declared?.kind === "site" && declared.root ? { root: true } : {}
|
|
922
|
+
};
|
|
923
|
+
}));
|
|
924
|
+
for (const site of sites) if (require_config.appKey(site.id) === root) site.root = true;
|
|
925
|
+
const workerBroker = events === "pgboss" && Object.values(manifest).some((d) => d?.kind === "worker") && resources.some((r) => r.kind === "database");
|
|
926
|
+
return {
|
|
927
|
+
stage,
|
|
928
|
+
events,
|
|
929
|
+
cache,
|
|
930
|
+
containers: [...containers],
|
|
931
|
+
resources,
|
|
932
|
+
...Object.keys(fakes).length ? { fakes } : {},
|
|
933
|
+
...workerBroker ? { workerBroker: true } : {}
|
|
934
|
+
};
|
|
686
935
|
}
|
|
687
936
|
/**
|
|
688
|
-
*
|
|
937
|
+
* Queues or topics were declared with pg-boss and no database to hold them.
|
|
689
938
|
*
|
|
690
|
-
*
|
|
691
|
-
*
|
|
692
|
-
*
|
|
939
|
+
* Not a reconcile failure but a manifest one: the fix is a line of application
|
|
940
|
+
* code either way — declare a database, or select a backend that brings its own
|
|
941
|
+
* broker.
|
|
693
942
|
*/
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
}
|
|
701
|
-
/** A planned port that allocation never assigned. */
|
|
702
|
-
var UnassignedPort = class extends Error {
|
|
703
|
-
/** The port key that went unassigned, e.g. `minio-console`. */
|
|
704
|
-
key;
|
|
705
|
-
constructor(key) {
|
|
706
|
-
super("No port was assigned for this container port");
|
|
707
|
-
this.name = "UnassignedPort";
|
|
708
|
-
this.key = key;
|
|
943
|
+
var CacheNeedsDatabase = class extends Error {
|
|
944
|
+
ids;
|
|
945
|
+
constructor(ids) {
|
|
946
|
+
super(`A cache backed by the database needs a declared database, and none was declared, and on this deploy target that is where a cache lives. Declare one. Caches affected: ${ids.join(", ")}.`);
|
|
947
|
+
this.ids = ids;
|
|
948
|
+
this.name = "CacheNeedsDatabase";
|
|
709
949
|
}
|
|
710
950
|
};
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
composePath,
|
|
739
|
-
"up",
|
|
740
|
-
"-d",
|
|
741
|
-
"--remove-orphans",
|
|
742
|
-
"--wait",
|
|
743
|
-
`--wait-timeout=${Math.floor(HEALTH_TIMEOUT_MS / 1e3)}`,
|
|
744
|
-
...services
|
|
745
|
-
]);
|
|
746
|
-
},
|
|
747
|
-
async copyOut(composePath, service, from, to) {
|
|
748
|
-
await (0, node_fs_promises.mkdir)((0, node_path.dirname)(to), { recursive: true });
|
|
749
|
-
await run("docker", [
|
|
750
|
-
"compose",
|
|
751
|
-
"-f",
|
|
752
|
-
composePath,
|
|
753
|
-
"cp",
|
|
754
|
-
`${service}:${from}`,
|
|
755
|
-
to
|
|
756
|
-
]);
|
|
757
|
-
},
|
|
758
|
-
async reload(composePath, service) {
|
|
759
|
-
await run("docker", [
|
|
760
|
-
"compose",
|
|
761
|
-
"-f",
|
|
762
|
-
composePath,
|
|
763
|
-
"exec",
|
|
764
|
-
"-T",
|
|
765
|
-
service,
|
|
766
|
-
"caddy",
|
|
767
|
-
"reload",
|
|
768
|
-
"--config",
|
|
769
|
-
"/etc/caddy/Caddyfile"
|
|
770
|
-
]);
|
|
771
|
-
},
|
|
772
|
-
async healthy(composePath, services) {
|
|
773
|
-
if (services.length === 0) return true;
|
|
774
|
-
try {
|
|
775
|
-
const { stdout } = await run("docker", [
|
|
776
|
-
"compose",
|
|
777
|
-
"-f",
|
|
778
|
-
composePath,
|
|
779
|
-
"ps",
|
|
780
|
-
"--format",
|
|
781
|
-
"json",
|
|
782
|
-
...services
|
|
783
|
-
]);
|
|
784
|
-
const running = /* @__PURE__ */ new Set();
|
|
785
|
-
for (const line of stdout.trim().split("\n").filter(Boolean)) {
|
|
786
|
-
const entry = JSON.parse(line);
|
|
787
|
-
const ok = entry.State === "running" && (entry.Health === void 0 || entry.Health === "" || entry.Health === "healthy");
|
|
788
|
-
if (ok && entry.Service) running.add(entry.Service);
|
|
789
|
-
}
|
|
790
|
-
return services.every((service) => running.has(service));
|
|
791
|
-
} catch {
|
|
792
|
-
return false;
|
|
793
|
-
}
|
|
951
|
+
/**
|
|
952
|
+
* A `'db'` cache — a server target's default — in an app that declares more
|
|
953
|
+
* than one database.
|
|
954
|
+
*
|
|
955
|
+
* The target says *a* database and the graph offers several, so there is no
|
|
956
|
+
* answer to give — and the wrong kind of failure would be to pick one, since a
|
|
957
|
+
* cache silently landing in the wrong database is a bug that surfaces as
|
|
958
|
+
* missing rows much later. The fix is a stronger statement in application code:
|
|
959
|
+
* `orders.cache('Sessions')` names the database, which is a fact about the
|
|
960
|
+
* application rather than a deployment choice.
|
|
961
|
+
*/
|
|
962
|
+
var CacheIsAmbiguous = class extends Error {
|
|
963
|
+
ids;
|
|
964
|
+
databases;
|
|
965
|
+
constructor(ids, databases) {
|
|
966
|
+
super(`A cache backed by the database needs to know which one, and this app declares ${databases.length}: ${databases.join(", ")}. Declare the cache from its database — e.g. ${databases[0]}.cache('Sessions') — rather than as a bare new Cache(). Caches affected: ${ids.join(", ")}.`);
|
|
967
|
+
this.ids = ids;
|
|
968
|
+
this.databases = databases;
|
|
969
|
+
this.name = "CacheIsAmbiguous";
|
|
970
|
+
}
|
|
971
|
+
};
|
|
972
|
+
var PgBossNeedsDatabase = class extends Error {
|
|
973
|
+
ids;
|
|
974
|
+
constructor(ids) {
|
|
975
|
+
super(`pg-boss keeps its queues in a declared database, and none was declared. Declare one: on this deploy target, events are carried by pg-boss. Queues and topics affected: ${ids.join(", ")}.`);
|
|
976
|
+
this.ids = ids;
|
|
977
|
+
this.name = "PgBossNeedsDatabase";
|
|
794
978
|
}
|
|
795
979
|
};
|
|
796
|
-
|
|
797
980
|
//#endregion
|
|
798
|
-
//#region src/reconcile/
|
|
799
|
-
/** The stage whose resources carry no suffix. */
|
|
800
|
-
const DEFAULT_STAGE = "development";
|
|
981
|
+
//#region src/reconcile/env.ts
|
|
801
982
|
/**
|
|
802
|
-
*
|
|
983
|
+
* The URLs a reconciled stage injects.
|
|
803
984
|
*
|
|
804
|
-
*
|
|
805
|
-
*
|
|
806
|
-
*
|
|
985
|
+
* One `<NAME>_URL` per construct, and the protocol picks the driver. This is the
|
|
986
|
+
* seam between the target that writes a URL and the client that parses it, so
|
|
987
|
+
* every component of it is read off the resource — never inherited from ambient
|
|
988
|
+
* environment. A bucket can live in a different region than the function reading
|
|
989
|
+
* it, and `AWS_REGION` in a Lambda is the *function's* region, so a URL that
|
|
990
|
+
* omits `?region=` breaks cross-region silently at runtime.
|
|
991
|
+
*
|
|
992
|
+
* Locally that self-containment is what lets the port be whatever was free: the
|
|
993
|
+
* app reads `ORDERS_URL` and never sees a host or a port.
|
|
807
994
|
*/
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
995
|
+
/**
|
|
996
|
+
* The credential local containers are brought up with.
|
|
997
|
+
*
|
|
998
|
+
* The design's `roles: false` case — both URLs fall back to the cluster's master
|
|
999
|
+
* credential. A deliberate downgrade, not a default: it holds until the role DDL
|
|
1000
|
+
* lands in `@geekmidas/db`, at which point the runtime role's URL replaces this
|
|
1001
|
+
* and the owner URL stops being reachable from any manifest edge.
|
|
1002
|
+
*/
|
|
1003
|
+
const LOCAL_USER$2 = "geekmidas";
|
|
1004
|
+
/** The host containers are published on. */
|
|
1005
|
+
const LOCAL_HOST = "localhost";
|
|
1006
|
+
/** The region local buckets claim, so the client has one to sign with. */
|
|
1007
|
+
const LOCAL_REGION = "us-east-1";
|
|
1008
|
+
/**
|
|
1009
|
+
* The credentials the S3 client resolves for MinIO.
|
|
1010
|
+
*
|
|
1011
|
+
* An `s3://` URL deliberately carries none: deployed, the SDK reads them from
|
|
1012
|
+
* the execution role, so a URL that embedded a key would be one more thing to
|
|
1013
|
+
* rotate and one more thing to leak into a log. Locally there is no role, and
|
|
1014
|
+
* the same chain reads these — which is why they are injected beside the URL
|
|
1015
|
+
* rather than written into it.
|
|
1016
|
+
*/
|
|
1017
|
+
const STORAGE_CREDENTIALS = {
|
|
1018
|
+
AWS_ACCESS_KEY_ID: LOCAL_USER$2,
|
|
1019
|
+
AWS_SECRET_ACCESS_KEY: LOCAL_USER$2,
|
|
1020
|
+
AWS_REGION: LOCAL_REGION
|
|
815
1021
|
};
|
|
1022
|
+
/** The token the local cache proxy accepts. Matches the compose definition. */
|
|
1023
|
+
const LOCAL_TOKEN$1 = "geekmidas";
|
|
1024
|
+
/** The port Mailpit's inbox — its web UI and HTTP API — is published under. */
|
|
1025
|
+
const MAILPIT_INBOX_PORT = "mailpit-web";
|
|
1026
|
+
/** The schema pg-boss keeps its tables in, inside the declared database. */
|
|
1027
|
+
const PGBOSS_SCHEMA = "pgboss";
|
|
1028
|
+
/** The exchange every local topic and queue shares on RabbitMQ. */
|
|
1029
|
+
const RABBITMQ_EXCHANGE = "geekmidas.events";
|
|
1030
|
+
/**
|
|
1031
|
+
* Every env key a reconciled plan resolves, and its value.
|
|
1032
|
+
*
|
|
1033
|
+
* Keys come from the declaration rather than being re-derived, so what the build
|
|
1034
|
+
* publishes and what the app reads cannot drift.
|
|
1035
|
+
*/
|
|
1036
|
+
function envFor(plan, options) {
|
|
1037
|
+
const env = {};
|
|
1038
|
+
const resolved = {};
|
|
1039
|
+
for (const resource of plan.resources) {
|
|
1040
|
+
const url = urlFor(resource, plan, options.ports, options.project ?? "", options.addresses);
|
|
1041
|
+
if (url) resolved[resource.id] = url;
|
|
1042
|
+
}
|
|
1043
|
+
for (const resource of plan.resources) {
|
|
1044
|
+
const url = resolved[resource.id];
|
|
1045
|
+
if (resource.kind === "rest-api") Object.assign(env, surfaceEnv(resource, url, resolved, {
|
|
1046
|
+
plan,
|
|
1047
|
+
...options.addresses ? { addresses: options.addresses } : {},
|
|
1048
|
+
...options.lanAddress ? { lanAddress: options.lanAddress } : {},
|
|
1049
|
+
...options.metroPorts ? { metroPorts: options.metroPorts } : {}
|
|
1050
|
+
}));
|
|
1051
|
+
if (url) env[resource.envKey] = url;
|
|
1052
|
+
if (isDatabase(resource.kind) && resource.roles !== false) {
|
|
1053
|
+
const owner = ownerUrl(resource, plan, options.ports, options.project ?? "");
|
|
1054
|
+
if (owner) env[(0, _geekmidas_manifest.provideKey)(resource.id, "ownerUrl")] = owner;
|
|
1055
|
+
}
|
|
1056
|
+
if (resource.kind === "external-api" && url && resource.fake) env[(0, _geekmidas_manifest.provideKey)(resource.id, "credentials")] = resource.fake.credentials;
|
|
1057
|
+
if (resource.kind === "email" && url) {
|
|
1058
|
+
env[(0, _geekmidas_manifest.provideKey)(resource.id, "from")] = options.mailFrom ?? `noreply@${LOCAL_HOST}`;
|
|
1059
|
+
const inbox = options.ports[MAILPIT_INBOX_PORT];
|
|
1060
|
+
if (inbox !== void 0) env[(0, _geekmidas_manifest.provideKey)(resource.id, "inboxUrl")] = `http://${LOCAL_HOST}:${inbox}`;
|
|
1061
|
+
}
|
|
1062
|
+
}
|
|
1063
|
+
Object.assign(env, publicEnv(plan, env, options.addresses));
|
|
1064
|
+
Object.assign(env, brokerEnv(plan, options.ports));
|
|
1065
|
+
if (plan.resources.some((r) => r.kind === "objects" && env[r.envKey])) Object.assign(env, STORAGE_CREDENTIALS);
|
|
1066
|
+
return env;
|
|
1067
|
+
}
|
|
1068
|
+
/**
|
|
1069
|
+
* The values a site's bundler inlines, under the names it inlines them by.
|
|
1070
|
+
*
|
|
1071
|
+
* A rename and nothing more. `API_URL` was resolved once, by the same code that
|
|
1072
|
+
* resolved it for the server; a site reads the same value under `VITE_API_URL`
|
|
1073
|
+
* because that prefix is how its bundler is told to ship it. Nothing is derived
|
|
1074
|
+
* twice, so a site and its API cannot come to disagree about where the API is.
|
|
1075
|
+
*
|
|
1076
|
+
* A source that resolved to nothing is skipped rather than written empty: an
|
|
1077
|
+
* inlined empty string is a frontend that builds and then fails at runtime
|
|
1078
|
+
* against `http:///`, where a missing variable fails at build with the name of
|
|
1079
|
+
* the thing that is missing.
|
|
1080
|
+
*/
|
|
1081
|
+
function publicEnv(plan, resolved, addresses = {}) {
|
|
1082
|
+
const env = {};
|
|
1083
|
+
const owners = new Map(plan.resources.map((r) => [r.envKey, r.id]));
|
|
1084
|
+
for (const resource of plan.resources) for (const [key, source] of Object.entries(resource.publicEnv ?? {})) {
|
|
1085
|
+
const value = (resource.kind === "mobile-app" ? addresses[owners.get(source) ?? ""] : void 0) ?? resolved[source];
|
|
1086
|
+
if (value) env[key] = value;
|
|
1087
|
+
}
|
|
1088
|
+
return env;
|
|
1089
|
+
}
|
|
816
1090
|
/**
|
|
817
|
-
*
|
|
1091
|
+
* What a surface publishes beyond its own address: who may call it, and where
|
|
1092
|
+
* a cookie set by it is readable.
|
|
818
1093
|
*
|
|
819
|
-
*
|
|
820
|
-
*
|
|
821
|
-
*
|
|
1094
|
+
* Both are read off the same list — the constructs that declared an edge to
|
|
1095
|
+
* this surface — which is why neither appears in application code. A surface
|
|
1096
|
+
* that listed its own callers would be edited every time something new called
|
|
1097
|
+
* it, and the thing being edited is already recorded in the graph.
|
|
822
1098
|
*
|
|
823
|
-
*
|
|
824
|
-
*
|
|
825
|
-
*
|
|
826
|
-
*
|
|
1099
|
+
* An empty origin list is written, and a surface with no address writes nothing
|
|
1100
|
+
* at all. The two cases look alike and are not: "nothing depends on this yet" is
|
|
1101
|
+
* a real state a target should publish, while "this surface has no address here"
|
|
1102
|
+
* means it is not running in this stage, and keys belong with the address they
|
|
1103
|
+
* describe.
|
|
827
1104
|
*/
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
1105
|
+
function surfaceEnv(resource, url, resolved = {}, local = {}) {
|
|
1106
|
+
if (!url) return {};
|
|
1107
|
+
const origins = [...new Set((resource.callers ?? []).map((caller) => resolved[caller]).filter((address) => Boolean(address)).map(originOf).filter((origin) => Boolean(origin)))].sort();
|
|
1108
|
+
const domain = (0, _geekmidas_manifest.cookieDomain)([url, ...origins]);
|
|
1109
|
+
const mobile = (resource.callers ?? []).map((caller) => local.plan?.resources.find((r) => r.id === caller && r.kind === "mobile-app")).filter((caller) => Boolean(caller));
|
|
1110
|
+
const hosts = [...local.lanAddress ? [local.lanAddress] : [], LOCAL_HOST];
|
|
1111
|
+
const schemes = mobile.flatMap((caller) => {
|
|
1112
|
+
const scheme = resolved[caller.id];
|
|
1113
|
+
const port = local.metroPorts?.[caller.id];
|
|
1114
|
+
return scheme ? (0, _geekmidas_manifest.mobileOrigins)(scheme, {
|
|
1115
|
+
hosts,
|
|
1116
|
+
...port ? { port } : {}
|
|
1117
|
+
}) : [];
|
|
1118
|
+
});
|
|
1119
|
+
const own = local.addresses?.[resource.id];
|
|
1120
|
+
const device = mobile.length > 0 && local.lanAddress && own ? own.replace(/\/\/(localhost|127\.0\.0\.1)(?=[:/]|$)/, `//${local.lanAddress}`) : void 0;
|
|
1121
|
+
return {
|
|
1122
|
+
[(0, _geekmidas_manifest.provideKey)(resource.id, "trustedOrigins")]: [...origins, ...new Set(schemes)].join(","),
|
|
1123
|
+
...domain ? { [(0, _geekmidas_manifest.provideKey)(resource.id, "cookieDomain")]: domain } : {},
|
|
1124
|
+
...device ? { [(0, _geekmidas_manifest.provideKey)(resource.id, "deviceUrl")]: device } : {}
|
|
1125
|
+
};
|
|
1126
|
+
}
|
|
1127
|
+
/** An address reduced to the origin a browser compares against. */
|
|
1128
|
+
function originOf(address) {
|
|
1129
|
+
try {
|
|
1130
|
+
return new URL(address).origin;
|
|
1131
|
+
} catch {
|
|
1132
|
+
return;
|
|
1133
|
+
}
|
|
1134
|
+
}
|
|
832
1135
|
/**
|
|
833
|
-
*
|
|
1136
|
+
* The runtime role of whatever a derived node hangs off.
|
|
834
1137
|
*
|
|
835
|
-
* A
|
|
836
|
-
*
|
|
837
|
-
*
|
|
1138
|
+
* A reader's parent may itself be a schema tenant, so this follows `of` by one
|
|
1139
|
+
* hop rather than assuming the cluster — the reader of a tenant reads that
|
|
1140
|
+
* tenant's schema, not the database's.
|
|
838
1141
|
*/
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
1142
|
+
function parentRole(resource, plan) {
|
|
1143
|
+
const parent = plan.resources.find((r) => r.id === resource.of);
|
|
1144
|
+
return parent ? localRole(parent) : resource.name;
|
|
1145
|
+
}
|
|
1146
|
+
/** Whether a kind connects to Postgres and therefore has an owner role. */
|
|
1147
|
+
function isDatabase(kind) {
|
|
1148
|
+
return kind === "database" || kind === "database-schema";
|
|
1149
|
+
}
|
|
845
1150
|
/**
|
|
846
|
-
*
|
|
1151
|
+
* The URL a migrator connects with — the owner role, which can create, alter
|
|
1152
|
+
* and drop.
|
|
847
1153
|
*
|
|
848
|
-
*
|
|
849
|
-
*
|
|
850
|
-
*
|
|
1154
|
+
* Never in `provides`, which is the whole point. A handler that could reach this
|
|
1155
|
+
* could `DROP TABLE`, and the security property the role split exists for is
|
|
1156
|
+
* that it cannot: the value is injected by `gkm exec` for the migrate step and
|
|
1157
|
+
* by nothing else.
|
|
851
1158
|
*/
|
|
852
|
-
|
|
1159
|
+
function ownerUrl(resource, plan, ports, project) {
|
|
1160
|
+
if (!resource.container) return void 0;
|
|
1161
|
+
const port = ports[primaryPortKey(resource.container)];
|
|
1162
|
+
if (port === void 0) return void 0;
|
|
1163
|
+
const owner = (0, _geekmidas_db_pg_roles.ownerRole)(localRole(resource));
|
|
1164
|
+
return postgres(port, rootDatabase(resource, plan), {
|
|
1165
|
+
user: owner,
|
|
1166
|
+
password: localRolePassword(project, plan, owner)
|
|
1167
|
+
});
|
|
1168
|
+
}
|
|
853
1169
|
/**
|
|
854
|
-
* The
|
|
1170
|
+
* The shared broker keys, when anything is published or consumed.
|
|
855
1171
|
*
|
|
856
|
-
*
|
|
857
|
-
*
|
|
858
|
-
*
|
|
1172
|
+
* A queue's own key is the producer's. These two are the *connection* itself,
|
|
1173
|
+
* which locally is one broker for every queue and topic in the project: the
|
|
1174
|
+
* generated pollers open a single connection and subscribe each worker by name
|
|
1175
|
+
* on it. Deployed there is no such thing — a Lambda is handed its own event
|
|
1176
|
+
* source — so this pair exists for the local target and says so.
|
|
859
1177
|
*/
|
|
860
|
-
|
|
861
|
-
queue
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
};
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
queue: true,
|
|
868
|
-
topic: true
|
|
869
|
-
};
|
|
1178
|
+
function brokerEnv(plan, ports) {
|
|
1179
|
+
const carrier = plan.resources.find((r) => r.kind === "queue" || r.kind === "topic");
|
|
1180
|
+
const publisher = carrier ? urlFor(carrier, plan, ports, "") : plan.workerBroker ? workerBroker(plan, ports) : void 0;
|
|
1181
|
+
if (!publisher) return {};
|
|
1182
|
+
if (plan.events === "sns") return {};
|
|
1183
|
+
return { EVENT_PUBLISHER_CONNECTION_STRING: publisher };
|
|
1184
|
+
}
|
|
870
1185
|
/**
|
|
871
|
-
*
|
|
872
|
-
*
|
|
873
|
-
* A database creates a database, a bucket creates a bucket; mail creates
|
|
874
|
-
* nothing — Mailpit accepts whatever is sent to it and has no per-stage object
|
|
875
|
-
* to name. Both still appear in the plan, because both still resolve a URL; the
|
|
876
|
-
* flag is the difference between "must be running" and "must be created".
|
|
1186
|
+
* The broker a worker schedules its crons through, when nothing else declared
|
|
1187
|
+
* one — pg-boss in the declared database, on that database's port.
|
|
877
1188
|
*/
|
|
878
|
-
|
|
879
|
-
database
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
"file-server": true
|
|
885
|
-
};
|
|
1189
|
+
function workerBroker(plan, ports) {
|
|
1190
|
+
const database = plan.resources.find((r) => r.kind === "database");
|
|
1191
|
+
if (!database?.container) return void 0;
|
|
1192
|
+
const port = ports[primaryPortKey(database.container)];
|
|
1193
|
+
return port === void 0 ? void 0 : broker(plan, port);
|
|
1194
|
+
}
|
|
886
1195
|
/**
|
|
887
|
-
* The
|
|
1196
|
+
* The URL for one planned resource.
|
|
888
1197
|
*
|
|
889
|
-
*
|
|
890
|
-
|
|
891
|
-
|
|
1198
|
+
* Every part of it comes from the resource and the port it was published on.
|
|
1199
|
+
*/
|
|
1200
|
+
function urlFor(resource, plan, ports, project, addresses = {}) {
|
|
1201
|
+
if (resource.kind === "secret") return localSecret(project, plan, resource);
|
|
1202
|
+
if (resource.kind === "encryption") return localKeyring(project, plan, resource);
|
|
1203
|
+
if (resource.kind === "mobile-app") return (0, _geekmidas_manifest.schemeBase)(project, resource.scheme);
|
|
1204
|
+
if (resource.kind === "credential") return void 0;
|
|
1205
|
+
if (resource.kind === "external-api") {
|
|
1206
|
+
if (!resource.fake) return resource.url === void 0 ? void 0 : (0, _geekmidas_manifest.externalApiUrl)({
|
|
1207
|
+
id: resource.id,
|
|
1208
|
+
url: resource.url
|
|
1209
|
+
}, plan.stage);
|
|
1210
|
+
const port = ports[resource.fake.key];
|
|
1211
|
+
return port === void 0 ? void 0 : `http://${LOCAL_HOST}:${port}`;
|
|
1212
|
+
}
|
|
1213
|
+
if (resource.kind === "rest-api" || resource.kind === "site") {
|
|
1214
|
+
const address = addresses[resource.id];
|
|
1215
|
+
const edge = plan.containers.includes("caddy") ? ports[primaryPortKey("caddy")] : void 0;
|
|
1216
|
+
return address && edge !== void 0 ? `https://${hostFor(resource, project)}:${edge}` : address;
|
|
1217
|
+
}
|
|
1218
|
+
if (!resource.container) return void 0;
|
|
1219
|
+
const port = ports[primaryPortKey(resource.container)];
|
|
1220
|
+
if (port === void 0) return void 0;
|
|
1221
|
+
switch (resource.kind) {
|
|
1222
|
+
case "database":
|
|
1223
|
+
case "database-schema":
|
|
1224
|
+
case "database-reader": {
|
|
1225
|
+
const database = rootDatabase(resource, plan);
|
|
1226
|
+
if (resource.roles === false) {
|
|
1227
|
+
const schema = schemaOf(resource, plan);
|
|
1228
|
+
return schema ? `${postgres(port, database)}?search_path=${schema}` : postgres(port, database);
|
|
1229
|
+
}
|
|
1230
|
+
const role = resource.kind === "database-reader" ? (0, _geekmidas_db_pg_roles.readerRole)(parentRole(resource, plan)) : localRole(resource);
|
|
1231
|
+
return postgres(port, database, {
|
|
1232
|
+
user: role,
|
|
1233
|
+
password: localRolePassword(project, plan, role)
|
|
1234
|
+
});
|
|
1235
|
+
}
|
|
1236
|
+
case "email": return `smtp://${LOCAL_HOST}:${port}`;
|
|
1237
|
+
case "objects": return `s3://${resource.name}?region=${LOCAL_REGION}&endpoint=http://${LOCAL_HOST}:${port}&forcePathStyle=true`;
|
|
1238
|
+
case "file-server": {
|
|
1239
|
+
const origin = plan.resources.find((r) => r.id === resource.of);
|
|
1240
|
+
if (!origin) return void 0;
|
|
1241
|
+
return plan.containers.includes("caddy") ? `https://${hostFor(resource, project)}:${port}` : `http://${LOCAL_HOST}:${port}/${origin.name}`;
|
|
1242
|
+
}
|
|
1243
|
+
case "cache":
|
|
1244
|
+
if (resource.of) {
|
|
1245
|
+
const parent = plan.resources.find((r) => r.id === resource.of);
|
|
1246
|
+
const url = parent ? urlFor(parent, plan, ports, project, addresses) : void 0;
|
|
1247
|
+
return url ? withTable(url, resource.table ?? (0, _geekmidas_manifest.cacheTable)(resource.id)) : void 0;
|
|
1248
|
+
}
|
|
1249
|
+
switch (plan.cache) {
|
|
1250
|
+
case "elasticache": return `redis://${LOCAL_HOST}:${port}`;
|
|
1251
|
+
default: return `http://:${LOCAL_TOKEN$1}@${LOCAL_HOST}:${port}`;
|
|
1252
|
+
}
|
|
1253
|
+
case "queue":
|
|
1254
|
+
case "topic": return broker(plan, port, resource);
|
|
1255
|
+
default: return;
|
|
1256
|
+
}
|
|
1257
|
+
}
|
|
1258
|
+
/**
|
|
1259
|
+
* The producer's connection string, composed from the backend the plan chose.
|
|
892
1260
|
*
|
|
893
|
-
*
|
|
894
|
-
*
|
|
895
|
-
*
|
|
1261
|
+
* The protocol is what picks the transport, so a producer never branches: the
|
|
1262
|
+
* same `.publish()` reaches pg-boss here and SQS deployed because the string it
|
|
1263
|
+
* was handed said so.
|
|
896
1264
|
*/
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
1265
|
+
function broker(plan, port, resource) {
|
|
1266
|
+
switch (plan.events) {
|
|
1267
|
+
case "pgboss": {
|
|
1268
|
+
const database = plan.resources.find((r) => r.kind === "database");
|
|
1269
|
+
if (!database) throw new PgBossNeedsDatabase([]);
|
|
1270
|
+
return `pgboss://${LOCAL_USER$2}:${LOCAL_USER$2}@${LOCAL_HOST}:${port}/${database.name}?schema=${PGBOSS_SCHEMA}`;
|
|
1271
|
+
}
|
|
1272
|
+
case "rabbitmq": return `rabbitmq://${LOCAL_USER$2}:${LOCAL_USER$2}@${LOCAL_HOST}:${port}?exchange=${RABBITMQ_EXCHANGE}`;
|
|
1273
|
+
case "sns": {
|
|
1274
|
+
if (!resource) throw new UnprovisionedEventsBackend("sns");
|
|
1275
|
+
const endpoint = emulatorEndpoint(port);
|
|
1276
|
+
const address = resource.kind === "topic" ? _geekmidas_events_sns_url.build({
|
|
1277
|
+
topicArn: emulatorTopicArn(resource.name),
|
|
1278
|
+
region: EMULATOR_REGION,
|
|
1279
|
+
endpoint
|
|
1280
|
+
}) : _geekmidas_events_sqs_url.build({
|
|
1281
|
+
queueUrl: emulatorQueueUrl(resource.name, port),
|
|
1282
|
+
region: EMULATOR_REGION,
|
|
1283
|
+
endpoint
|
|
1284
|
+
});
|
|
1285
|
+
const url = new URL(address);
|
|
1286
|
+
url.searchParams.set("accessKeyId", EMULATOR_CREDENTIALS.accessKeyId);
|
|
1287
|
+
url.searchParams.set("secretAccessKey", EMULATOR_CREDENTIALS.secretAccessKey);
|
|
1288
|
+
return url.toString();
|
|
1289
|
+
}
|
|
1290
|
+
}
|
|
1291
|
+
}
|
|
1292
|
+
/** A local Postgres URL, master credential and all. */
|
|
1293
|
+
function postgres(port, database, credential = {
|
|
1294
|
+
user: LOCAL_USER$2,
|
|
1295
|
+
password: LOCAL_USER$2
|
|
1296
|
+
}) {
|
|
1297
|
+
return `postgres://${credential.user}:${credential.password}@${LOCAL_HOST}:${port}/${database}`;
|
|
1298
|
+
}
|
|
903
1299
|
/**
|
|
904
|
-
*
|
|
1300
|
+
* The role a handler connects as, for one database or tenant.
|
|
905
1301
|
*
|
|
906
|
-
*
|
|
907
|
-
*
|
|
908
|
-
*
|
|
1302
|
+
* The construct's id, lowercased and stage-scoped exactly as its database or
|
|
1303
|
+
* schema is — so `Orders` in the `test` stage connects as `orders_test`, and two
|
|
1304
|
+
* stages sharing one cluster cannot share a credential. Roles are cluster-scoped
|
|
1305
|
+
* in Postgres, which is why the suffix is not optional here the way it is for a
|
|
1306
|
+
* schema.
|
|
909
1307
|
*/
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
"database-schema": "_",
|
|
914
|
-
objects: "-"
|
|
915
|
-
};
|
|
1308
|
+
function localRole(resource) {
|
|
1309
|
+
return resource.name;
|
|
1310
|
+
}
|
|
916
1311
|
/**
|
|
917
|
-
* The
|
|
1312
|
+
* The password for a derived local role.
|
|
1313
|
+
*
|
|
1314
|
+
* Derived rather than random, for the same reason the local secret is: a
|
|
1315
|
+
* password that changed on every `gkm dev` would lock a developer out of the
|
|
1316
|
+
* data they had a moment ago. Seeded by the project so two checkouts do not
|
|
1317
|
+
* share one, and by the stage so `test` and `development` do not.
|
|
918
1318
|
*
|
|
919
|
-
*
|
|
920
|
-
*
|
|
921
|
-
* change. Every other stage is suffixed.
|
|
1319
|
+
* It is a *local* credential by construction — the cluster is on loopback and
|
|
1320
|
+
* the seed is a checkout path — and no deployed target uses this function.
|
|
922
1321
|
*/
|
|
923
|
-
function
|
|
924
|
-
|
|
925
|
-
if (stage === DEFAULT_STAGE) return base;
|
|
926
|
-
return `${base}${SEPARATORS[kind] ?? "-"}${stage}`;
|
|
1322
|
+
function localRolePassword(project, plan, role) {
|
|
1323
|
+
return (0, node_crypto.createHash)("sha256").update(`${project}:${plan.stage}:role:${role}`).digest("base64url").slice(0, 32);
|
|
927
1324
|
}
|
|
928
1325
|
/**
|
|
929
|
-
*
|
|
1326
|
+
* A cache's address: its database's URL, carrying the table it reads.
|
|
930
1327
|
*
|
|
931
|
-
*
|
|
932
|
-
*
|
|
933
|
-
*
|
|
1328
|
+
* Appended rather than kept beside the URL as a second key, for the reason the
|
|
1329
|
+
* design gives everywhere else — an address and what it opens are one fact, and
|
|
1330
|
+
* two keys are one more thing to keep in step.
|
|
934
1331
|
*/
|
|
935
|
-
function
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
if (derived) return CONTAINERS.database;
|
|
940
|
-
return CACHE_CONTAINERS[cache] ?? CONTAINERS.database;
|
|
941
|
-
}
|
|
942
|
-
return CONTAINERS[kind];
|
|
1332
|
+
function withTable(url, table) {
|
|
1333
|
+
const parsed = new URL(url);
|
|
1334
|
+
parsed.searchParams.set("table", table);
|
|
1335
|
+
return parsed.toString();
|
|
943
1336
|
}
|
|
944
1337
|
/**
|
|
945
|
-
*
|
|
1338
|
+
* The physical database a derived resource lives in.
|
|
946
1339
|
*
|
|
947
|
-
* `
|
|
948
|
-
*
|
|
949
|
-
*
|
|
1340
|
+
* Walks `of` to the top rather than reading the immediate parent, because a
|
|
1341
|
+
* reader's parent may itself be a schema tenant — two hops from the database
|
|
1342
|
+
* that actually exists.
|
|
950
1343
|
*/
|
|
951
|
-
function
|
|
952
|
-
const
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
if (!declaration) continue;
|
|
959
|
-
const container = containerFor(declaration.kind, events, cache, "of" in declaration && typeof declaration.of === "string", options.edge !== false);
|
|
960
|
-
if (!container && !CONTAINERLESS[declaration.kind]) continue;
|
|
961
|
-
if (container) {
|
|
962
|
-
containers.add(container);
|
|
963
|
-
for (const required of REQUIRES[container] ?? []) containers.add(required);
|
|
964
|
-
}
|
|
965
|
-
resources.push({
|
|
966
|
-
id,
|
|
967
|
-
kind: declaration.kind,
|
|
968
|
-
...container ? { container } : {},
|
|
969
|
-
name: resourceName(id, declaration.kind, stage),
|
|
970
|
-
envKey: (0, __geekmidas_manifest.providedKeyFor)(id, declaration.kind, ROLES[declaration.kind] ?? "url"),
|
|
971
|
-
provisions: PROVISIONS[declaration.kind] === true,
|
|
972
|
-
...declaration.kind === "rest-api" ? { callers: (0, __geekmidas_manifest.dependentsOf)(manifest, id) } : {},
|
|
973
|
-
...declaration.kind === "site" ? { publicEnv: (0, __geekmidas_manifest.publicEnvFor)(declaration, manifest) } : {},
|
|
974
|
-
...declaration.kind === "file-server" && declaration.open?.length ? { open: declaration.open } : {},
|
|
975
|
-
..."of" in declaration ? { of: declaration.of } : {},
|
|
976
|
-
..."schema" in declaration && declaration.schema ? { schema: declaration.schema } : {},
|
|
977
|
-
..."version" in declaration && declaration.version ? { version: declaration.version } : {},
|
|
978
|
-
..."roles" in declaration && declaration.roles === false ? { roles: false } : {},
|
|
979
|
-
..."table" in declaration && declaration.table ? { table: declaration.table } : {}
|
|
980
|
-
});
|
|
1344
|
+
function rootDatabase(resource, plan) {
|
|
1345
|
+
const byId = new Map(plan.resources.map((r) => [r.id, r]));
|
|
1346
|
+
let current = resource;
|
|
1347
|
+
while (current.of) {
|
|
1348
|
+
const parent = byId.get(current.of);
|
|
1349
|
+
if (!parent) break;
|
|
1350
|
+
current = parent;
|
|
981
1351
|
}
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
if (databases.length > 1) throw new CacheIsAmbiguous(placeless.map((r) => r.id), databases.map((r) => r.id));
|
|
992
|
-
for (const resource of placeless) resource.of = only.id;
|
|
993
|
-
}
|
|
1352
|
+
return current.name;
|
|
1353
|
+
}
|
|
1354
|
+
/** The schema a derived resource puts on its search path, if it has one. */
|
|
1355
|
+
function schemaOf(resource, plan) {
|
|
1356
|
+
const byId = new Map(plan.resources.map((r) => [r.id, r]));
|
|
1357
|
+
let current = resource;
|
|
1358
|
+
while (current) {
|
|
1359
|
+
if (current.kind === "database-schema") return current.schema;
|
|
1360
|
+
current = current.of ? byId.get(current.of) : void 0;
|
|
994
1361
|
}
|
|
995
|
-
return {
|
|
996
|
-
stage,
|
|
997
|
-
events,
|
|
998
|
-
cache,
|
|
999
|
-
containers: [...containers],
|
|
1000
|
-
resources
|
|
1001
|
-
};
|
|
1002
1362
|
}
|
|
1003
1363
|
/**
|
|
1004
|
-
*
|
|
1364
|
+
* A broker address asked for without the topic or queue it would name.
|
|
1005
1365
|
*
|
|
1006
|
-
*
|
|
1007
|
-
*
|
|
1008
|
-
* broker.
|
|
1366
|
+
* On SNS each topic and queue is its own address, so there is no project-wide
|
|
1367
|
+
* one to hand out — a cron's schedule store, say, cannot live there.
|
|
1009
1368
|
*/
|
|
1010
|
-
var
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
this.
|
|
1369
|
+
var UnprovisionedEventsBackend = class extends Error {
|
|
1370
|
+
backend;
|
|
1371
|
+
constructor(backend) {
|
|
1372
|
+
super(`'${backend}' has no single broker address: each topic and queue is addressed by its own ARN. Something asked for one without naming the topic or queue.`);
|
|
1373
|
+
this.backend = backend;
|
|
1374
|
+
this.name = "UnprovisionedEventsBackend";
|
|
1015
1375
|
}
|
|
1016
1376
|
};
|
|
1017
1377
|
/**
|
|
1018
|
-
*
|
|
1378
|
+
* The keyring an `Encryption` construct resolves to locally.
|
|
1379
|
+
*
|
|
1380
|
+
* Derived like a secret — stable across restarts, distinct per project, stage
|
|
1381
|
+
* and construct, never written to disk — so what `gkm dev` encrypted yesterday
|
|
1382
|
+
* still opens today. One key, because nothing local is worth rotating: a
|
|
1383
|
+
* server stage's keyring is generated and rotated in its secrets instead.
|
|
1384
|
+
*/
|
|
1385
|
+
function localKeyring(project, plan, resource) {
|
|
1386
|
+
const derive = (purpose) => (0, node_crypto.createHash)("sha256").update(`${project}:${plan.stage}:${resource.id}:${purpose}`).digest();
|
|
1387
|
+
return (0, _geekmidas_constructs_encryption.formatKeyring)({
|
|
1388
|
+
keys: [{
|
|
1389
|
+
id: "k1",
|
|
1390
|
+
key: derive("k1")
|
|
1391
|
+
}],
|
|
1392
|
+
index: derive("index")
|
|
1393
|
+
});
|
|
1394
|
+
}
|
|
1395
|
+
/**
|
|
1396
|
+
* The value a secret resolves to locally.
|
|
1019
1397
|
*
|
|
1020
|
-
*
|
|
1021
|
-
*
|
|
1022
|
-
*
|
|
1023
|
-
*
|
|
1024
|
-
* `orders.cache('Sessions')` names the database, which is a fact about the
|
|
1025
|
-
* application rather than a deployment choice.
|
|
1398
|
+
* A hash of what identifies it, so it is stable, distinct per project, stage
|
|
1399
|
+
* and construct, and never written to disk as a literal. Deployed this is the
|
|
1400
|
+
* one kind whose value does *not* come from here — a secret manager generates
|
|
1401
|
+
* it once and the target reads it back.
|
|
1026
1402
|
*/
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
this.ids = ids;
|
|
1031
|
-
this.databases = databases;
|
|
1032
|
-
this.name = "CacheIsAmbiguous";
|
|
1033
|
-
}
|
|
1034
|
-
};
|
|
1035
|
-
var PgBossNeedsDatabase = class extends Error {
|
|
1036
|
-
constructor(ids) {
|
|
1037
|
-
super(`pg-boss keeps its queues in a declared database, and none was declared. Declare one, or set services.events to 'rabbitmq' or 'sns'. Queues and topics affected: ${ids.join(", ")}.`);
|
|
1038
|
-
this.ids = ids;
|
|
1039
|
-
this.name = "PgBossNeedsDatabase";
|
|
1040
|
-
}
|
|
1041
|
-
};
|
|
1042
|
-
|
|
1403
|
+
function localSecret(project, plan, resource) {
|
|
1404
|
+
return (0, node_crypto.createHash)("sha256").update(`${project}:${plan.stage}:${resource.id}`).digest("base64url").slice(0, 43);
|
|
1405
|
+
}
|
|
1043
1406
|
//#endregion
|
|
1044
|
-
//#region src/reconcile/
|
|
1407
|
+
//#region src/reconcile/apps.ts
|
|
1045
1408
|
/**
|
|
1046
|
-
* The
|
|
1409
|
+
* The apps, as services beside the containers their constructs derive.
|
|
1047
1410
|
*
|
|
1048
|
-
*
|
|
1049
|
-
*
|
|
1050
|
-
*
|
|
1051
|
-
*
|
|
1411
|
+
* `gkm docker` used to write these by hand: every backend got
|
|
1412
|
+
* `DATABASE_URL=postgresql://…@postgres:5432/app` and `REDIS_URL=redis://redis`,
|
|
1413
|
+
* which was right only for a project whose single database happened to be
|
|
1414
|
+
* called `Database` — an `Orders` database publishes `ORDERS_URL`, a schema
|
|
1415
|
+
* tenant has a URL of its own, and buckets and mail were not wired at all.
|
|
1416
|
+
*
|
|
1417
|
+
* Now an app's environment is exactly what reconcile hands `gkm dev`: every key
|
|
1418
|
+
* the declared constructs provide, from the same derivation. The only
|
|
1419
|
+
* difference is where the addresses point — at the containers by service name
|
|
1420
|
+
* on the compose network, rather than at `localhost` on the ports published for
|
|
1421
|
+
* the host.
|
|
1422
|
+
*
|
|
1423
|
+
* Always from the *local* stage's plan, whichever stage is being reconciled:
|
|
1424
|
+
* `gkm test` rewrites the same file, and running the tests must not quietly
|
|
1425
|
+
* point these apps at the test databases.
|
|
1052
1426
|
*/
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
const LOCAL_HOST = "localhost";
|
|
1056
|
-
/** The region local buckets claim, so the client has one to sign with. */
|
|
1057
|
-
const LOCAL_REGION = "us-east-1";
|
|
1427
|
+
/** The profile app services carry, so `gkm dev` starts only the containers. */
|
|
1428
|
+
const APPS_PROFILE = "apps";
|
|
1058
1429
|
/**
|
|
1059
|
-
*
|
|
1430
|
+
* Where an app's image is built from.
|
|
1060
1431
|
*
|
|
1061
|
-
* An
|
|
1062
|
-
*
|
|
1063
|
-
* rotate and one more thing to leak into a log. Locally there is no role, and
|
|
1064
|
-
* the same chain reads these — which is why they are injected beside the URL
|
|
1065
|
-
* rather than written into it.
|
|
1432
|
+
* An app at the project root is a single-app project, whose `gkm docker`
|
|
1433
|
+
* writes `.gkm/docker/Dockerfile`; a workspace writes one per app.
|
|
1066
1434
|
*/
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
AWS_REGION: LOCAL_REGION
|
|
1071
|
-
};
|
|
1072
|
-
/** The token the local cache proxy accepts. Matches the compose definition. */
|
|
1073
|
-
const LOCAL_TOKEN = "geekmidas";
|
|
1074
|
-
/** The schema pg-boss keeps its tables in, inside the declared database. */
|
|
1075
|
-
const PGBOSS_SCHEMA = "pgboss";
|
|
1076
|
-
/** The exchange every local topic and queue shares on RabbitMQ. */
|
|
1077
|
-
const RABBITMQ_EXCHANGE = "geekmidas.events";
|
|
1435
|
+
function dockerfileOf(appName, path) {
|
|
1436
|
+
return path === "." ? ".gkm/docker/Dockerfile" : `.gkm/docker/Dockerfile.${appName}`;
|
|
1437
|
+
}
|
|
1078
1438
|
/**
|
|
1079
|
-
* Every
|
|
1439
|
+
* Every construct key, addressed across the compose network.
|
|
1080
1440
|
*
|
|
1081
|
-
*
|
|
1082
|
-
*
|
|
1441
|
+
* `envFor` is asked with a placeholder port for every port key, so each
|
|
1442
|
+
* `localhost:<placeholder>` in its answer names exactly one container port —
|
|
1443
|
+
* two containers listening on the same port inside cannot be confused — and is
|
|
1444
|
+
* rewritten to `<container>:<inside>`.
|
|
1083
1445
|
*/
|
|
1084
|
-
function
|
|
1085
|
-
const
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1446
|
+
function inNetworkEnv(workspace, manifest, fakes = {}) {
|
|
1447
|
+
const plan = planFor(manifest, workspace.stages.local, (0, _geekmidas_manifest.provisionOrder)(manifest), {
|
|
1448
|
+
localStage: workspace.stages.local,
|
|
1449
|
+
...backendsOf(workspace),
|
|
1450
|
+
fakes
|
|
1451
|
+
});
|
|
1452
|
+
const placeholders = {};
|
|
1453
|
+
const targets = /* @__PURE__ */ new Map();
|
|
1454
|
+
let next = 49152;
|
|
1455
|
+
for (const container of [...plan.containers].sort()) for (const port of portsOf(container, plan.fakes)) {
|
|
1456
|
+
placeholders[port.key] = next;
|
|
1457
|
+
targets.set(next, `${container}:${port.inside}`);
|
|
1458
|
+
next += 1;
|
|
1090
1459
|
}
|
|
1091
|
-
for (const
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1460
|
+
for (const key of portKeys(plan.containers, plan.fakes)) placeholders[key] ??= next++;
|
|
1461
|
+
const env = envFor(plan, {
|
|
1462
|
+
ports: placeholders,
|
|
1463
|
+
project: workspace.name,
|
|
1464
|
+
addresses: surfaceAddresses(workspace, manifest, (app, port) => `http://${app}:${port}`)
|
|
1465
|
+
});
|
|
1466
|
+
const rewrite = (value) => value.replace(/(?:localhost|127\.0\.0\.1):(\d+)/g, (match, port) => {
|
|
1467
|
+
return targets.get(Number(port)) ?? match;
|
|
1468
|
+
});
|
|
1469
|
+
return Object.fromEntries(Object.entries(env).map(([key, value]) => [key, rewrite(value)]));
|
|
1470
|
+
}
|
|
1471
|
+
/**
|
|
1472
|
+
* The keys one app's environment may hold: what its own declaration provides
|
|
1473
|
+
* and requires, and what each construct it has an edge to provides.
|
|
1474
|
+
*
|
|
1475
|
+
* The edges, not the manifest. Every app used to be handed every key the
|
|
1476
|
+
* workspace resolved — a web app got the database's owner URL and the auth
|
|
1477
|
+
* server's signing secret, and the API got the auth server's database — which
|
|
1478
|
+
* is exactly what a declared edge exists to rule out. A deploy composes an
|
|
1479
|
+
* app's environment from its edges; so does this.
|
|
1480
|
+
*
|
|
1481
|
+
* One hop: a surface an app calls is reached over HTTP, so its URL is the
|
|
1482
|
+
* app's business and its database is not. A site also gets the public
|
|
1483
|
+
* variant of each key its bundle inlines (`NEXT_PUBLIC_API_URL`), and a surface
|
|
1484
|
+
* the edges of the workers whose crons and subscribers its server runs.
|
|
1485
|
+
*
|
|
1486
|
+
* `undefined` for an app no declaration describes, which gets nothing but its
|
|
1487
|
+
* port.
|
|
1488
|
+
*/
|
|
1489
|
+
function appEnvKeys(manifest, appName, runnables = {}) {
|
|
1490
|
+
const entry = Object.entries(manifest).find(([id, d]) => (d.kind === "rest-api" || d.kind === "site" || d.kind === "mobile-app") && require_config.appKey(id) === appName);
|
|
1491
|
+
if (!entry) return void 0;
|
|
1492
|
+
const [id, declaration] = entry;
|
|
1493
|
+
const keys = /* @__PURE__ */ new Set([
|
|
1494
|
+
...declaration.provides ?? [],
|
|
1495
|
+
...declaration.requires ?? [],
|
|
1496
|
+
...declaration.kind === "rest-api" ? declaration.endpoints.flatMap((endpoint) => endpoint.requires ?? []) : []
|
|
1497
|
+
]);
|
|
1498
|
+
const edges = [...(0, _geekmidas_manifest.dependenciesOf)(declaration).map((edge) => edge.target), ...runnables[id] ?? []];
|
|
1499
|
+
if (declaration.kind === "rest-api" && declaration.endpoints.length === 0) {
|
|
1500
|
+
const runsWorkers = Object.values(manifest).some((other) => other.kind === "worker");
|
|
1501
|
+
for (const [otherId, other] of Object.entries(manifest)) {
|
|
1502
|
+
if (other.kind !== "worker") continue;
|
|
1503
|
+
edges.push(...(0, _geekmidas_manifest.dependenciesOf)(other).map((edge) => edge.target), ...runnables[otherId] ?? []);
|
|
1504
|
+
keys.add("EVENT_PUBLISHER_CONNECTION_STRING");
|
|
1505
|
+
}
|
|
1506
|
+
if (runsWorkers) for (const other of Object.values(manifest)) {
|
|
1507
|
+
if (other.kind !== "queue" && other.kind !== "topic") continue;
|
|
1508
|
+
for (const key of other.provides ?? []) keys.add(key);
|
|
1098
1509
|
}
|
|
1099
|
-
if (resource.kind === "email" && url) env[(0, __geekmidas_manifest.provideKey)(resource.id, "from")] = options.mailFrom ?? `noreply@${LOCAL_HOST}`;
|
|
1100
1510
|
}
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1511
|
+
for (const id of edges) {
|
|
1512
|
+
const target = manifest[id];
|
|
1513
|
+
if (!target) continue;
|
|
1514
|
+
for (const key of target.provides ?? []) keys.add(key);
|
|
1515
|
+
if (target.kind === "queue" || target.kind === "topic") keys.add("EVENT_PUBLISHER_CONNECTION_STRING");
|
|
1516
|
+
if (target.kind === "objects") {
|
|
1517
|
+
keys.add("AWS_ACCESS_KEY_ID");
|
|
1518
|
+
keys.add("AWS_SECRET_ACCESS_KEY");
|
|
1519
|
+
keys.add("AWS_REGION");
|
|
1520
|
+
}
|
|
1521
|
+
}
|
|
1522
|
+
if (declaration.kind === "site" || declaration.kind === "mobile-app") for (const key of Object.keys((0, _geekmidas_manifest.publicEnvFor)(declaration, manifest))) keys.add(key);
|
|
1523
|
+
return keys;
|
|
1524
|
+
}
|
|
1525
|
+
/** One compose service per app the workspace runs, behind the apps profile. */
|
|
1526
|
+
function appServices(workspace, manifest, containers, runnables = {}, fakes = {}) {
|
|
1527
|
+
const env = inNetworkEnv(workspace, manifest, fakes);
|
|
1528
|
+
const services = {};
|
|
1529
|
+
for (const [name, app] of Object.entries(workspace.apps)) {
|
|
1530
|
+
if (app.type === "mobile" || !app.port) continue;
|
|
1531
|
+
const key = require_config.appKey(name);
|
|
1532
|
+
const health = app.type === "web" ? "/" : "/health";
|
|
1533
|
+
const allowed = appEnvKeys(manifest, name, runnables);
|
|
1534
|
+
const own = Object.fromEntries(Object.entries(env).filter(([envKey]) => allowed?.has(envKey)));
|
|
1535
|
+
services[key] = {
|
|
1536
|
+
image: `${key}:\${TAG:-latest}`,
|
|
1537
|
+
build: {
|
|
1538
|
+
context: ".",
|
|
1539
|
+
dockerfile: dockerfileOf(name, app.path)
|
|
1540
|
+
},
|
|
1541
|
+
profiles: [APPS_PROFILE],
|
|
1542
|
+
ports: [`${app.port}:${app.port}`],
|
|
1543
|
+
environment: {
|
|
1544
|
+
NODE_ENV: "production",
|
|
1545
|
+
PORT: String(app.port),
|
|
1546
|
+
...own
|
|
1547
|
+
},
|
|
1548
|
+
...containers.some((c) => c !== "caddy") ? { depends_on: containers.filter((c) => c !== "caddy") } : {},
|
|
1549
|
+
healthcheck: {
|
|
1550
|
+
test: [
|
|
1551
|
+
"CMD",
|
|
1552
|
+
"wget",
|
|
1553
|
+
"-q",
|
|
1554
|
+
"--spider",
|
|
1555
|
+
`http://localhost:${app.port}${health}`
|
|
1556
|
+
],
|
|
1557
|
+
interval: "10s",
|
|
1558
|
+
timeout: "5s",
|
|
1559
|
+
retries: 5
|
|
1560
|
+
}
|
|
1561
|
+
};
|
|
1562
|
+
}
|
|
1563
|
+
return services;
|
|
1105
1564
|
}
|
|
1565
|
+
//#endregion
|
|
1566
|
+
//#region src/reconcile/clients.ts
|
|
1106
1567
|
/**
|
|
1107
|
-
* The
|
|
1568
|
+
* The real Postgres and MinIO clients the applier runs against.
|
|
1108
1569
|
*
|
|
1109
|
-
*
|
|
1110
|
-
*
|
|
1111
|
-
*
|
|
1112
|
-
* twice, so a site and its API cannot come to disagree about where the API is.
|
|
1570
|
+
* Kept apart from `provision.ts` so the rules there — what gets created, in what
|
|
1571
|
+
* order, and never dropping anything — are asserted against fakes, while the
|
|
1572
|
+
* drivers live here where there is nothing to assert but wiring.
|
|
1113
1573
|
*
|
|
1114
|
-
*
|
|
1115
|
-
*
|
|
1116
|
-
* against `http:///`, where a missing variable fails at build with the name of
|
|
1117
|
-
* the thing that is missing.
|
|
1574
|
+
* Both are constructed from the same local addresses the env writer composes,
|
|
1575
|
+
* so the applier cannot end up talking to a different container than the app.
|
|
1118
1576
|
*/
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
for (const resource of plan.resources) for (const [key, source] of Object.entries(resource.publicEnv ?? {})) {
|
|
1122
|
-
const value = resolved[source];
|
|
1123
|
-
if (value) env[key] = value;
|
|
1124
|
-
}
|
|
1125
|
-
return env;
|
|
1126
|
-
}
|
|
1577
|
+
/** The credential local containers are brought up with. */
|
|
1578
|
+
const LOCAL_USER$1 = "geekmidas";
|
|
1127
1579
|
/**
|
|
1128
|
-
*
|
|
1129
|
-
* a cookie set by it is readable.
|
|
1130
|
-
*
|
|
1131
|
-
* Both are read off the same list — the constructs that declared an edge to
|
|
1132
|
-
* this surface — which is why neither appears in application code. A surface
|
|
1133
|
-
* that listed its own callers would be edited every time something new called
|
|
1134
|
-
* it, and the thing being edited is already recorded in the graph.
|
|
1580
|
+
* A Postgres client that opens one connection per database it is asked about.
|
|
1135
1581
|
*
|
|
1136
|
-
*
|
|
1137
|
-
*
|
|
1138
|
-
*
|
|
1139
|
-
* means it is not running in this stage, and keys belong with the address they
|
|
1140
|
-
* describe.
|
|
1582
|
+
* `CREATE DATABASE` cannot run from a connection to the database being created,
|
|
1583
|
+
* and a schema must be created from inside its own database — so the database is
|
|
1584
|
+
* part of each query rather than fixed when the client is built.
|
|
1141
1585
|
*/
|
|
1142
|
-
function
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1586
|
+
function pgClient(port) {
|
|
1587
|
+
return { async query(database, sql, values) {
|
|
1588
|
+
const client = new pg.Client({
|
|
1589
|
+
host: "localhost",
|
|
1590
|
+
port,
|
|
1591
|
+
user: LOCAL_USER$1,
|
|
1592
|
+
password: LOCAL_USER$1,
|
|
1593
|
+
database: database ?? LOCAL_USER$1
|
|
1594
|
+
});
|
|
1595
|
+
await client.connect();
|
|
1596
|
+
try {
|
|
1597
|
+
return (await client.query(sql, values)).rows;
|
|
1598
|
+
} finally {
|
|
1599
|
+
await client.end();
|
|
1600
|
+
}
|
|
1601
|
+
} };
|
|
1602
|
+
}
|
|
1603
|
+
/** A bucket client pointed at the local MinIO. */
|
|
1604
|
+
function bucketClient(port) {
|
|
1605
|
+
const s3 = new _aws_sdk_client_s3.S3Client({
|
|
1606
|
+
region: "us-east-1",
|
|
1607
|
+
endpoint: `http://localhost:${port}`,
|
|
1608
|
+
forcePathStyle: true,
|
|
1609
|
+
credentials: {
|
|
1610
|
+
accessKeyId: LOCAL_USER$1,
|
|
1611
|
+
secretAccessKey: LOCAL_USER$1
|
|
1612
|
+
}
|
|
1613
|
+
});
|
|
1614
|
+
return {
|
|
1615
|
+
async exists(bucket) {
|
|
1616
|
+
try {
|
|
1617
|
+
await s3.send(new _aws_sdk_client_s3.HeadBucketCommand({ Bucket: bucket }));
|
|
1618
|
+
return true;
|
|
1619
|
+
} catch {
|
|
1620
|
+
return false;
|
|
1621
|
+
}
|
|
1622
|
+
},
|
|
1623
|
+
async create(bucket) {
|
|
1624
|
+
await s3.send(new _aws_sdk_client_s3.CreateBucketCommand({ Bucket: bucket }));
|
|
1625
|
+
},
|
|
1626
|
+
async policy(bucket) {
|
|
1627
|
+
try {
|
|
1628
|
+
return (await s3.send(new _aws_sdk_client_s3.GetBucketPolicyCommand({ Bucket: bucket }))).Policy;
|
|
1629
|
+
} catch {
|
|
1630
|
+
return;
|
|
1631
|
+
}
|
|
1632
|
+
},
|
|
1633
|
+
async setPolicy(bucket, policy) {
|
|
1634
|
+
await s3.send(new _aws_sdk_client_s3.PutBucketPolicyCommand({
|
|
1635
|
+
Bucket: bucket,
|
|
1636
|
+
Policy: policy
|
|
1637
|
+
}));
|
|
1638
|
+
}
|
|
1639
|
+
};
|
|
1640
|
+
}
|
|
1641
|
+
/** A topic and queue client pointed at the local AWS emulator. */
|
|
1642
|
+
function carrierClient(port) {
|
|
1643
|
+
const config = {
|
|
1644
|
+
region: EMULATOR_REGION,
|
|
1645
|
+
endpoint: emulatorEndpoint(port),
|
|
1646
|
+
credentials: EMULATOR_CREDENTIALS
|
|
1647
|
+
};
|
|
1648
|
+
const sns = new _aws_sdk_client_sns.SNSClient(config);
|
|
1649
|
+
const sqs = new _aws_sdk_client_sqs.SQSClient(config);
|
|
1146
1650
|
return {
|
|
1147
|
-
|
|
1148
|
-
|
|
1651
|
+
async topicExists(name) {
|
|
1652
|
+
try {
|
|
1653
|
+
await sns.send(new _aws_sdk_client_sns.GetTopicAttributesCommand({ TopicArn: emulatorTopicArn(name) }));
|
|
1654
|
+
return true;
|
|
1655
|
+
} catch {
|
|
1656
|
+
return false;
|
|
1657
|
+
}
|
|
1658
|
+
},
|
|
1659
|
+
async createTopic(name) {
|
|
1660
|
+
await sns.send(new _aws_sdk_client_sns.CreateTopicCommand({ Name: name }));
|
|
1661
|
+
},
|
|
1662
|
+
async queueExists(name) {
|
|
1663
|
+
try {
|
|
1664
|
+
await sqs.send(new _aws_sdk_client_sqs.GetQueueUrlCommand({ QueueName: name }));
|
|
1665
|
+
return true;
|
|
1666
|
+
} catch {
|
|
1667
|
+
return false;
|
|
1668
|
+
}
|
|
1669
|
+
},
|
|
1670
|
+
async createQueue(name) {
|
|
1671
|
+
await sqs.send(new _aws_sdk_client_sqs.CreateQueueCommand({ QueueName: name }));
|
|
1672
|
+
}
|
|
1149
1673
|
};
|
|
1150
1674
|
}
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
try {
|
|
1154
|
-
return new URL(address).origin;
|
|
1155
|
-
} catch {
|
|
1156
|
-
return void 0;
|
|
1157
|
-
}
|
|
1158
|
-
}
|
|
1675
|
+
//#endregion
|
|
1676
|
+
//#region src/reconcile/compose.ts
|
|
1159
1677
|
/**
|
|
1160
|
-
* The
|
|
1678
|
+
* The compose document a plan implies.
|
|
1161
1679
|
*
|
|
1162
|
-
*
|
|
1163
|
-
*
|
|
1164
|
-
*
|
|
1680
|
+
* The third declaration of the same containers disappears here: today a
|
|
1681
|
+
* `services: ['postgres','minio']` block is kept in step with the code by hand,
|
|
1682
|
+
* which is the triplication this design exists to remove, in the one place you
|
|
1683
|
+
* touch every day. A `database` implies Postgres; the list is derived.
|
|
1684
|
+
*
|
|
1685
|
+
* Returns an object rather than a string for the same reason `plan` is pure —
|
|
1686
|
+
* what should exist is asserted as data, and turning it into YAML is one line at
|
|
1687
|
+
* the edge.
|
|
1688
|
+
*
|
|
1689
|
+
* What stays config is unchanged: images and versions are pinned explicitly, and
|
|
1690
|
+
* a container no construct implies is still declared by hand. Neutral facts come
|
|
1691
|
+
* from the declaration, provider detail from config.
|
|
1165
1692
|
*/
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
return parent ? localRole(parent) : resource.name;
|
|
1169
|
-
}
|
|
1170
|
-
/** Whether a kind connects to Postgres and therefore has an owner role. */
|
|
1171
|
-
function isDatabase(kind) {
|
|
1172
|
-
return kind === "database" || kind === "database-schema";
|
|
1173
|
-
}
|
|
1693
|
+
/** The credential every derived container is brought up with locally. */
|
|
1694
|
+
const LOCAL_USER = "geekmidas";
|
|
1174
1695
|
/**
|
|
1175
|
-
* The
|
|
1176
|
-
* and drop.
|
|
1696
|
+
* The token the local cache accepts.
|
|
1177
1697
|
*
|
|
1178
|
-
*
|
|
1179
|
-
*
|
|
1180
|
-
*
|
|
1181
|
-
* by nothing else.
|
|
1698
|
+
* Fixed rather than generated: it is only ever reachable on a port this project
|
|
1699
|
+
* published, and the URL that carries it is derived, so nothing is made safer
|
|
1700
|
+
* by making it unguessable and a stable one keeps `redis-cli` sessions working.
|
|
1182
1701
|
*/
|
|
1183
|
-
|
|
1184
|
-
if (!resource.container) return void 0;
|
|
1185
|
-
const port = ports[primaryPortKey(resource.container)];
|
|
1186
|
-
if (port === void 0) return void 0;
|
|
1187
|
-
const owner = (0, __geekmidas_db_pg_roles.ownerRole)(localRole(resource));
|
|
1188
|
-
return postgres(port, rootDatabase(resource, plan), {
|
|
1189
|
-
user: owner,
|
|
1190
|
-
password: localRolePassword(project, plan, owner)
|
|
1191
|
-
});
|
|
1192
|
-
}
|
|
1702
|
+
const LOCAL_TOKEN = "geekmidas";
|
|
1193
1703
|
/**
|
|
1194
|
-
*
|
|
1704
|
+
* Build the compose document for a plan.
|
|
1195
1705
|
*
|
|
1196
|
-
*
|
|
1197
|
-
*
|
|
1198
|
-
*
|
|
1199
|
-
* on it. Deployed there is no such thing — a Lambda is handed its own event
|
|
1200
|
-
* source — so this pair exists for the local target and says so.
|
|
1706
|
+
* Every container is published on its assigned port, never on the image's
|
|
1707
|
+
* default: the point of allocation is that two projects can run at once, and
|
|
1708
|
+
* one container publishing 5432 puts that back.
|
|
1201
1709
|
*/
|
|
1202
|
-
function
|
|
1203
|
-
const
|
|
1204
|
-
|
|
1205
|
-
const
|
|
1206
|
-
|
|
1710
|
+
function composeFor(plan, options) {
|
|
1711
|
+
const services = {};
|
|
1712
|
+
const volumes = {};
|
|
1713
|
+
for (const container of [...plan.containers].sort()) {
|
|
1714
|
+
const declared = container === "postgres" ? plan.resources.find((r) => r.version)?.version : void 0;
|
|
1715
|
+
const fake = plan.fakes?.[container];
|
|
1716
|
+
const image = declared ? postgresImage(declared) : fake?.image ?? DEFAULT_IMAGES[container];
|
|
1717
|
+
if (!image) throw new UnknownContainer(container);
|
|
1718
|
+
const published = publish(container, options.ports, plan.fakes);
|
|
1719
|
+
services[container] = fake ? {
|
|
1720
|
+
image,
|
|
1721
|
+
restart: "unless-stopped",
|
|
1722
|
+
ports: published
|
|
1723
|
+
} : define(container, image, published);
|
|
1724
|
+
const volume = volumeOf(container);
|
|
1725
|
+
if (volume) volumes[volume] = {};
|
|
1726
|
+
}
|
|
1207
1727
|
return {
|
|
1208
|
-
|
|
1209
|
-
|
|
1728
|
+
name: options.project,
|
|
1729
|
+
services: {
|
|
1730
|
+
...services,
|
|
1731
|
+
...options.apps
|
|
1732
|
+
},
|
|
1733
|
+
...Object.keys(volumes).length ? { volumes } : {}
|
|
1210
1734
|
};
|
|
1211
1735
|
}
|
|
1212
|
-
/**
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1736
|
+
/** Render a compose document as the file it becomes. */
|
|
1737
|
+
function toYaml(file) {
|
|
1738
|
+
return `# Generated by gkm from the construct manifest — do not edit.
|
|
1739
|
+
# Containers are derived from what the app declares. Image pins and anything
|
|
1740
|
+
# no construct implies go in your own docker-compose.yml, which is merged over
|
|
1741
|
+
# this file and wins:
|
|
1742
|
+
#
|
|
1743
|
+
# docker compose -f docker-compose.constructs.yml -f docker-compose.yml …
|
|
1744
|
+
#
|
|
1745
|
+
# "gkm dev" and "gkm test" start the containers. The apps sit behind the
|
|
1746
|
+
# "apps" profile: run "gkm setup", then
|
|
1747
|
+
# docker compose -f docker-compose.constructs.yml --profile apps up --build
|
|
1748
|
+
${(0, yaml.stringify)(file, { lineWidth: 0 })}`;
|
|
1749
|
+
}
|
|
1750
|
+
/** A container with no image, from config or from the defaults. */
|
|
1751
|
+
var UnknownContainer = class extends Error {
|
|
1752
|
+
/** The container that could not be resolved. */
|
|
1753
|
+
container;
|
|
1754
|
+
/** The containers that have a default, so the caller can see the set. */
|
|
1755
|
+
known = Object.keys(DEFAULT_IMAGES).sort();
|
|
1756
|
+
constructor(container) {
|
|
1757
|
+
super("No image is known for this container; pin one in config");
|
|
1758
|
+
this.name = "UnknownContainer";
|
|
1759
|
+
this.container = container;
|
|
1224
1760
|
}
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
switch (
|
|
1229
|
-
case "
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1761
|
+
};
|
|
1762
|
+
/** One container's definition, published on the port it was assigned. */
|
|
1763
|
+
function define(container, image, published) {
|
|
1764
|
+
switch (container) {
|
|
1765
|
+
case "postgres": return {
|
|
1766
|
+
image,
|
|
1767
|
+
restart: "unless-stopped",
|
|
1768
|
+
ports: published,
|
|
1769
|
+
environment: {
|
|
1770
|
+
POSTGRES_USER: LOCAL_USER,
|
|
1771
|
+
POSTGRES_PASSWORD: LOCAL_USER,
|
|
1772
|
+
POSTGRES_DB: LOCAL_USER
|
|
1773
|
+
},
|
|
1774
|
+
volumes: ["postgres-data:/var/lib/postgresql"],
|
|
1775
|
+
healthcheck: {
|
|
1776
|
+
test: ["CMD-SHELL", `pg_isready -U ${LOCAL_USER}`],
|
|
1777
|
+
interval: "5s",
|
|
1778
|
+
timeout: "3s",
|
|
1779
|
+
retries: 10,
|
|
1780
|
+
start_period: "10s"
|
|
1236
1781
|
}
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1782
|
+
};
|
|
1783
|
+
case "minio": return {
|
|
1784
|
+
image,
|
|
1785
|
+
restart: "unless-stopped",
|
|
1786
|
+
ports: published,
|
|
1787
|
+
environment: {
|
|
1788
|
+
MINIO_ROOT_USER: LOCAL_USER,
|
|
1789
|
+
MINIO_ROOT_PASSWORD: LOCAL_USER
|
|
1790
|
+
},
|
|
1791
|
+
command: "server --console-address \":9001\" /data",
|
|
1792
|
+
volumes: ["minio-data:/data"],
|
|
1793
|
+
healthcheck: {
|
|
1794
|
+
test: [
|
|
1795
|
+
"CMD",
|
|
1796
|
+
"mc",
|
|
1797
|
+
"ready",
|
|
1798
|
+
"local"
|
|
1799
|
+
],
|
|
1800
|
+
interval: "10s",
|
|
1801
|
+
timeout: "5s",
|
|
1802
|
+
retries: 5,
|
|
1803
|
+
start_period: "10s"
|
|
1804
|
+
}
|
|
1805
|
+
};
|
|
1806
|
+
case "caddy": return {
|
|
1807
|
+
image,
|
|
1808
|
+
restart: "unless-stopped",
|
|
1809
|
+
ports: published,
|
|
1810
|
+
volumes: [
|
|
1811
|
+
"./.gkm/Caddyfile:/etc/caddy/Caddyfile:ro",
|
|
1812
|
+
"./.gkm/caddy-sites:/etc/caddy/sites:ro",
|
|
1813
|
+
"caddy-data:/data"
|
|
1814
|
+
],
|
|
1815
|
+
extra_hosts: ["host.docker.internal:host-gateway"],
|
|
1816
|
+
healthcheck: {
|
|
1817
|
+
test: [
|
|
1818
|
+
"CMD",
|
|
1819
|
+
"caddy",
|
|
1820
|
+
"version"
|
|
1821
|
+
],
|
|
1822
|
+
interval: "10s",
|
|
1823
|
+
timeout: "5s",
|
|
1824
|
+
retries: 5
|
|
1825
|
+
}
|
|
1826
|
+
};
|
|
1827
|
+
case "mailpit": return {
|
|
1828
|
+
image,
|
|
1829
|
+
restart: "unless-stopped",
|
|
1830
|
+
ports: published,
|
|
1831
|
+
environment: {
|
|
1832
|
+
MP_SMTP_AUTH_ACCEPT_ANY: "1",
|
|
1833
|
+
MP_SMTP_AUTH_ALLOW_INSECURE: "1"
|
|
1834
|
+
},
|
|
1835
|
+
healthcheck: {
|
|
1836
|
+
test: [
|
|
1837
|
+
"CMD",
|
|
1838
|
+
"wget",
|
|
1839
|
+
"-q",
|
|
1840
|
+
"--spider",
|
|
1841
|
+
"http://localhost:8025"
|
|
1842
|
+
],
|
|
1843
|
+
interval: "10s",
|
|
1844
|
+
timeout: "5s",
|
|
1845
|
+
retries: 5
|
|
1846
|
+
}
|
|
1847
|
+
};
|
|
1848
|
+
case "redis": return {
|
|
1849
|
+
image,
|
|
1850
|
+
restart: "unless-stopped",
|
|
1851
|
+
ports: published,
|
|
1852
|
+
volumes: ["redis-data:/data"],
|
|
1853
|
+
healthcheck: {
|
|
1854
|
+
test: [
|
|
1855
|
+
"CMD",
|
|
1856
|
+
"redis-cli",
|
|
1857
|
+
"ping"
|
|
1858
|
+
],
|
|
1859
|
+
interval: "5s",
|
|
1860
|
+
timeout: "3s",
|
|
1861
|
+
retries: 5
|
|
1862
|
+
}
|
|
1863
|
+
};
|
|
1864
|
+
case "redis-http": return {
|
|
1865
|
+
image,
|
|
1866
|
+
restart: "unless-stopped",
|
|
1867
|
+
ports: published,
|
|
1868
|
+
environment: {
|
|
1869
|
+
SRH_MODE: "env",
|
|
1870
|
+
SRH_TOKEN: LOCAL_TOKEN,
|
|
1871
|
+
SRH_CONNECTION_STRING: "redis://redis:6379"
|
|
1872
|
+
},
|
|
1873
|
+
depends_on: ["redis"],
|
|
1874
|
+
healthcheck: {
|
|
1875
|
+
test: [
|
|
1876
|
+
"CMD",
|
|
1877
|
+
"wget",
|
|
1878
|
+
"-q",
|
|
1879
|
+
"-O",
|
|
1880
|
+
"/dev/null",
|
|
1881
|
+
"http://127.0.0.1:80/"
|
|
1882
|
+
],
|
|
1883
|
+
interval: "5s",
|
|
1884
|
+
timeout: "3s",
|
|
1885
|
+
retries: 10
|
|
1886
|
+
}
|
|
1887
|
+
};
|
|
1888
|
+
case "rabbitmq": return {
|
|
1889
|
+
image,
|
|
1890
|
+
restart: "unless-stopped",
|
|
1891
|
+
ports: published,
|
|
1892
|
+
environment: {
|
|
1893
|
+
RABBITMQ_DEFAULT_USER: LOCAL_USER,
|
|
1894
|
+
RABBITMQ_DEFAULT_PASS: LOCAL_USER
|
|
1895
|
+
},
|
|
1896
|
+
volumes: ["rabbitmq-data:/var/lib/rabbitmq"],
|
|
1897
|
+
healthcheck: {
|
|
1898
|
+
test: [
|
|
1899
|
+
"CMD",
|
|
1900
|
+
"rabbitmq-diagnostics",
|
|
1901
|
+
"-q",
|
|
1902
|
+
"ping"
|
|
1903
|
+
],
|
|
1904
|
+
interval: "10s",
|
|
1905
|
+
timeout: "5s",
|
|
1906
|
+
retries: 5
|
|
1255
1907
|
}
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1908
|
+
};
|
|
1909
|
+
case "localstack": return {
|
|
1910
|
+
image,
|
|
1911
|
+
restart: "unless-stopped",
|
|
1912
|
+
ports: published,
|
|
1913
|
+
extra_hosts: ["host.docker.internal:host-gateway"],
|
|
1914
|
+
environment: {
|
|
1915
|
+
AWS_DEFAULT_REGION: EMULATOR_REGION,
|
|
1916
|
+
AWS_ACCESS_KEY_ID: EMULATOR_CREDENTIALS.accessKeyId,
|
|
1917
|
+
AWS_SECRET_ACCESS_KEY: EMULATOR_CREDENTIALS.secretAccessKey
|
|
1918
|
+
},
|
|
1919
|
+
volumes: ["localstack-data:/var/lib/localstack"],
|
|
1920
|
+
healthcheck: {
|
|
1921
|
+
test: [
|
|
1922
|
+
"CMD",
|
|
1923
|
+
"bash",
|
|
1924
|
+
"-c",
|
|
1925
|
+
"exec 3<>/dev/tcp/localhost/4566"
|
|
1926
|
+
],
|
|
1927
|
+
interval: "10s",
|
|
1928
|
+
timeout: "5s",
|
|
1929
|
+
retries: 5,
|
|
1930
|
+
start_period: "10s"
|
|
1259
1931
|
}
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
default: return void 0;
|
|
1263
|
-
}
|
|
1264
|
-
}
|
|
1265
|
-
/**
|
|
1266
|
-
* The producer's connection string, composed from the backend the plan chose.
|
|
1267
|
-
*
|
|
1268
|
-
* The protocol is what picks the transport, so a producer never branches: the
|
|
1269
|
-
* same `.publish()` reaches pg-boss here and SQS deployed because the string it
|
|
1270
|
-
* was handed said so.
|
|
1271
|
-
*/
|
|
1272
|
-
function broker(plan, port) {
|
|
1273
|
-
switch (plan.events) {
|
|
1274
|
-
case "pgboss": {
|
|
1275
|
-
const database = plan.resources.find((r) => r.kind === "database");
|
|
1276
|
-
if (!database) throw new PgBossNeedsDatabase([]);
|
|
1277
|
-
return `pgboss://${LOCAL_USER}:${LOCAL_USER}@${LOCAL_HOST}:${port}/${database.name}?schema=${PGBOSS_SCHEMA}`;
|
|
1278
|
-
}
|
|
1279
|
-
case "rabbitmq": return `rabbitmq://${LOCAL_USER}:${LOCAL_USER}@${LOCAL_HOST}:${port}?exchange=${RABBITMQ_EXCHANGE}`;
|
|
1280
|
-
case "sns": throw new UnprovisionedEventsBackend("sns");
|
|
1932
|
+
};
|
|
1933
|
+
default: throw new UnknownContainer(container);
|
|
1281
1934
|
}
|
|
1282
1935
|
}
|
|
1283
|
-
/** A local Postgres URL, master credential and all. */
|
|
1284
|
-
function postgres(port, database, credential = {
|
|
1285
|
-
user: LOCAL_USER,
|
|
1286
|
-
password: LOCAL_USER
|
|
1287
|
-
}) {
|
|
1288
|
-
return `postgres://${credential.user}:${credential.password}@${LOCAL_HOST}:${port}/${database}`;
|
|
1289
|
-
}
|
|
1290
1936
|
/**
|
|
1291
|
-
* The
|
|
1937
|
+
* The published port mappings for a container.
|
|
1292
1938
|
*
|
|
1293
|
-
*
|
|
1294
|
-
*
|
|
1295
|
-
*
|
|
1296
|
-
* in Postgres, which is why the suffix is not optional here the way it is for a
|
|
1297
|
-
* schema.
|
|
1939
|
+
* Every port is looked up by its own key rather than being derived as an offset
|
|
1940
|
+
* from the container's first, so MinIO's console cannot land on whatever was
|
|
1941
|
+
* allocated to the next container.
|
|
1298
1942
|
*/
|
|
1299
|
-
function
|
|
1300
|
-
return
|
|
1943
|
+
function publish(container, ports, fakes) {
|
|
1944
|
+
return portsOf(container, fakes).map((port) => {
|
|
1945
|
+
const assigned = ports[port.key];
|
|
1946
|
+
if (assigned === void 0) throw new UnassignedPort(port.key);
|
|
1947
|
+
return `${assigned}:${port.inside}`;
|
|
1948
|
+
});
|
|
1301
1949
|
}
|
|
1950
|
+
/** A planned port that allocation never assigned. */
|
|
1951
|
+
var UnassignedPort = class extends Error {
|
|
1952
|
+
/** The port key that went unassigned, e.g. `minio-console`. */
|
|
1953
|
+
key;
|
|
1954
|
+
constructor(key) {
|
|
1955
|
+
super("No port was assigned for this container port");
|
|
1956
|
+
this.name = "UnassignedPort";
|
|
1957
|
+
this.key = key;
|
|
1958
|
+
}
|
|
1959
|
+
};
|
|
1960
|
+
//#endregion
|
|
1961
|
+
//#region src/reconcile/docker.ts
|
|
1302
1962
|
/**
|
|
1303
|
-
* The
|
|
1963
|
+
* The real Docker, behind the small interface reconcile needs.
|
|
1304
1964
|
*
|
|
1305
|
-
*
|
|
1306
|
-
*
|
|
1307
|
-
*
|
|
1308
|
-
* share one, and by the stage so `test` and `development` do not.
|
|
1965
|
+
* Shells out to `docker compose` rather than talking to the daemon socket: it is
|
|
1966
|
+
* what a developer runs by hand when something is wrong, so the two cannot
|
|
1967
|
+
* disagree, and it keeps Docker out of this package's dependencies.
|
|
1309
1968
|
*
|
|
1310
|
-
*
|
|
1311
|
-
*
|
|
1969
|
+
* Every call is scoped to the generated compose file. Nothing here can touch a
|
|
1970
|
+
* container this project did not generate.
|
|
1312
1971
|
*/
|
|
1313
|
-
|
|
1314
|
-
return (0, node_crypto.createHash)("sha256").update(`${project}:${plan.stage}:role:${role}`).digest("base64url").slice(0, 32);
|
|
1315
|
-
}
|
|
1972
|
+
const run = (0, node_util.promisify)(node_child_process.execFile);
|
|
1316
1973
|
/**
|
|
1317
|
-
*
|
|
1974
|
+
* The generated file, then the project's own if it has one.
|
|
1318
1975
|
*
|
|
1319
|
-
*
|
|
1320
|
-
*
|
|
1321
|
-
* two keys are one more thing to keep in step.
|
|
1976
|
+
* Merged in that order so the project's wins — an `image:` there pins a
|
|
1977
|
+
* container this file derived, and a service there is added beside them.
|
|
1322
1978
|
*/
|
|
1323
|
-
function
|
|
1324
|
-
const
|
|
1325
|
-
|
|
1326
|
-
|
|
1979
|
+
function composeFiles(composePath) {
|
|
1980
|
+
const project = (0, node_path.join)((0, node_path.dirname)(composePath), "docker-compose.yml");
|
|
1981
|
+
return [
|
|
1982
|
+
"-f",
|
|
1983
|
+
composePath,
|
|
1984
|
+
...(0, node_fs.existsSync)(project) ? ["-f", project] : []
|
|
1985
|
+
];
|
|
1327
1986
|
}
|
|
1328
|
-
/**
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
const parent = byId.get(current.of);
|
|
1340
|
-
if (!parent) break;
|
|
1341
|
-
current = parent;
|
|
1987
|
+
/** How long to wait for containers to pass their health checks. */
|
|
1988
|
+
const HEALTH_TIMEOUT_MS = 12e4;
|
|
1989
|
+
/** `docker compose up` exited unsuccessfully; its own output said why. */
|
|
1990
|
+
var ComposeUpFailed = class extends Error {
|
|
1991
|
+
services;
|
|
1992
|
+
code;
|
|
1993
|
+
constructor(services, code) {
|
|
1994
|
+
super(`docker compose could not start ${services.join(", ")} (exit ${code ?? "signal"}). Its output above names the container; \`docker compose logs <service>\` shows why it stopped.`);
|
|
1995
|
+
this.services = services;
|
|
1996
|
+
this.code = code;
|
|
1997
|
+
this.name = "ComposeUpFailed";
|
|
1342
1998
|
}
|
|
1343
|
-
|
|
1999
|
+
};
|
|
2000
|
+
/** Run compose with its output on this terminal rather than captured. */
|
|
2001
|
+
function shown(args, services) {
|
|
2002
|
+
return new Promise((resolve, reject) => {
|
|
2003
|
+
const child = (0, node_child_process.spawn)("docker", args, { stdio: [
|
|
2004
|
+
"ignore",
|
|
2005
|
+
"inherit",
|
|
2006
|
+
"inherit"
|
|
2007
|
+
] });
|
|
2008
|
+
child.on("error", reject);
|
|
2009
|
+
child.on("close", (code) => code === 0 ? resolve() : reject(new ComposeUpFailed(services, code)));
|
|
2010
|
+
});
|
|
1344
2011
|
}
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
2012
|
+
const dockerCli = {
|
|
2013
|
+
async publishedPort(composePath, service, inside) {
|
|
2014
|
+
try {
|
|
2015
|
+
const { stdout } = await run("docker", [
|
|
2016
|
+
"compose",
|
|
2017
|
+
...composeFiles(composePath),
|
|
2018
|
+
"port",
|
|
2019
|
+
service,
|
|
2020
|
+
String(inside)
|
|
2021
|
+
]);
|
|
2022
|
+
const port = Number(stdout.trim().split(":").pop());
|
|
2023
|
+
return Number.isFinite(port) && port > 0 ? port : void 0;
|
|
2024
|
+
} catch {
|
|
2025
|
+
return;
|
|
2026
|
+
}
|
|
2027
|
+
},
|
|
2028
|
+
async up(composePath, services, options = {}) {
|
|
2029
|
+
const args = [
|
|
2030
|
+
"compose",
|
|
2031
|
+
...composeFiles(composePath),
|
|
2032
|
+
"up",
|
|
2033
|
+
"-d",
|
|
2034
|
+
"--remove-orphans",
|
|
2035
|
+
"--wait",
|
|
2036
|
+
`--wait-timeout=${Math.floor(HEALTH_TIMEOUT_MS / 1e3)}`,
|
|
2037
|
+
...services
|
|
2038
|
+
];
|
|
2039
|
+
if (options.show) return shown(args, services);
|
|
2040
|
+
await run("docker", args);
|
|
2041
|
+
},
|
|
2042
|
+
async copyOut(composePath, service, from, to) {
|
|
2043
|
+
await (0, node_fs_promises.mkdir)((0, node_path.dirname)(to), { recursive: true });
|
|
2044
|
+
await run("docker", [
|
|
2045
|
+
"compose",
|
|
2046
|
+
...composeFiles(composePath),
|
|
2047
|
+
"cp",
|
|
2048
|
+
`${service}:${from}`,
|
|
2049
|
+
to
|
|
2050
|
+
]);
|
|
2051
|
+
},
|
|
2052
|
+
async reload(composePath, service) {
|
|
2053
|
+
await run("docker", [
|
|
2054
|
+
"compose",
|
|
2055
|
+
...composeFiles(composePath),
|
|
2056
|
+
"exec",
|
|
2057
|
+
"-T",
|
|
2058
|
+
service,
|
|
2059
|
+
"caddy",
|
|
2060
|
+
"reload",
|
|
2061
|
+
"--config",
|
|
2062
|
+
"/etc/caddy/Caddyfile"
|
|
2063
|
+
]);
|
|
2064
|
+
},
|
|
2065
|
+
async healthy(composePath, services) {
|
|
2066
|
+
if (services.length === 0) return true;
|
|
2067
|
+
try {
|
|
2068
|
+
const { stdout } = await run("docker", [
|
|
2069
|
+
"compose",
|
|
2070
|
+
...composeFiles(composePath),
|
|
2071
|
+
"ps",
|
|
2072
|
+
"--format",
|
|
2073
|
+
"json",
|
|
2074
|
+
...services
|
|
2075
|
+
]);
|
|
2076
|
+
const running = /* @__PURE__ */ new Set();
|
|
2077
|
+
for (const line of stdout.trim().split("\n").filter(Boolean)) {
|
|
2078
|
+
const entry = JSON.parse(line);
|
|
2079
|
+
if (entry.State === "running" && (entry.Health === void 0 || entry.Health === "" || entry.Health === "healthy") && entry.Service) running.add(entry.Service);
|
|
2080
|
+
}
|
|
2081
|
+
return services.every((service) => running.has(service));
|
|
2082
|
+
} catch {
|
|
2083
|
+
return false;
|
|
2084
|
+
}
|
|
1352
2085
|
}
|
|
1353
|
-
|
|
1354
|
-
|
|
2086
|
+
};
|
|
2087
|
+
//#endregion
|
|
2088
|
+
//#region src/reconcile/lan.ts
|
|
1355
2089
|
/**
|
|
1356
|
-
*
|
|
1357
|
-
*
|
|
1358
|
-
* SNS and SQS are addressed by ARN, which means the topic and queue have to be
|
|
1359
|
-
* created in LocalStack before a URL can name them. Until that provisioning
|
|
1360
|
-
* lands, saying so is better than handing out a string that fails on first use.
|
|
2090
|
+
* This machine's address on the local network — what a phone running the app
|
|
2091
|
+
* reaches it on.
|
|
1361
2092
|
*/
|
|
1362
|
-
var UnprovisionedEventsBackend = class extends Error {
|
|
1363
|
-
constructor(backend) {
|
|
1364
|
-
super(`The local target cannot derive addresses for '${backend}' yet — its topics and queues are named by ARN, which nothing creates locally. Use 'pgboss' (the default) or 'rabbitmq' for local development.`);
|
|
1365
|
-
this.backend = backend;
|
|
1366
|
-
this.name = "UnprovisionedEventsBackend";
|
|
1367
|
-
}
|
|
1368
|
-
};
|
|
1369
2093
|
/**
|
|
1370
|
-
* The
|
|
2094
|
+
* The first private IPv4 address of an interface that is up and not loopback.
|
|
1371
2095
|
*
|
|
1372
|
-
*
|
|
1373
|
-
*
|
|
1374
|
-
*
|
|
1375
|
-
*
|
|
2096
|
+
* Private ranges only (`10/8`, `172.16/12`, `192.168/16`): a public address
|
|
2097
|
+
* would mean listening for a phone on the open internet, and a link-local one
|
|
2098
|
+
* (`169.254/16`) is what an interface has when it found no network at all.
|
|
2099
|
+
* Undefined when there is none — a laptop on no network still runs, its mobile
|
|
2100
|
+
* app reaching only a simulator.
|
|
1376
2101
|
*/
|
|
1377
|
-
function
|
|
1378
|
-
|
|
2102
|
+
function lanAddress(interfaces = (0, node_os.networkInterfaces)()) {
|
|
2103
|
+
for (const entries of Object.values(interfaces)) for (const entry of entries ?? []) {
|
|
2104
|
+
if (entry.family !== "IPv4" || entry.internal) continue;
|
|
2105
|
+
if (isPrivate(entry.address)) return entry.address;
|
|
2106
|
+
}
|
|
2107
|
+
}
|
|
2108
|
+
function isPrivate(address) {
|
|
2109
|
+
return /^10\./.test(address) || /^192\.168\./.test(address) || /^172\.(1[6-9]|2\d|3[01])\./.test(address);
|
|
1379
2110
|
}
|
|
1380
|
-
|
|
1381
2111
|
//#endregion
|
|
1382
2112
|
//#region src/reconcile/ports.ts
|
|
1383
2113
|
/**
|
|
2114
|
+
* Port allocation — why two projects can run at once.
|
|
2115
|
+
*
|
|
2116
|
+
* Publishing `5432:5432` means the second project on your machine cannot start.
|
|
2117
|
+
* Nothing solves that except giving each project its own ports, and what makes
|
|
2118
|
+
* it *possible* is the single-`<NAME>_URL` rule: an app reads `ORDERS_URL` and
|
|
2119
|
+
* never sees a host or a port, so reconcile is free to bind whatever is
|
|
2120
|
+
* available and compose the URL from what it bound. An app reading `DB_HOST` and
|
|
2121
|
+
* `DB_PORT` separately could not be moved this way.
|
|
2122
|
+
*
|
|
2123
|
+
* Assignments are **persisted, not recomputed**. Recomputing means adding a
|
|
2124
|
+
* construct renumbers its neighbours, and every running container, saved
|
|
2125
|
+
* connection string, and `psql` history goes stale at once.
|
|
2126
|
+
*
|
|
2127
|
+
* Pure, with the liveness probe injected — a collision with another project's
|
|
2128
|
+
* stack is a fact about the machine, and keeping it a parameter is what lets the
|
|
2129
|
+
* rules be asserted without binding a socket.
|
|
2130
|
+
*/
|
|
2131
|
+
/**
|
|
1384
2132
|
* The window ports are drawn from.
|
|
1385
2133
|
*
|
|
1386
2134
|
* Above the registered range so nothing here needs privileges, and below the
|
|
@@ -1438,6 +2186,27 @@ async function allocate(project, containers, existing = {}, probe = isPortFree)
|
|
|
1438
2186
|
}
|
|
1439
2187
|
return assignments;
|
|
1440
2188
|
}
|
|
2189
|
+
/**
|
|
2190
|
+
* The ports to keep: what running containers are observed on, then what was
|
|
2191
|
+
* saved — minus any saved entry whose port something else already holds.
|
|
2192
|
+
*
|
|
2193
|
+
* Spreading one over the other let an observed port override its own key and
|
|
2194
|
+
* leave a *different* key still saved on the same number: two services on one
|
|
2195
|
+
* port, and whichever answered first won. Saved keys for containers the plan no
|
|
2196
|
+
* longer has — a backend switched and back — were the usual source. Observed
|
|
2197
|
+
* wins because it is what is actually bound; a dropped entry is simply
|
|
2198
|
+
* allocated again.
|
|
2199
|
+
*/
|
|
2200
|
+
function keptPorts(saved = {}, observed = {}) {
|
|
2201
|
+
const kept = { ...observed };
|
|
2202
|
+
const taken = new Set(Object.values(observed));
|
|
2203
|
+
for (const [key, port] of Object.entries(saved).sort(([a], [b]) => a < b ? -1 : 1)) {
|
|
2204
|
+
if (key in kept || taken.has(port)) continue;
|
|
2205
|
+
kept[key] = port;
|
|
2206
|
+
taken.add(port);
|
|
2207
|
+
}
|
|
2208
|
+
return kept;
|
|
2209
|
+
}
|
|
1441
2210
|
/** The window was exhausted. */
|
|
1442
2211
|
var NoPortAvailable = class extends Error {
|
|
1443
2212
|
/** Where the search started. */
|
|
@@ -1478,17 +2247,33 @@ async function nextFree(from, taken, probe) {
|
|
|
1478
2247
|
* rather than as a connection failure ten minutes later.
|
|
1479
2248
|
*/
|
|
1480
2249
|
function isPortFree(port) {
|
|
1481
|
-
return new Promise((resolve
|
|
2250
|
+
return new Promise((resolve) => {
|
|
1482
2251
|
const server = (0, node_net.createServer)();
|
|
1483
|
-
server.once("error", () => resolve
|
|
1484
|
-
server.once("listening", () => server.close(() => resolve
|
|
2252
|
+
server.once("error", () => resolve(false));
|
|
2253
|
+
server.once("listening", () => server.close(() => resolve(true)));
|
|
1485
2254
|
server.listen(port, "0.0.0.0");
|
|
1486
2255
|
});
|
|
1487
2256
|
}
|
|
1488
|
-
|
|
1489
2257
|
//#endregion
|
|
1490
2258
|
//#region src/reconcile/provision.ts
|
|
1491
2259
|
/**
|
|
2260
|
+
* Creating what the URLs name.
|
|
2261
|
+
*
|
|
2262
|
+
* Convergent and idempotent: every statement asks whether the thing exists
|
|
2263
|
+
* first, so reconciling repeatedly is free and a half-applied run recovers by
|
|
2264
|
+
* being run again. That property is what lets `gkm dev` do this on every start.
|
|
2265
|
+
*
|
|
2266
|
+
* The line the design draws is at data, not at side effects — this creates
|
|
2267
|
+
* databases, schemas, and buckets, and it never seeds, resets, or drops. A
|
|
2268
|
+
* developer who wants their data gone asks for it explicitly.
|
|
2269
|
+
*
|
|
2270
|
+
* Statement generation is separated from application for the reason the design
|
|
2271
|
+
* gives: the same DDL has to run in-process locally and from a provisioner in a
|
|
2272
|
+
* VPC, and one implementation is what stops "works locally, fails deployed".
|
|
2273
|
+
* When the role DDL lands in `@geekmidas/db` this delegates to it rather than
|
|
2274
|
+
* growing its own.
|
|
2275
|
+
*/
|
|
2276
|
+
/**
|
|
1492
2277
|
* The Postgres work a plan implies.
|
|
1493
2278
|
*
|
|
1494
2279
|
* Databases before the schemas inside them, which `provisionOrder` already
|
|
@@ -1539,9 +2324,9 @@ function postgresStatements(plan, project = "") {
|
|
|
1539
2324
|
function cacheTableDdl(cache, home, plan) {
|
|
1540
2325
|
const database = rootDatabase(home, plan);
|
|
1541
2326
|
const schema = home.roles === false ? void 0 : home.schema;
|
|
1542
|
-
const name = cache.table ?? (0,
|
|
2327
|
+
const name = cache.table ?? (0, _geekmidas_manifest.cacheTable)(cache.id);
|
|
1543
2328
|
const table = schema ? `${schema}.${name}` : name;
|
|
1544
|
-
const created = (0,
|
|
2329
|
+
const created = (0, _geekmidas_cache_postgres.cacheTableStatements)({ table }).map((statement) => ({
|
|
1545
2330
|
id: cache.id,
|
|
1546
2331
|
describe: statement.describe,
|
|
1547
2332
|
database,
|
|
@@ -1550,7 +2335,7 @@ function cacheTableDdl(cache, home, plan) {
|
|
|
1550
2335
|
}));
|
|
1551
2336
|
if (!schema) return created;
|
|
1552
2337
|
const runtime = localRole(home);
|
|
1553
|
-
const owner = (0,
|
|
2338
|
+
const owner = (0, _geekmidas_db_pg_roles.ownerRole)(runtime);
|
|
1554
2339
|
const qualified = table.split(".").map((part) => quoteIdentifier(part)).join(".");
|
|
1555
2340
|
return [
|
|
1556
2341
|
...created,
|
|
@@ -1578,13 +2363,14 @@ function cacheTableDdl(cache, home, plan) {
|
|
|
1578
2363
|
function rolesFor(resource, schema, plan, project) {
|
|
1579
2364
|
if (resource.roles === false) return [];
|
|
1580
2365
|
const runtime = localRole(resource);
|
|
1581
|
-
const owner = (0,
|
|
1582
|
-
const reader = plan.resources.some((r) => r.kind === "database-reader" && r.of === resource.id) ? (0,
|
|
1583
|
-
return (0,
|
|
2366
|
+
const owner = (0, _geekmidas_db_pg_roles.ownerRole)(runtime);
|
|
2367
|
+
const reader = plan.resources.some((r) => r.kind === "database-reader" && r.of === resource.id) ? (0, _geekmidas_db_pg_roles.readerRole)(runtime) : void 0;
|
|
2368
|
+
return (0, _geekmidas_db_pg_roles.roleStatements)({
|
|
1584
2369
|
runtime,
|
|
1585
2370
|
owner,
|
|
1586
2371
|
...reader ? { reader } : {},
|
|
1587
2372
|
schema,
|
|
2373
|
+
...resource.kind === "database" ? { database: rootDatabase(resource, plan) } : {},
|
|
1588
2374
|
passwords: {
|
|
1589
2375
|
runtime: localRolePassword(project, plan, runtime),
|
|
1590
2376
|
owner: localRolePassword(project, plan, owner),
|
|
@@ -1630,8 +2416,7 @@ async function applyPostgres(client, statements) {
|
|
|
1630
2416
|
});
|
|
1631
2417
|
continue;
|
|
1632
2418
|
}
|
|
1633
|
-
|
|
1634
|
-
if (rows.length > 0) {
|
|
2419
|
+
if ((await client.query(statement.database, statement.exists.sql, statement.exists.values)).length > 0) {
|
|
1635
2420
|
applied.push({
|
|
1636
2421
|
id: statement.id,
|
|
1637
2422
|
describe: statement.describe,
|
|
@@ -1698,6 +2483,66 @@ function bucketPolicy(bucket, open) {
|
|
|
1698
2483
|
});
|
|
1699
2484
|
}
|
|
1700
2485
|
/**
|
|
2486
|
+
* The topics and queues to create on the AWS emulator.
|
|
2487
|
+
*
|
|
2488
|
+
* Only on the `sns` backend: pg-boss makes its own tables on first connect and
|
|
2489
|
+
* a RabbitMQ exchange is declared by the client, but an SNS topic and an SQS
|
|
2490
|
+
* queue must exist before anything can publish to them.
|
|
2491
|
+
*/
|
|
2492
|
+
function carrierNames(plan) {
|
|
2493
|
+
if (plan.events !== "sns") return {
|
|
2494
|
+
topics: [],
|
|
2495
|
+
queues: []
|
|
2496
|
+
};
|
|
2497
|
+
const named = (kind) => plan.resources.filter((r) => r.kind === kind).map((r) => r.name);
|
|
2498
|
+
return {
|
|
2499
|
+
topics: named("topic"),
|
|
2500
|
+
queues: named("queue")
|
|
2501
|
+
};
|
|
2502
|
+
}
|
|
2503
|
+
/** Create each topic and queue the plan names, skipping those that exist. */
|
|
2504
|
+
async function applyCarriers(client, carriers) {
|
|
2505
|
+
const applied = [];
|
|
2506
|
+
for (const name of carriers.topics) {
|
|
2507
|
+
const created = !await client.topicExists(name);
|
|
2508
|
+
if (created) await client.createTopic(name);
|
|
2509
|
+
applied.push({
|
|
2510
|
+
id: name,
|
|
2511
|
+
describe: `topic ${name}`,
|
|
2512
|
+
created
|
|
2513
|
+
});
|
|
2514
|
+
}
|
|
2515
|
+
for (const name of carriers.queues) {
|
|
2516
|
+
const created = !await client.queueExists(name);
|
|
2517
|
+
if (created) await client.createQueue(name);
|
|
2518
|
+
applied.push({
|
|
2519
|
+
id: name,
|
|
2520
|
+
describe: `queue ${name}`,
|
|
2521
|
+
created
|
|
2522
|
+
});
|
|
2523
|
+
}
|
|
2524
|
+
return applied;
|
|
2525
|
+
}
|
|
2526
|
+
/** The Postgres databases the plan creates — each is a `CREATE DATABASE`. */
|
|
2527
|
+
function postgresDatabaseNames(plan) {
|
|
2528
|
+
return plan.resources.filter((resource) => resource.kind === "database" && resource.provisions && resource.container === "postgres").map((resource) => resource.name);
|
|
2529
|
+
}
|
|
2530
|
+
/**
|
|
2531
|
+
* Whether every one of these databases exists. A database dropped behind the
|
|
2532
|
+
* recorded state's back — by another checkout's test teardown, against the
|
|
2533
|
+
* same container — makes the state a lie, and only asking Postgres finds out.
|
|
2534
|
+
* Unreachable counts as missing: applying again is what finds out why.
|
|
2535
|
+
*/
|
|
2536
|
+
async function databasesExist(client, names) {
|
|
2537
|
+
if (names.length === 0) return true;
|
|
2538
|
+
try {
|
|
2539
|
+
const rows = await client.query(void 0, "SELECT datname FROM pg_catalog.pg_database WHERE datname = ANY($1)", [names]);
|
|
2540
|
+
return new Set(rows.map((row) => row.datname)).size === names.length;
|
|
2541
|
+
} catch {
|
|
2542
|
+
return false;
|
|
2543
|
+
}
|
|
2544
|
+
}
|
|
2545
|
+
/**
|
|
1701
2546
|
* Apply each served bucket's open-path policy, skipping those already correct.
|
|
1702
2547
|
*
|
|
1703
2548
|
* Compared as parsed JSON rather than as text: the same policy re-serialised
|
|
@@ -1756,9 +2601,20 @@ async function applyBuckets(client, buckets) {
|
|
|
1756
2601
|
}
|
|
1757
2602
|
return applied;
|
|
1758
2603
|
}
|
|
1759
|
-
|
|
1760
2604
|
//#endregion
|
|
1761
2605
|
//#region src/reconcile/state.ts
|
|
2606
|
+
/**
|
|
2607
|
+
* What reconcile records, and the hash that lets it do nothing.
|
|
2608
|
+
*
|
|
2609
|
+
* Reconciling on every `gkm dev` is only acceptable if the converged case is
|
|
2610
|
+
* free, so the desired plan is hashed: matching hash plus healthy containers
|
|
2611
|
+
* means there is nothing to do. Without that, the automatic reconcile the design
|
|
2612
|
+
* asks for would tax every start.
|
|
2613
|
+
*
|
|
2614
|
+
* Almost nothing needs recording — roles are queried, migrations have their own
|
|
2615
|
+
* table, containers are remembered by Docker. Only ports and this hash have no
|
|
2616
|
+
* other owner.
|
|
2617
|
+
*/
|
|
1762
2618
|
const STATE_DIR = ".gkm/reconcile";
|
|
1763
2619
|
/**
|
|
1764
2620
|
* The hash of everything a reconcile would act on.
|
|
@@ -1787,7 +2643,7 @@ async function loadState(root, stage) {
|
|
|
1787
2643
|
const state = JSON.parse(raw);
|
|
1788
2644
|
return state.stage === stage ? state : void 0;
|
|
1789
2645
|
} catch {
|
|
1790
|
-
return
|
|
2646
|
+
return;
|
|
1791
2647
|
}
|
|
1792
2648
|
}
|
|
1793
2649
|
/** Record what was applied, so the next run can skip it. */
|
|
@@ -1796,14 +2652,46 @@ async function saveState(root, state) {
|
|
|
1796
2652
|
await (0, node_fs_promises.mkdir)((0, node_path.dirname)(path), { recursive: true });
|
|
1797
2653
|
await (0, node_fs_promises.writeFile)(path, `${JSON.stringify(state, null, 2)}\n`);
|
|
1798
2654
|
}
|
|
2655
|
+
/**
|
|
2656
|
+
* Forget what was applied, so the next reconcile of this stage converges from
|
|
2657
|
+
* nothing — creating again whatever was dropped underneath the record.
|
|
2658
|
+
*/
|
|
2659
|
+
async function forgetState(root, stage) {
|
|
2660
|
+
await (0, node_fs_promises.rm)(statePath(root, stage), { force: true });
|
|
2661
|
+
}
|
|
1799
2662
|
function statePath(root, stage) {
|
|
1800
2663
|
return (0, node_path.join)(root, STATE_DIR, `${stage}.json`);
|
|
1801
2664
|
}
|
|
1802
|
-
|
|
1803
2665
|
//#endregion
|
|
1804
2666
|
//#region src/reconcile/index.ts
|
|
1805
|
-
/**
|
|
1806
|
-
|
|
2667
|
+
/**
|
|
2668
|
+
* Reconcile — the one convergent function `gkm dev`, `gkm test`, and `gkm setup`
|
|
2669
|
+
* all call.
|
|
2670
|
+
*
|
|
2671
|
+
* Three phases, and only this one has side effects: declaring is pure (`gkm
|
|
2672
|
+
* build` and the dev watcher), running reads `<NAME>_URL` and provisions
|
|
2673
|
+
* nothing. Reconcile computes the desired state, compares, and applies the
|
|
2674
|
+
* difference — which is what makes "when does it run" answerable with
|
|
2675
|
+
* *whenever, repeatedly*.
|
|
2676
|
+
*
|
|
2677
|
+
* It is safe to run automatically because its blast radius is entirely local:
|
|
2678
|
+
* this project's containers, this project's `.gkm/`. Nothing it does can reach a
|
|
2679
|
+
* cloud. The line is drawn at data, not at side effects — it allocates ports,
|
|
2680
|
+
* writes compose, starts containers, and creates roles; it never seeds, resets,
|
|
2681
|
+
* or drops.
|
|
2682
|
+
*
|
|
2683
|
+
* Docker is injected rather than imported so the rules above can be asserted
|
|
2684
|
+
* without a daemon. The default implementation is the real one.
|
|
2685
|
+
*/
|
|
2686
|
+
/**
|
|
2687
|
+
* Where the generated compose file is written, relative to the project root.
|
|
2688
|
+
*
|
|
2689
|
+
* At the root, beside the project's own `docker-compose.yml`, because the two
|
|
2690
|
+
* are one stack: this file is everything the constructs imply and is never
|
|
2691
|
+
* edited, that one is anything they cannot express — an image pin, an extra
|
|
2692
|
+
* service — and is merged over it, so it wins.
|
|
2693
|
+
*/
|
|
2694
|
+
const COMPOSE_PATH = "docker-compose.constructs.yml";
|
|
1807
2695
|
/**
|
|
1808
2696
|
* The local edge's config, beside the compose file that mounts it.
|
|
1809
2697
|
*
|
|
@@ -1839,32 +2727,37 @@ const CADDY_ROOT_IN_CONTAINER = "/data/caddy/pki/authorities/local/root.crt";
|
|
|
1839
2727
|
* hash and one health check.
|
|
1840
2728
|
*/
|
|
1841
2729
|
async function reconcile(options) {
|
|
1842
|
-
const { root, project, manifest, stage, start = true, provision = true, docker = dockerCli, probe = isPortFree, sql = pgClient, buckets = bucketClient } = options;
|
|
1843
|
-
const plan = planFor(manifest, stage, (0,
|
|
2730
|
+
const { root, project, manifest, stage, start = true, provision = true, docker = dockerCli, probe = isPortFree, sql = pgClient, buckets = bucketClient, carriers = carrierClient } = options;
|
|
2731
|
+
const plan = planFor(manifest, stage, (0, _geekmidas_manifest.provisionOrder)(manifest), {
|
|
2732
|
+
localStage: options.localStage,
|
|
1844
2733
|
events: options.events,
|
|
1845
2734
|
cache: options.cache,
|
|
1846
2735
|
extraContainers: options.extraContainers,
|
|
2736
|
+
...options.fakes ? { fakes: options.fakes } : {},
|
|
1847
2737
|
...options.edge === void 0 ? {} : { edge: options.edge }
|
|
1848
2738
|
});
|
|
1849
2739
|
const composePath = (0, node_path.join)(root, COMPOSE_PATH);
|
|
1850
|
-
const observed = await observedPorts(docker, composePath, plan.containers);
|
|
1851
|
-
const ports = await allocate(project, portKeys(plan.containers),
|
|
1852
|
-
...options.saved,
|
|
1853
|
-
...observed
|
|
1854
|
-
}, probe);
|
|
2740
|
+
const observed = await observedPorts(docker, composePath, plan.containers, plan.fakes);
|
|
2741
|
+
const ports = await allocate(project, portKeys(plan.containers, plan.fakes), keptPorts(options.saved, observed), probe);
|
|
1855
2742
|
const compose = composeFor(plan, {
|
|
1856
2743
|
project,
|
|
1857
2744
|
ports,
|
|
1858
|
-
...options.
|
|
2745
|
+
...options.apps ? { apps: options.apps(plan.containers) } : {}
|
|
1859
2746
|
});
|
|
1860
2747
|
const caddyfile = toCaddyfile(sitesFor(plan, project, options.addresses));
|
|
1861
|
-
const hash = planHash(plan, compose, {
|
|
1862
|
-
|
|
2748
|
+
const hash = planHash(plan, compose, {
|
|
2749
|
+
caddyfile,
|
|
2750
|
+
postgres: postgresStatements(plan, project).map((statement) => statement.create).join(";\n")
|
|
2751
|
+
});
|
|
2752
|
+
const services = serviceAddresses(plan.containers, ports, plan.fakes);
|
|
2753
|
+
const lan = plan.resources.some((r) => r.kind === "mobile-app") ? options.lanAddress === void 0 ? lanAddress() : options.lanAddress ?? void 0 : void 0;
|
|
1863
2754
|
const env = envFor(plan, {
|
|
1864
2755
|
ports,
|
|
1865
2756
|
project,
|
|
1866
2757
|
...options.mailFrom ? { mailFrom: options.mailFrom } : {},
|
|
1867
|
-
...options.addresses ? { addresses: options.addresses } : {}
|
|
2758
|
+
...options.addresses ? { addresses: options.addresses } : {},
|
|
2759
|
+
...lan ? { lanAddress: lan } : {},
|
|
2760
|
+
...options.metroPorts ? { metroPorts: options.metroPorts } : {}
|
|
1868
2761
|
});
|
|
1869
2762
|
if (plan.containers.includes("caddy")) env.NODE_EXTRA_CA_CERTS = (0, node_path.join)(root, LOCAL_CA_PATH);
|
|
1870
2763
|
const result = {
|
|
@@ -1872,24 +2765,34 @@ async function reconcile(options) {
|
|
|
1872
2765
|
plan,
|
|
1873
2766
|
compose,
|
|
1874
2767
|
ports,
|
|
1875
|
-
|
|
2768
|
+
services,
|
|
1876
2769
|
env,
|
|
1877
2770
|
provisioned: [],
|
|
2771
|
+
fakes: options.fakes ?? {},
|
|
1878
2772
|
hash,
|
|
1879
2773
|
changed: false
|
|
1880
2774
|
};
|
|
1881
2775
|
const recorded = await loadState(root, stage);
|
|
1882
|
-
const
|
|
1883
|
-
if (
|
|
2776
|
+
const postgresPort = ports[primaryPortKey("postgres")];
|
|
2777
|
+
if (recorded?.hash === hash && (0, node_fs.existsSync)(composePath) && (!start || await docker.healthy(composePath, plan.containers)) && (!start || !provision || postgresPort === void 0 || await databasesExist(sql(postgresPort), postgresDatabaseNames(plan)))) return result;
|
|
1884
2778
|
await write(composePath, toYaml(compose));
|
|
1885
2779
|
if (plan.containers.includes("caddy")) {
|
|
1886
2780
|
await write((0, node_path.join)(root, CADDYFILE_PATH), caddyfileRoot());
|
|
1887
2781
|
await write((0, node_path.join)(root, caddySitesPath(stage)), caddyfile);
|
|
2782
|
+
await pruneCaddySites(root, [
|
|
2783
|
+
stage,
|
|
2784
|
+
options.localStage,
|
|
2785
|
+
require_workspace.TEST_STAGE
|
|
2786
|
+
]);
|
|
2787
|
+
}
|
|
2788
|
+
if (start && plan.containers.length > 0) {
|
|
2789
|
+
options.progress?.(`🐳 Starting ${plan.containers.join(", ")} — the first start pulls each image, which can take a few minutes`);
|
|
2790
|
+
await docker.up(composePath, plan.containers, options.progress ? { show: true } : {});
|
|
1888
2791
|
}
|
|
1889
|
-
if (start && plan.containers.length > 0) await docker.up(composePath, plan.containers);
|
|
1890
2792
|
if (start && plan.containers.includes("caddy")) await docker.reload(composePath, "caddy").catch(() => {});
|
|
1891
2793
|
if (start && plan.containers.includes("caddy")) await docker.copyOut(composePath, "caddy", CADDY_ROOT_IN_CONTAINER, (0, node_path.join)(root, LOCAL_CA_PATH)).catch(() => {});
|
|
1892
|
-
|
|
2794
|
+
if (start && provision) options.progress?.("🗄️ Creating what the constructs declare — databases, roles, buckets, topics");
|
|
2795
|
+
const provisioned = start && provision ? await create(plan, ports, sql, buckets, carriers, project) : [];
|
|
1893
2796
|
await saveState(root, {
|
|
1894
2797
|
hash,
|
|
1895
2798
|
stage
|
|
@@ -1898,783 +2801,368 @@ async function reconcile(options) {
|
|
|
1898
2801
|
...result,
|
|
1899
2802
|
provisioned,
|
|
1900
2803
|
changed: true
|
|
1901
|
-
};
|
|
1902
|
-
}
|
|
1903
|
-
/**
|
|
1904
|
-
* Create the databases, schemas, and buckets the plan names.
|
|
1905
|
-
*
|
|
1906
|
-
* Idempotent throughout, so this runs on every non-converged reconcile rather
|
|
1907
|
-
* than being something to remember.
|
|
1908
|
-
*/
|
|
1909
|
-
async function create(plan, ports, sql, buckets, project) {
|
|
1910
|
-
const applied = [];
|
|
1911
|
-
const postgresPort = ports[primaryPortKey("postgres")];
|
|
1912
|
-
const statements = postgresStatements(plan, project);
|
|
1913
|
-
if (postgresPort !== void 0 && statements.length > 0) applied.push(...await applyPostgres(sql(postgresPort), statements));
|
|
1914
|
-
const minioPort = ports[primaryPortKey("minio")];
|
|
1915
|
-
const names = bucketNames(plan);
|
|
1916
|
-
const policies = bucketPolicies(plan);
|
|
1917
|
-
if (minioPort !== void 0 && (names.length > 0 || policies.length > 0)) {
|
|
1918
|
-
const client = buckets(minioPort);
|
|
1919
|
-
if (names.length > 0) applied.push(...await applyBuckets(client, names));
|
|
1920
|
-
if (policies.length > 0) applied.push(...await applyPolicies(client, policies));
|
|
1921
|
-
}
|
|
1922
|
-
return applied;
|
|
1923
|
-
}
|
|
1924
|
-
/**
|
|
1925
|
-
* The host ports of containers already running.
|
|
1926
|
-
*
|
|
1927
|
-
* Keyed the same way allocation keys them, so the two merge without either
|
|
1928
|
-
* knowing about the other.
|
|
1929
|
-
*/
|
|
1930
|
-
async function observedPorts(docker, composePath, containers) {
|
|
1931
|
-
const observed = {};
|
|
1932
|
-
for (const container of containers) for (const port of portsOf(container)) {
|
|
1933
|
-
const running = await docker.publishedPort(composePath, container, port.inside);
|
|
1934
|
-
if (running !== void 0) observed[port.key] = running;
|
|
1935
|
-
}
|
|
1936
|
-
return observed;
|
|
1937
|
-
}
|
|
1938
|
-
/**
|
|
1939
|
-
* Where each container can be reached on this machine.
|
|
1940
|
-
*
|
|
1941
|
-
* The primary port only — a container's console is for a human to open, not
|
|
1942
|
-
* something an app connects to.
|
|
1943
|
-
*/
|
|
1944
|
-
function addressesFor(containers, ports) {
|
|
1945
|
-
const addresses = {};
|
|
1946
|
-
for (const container of containers) {
|
|
1947
|
-
const port = ports[primaryPortKey(container)];
|
|
1948
|
-
if (port !== void 0) addresses[container] = `localhost:${port}`;
|
|
1949
|
-
}
|
|
1950
|
-
return addresses;
|
|
1951
|
-
}
|
|
1952
|
-
/** Write a file only when its content would change, so mtimes stay meaningful. */
|
|
1953
|
-
async function write(path, content) {
|
|
1954
|
-
try {
|
|
1955
|
-
if (await (0, node_fs_promises.readFile)(path, "utf-8") === content) return;
|
|
1956
|
-
} catch {}
|
|
1957
|
-
await (0, node_fs_promises.mkdir)((0, node_path.dirname)(path), { recursive: true });
|
|
1958
|
-
await (0, node_fs_promises.writeFile)(path, content);
|
|
1959
|
-
}
|
|
1960
|
-
|
|
1961
|
-
//#endregion
|
|
1962
|
-
//#region src/reconcile/workspace.ts
|
|
1963
|
-
/**
|
|
1964
|
-
* Every constructs glob in the workspace, resolved against its app.
|
|
1965
|
-
*
|
|
1966
|
-
* Absolute because discovery globs from a single cwd while apps live in
|
|
1967
|
-
* different directories.
|
|
1968
|
-
*/
|
|
1969
|
-
function constructGlobs(workspace) {
|
|
1970
|
-
return require_workspace.allConstructGlobs(workspace);
|
|
1971
|
-
}
|
|
1972
|
-
/** Whether any app has adopted the constructs glob. */
|
|
1973
|
-
function usesConstructs(workspace) {
|
|
1974
|
-
return constructGlobs(workspace).length > 0;
|
|
1975
|
-
}
|
|
1976
|
-
/**
|
|
1977
|
-
* Image pins, by container. The config half of the derived/config split.
|
|
1978
|
-
*
|
|
1979
|
-
* Read from `services.images` rather than from the backend keys beside it.
|
|
1980
|
-
* They used to share one key, which is how `cache: true` came to mean "start a
|
|
1981
|
-
* Redis" — the last way a container could exist because config asked for one
|
|
1982
|
-
* instead of because something declared it.
|
|
1983
|
-
*/
|
|
1984
|
-
function imagePins(workspace) {
|
|
1985
|
-
return { ...workspace.services.images };
|
|
1986
|
-
}
|
|
1987
|
-
/**
|
|
1988
|
-
* The containers a workspace's declarations imply, without reconciling.
|
|
1989
|
-
*
|
|
1990
|
-
* The same derivation `reconcileWorkspace` makes, available to callers that
|
|
1991
|
-
* need to know *what would run* without starting anything or writing ports —
|
|
1992
|
-
* `gkm setup` deciding which credentials to generate, `gkm docker` writing a
|
|
1993
|
-
* compose file. Those used to each read a boolean per service out of config,
|
|
1994
|
-
* which is how a container could exist because config asked for one rather than
|
|
1995
|
-
* because something declared it.
|
|
1996
|
-
*/
|
|
1997
|
-
async function derivedContainers(workspace, stage, manifest) {
|
|
1998
|
-
const found = manifest ?? await require_discover.discover({
|
|
1999
|
-
patterns: constructGlobs(workspace),
|
|
2000
|
-
cwd: workspace.root
|
|
2001
|
-
});
|
|
2002
|
-
return planFor(found, stage, (0, __geekmidas_manifest.provisionOrder)(found), {
|
|
2003
|
-
events: workspace.services.events,
|
|
2004
|
-
cache: cacheBackendOf(workspace.services.cache, providerOf(workspace))
|
|
2005
|
-
}).containers;
|
|
2006
|
-
}
|
|
2007
|
-
/**
|
|
2008
|
-
* Reconcile a workspace for one stage.
|
|
2009
|
-
*
|
|
2010
|
-
* Ports are loaded and saved around the call rather than inside it, so the loop
|
|
2011
|
-
* stays a pure-ish function of its inputs and the store keeps its single owner.
|
|
2012
|
-
*/
|
|
2013
|
-
async function reconcileWorkspace(workspace, options) {
|
|
2014
|
-
const manifest = options.manifest ?? await require_discover.discover({
|
|
2015
|
-
patterns: constructGlobs(workspace),
|
|
2016
|
-
cwd: workspace.root
|
|
2017
|
-
});
|
|
2018
|
-
const result = await reconcile({
|
|
2019
|
-
root: workspace.root,
|
|
2020
|
-
project: workspace.name,
|
|
2021
|
-
manifest,
|
|
2022
|
-
stage: options.stage,
|
|
2023
|
-
events: workspace.services.events,
|
|
2024
|
-
cache: cacheBackendOf(workspace.services.cache, providerOf(workspace)),
|
|
2025
|
-
images: imagePins(workspace),
|
|
2026
|
-
saved: await loadPortState(workspace.root),
|
|
2027
|
-
addresses: surfaceAddresses(workspace, manifest),
|
|
2028
|
-
...options.start === void 0 ? {} : { start: options.start }
|
|
2029
|
-
});
|
|
2030
|
-
await savePortState(workspace.root, { ...result.ports });
|
|
2031
|
-
return result;
|
|
2032
|
-
}
|
|
2033
|
-
/**
|
|
2034
|
-
* Where each declared surface and site answers locally.
|
|
2035
|
-
*
|
|
2036
|
-
* The addresses come from the ports the workspace already assigns; which
|
|
2037
|
-
* construct sits at which one comes from the manifest. That split is the point:
|
|
2038
|
-
* this used to answer "who may call whom" by listing every app the workspace
|
|
2039
|
-
* runs, which is a different question that happened to give the same answer in
|
|
2040
|
-
* a single-repo workspace and no answer at all deployed. Now it answers only
|
|
2041
|
-
* "where does this construct answer", and the graph answers the rest.
|
|
2042
|
-
*
|
|
2043
|
-
* A site is matched to its app by `path`, because that is the one thing a site
|
|
2044
|
-
* declaration and a workspace app both name. Surfaces are matched to the
|
|
2045
|
-
* backend app: every `rest-api` in a process answers on that process's port, so
|
|
2046
|
-
* an app serving both its own API and an auth server publishes one address
|
|
2047
|
-
* twice — which is exactly what it does at runtime.
|
|
2048
|
-
*/
|
|
2049
|
-
function surfaceAddresses(workspace, manifest) {
|
|
2050
|
-
const addresses = {};
|
|
2051
|
-
for (const [id, declaration] of Object.entries(manifest)) {
|
|
2052
|
-
if (declaration.kind !== "rest-api" && declaration.kind !== "site") continue;
|
|
2053
|
-
const host = declaration.kind === "site" ? require_config.appKey(id) : appKeyOfHost(manifest, id);
|
|
2054
|
-
const app = host ? workspace.apps[host] : void 0;
|
|
2055
|
-
if (app?.port) addresses[id] = localAddress(app.port);
|
|
2056
|
-
}
|
|
2057
|
-
return addresses;
|
|
2058
|
-
}
|
|
2059
|
-
/** The app key serving a surface, following a mount to its host. */
|
|
2060
|
-
function appKeyOfHost(manifest, id) {
|
|
2061
|
-
const host = require_config.hostOf(manifest, id);
|
|
2062
|
-
return host ? require_config.appKey(host) : void 0;
|
|
2063
|
-
}
|
|
2064
|
-
/** Where a local process answers, given the port the workspace gave it. */
|
|
2065
|
-
function localAddress(port) {
|
|
2066
|
-
return `http://localhost:${port}`;
|
|
2067
|
-
}
|
|
2068
|
-
|
|
2069
|
-
//#endregion
|
|
2070
|
-
//#region src/credentials/index.ts
|
|
2071
|
-
const logger = console;
|
|
2072
|
-
/**
|
|
2073
|
-
* Load environment files
|
|
2074
|
-
* @internal Exported for testing
|
|
2075
|
-
*/
|
|
2076
|
-
function loadEnvFiles(envConfig, cwd = process.cwd()) {
|
|
2077
|
-
const loaded = [];
|
|
2078
|
-
const missing = [];
|
|
2079
|
-
const envFiles = envConfig ? Array.isArray(envConfig) ? envConfig : [envConfig] : [".env"];
|
|
2080
|
-
for (const envFile of envFiles) {
|
|
2081
|
-
const envPath = (0, node_path.resolve)(cwd, envFile);
|
|
2082
|
-
if ((0, node_fs.existsSync)(envPath)) {
|
|
2083
|
-
(0, dotenv.config)({
|
|
2084
|
-
path: envPath,
|
|
2085
|
-
override: true,
|
|
2086
|
-
quiet: true
|
|
2087
|
-
});
|
|
2088
|
-
loaded.push(envFile);
|
|
2089
|
-
} else if (envConfig) missing.push(envFile);
|
|
2090
|
-
}
|
|
2091
|
-
return {
|
|
2092
|
-
loaded,
|
|
2093
|
-
missing
|
|
2094
|
-
};
|
|
2095
|
-
}
|
|
2096
|
-
/**
|
|
2097
|
-
* Check if a port is available
|
|
2098
|
-
* @internal Exported for testing
|
|
2099
|
-
*/
|
|
2100
|
-
async function isPortAvailable(port) {
|
|
2101
|
-
return new Promise((resolve$1) => {
|
|
2102
|
-
const server = (0, node_net.createServer)();
|
|
2103
|
-
server.once("error", (err) => {
|
|
2104
|
-
if (err.code === "EADDRINUSE") resolve$1(false);
|
|
2105
|
-
else resolve$1(false);
|
|
2106
|
-
});
|
|
2107
|
-
server.once("listening", () => {
|
|
2108
|
-
server.close();
|
|
2109
|
-
resolve$1(true);
|
|
2110
|
-
});
|
|
2111
|
-
server.listen(port);
|
|
2112
|
-
});
|
|
2113
|
-
}
|
|
2114
|
-
/**
|
|
2115
|
-
* Find an available port starting from the preferred port
|
|
2116
|
-
* @internal Exported for testing
|
|
2117
|
-
*/
|
|
2118
|
-
async function findAvailablePort(preferredPort, maxAttempts = 10) {
|
|
2119
|
-
for (let i = 0; i < maxAttempts; i++) {
|
|
2120
|
-
const port = preferredPort + i;
|
|
2121
|
-
if (await isPortAvailable(port)) return port;
|
|
2122
|
-
logger.log(`⚠️ Port ${port} is in use, trying ${port + 1}...`);
|
|
2123
|
-
}
|
|
2124
|
-
throw new Error(`Could not find an available port after trying ${maxAttempts} ports starting from ${preferredPort}`);
|
|
2125
|
-
}
|
|
2126
|
-
const PORT_STATE_PATH = ".gkm/ports.json";
|
|
2127
|
-
/**
|
|
2128
|
-
* Parse docker-compose.yml and extract all port mappings that use env var interpolation.
|
|
2129
|
-
* Entries like `'${POSTGRES_HOST_PORT:-5432}:5432'` are captured.
|
|
2130
|
-
* Fixed port mappings like `'5050:80'` are skipped.
|
|
2131
|
-
* @internal Exported for testing
|
|
2132
|
-
*/
|
|
2133
|
-
function parseComposePortMappings(composePath) {
|
|
2134
|
-
if (!(0, node_fs.existsSync)(composePath)) return [];
|
|
2135
|
-
const content = (0, node_fs.readFileSync)(composePath, "utf-8");
|
|
2136
|
-
const compose = (0, yaml.parse)(content);
|
|
2137
|
-
if (!compose?.services) return [];
|
|
2138
|
-
const results = [];
|
|
2139
|
-
for (const [serviceName, serviceConfig] of Object.entries(compose.services)) for (const portMapping of serviceConfig?.ports ?? []) {
|
|
2140
|
-
const match = String(portMapping).match(/\$\{(\w+):-(\d+)\}:(\d+)/);
|
|
2141
|
-
if (match?.[1] && match[2] && match[3]) results.push({
|
|
2142
|
-
service: serviceName,
|
|
2143
|
-
envVar: match[1],
|
|
2144
|
-
defaultPort: Number(match[2]),
|
|
2145
|
-
containerPort: Number(match[3])
|
|
2146
|
-
});
|
|
2147
|
-
}
|
|
2148
|
-
return results;
|
|
2149
|
-
}
|
|
2150
|
-
/**
|
|
2151
|
-
* Load saved port state from .gkm/ports.json.
|
|
2152
|
-
* @internal Exported for testing
|
|
2153
|
-
*/
|
|
2154
|
-
async function loadPortState(workspaceRoot) {
|
|
2155
|
-
try {
|
|
2156
|
-
const raw = await (0, node_fs_promises.readFile)((0, node_path.join)(workspaceRoot, PORT_STATE_PATH), "utf-8");
|
|
2157
|
-
return JSON.parse(raw);
|
|
2158
|
-
} catch {
|
|
2159
|
-
return {};
|
|
2160
|
-
}
|
|
2161
|
-
}
|
|
2162
|
-
/**
|
|
2163
|
-
* Save port state to .gkm/ports.json.
|
|
2164
|
-
* @internal Exported for testing
|
|
2165
|
-
*/
|
|
2166
|
-
async function savePortState(workspaceRoot, ports) {
|
|
2167
|
-
const dir = (0, node_path.join)(workspaceRoot, ".gkm");
|
|
2168
|
-
await (0, node_fs_promises.mkdir)(dir, { recursive: true });
|
|
2169
|
-
await (0, node_fs_promises.writeFile)((0, node_path.join)(workspaceRoot, PORT_STATE_PATH), `${JSON.stringify(ports, null, 2)}\n`);
|
|
2170
|
-
}
|
|
2171
|
-
/**
|
|
2172
|
-
* Check if a project's own Docker container is running and return its host port.
|
|
2173
|
-
* Uses `docker compose port` scoped to the project's compose file.
|
|
2174
|
-
* @internal Exported for testing
|
|
2175
|
-
*/
|
|
2176
|
-
function getContainerHostPort(workspaceRoot, service, containerPort) {
|
|
2177
|
-
try {
|
|
2178
|
-
const result = (0, node_child_process.execSync)(`docker compose port ${service} ${containerPort}`, {
|
|
2179
|
-
cwd: workspaceRoot,
|
|
2180
|
-
stdio: "pipe"
|
|
2181
|
-
}).toString().trim();
|
|
2182
|
-
const match = result.match(/:(\d+)$/);
|
|
2183
|
-
return match ? Number(match[1]) : null;
|
|
2184
|
-
} catch {
|
|
2185
|
-
return null;
|
|
2186
|
-
}
|
|
2187
|
-
}
|
|
2188
|
-
/**
|
|
2189
|
-
* Resolve host ports for Docker services by parsing docker-compose.yml.
|
|
2190
|
-
* Priority: running container → saved state → find available port.
|
|
2191
|
-
* Persists resolved ports to .gkm/ports.json.
|
|
2192
|
-
* @internal Exported for testing
|
|
2193
|
-
*/
|
|
2194
|
-
async function resolveServicePorts(workspaceRoot) {
|
|
2195
|
-
const composePath = (0, node_path.join)(workspaceRoot, "docker-compose.yml");
|
|
2196
|
-
const mappings = parseComposePortMappings(composePath);
|
|
2197
|
-
if (mappings.length === 0) return {
|
|
2198
|
-
dockerEnv: {},
|
|
2199
|
-
ports: {},
|
|
2200
|
-
mappings: []
|
|
2201
|
-
};
|
|
2202
|
-
const savedState = await loadPortState(workspaceRoot);
|
|
2203
|
-
const dockerEnv = {};
|
|
2204
|
-
const ports = {};
|
|
2205
|
-
const assignedPorts = /* @__PURE__ */ new Set();
|
|
2206
|
-
logger.log("\n🔌 Resolving service ports...");
|
|
2207
|
-
for (const mapping of mappings) {
|
|
2208
|
-
const containerPort = getContainerHostPort(workspaceRoot, mapping.service, mapping.containerPort);
|
|
2209
|
-
if (containerPort !== null) {
|
|
2210
|
-
ports[mapping.envVar] = containerPort;
|
|
2211
|
-
dockerEnv[mapping.envVar] = String(containerPort);
|
|
2212
|
-
assignedPorts.add(containerPort);
|
|
2213
|
-
logger.log(` 🔄 ${mapping.service}:${mapping.containerPort}: reusing existing container on port ${containerPort}`);
|
|
2214
|
-
continue;
|
|
2215
|
-
}
|
|
2216
|
-
const savedPort = savedState[mapping.envVar];
|
|
2217
|
-
if (savedPort && !assignedPorts.has(savedPort) && await isPortAvailable(savedPort)) {
|
|
2218
|
-
ports[mapping.envVar] = savedPort;
|
|
2219
|
-
dockerEnv[mapping.envVar] = String(savedPort);
|
|
2220
|
-
assignedPorts.add(savedPort);
|
|
2221
|
-
logger.log(` 💾 ${mapping.service}:${mapping.containerPort}: using saved port ${savedPort}`);
|
|
2222
|
-
continue;
|
|
2223
|
-
}
|
|
2224
|
-
let resolvedPort = await findAvailablePort(mapping.defaultPort);
|
|
2225
|
-
while (assignedPorts.has(resolvedPort)) resolvedPort = await findAvailablePort(resolvedPort + 1);
|
|
2226
|
-
ports[mapping.envVar] = resolvedPort;
|
|
2227
|
-
dockerEnv[mapping.envVar] = String(resolvedPort);
|
|
2228
|
-
assignedPorts.add(resolvedPort);
|
|
2229
|
-
if (resolvedPort !== mapping.defaultPort) logger.log(` ⚡ ${mapping.service}:${mapping.containerPort}: port ${mapping.defaultPort} occupied, using port ${resolvedPort}`);
|
|
2230
|
-
else logger.log(` ✅ ${mapping.service}:${mapping.containerPort}: using default port ${resolvedPort}`);
|
|
2231
|
-
}
|
|
2232
|
-
await savePortState(workspaceRoot, ports);
|
|
2233
|
-
return {
|
|
2234
|
-
dockerEnv,
|
|
2235
|
-
ports,
|
|
2236
|
-
mappings
|
|
2237
|
-
};
|
|
2238
|
-
}
|
|
2239
|
-
/**
|
|
2240
|
-
* Replace a port in a URL string.
|
|
2241
|
-
* Handles both `hostname:port` and `localhost:port` patterns.
|
|
2242
|
-
* @internal Exported for testing
|
|
2243
|
-
*/
|
|
2244
|
-
function replacePortInUrl(url, oldPort, newPort) {
|
|
2245
|
-
if (oldPort === newPort) return url;
|
|
2246
|
-
let result = url.replace(new RegExp(`:${oldPort}(?=[/?#]|$)`, "g"), `:${newPort}`);
|
|
2247
|
-
result = result.replace(new RegExp(`%3A${oldPort}(?=[%/?#&]|$)`, "gi"), `%3A${newPort}`);
|
|
2248
|
-
return result;
|
|
2804
|
+
};
|
|
2249
2805
|
}
|
|
2250
2806
|
/**
|
|
2251
|
-
*
|
|
2252
|
-
*
|
|
2253
|
-
*
|
|
2254
|
-
*
|
|
2807
|
+
* Create the databases, schemas, buckets, topics and queues the plan names.
|
|
2808
|
+
*
|
|
2809
|
+
* Idempotent throughout, so this runs on every non-converged reconcile rather
|
|
2810
|
+
* than being something to remember.
|
|
2255
2811
|
*/
|
|
2256
|
-
function
|
|
2257
|
-
const
|
|
2258
|
-
const
|
|
2259
|
-
const
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
}
|
|
2269
|
-
for (const [key, value] of Object.entries(result)) {
|
|
2270
|
-
if (!key.endsWith("_HOST")) continue;
|
|
2271
|
-
if (serviceNames.has(value)) result[key] = "localhost";
|
|
2272
|
-
}
|
|
2273
|
-
for (const [key, value] of Object.entries(result)) {
|
|
2274
|
-
if (!key.endsWith("_PORT")) continue;
|
|
2275
|
-
for (const { defaultPort, resolvedPort } of portReplacements) if (value === String(defaultPort)) result[key] = String(resolvedPort);
|
|
2276
|
-
}
|
|
2277
|
-
for (const [key, value] of Object.entries(result)) {
|
|
2278
|
-
if (!key.endsWith("_URL") && !key.endsWith("_ENDPOINT") && !key.endsWith("_CONNECTION_STRING") && key !== "DATABASE_URL") continue;
|
|
2279
|
-
let rewritten = value;
|
|
2280
|
-
for (const name of serviceNames) rewritten = rewritten.replace(new RegExp(`@${name}:`, "g"), "@localhost:");
|
|
2281
|
-
for (const { defaultPort, resolvedPort } of portReplacements) rewritten = replacePortInUrl(rewritten, defaultPort, resolvedPort);
|
|
2282
|
-
result[key] = rewritten;
|
|
2812
|
+
async function create(plan, ports, sql, buckets, emulatorCarriers, project) {
|
|
2813
|
+
const applied = [];
|
|
2814
|
+
const postgresPort = ports[primaryPortKey("postgres")];
|
|
2815
|
+
const statements = postgresStatements(plan, project);
|
|
2816
|
+
if (postgresPort !== void 0 && statements.length > 0) applied.push(...await applyPostgres(sql(postgresPort), statements));
|
|
2817
|
+
const minioPort = ports[primaryPortKey("minio")];
|
|
2818
|
+
const names = bucketNames(plan);
|
|
2819
|
+
const policies = bucketPolicies(plan);
|
|
2820
|
+
if (minioPort !== void 0 && (names.length > 0 || policies.length > 0)) {
|
|
2821
|
+
const client = buckets(minioPort);
|
|
2822
|
+
if (names.length > 0) applied.push(...await applyBuckets(client, names));
|
|
2823
|
+
if (policies.length > 0) applied.push(...await applyPolicies(client, policies));
|
|
2283
2824
|
}
|
|
2284
|
-
|
|
2825
|
+
const emulatorPort = ports[primaryPortKey("localstack")];
|
|
2826
|
+
const carriers = carrierNames(plan);
|
|
2827
|
+
if (emulatorPort !== void 0 && carriers.topics.length + carriers.queues.length > 0) applied.push(...await applyCarriers(emulatorCarriers(emulatorPort), carriers));
|
|
2828
|
+
return applied;
|
|
2285
2829
|
}
|
|
2286
2830
|
/**
|
|
2287
|
-
*
|
|
2288
|
-
*
|
|
2289
|
-
*
|
|
2290
|
-
*
|
|
2831
|
+
* The host ports of containers already running.
|
|
2832
|
+
*
|
|
2833
|
+
* Keyed the same way allocation keys them, so the two merge without either
|
|
2834
|
+
* knowing about the other.
|
|
2291
2835
|
*/
|
|
2292
|
-
function
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
}
|
|
2836
|
+
async function observedPorts(docker, composePath, containers, fakes) {
|
|
2837
|
+
const observed = {};
|
|
2838
|
+
for (const container of containers) for (const port of portsOf(container, fakes)) {
|
|
2839
|
+
const running = await docker.publishedPort(composePath, container, port.inside);
|
|
2840
|
+
if (running !== void 0) observed[port.key] = running;
|
|
2841
|
+
}
|
|
2842
|
+
return observed;
|
|
2298
2843
|
}
|
|
2844
|
+
/** Write a file only when its content would change, so mtimes stay meaningful. */
|
|
2299
2845
|
/**
|
|
2300
|
-
*
|
|
2301
|
-
*
|
|
2846
|
+
* Remove the routes of stages this project no longer reconciles.
|
|
2847
|
+
*
|
|
2848
|
+
* Only the local stage and `test` are ever written, so any other file is left
|
|
2849
|
+
* over from a stage that was renamed — `development` becoming `dev`. Caddy
|
|
2850
|
+
* imports every file, and the leftover declares the same hosts as its
|
|
2851
|
+
* replacement: it refuses the whole config as ambiguous, and every URL behind
|
|
2852
|
+
* the edge goes with it.
|
|
2302
2853
|
*/
|
|
2303
|
-
function
|
|
2304
|
-
|
|
2305
|
-
const
|
|
2306
|
-
const
|
|
2307
|
-
return Object.keys(compose?.services ?? {});
|
|
2854
|
+
async function pruneCaddySites(root, stages) {
|
|
2855
|
+
const dir = (0, node_path.dirname)((0, node_path.join)(root, caddySitesPath(require_workspace.TEST_STAGE)));
|
|
2856
|
+
const keep = new Set(stages.map((stage) => stage && `${stage}.caddy`));
|
|
2857
|
+
for (const file of await (0, node_fs_promises.readdir)(dir)) if (file.endsWith(".caddy") && !keep.has(file)) await (0, node_fs_promises.rm)((0, node_path.join)(dir, file));
|
|
2308
2858
|
}
|
|
2309
|
-
|
|
2310
|
-
* Start docker-compose services for a single-app project (no workspace config).
|
|
2311
|
-
* Starts all services defined in docker-compose.yml.
|
|
2312
|
-
*/
|
|
2313
|
-
async function startComposeServices(cwd, portEnv, secretsEnv) {
|
|
2314
|
-
const composeFile = (0, node_path.join)(cwd, "docker-compose.yml");
|
|
2315
|
-
if (!(0, node_fs.existsSync)(composeFile)) return;
|
|
2316
|
-
const servicesToStart = parseComposeServiceNames(composeFile);
|
|
2317
|
-
if (servicesToStart.length === 0) return;
|
|
2318
|
-
logger.log(`🐳 Starting services: ${servicesToStart.join(", ")}`);
|
|
2859
|
+
async function write(path, content) {
|
|
2319
2860
|
try {
|
|
2320
|
-
(0,
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
});
|
|
2325
|
-
logger.log("✅ Services started");
|
|
2326
|
-
} catch (error) {
|
|
2327
|
-
logger.error("❌ Failed to start services:", error.message);
|
|
2328
|
-
throw error;
|
|
2329
|
-
}
|
|
2861
|
+
if (await (0, node_fs_promises.readFile)(path, "utf-8") === content) return;
|
|
2862
|
+
} catch {}
|
|
2863
|
+
await (0, node_fs_promises.mkdir)((0, node_path.dirname)(path), { recursive: true });
|
|
2864
|
+
await (0, node_fs_promises.writeFile)(path, content);
|
|
2330
2865
|
}
|
|
2866
|
+
//#endregion
|
|
2867
|
+
//#region src/reconcile/workspace.ts
|
|
2331
2868
|
/**
|
|
2332
|
-
*
|
|
2333
|
-
*
|
|
2334
|
-
*
|
|
2335
|
-
*
|
|
2869
|
+
* Workspace config → reconcile.
|
|
2870
|
+
*
|
|
2871
|
+
* Nothing here is read from a `services:` block — there is none. Which
|
|
2872
|
+
* containers exist comes from the manifest; which backend a cache or a broker
|
|
2873
|
+
* resolves to comes from the deploy target; and an image pin is the project's
|
|
2874
|
+
* own `docker-compose.yml`, merged over the generated file.
|
|
2875
|
+
*
|
|
2876
|
+
* Shared by `gkm setup`, `gkm dev`, and `gkm test` so all three converge on the
|
|
2877
|
+
* same state, differing only in the stage they pass.
|
|
2878
|
+
*/
|
|
2879
|
+
var workspace_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({
|
|
2880
|
+
FAKE_ENV: () => FAKE_ENV,
|
|
2881
|
+
backendsOf: () => backendsOf,
|
|
2882
|
+
constructGlobs: () => constructGlobs,
|
|
2883
|
+
derivedContainers: () => derivedContainers,
|
|
2884
|
+
fakesApply: () => fakesApply,
|
|
2885
|
+
metroPorts: () => metroPorts,
|
|
2886
|
+
reconcileWorkspace: () => reconcileWorkspace,
|
|
2887
|
+
surfaceAddresses: () => surfaceAddresses
|
|
2888
|
+
});
|
|
2889
|
+
/**
|
|
2890
|
+
* Every constructs glob in the workspace, resolved against its app.
|
|
2891
|
+
*
|
|
2892
|
+
* Absolute because discovery globs from a single cwd while apps live in
|
|
2893
|
+
* different directories.
|
|
2336
2894
|
*/
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
const
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
cwd: workspace.root,
|
|
2348
|
-
stdio: "inherit",
|
|
2349
|
-
env: buildDockerComposeEnv(secretsEnv, portEnv)
|
|
2350
|
-
});
|
|
2351
|
-
logger.log("✅ Services started");
|
|
2352
|
-
} catch (error) {
|
|
2353
|
-
logger.error("❌ Failed to start services:", error.message);
|
|
2354
|
-
throw error;
|
|
2355
|
-
}
|
|
2895
|
+
function constructGlobs(workspace) {
|
|
2896
|
+
return require_workspace.allConstructGlobs(workspace);
|
|
2897
|
+
}
|
|
2898
|
+
/** The backends a workspace's target implies, as the plan takes them. */
|
|
2899
|
+
function backendsOf(workspace) {
|
|
2900
|
+
const on = require_backends.providerOf(workspace);
|
|
2901
|
+
return {
|
|
2902
|
+
events: require_backends.eventsBackendFor(on),
|
|
2903
|
+
cache: require_backends.cacheBackendFor(on)
|
|
2904
|
+
};
|
|
2356
2905
|
}
|
|
2357
2906
|
/**
|
|
2358
|
-
*
|
|
2359
|
-
*
|
|
2360
|
-
*
|
|
2907
|
+
* The containers a workspace's declarations imply, without reconciling.
|
|
2908
|
+
*
|
|
2909
|
+
* The same derivation `reconcileWorkspace` makes, available to callers that
|
|
2910
|
+
* need to know *what would run* without starting anything or writing ports —
|
|
2911
|
+
* `gkm setup` deciding which credentials to generate, `gkm docker` writing a
|
|
2912
|
+
* compose file. Those used to each read a boolean per service out of config,
|
|
2913
|
+
* which is how a container could exist because config asked for one rather than
|
|
2914
|
+
* because something declared it.
|
|
2361
2915
|
*/
|
|
2362
|
-
async function
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
}
|
|
2372
|
-
if (Object.keys(secrets).length === 0) return {};
|
|
2373
|
-
if (!appName) return secrets;
|
|
2374
|
-
const prefix = appName.toUpperCase();
|
|
2375
|
-
const mapped = { ...secrets };
|
|
2376
|
-
const appDbUrl = secrets[`${prefix}_DATABASE_URL`];
|
|
2377
|
-
if (appDbUrl) mapped.DATABASE_URL = appDbUrl;
|
|
2378
|
-
return mapped;
|
|
2916
|
+
async function derivedContainers(workspace, stage, manifest) {
|
|
2917
|
+
const found = manifest ?? await require_discover.discover({
|
|
2918
|
+
patterns: constructGlobs(workspace),
|
|
2919
|
+
cwd: workspace.root
|
|
2920
|
+
});
|
|
2921
|
+
return planFor(found, stage, (0, _geekmidas_manifest.provisionOrder)(found), {
|
|
2922
|
+
localStage: workspace.stages.local,
|
|
2923
|
+
...backendsOf(workspace)
|
|
2924
|
+
}).containers;
|
|
2379
2925
|
}
|
|
2380
2926
|
/**
|
|
2381
|
-
*
|
|
2382
|
-
*
|
|
2927
|
+
* Set by `gkm dev --fake` for the apps it starts. Each app's own `gkm dev`
|
|
2928
|
+
* reconciles too, and must answer the way the workspace did.
|
|
2383
2929
|
*/
|
|
2384
|
-
|
|
2385
|
-
let dir = startDir;
|
|
2386
|
-
while (dir !== "/") {
|
|
2387
|
-
if ((0, node_fs.existsSync)((0, node_path.join)(dir, ".gkm", "secrets"))) return dir;
|
|
2388
|
-
const parent = (0, node_path.dirname)(dir);
|
|
2389
|
-
if (parent === dir) break;
|
|
2390
|
-
dir = parent;
|
|
2391
|
-
}
|
|
2392
|
-
return startDir;
|
|
2393
|
-
}
|
|
2930
|
+
const FAKE_ENV = "GKM_FAKE";
|
|
2394
2931
|
/**
|
|
2395
|
-
*
|
|
2396
|
-
*
|
|
2397
|
-
*
|
|
2932
|
+
* Whether external APIs are faked: always for `gkm test`, and for `gkm dev`
|
|
2933
|
+
* only when asked — by `--fake`, or by the workspace that started this app
|
|
2934
|
+
* with it. Never for anything acting on a deployed stage.
|
|
2398
2935
|
*/
|
|
2399
|
-
function
|
|
2400
|
-
return
|
|
2401
|
-
|
|
2402
|
-
// Inject dev secrets via globalThis and process.env
|
|
2403
|
-
// Using globalThis.__gkm_credentials__ avoids CJS/ESM interop issues where
|
|
2404
|
-
// Object.assign on the Credentials export only mutates one module copy.
|
|
2405
|
-
const secretsPath = '${secretsJsonPath}';
|
|
2406
|
-
if (existsSync(secretsPath)) {
|
|
2407
|
-
const secrets = JSON.parse(readFileSync(secretsPath, 'utf-8'));
|
|
2408
|
-
globalThis.__gkm_credentials__ = secrets;
|
|
2409
|
-
Object.assign(process.env, secrets);
|
|
2410
|
-
}
|
|
2411
|
-
`;
|
|
2936
|
+
function fakesApply(stage, fake, env = process.env) {
|
|
2937
|
+
return fake === true || stage === "test" || env["GKM_FAKE"] === "1";
|
|
2412
2938
|
}
|
|
2413
2939
|
/**
|
|
2414
|
-
*
|
|
2415
|
-
*
|
|
2416
|
-
*
|
|
2940
|
+
* Reconcile a workspace for one stage.
|
|
2941
|
+
*
|
|
2942
|
+
* Ports are loaded and saved around the call rather than inside it, so the loop
|
|
2943
|
+
* stays a pure-ish function of its inputs and the store keeps its single owner.
|
|
2417
2944
|
*/
|
|
2418
|
-
async function
|
|
2419
|
-
const
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2945
|
+
async function reconcileWorkspace(workspace, options) {
|
|
2946
|
+
const runnables = {};
|
|
2947
|
+
const discovered = await require_discover.discover({
|
|
2948
|
+
patterns: constructGlobs(workspace),
|
|
2949
|
+
cwd: workspace.root,
|
|
2950
|
+
runnables
|
|
2951
|
+
});
|
|
2952
|
+
const manifest = options.manifest ?? discovered;
|
|
2953
|
+
const fakes = fakesApply(options.stage, options.fake) ? await require_ready.readFakes(workspace.root, manifest) : {};
|
|
2954
|
+
const result = await reconcile({
|
|
2955
|
+
root: workspace.root,
|
|
2956
|
+
project: workspace.name,
|
|
2957
|
+
manifest,
|
|
2958
|
+
stage: options.stage,
|
|
2959
|
+
localStage: workspace.stages.local,
|
|
2960
|
+
...backendsOf(workspace),
|
|
2961
|
+
saved: await loadPortState(workspace.root),
|
|
2962
|
+
addresses: surfaceAddresses(workspace, manifest),
|
|
2963
|
+
metroPorts: metroPorts(workspace, manifest),
|
|
2964
|
+
fakes,
|
|
2965
|
+
apps: (containers) => appServices(workspace, manifest, containers, runnables, fakes),
|
|
2966
|
+
...options.start === void 0 ? {} : { start: options.start },
|
|
2967
|
+
...options.progress ? { progress: options.progress } : {}
|
|
2968
|
+
});
|
|
2969
|
+
await savePortState(workspace.root, { ...result.ports });
|
|
2970
|
+
return result;
|
|
2425
2971
|
}
|
|
2426
2972
|
/**
|
|
2427
|
-
*
|
|
2428
|
-
*
|
|
2973
|
+
* Where each mobile app's Metro runs: its app's port, which `gkm exec` hands
|
|
2974
|
+
* Expo as `RCT_METRO_PORT`. Kept apart from the surfaces' addresses — a phone
|
|
2975
|
+
* reaches Metro by `exp://`, not through the edge.
|
|
2429
2976
|
*/
|
|
2430
|
-
|
|
2431
|
-
const
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
await import('${entryPath}');
|
|
2439
|
-
`;
|
|
2440
|
-
await (0, node_fs_promises.writeFile)(wrapperPath, content);
|
|
2977
|
+
function metroPorts(workspace, manifest) {
|
|
2978
|
+
const ports = {};
|
|
2979
|
+
for (const [id, declaration] of Object.entries(manifest)) {
|
|
2980
|
+
if (declaration.kind !== "mobile-app") continue;
|
|
2981
|
+
const port = workspace.apps[require_config.appKey(id)]?.port;
|
|
2982
|
+
if (port) ports[id] = port;
|
|
2983
|
+
}
|
|
2984
|
+
return ports;
|
|
2441
2985
|
}
|
|
2442
2986
|
/**
|
|
2443
|
-
*
|
|
2444
|
-
* Loads workspace config, secrets, resolves Docker ports, rewrites URLs,
|
|
2445
|
-
* injects PORT, dependency URLs, and writes credentials JSON.
|
|
2987
|
+
* Where each declared surface and site answers locally.
|
|
2446
2988
|
*
|
|
2447
|
-
*
|
|
2448
|
-
*
|
|
2449
|
-
*
|
|
2450
|
-
*
|
|
2451
|
-
*
|
|
2452
|
-
*
|
|
2453
|
-
*
|
|
2989
|
+
* The addresses come from the ports the workspace already assigns; which
|
|
2990
|
+
* construct sits at which one comes from the manifest. That split is the point:
|
|
2991
|
+
* this used to answer "who may call whom" by listing every app the workspace
|
|
2992
|
+
* runs, which is a different question that happened to give the same answer in
|
|
2993
|
+
* a single-repo workspace and no answer at all deployed. Now it answers only
|
|
2994
|
+
* "where does this construct answer", and the graph answers the rest.
|
|
2995
|
+
*
|
|
2996
|
+
* A site is matched to its app by `path`, because that is the one thing a site
|
|
2997
|
+
* declaration and a workspace app both name. Surfaces are matched to the
|
|
2998
|
+
* backend app: every `rest-api` in a process answers on that process's port, so
|
|
2999
|
+
* an app serving both its own API and an auth server publishes one address
|
|
3000
|
+
* twice — which is exactly what it does at runtime.
|
|
2454
3001
|
*/
|
|
2455
|
-
|
|
2456
|
-
const
|
|
2457
|
-
const
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
try {
|
|
2463
|
-
appInfo = await require_config.loadWorkspaceAppInfo(cwd);
|
|
2464
|
-
workspaceAppPort = appInfo.app.port;
|
|
2465
|
-
secretsRoot = appInfo.workspaceRoot;
|
|
2466
|
-
appName = appInfo.appName;
|
|
2467
|
-
} catch {
|
|
2468
|
-
secretsRoot = findSecretsRoot(cwd);
|
|
2469
|
-
appName = require_config.getAppNameFromCwd(cwd) ?? void 0;
|
|
2470
|
-
}
|
|
2471
|
-
const resolvedPort = options.explicitPort ?? workspaceAppPort ?? 3e3;
|
|
2472
|
-
const credentials = await loadSecretsForApp(secretsRoot, appName, options.stages);
|
|
2473
|
-
credentials.PORT = String(resolvedPort);
|
|
2474
|
-
const declaredKeys = [];
|
|
2475
|
-
if (appInfo && usesConstructs(appInfo.workspace)) {
|
|
2476
|
-
const { reconcileWorkspace: reconcileWorkspace$1 } = await Promise.resolve().then(() => require("./workspace-DdJss8I6.cjs"));
|
|
2477
|
-
const reconciled = await reconcileWorkspace$1(appInfo.workspace, {
|
|
2478
|
-
stage: options.reconcileStage ?? "development",
|
|
2479
|
-
start: options.startDocker ?? false
|
|
2480
|
-
});
|
|
2481
|
-
Object.assign(credentials, reconciled.env);
|
|
2482
|
-
declaredKeys.push(...Object.keys(reconciled.env));
|
|
2483
|
-
if (Object.keys(reconciled.env).length > 0) logger.log(`🔌 Resolved ${Object.keys(reconciled.env).length} declared URL(s)`);
|
|
2484
|
-
} else {
|
|
2485
|
-
const composePath = (0, node_path.join)(secretsRoot, "docker-compose.yml");
|
|
2486
|
-
const mappings = parseComposePortMappings(composePath);
|
|
2487
|
-
if (mappings.length > 0) {
|
|
2488
|
-
let resolvedPorts;
|
|
2489
|
-
if (portMode === "full") resolvedPorts = await resolveServicePorts(secretsRoot);
|
|
2490
|
-
else {
|
|
2491
|
-
const savedPorts = await loadPortState(secretsRoot);
|
|
2492
|
-
const ports = {};
|
|
2493
|
-
for (const mapping of mappings) {
|
|
2494
|
-
const containerPort = getContainerHostPort(secretsRoot, mapping.service, mapping.containerPort);
|
|
2495
|
-
if (containerPort !== null) ports[mapping.envVar] = containerPort;
|
|
2496
|
-
else {
|
|
2497
|
-
const saved = savedPorts[mapping.envVar];
|
|
2498
|
-
if (saved !== void 0) ports[mapping.envVar] = saved;
|
|
2499
|
-
}
|
|
2500
|
-
}
|
|
2501
|
-
resolvedPorts = {
|
|
2502
|
-
dockerEnv: {},
|
|
2503
|
-
ports,
|
|
2504
|
-
mappings
|
|
2505
|
-
};
|
|
2506
|
-
}
|
|
2507
|
-
if (options.startDocker) if (appInfo) await startWorkspaceServices(appInfo.workspace, resolvedPorts.dockerEnv, credentials);
|
|
2508
|
-
else await startComposeServices(secretsRoot, resolvedPorts.dockerEnv, credentials);
|
|
2509
|
-
if (Object.keys(resolvedPorts.ports).length > 0) {
|
|
2510
|
-
const rewritten = rewriteUrlsWithPorts(credentials, resolvedPorts);
|
|
2511
|
-
Object.assign(credentials, rewritten);
|
|
2512
|
-
logger.log(`🔌 Applied ${Object.keys(resolvedPorts.ports).length} port mapping(s)`);
|
|
2513
|
-
}
|
|
2514
|
-
}
|
|
2515
|
-
}
|
|
2516
|
-
if (appInfo?.appName) {
|
|
2517
|
-
const depEnv = require_workspace.getDependencyEnvVars(appInfo.workspace, appInfo.appName);
|
|
2518
|
-
Object.assign(credentials, depEnv);
|
|
2519
|
-
}
|
|
2520
|
-
if (!credentials.EVENT_PUBLISHER_CONNECTION_STRING && !credentials.EVENT_SUBSCRIBER_CONNECTION_STRING && credentials.PGBOSS_DB_USER) {
|
|
2521
|
-
const pgbossUrl = require_generator.generatePgBossUrl({
|
|
2522
|
-
username: credentials.PGBOSS_DB_USER,
|
|
2523
|
-
password: credentials.PGBOSS_DB_PASSWORD ?? "",
|
|
2524
|
-
host: credentials.POSTGRES_HOST ?? "localhost",
|
|
2525
|
-
port: Number(credentials.POSTGRES_PORT ?? "5432"),
|
|
2526
|
-
database: credentials.POSTGRES_DB ?? "app"
|
|
2527
|
-
});
|
|
2528
|
-
credentials.EVENT_PUBLISHER_CONNECTION_STRING = pgbossUrl;
|
|
2529
|
-
credentials.EVENT_SUBSCRIBER_CONNECTION_STRING = pgbossUrl;
|
|
3002
|
+
function surfaceAddresses(workspace, manifest, at = (_app, port) => localAddress(port)) {
|
|
3003
|
+
const addresses = {};
|
|
3004
|
+
for (const [id, declaration] of Object.entries(manifest)) {
|
|
3005
|
+
if (declaration.kind !== "rest-api" && declaration.kind !== "site") continue;
|
|
3006
|
+
const host = require_config.appKey(id);
|
|
3007
|
+
const port = workspace.apps[host]?.port;
|
|
3008
|
+
if (port) addresses[id] = at(host, port);
|
|
2530
3009
|
}
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
return {
|
|
2537
|
-
credentials,
|
|
2538
|
-
resolvedPort,
|
|
2539
|
-
secretsJsonPath,
|
|
2540
|
-
appName,
|
|
2541
|
-
secretsRoot,
|
|
2542
|
-
appInfo,
|
|
2543
|
-
declaredKeys
|
|
2544
|
-
};
|
|
3010
|
+
return addresses;
|
|
3011
|
+
}
|
|
3012
|
+
/** Where a local process answers, given the port the workspace gave it. */
|
|
3013
|
+
function localAddress(port) {
|
|
3014
|
+
return `http://localhost:${port}`;
|
|
2545
3015
|
}
|
|
2546
|
-
|
|
2547
3016
|
//#endregion
|
|
2548
|
-
Object.defineProperty(exports,
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
3017
|
+
Object.defineProperty(exports, "COMPOSE_PATH", {
|
|
3018
|
+
enumerable: true,
|
|
3019
|
+
get: function() {
|
|
3020
|
+
return COMPOSE_PATH;
|
|
3021
|
+
}
|
|
3022
|
+
});
|
|
3023
|
+
Object.defineProperty(exports, "FAKE_ENV", {
|
|
3024
|
+
enumerable: true,
|
|
3025
|
+
get: function() {
|
|
3026
|
+
return FAKE_ENV;
|
|
3027
|
+
}
|
|
3028
|
+
});
|
|
3029
|
+
Object.defineProperty(exports, "LOCAL_CA_PATH", {
|
|
3030
|
+
enumerable: true,
|
|
3031
|
+
get: function() {
|
|
3032
|
+
return LOCAL_CA_PATH;
|
|
3033
|
+
}
|
|
2553
3034
|
});
|
|
2554
|
-
Object.defineProperty(exports,
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
|
|
3035
|
+
Object.defineProperty(exports, "applyPostgres", {
|
|
3036
|
+
enumerable: true,
|
|
3037
|
+
get: function() {
|
|
3038
|
+
return applyPostgres;
|
|
3039
|
+
}
|
|
3040
|
+
});
|
|
3041
|
+
Object.defineProperty(exports, "backendsOf", {
|
|
3042
|
+
enumerable: true,
|
|
3043
|
+
get: function() {
|
|
3044
|
+
return backendsOf;
|
|
3045
|
+
}
|
|
2559
3046
|
});
|
|
2560
|
-
Object.defineProperty(exports,
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
|
|
3047
|
+
Object.defineProperty(exports, "constructGlobs", {
|
|
3048
|
+
enumerable: true,
|
|
3049
|
+
get: function() {
|
|
3050
|
+
return constructGlobs;
|
|
3051
|
+
}
|
|
2565
3052
|
});
|
|
2566
|
-
Object.defineProperty(exports,
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
3053
|
+
Object.defineProperty(exports, "createCredentialsPreload", {
|
|
3054
|
+
enumerable: true,
|
|
3055
|
+
get: function() {
|
|
3056
|
+
return createCredentialsPreload;
|
|
3057
|
+
}
|
|
2571
3058
|
});
|
|
2572
|
-
Object.defineProperty(exports,
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
3059
|
+
Object.defineProperty(exports, "createEntryWrapper", {
|
|
3060
|
+
enumerable: true,
|
|
3061
|
+
get: function() {
|
|
3062
|
+
return createEntryWrapper;
|
|
3063
|
+
}
|
|
2577
3064
|
});
|
|
2578
|
-
Object.defineProperty(exports,
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
3065
|
+
Object.defineProperty(exports, "derivedContainers", {
|
|
3066
|
+
enumerable: true,
|
|
3067
|
+
get: function() {
|
|
3068
|
+
return derivedContainers;
|
|
3069
|
+
}
|
|
2583
3070
|
});
|
|
2584
|
-
Object.defineProperty(exports,
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
3071
|
+
Object.defineProperty(exports, "describeServices", {
|
|
3072
|
+
enumerable: true,
|
|
3073
|
+
get: function() {
|
|
3074
|
+
return describeServices;
|
|
3075
|
+
}
|
|
2589
3076
|
});
|
|
2590
|
-
Object.defineProperty(exports,
|
|
2591
|
-
|
|
2592
|
-
|
|
2593
|
-
|
|
2594
|
-
|
|
3077
|
+
Object.defineProperty(exports, "fakeKey", {
|
|
3078
|
+
enumerable: true,
|
|
3079
|
+
get: function() {
|
|
3080
|
+
return fakeKey;
|
|
3081
|
+
}
|
|
2595
3082
|
});
|
|
2596
|
-
Object.defineProperty(exports,
|
|
2597
|
-
|
|
2598
|
-
|
|
2599
|
-
|
|
2600
|
-
|
|
3083
|
+
Object.defineProperty(exports, "findAvailablePort", {
|
|
3084
|
+
enumerable: true,
|
|
3085
|
+
get: function() {
|
|
3086
|
+
return findAvailablePort;
|
|
3087
|
+
}
|
|
2601
3088
|
});
|
|
2602
|
-
Object.defineProperty(exports,
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
3089
|
+
Object.defineProperty(exports, "forgetState", {
|
|
3090
|
+
enumerable: true,
|
|
3091
|
+
get: function() {
|
|
3092
|
+
return forgetState;
|
|
3093
|
+
}
|
|
2607
3094
|
});
|
|
2608
|
-
Object.defineProperty(exports,
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
|
|
3095
|
+
Object.defineProperty(exports, "isPortAvailable", {
|
|
3096
|
+
enumerable: true,
|
|
3097
|
+
get: function() {
|
|
3098
|
+
return isPortAvailable;
|
|
3099
|
+
}
|
|
2613
3100
|
});
|
|
2614
|
-
Object.defineProperty(exports,
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
3101
|
+
Object.defineProperty(exports, "loadEnvFiles", {
|
|
3102
|
+
enumerable: true,
|
|
3103
|
+
get: function() {
|
|
3104
|
+
return loadEnvFiles;
|
|
3105
|
+
}
|
|
2619
3106
|
});
|
|
2620
|
-
Object.defineProperty(exports,
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
|
|
3107
|
+
Object.defineProperty(exports, "loadSecretsForApp", {
|
|
3108
|
+
enumerable: true,
|
|
3109
|
+
get: function() {
|
|
3110
|
+
return loadSecretsForApp;
|
|
3111
|
+
}
|
|
2625
3112
|
});
|
|
2626
|
-
Object.defineProperty(exports,
|
|
2627
|
-
|
|
2628
|
-
|
|
2629
|
-
|
|
2630
|
-
|
|
3113
|
+
Object.defineProperty(exports, "pgClient", {
|
|
3114
|
+
enumerable: true,
|
|
3115
|
+
get: function() {
|
|
3116
|
+
return pgClient;
|
|
3117
|
+
}
|
|
2631
3118
|
});
|
|
2632
|
-
Object.defineProperty(exports,
|
|
2633
|
-
|
|
2634
|
-
|
|
2635
|
-
|
|
2636
|
-
|
|
3119
|
+
Object.defineProperty(exports, "postgresDatabaseNames", {
|
|
3120
|
+
enumerable: true,
|
|
3121
|
+
get: function() {
|
|
3122
|
+
return postgresDatabaseNames;
|
|
3123
|
+
}
|
|
2637
3124
|
});
|
|
2638
|
-
Object.defineProperty(exports,
|
|
2639
|
-
|
|
2640
|
-
|
|
2641
|
-
|
|
2642
|
-
|
|
3125
|
+
Object.defineProperty(exports, "prepareEntryCredentials", {
|
|
3126
|
+
enumerable: true,
|
|
3127
|
+
get: function() {
|
|
3128
|
+
return prepareEntryCredentials;
|
|
3129
|
+
}
|
|
2643
3130
|
});
|
|
2644
|
-
Object.defineProperty(exports,
|
|
2645
|
-
|
|
2646
|
-
|
|
2647
|
-
|
|
2648
|
-
|
|
3131
|
+
Object.defineProperty(exports, "primaryPortKey", {
|
|
3132
|
+
enumerable: true,
|
|
3133
|
+
get: function() {
|
|
3134
|
+
return primaryPortKey;
|
|
3135
|
+
}
|
|
2649
3136
|
});
|
|
2650
|
-
Object.defineProperty(exports,
|
|
2651
|
-
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
-
|
|
3137
|
+
Object.defineProperty(exports, "quoteIdentifier", {
|
|
3138
|
+
enumerable: true,
|
|
3139
|
+
get: function() {
|
|
3140
|
+
return quoteIdentifier;
|
|
3141
|
+
}
|
|
2655
3142
|
});
|
|
2656
|
-
Object.defineProperty(exports,
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
|
|
2660
|
-
|
|
3143
|
+
Object.defineProperty(exports, "reconcileWorkspace", {
|
|
3144
|
+
enumerable: true,
|
|
3145
|
+
get: function() {
|
|
3146
|
+
return reconcileWorkspace;
|
|
3147
|
+
}
|
|
2661
3148
|
});
|
|
2662
|
-
Object.defineProperty(exports,
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
|
|
2666
|
-
|
|
3149
|
+
Object.defineProperty(exports, "resourceName", {
|
|
3150
|
+
enumerable: true,
|
|
3151
|
+
get: function() {
|
|
3152
|
+
return resourceName;
|
|
3153
|
+
}
|
|
2667
3154
|
});
|
|
2668
|
-
Object.defineProperty(exports,
|
|
2669
|
-
|
|
2670
|
-
|
|
2671
|
-
|
|
2672
|
-
|
|
3155
|
+
Object.defineProperty(exports, "rootSite", {
|
|
3156
|
+
enumerable: true,
|
|
3157
|
+
get: function() {
|
|
3158
|
+
return rootSite;
|
|
3159
|
+
}
|
|
2673
3160
|
});
|
|
2674
|
-
Object.defineProperty(exports,
|
|
2675
|
-
|
|
2676
|
-
|
|
2677
|
-
|
|
2678
|
-
|
|
3161
|
+
Object.defineProperty(exports, "workspace_exports", {
|
|
3162
|
+
enumerable: true,
|
|
3163
|
+
get: function() {
|
|
3164
|
+
return workspace_exports;
|
|
3165
|
+
}
|
|
2679
3166
|
});
|
|
2680
|
-
|
|
3167
|
+
|
|
3168
|
+
//# sourceMappingURL=workspace-j6ZxvJqq.cjs.map
|