@geekmidas/cli 10.0.0-alpha.15 → 10.0.0-alpha.151
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 +313 -380
- package/bin/adjacent-tsconfig.mjs +46 -8
- package/bin/gkm.mjs +11 -3
- package/bin/owning-tsconfig-jsx-register.mjs +18 -0
- package/bin/owning-tsconfig-jsx.mjs +108 -0
- package/dist/EndpointGenerator-CusLH-9S.mjs +1037 -0
- package/dist/EndpointGenerator-CusLH-9S.mjs.map +1 -0
- package/dist/EndpointGenerator-DyLMYClE.cjs +1096 -0
- package/dist/EndpointGenerator-DyLMYClE.cjs.map +1 -0
- package/dist/GoDaddyProvider-BZYq0-nV.cjs +412 -0
- package/dist/GoDaddyProvider-BZYq0-nV.cjs.map +1 -0
- package/dist/GoDaddyProvider-D-8GW8cP.mjs +412 -0
- package/dist/GoDaddyProvider-D-8GW8cP.mjs.map +1 -0
- package/dist/{HostingerProvider-BZFGYYVA.cjs → HostingerProvider-BxRR2ibx.cjs} +23 -9
- package/dist/HostingerProvider-BxRR2ibx.cjs.map +1 -0
- package/dist/{HostingerProvider-BY26bWwB.mjs → HostingerProvider-C-C4aiKF.mjs} +23 -9
- package/dist/HostingerProvider-C-C4aiKF.mjs.map +1 -0
- package/dist/LegacyStateStore-BFkNiBxC.mjs +124 -0
- package/dist/LegacyStateStore-BFkNiBxC.mjs.map +1 -0
- package/dist/LegacyStateStore-DYaamZqR.cjs +124 -0
- package/dist/LegacyStateStore-DYaamZqR.cjs.map +1 -0
- package/dist/LocalStateStore-7pP4naiB.mjs +167 -0
- package/dist/LocalStateStore-7pP4naiB.mjs.map +1 -0
- package/dist/LocalStateStore-C0JSjyCg.cjs +178 -0
- package/dist/LocalStateStore-C0JSjyCg.cjs.map +1 -0
- package/dist/OpenApiTsGenerator-BTMuu1WS.mjs +534 -0
- package/dist/OpenApiTsGenerator-BTMuu1WS.mjs.map +1 -0
- package/dist/OpenApiTsGenerator-CI-tceXV.cjs +539 -0
- package/dist/OpenApiTsGenerator-CI-tceXV.cjs.map +1 -0
- package/dist/{Route53Provider-Cvj40A8I.mjs → Route53Provider-Di_SD9CF.mjs} +3 -3
- package/dist/Route53Provider-Di_SD9CF.mjs.map +1 -0
- package/dist/{Route53Provider-DVILBsvV.cjs → Route53Provider-emLuQHVw.cjs} +3 -3
- package/dist/Route53Provider-emLuQHVw.cjs.map +1 -0
- package/dist/S3StateStore-BnmbFco-.cjs +222 -0
- package/dist/S3StateStore-BnmbFco-.cjs.map +1 -0
- package/dist/S3StateStore-Dzyuiy3V.mjs +223 -0
- package/dist/S3StateStore-Dzyuiy3V.mjs.map +1 -0
- package/dist/SSMStateStore-BLbjoEFc.cjs +204 -0
- package/dist/SSMStateStore-BLbjoEFc.cjs.map +1 -0
- package/dist/SSMStateStore-BcNH7efc.mjs +205 -0
- package/dist/SSMStateStore-BcNH7efc.mjs.map +1 -0
- package/dist/SubscriberGenerator-BNJyPmXJ.cjs +848 -0
- package/dist/SubscriberGenerator-BNJyPmXJ.cjs.map +1 -0
- package/dist/SubscriberGenerator-CzPrixYu.mjs +783 -0
- package/dist/SubscriberGenerator-CzPrixYu.mjs.map +1 -0
- package/dist/add-SHsas9Yu.mjs +711 -0
- package/dist/add-SHsas9Yu.mjs.map +1 -0
- package/dist/add-moAE6nV4.cjs +713 -0
- package/dist/add-moAE6nV4.cjs.map +1 -0
- package/dist/appPorts-BoXMwolc.mjs +249 -0
- package/dist/appPorts-BoXMwolc.mjs.map +1 -0
- package/dist/appPorts-IW-OZmRi.cjs +296 -0
- package/dist/appPorts-IW-OZmRi.cjs.map +1 -0
- package/dist/apps-BOgA6AcI.mjs +5534 -0
- package/dist/apps-BOgA6AcI.mjs.map +1 -0
- package/dist/apps-DkxHjd59.cjs +6148 -0
- package/dist/apps-DkxHjd59.cjs.map +1 -0
- package/dist/aws-8QQ8n-t6.mjs +89 -0
- package/dist/aws-8QQ8n-t6.mjs.map +1 -0
- package/dist/aws-DY9NqQIT.cjs +100 -0
- package/dist/aws-DY9NqQIT.cjs.map +1 -0
- package/dist/awsStore-Bx5nCFnS.mjs +121 -0
- package/dist/awsStore-Bx5nCFnS.mjs.map +1 -0
- package/dist/awsStore-u3ehhMoY.cjs +138 -0
- package/dist/awsStore-u3ehhMoY.cjs.map +1 -0
- package/dist/{backup-provisioner-DIVCbfee.mjs → backup-provisioner-C8DnCmxK.mjs} +2 -2
- package/dist/backup-provisioner-C8DnCmxK.mjs.map +1 -0
- package/dist/{backup-provisioner-BmhIO_Yr.cjs → backup-provisioner-oDEsPj02.cjs} +2 -2
- package/dist/backup-provisioner-oDEsPj02.cjs.map +1 -0
- package/dist/backups/runner.cjs +519 -0
- package/dist/backups/runner.cjs.map +1 -0
- package/dist/backups/runner.d.cts +102 -0
- package/dist/backups/runner.d.cts.map +1 -0
- package/dist/backups/runner.d.mts +102 -0
- package/dist/backups/runner.d.mts.map +1 -0
- package/dist/backups/runner.mjs +506 -0
- package/dist/backups/runner.mjs.map +1 -0
- package/dist/{bundler-BeNDZdHQ.cjs → bundler-D0spRLb-.cjs} +59 -14
- package/dist/bundler-D0spRLb-.cjs.map +1 -0
- package/dist/{bundler-BodTL4kf.mjs → bundler-Dy-Dfchf.mjs} +59 -14
- package/dist/bundler-Dy-Dfchf.mjs.map +1 -0
- package/dist/cli-BmCyUTZf.cjs +71 -0
- package/dist/cli-BmCyUTZf.cjs.map +1 -0
- package/dist/cli-BpT_gg4n.mjs +71 -0
- package/dist/cli-BpT_gg4n.mjs.map +1 -0
- package/dist/compose-0HkjQywT.cjs +3046 -0
- package/dist/compose-0HkjQywT.cjs.map +1 -0
- package/dist/compose-B3OOowfE.mjs +1560 -0
- package/dist/compose-B3OOowfE.mjs.map +1 -0
- package/dist/compose-BIXEPrGA.mjs +2957 -0
- package/dist/compose-BIXEPrGA.mjs.map +1 -0
- package/dist/compose-BP8OeV7P.cjs +1919 -0
- package/dist/compose-BP8OeV7P.cjs.map +1 -0
- package/dist/config-BLrAd7Of.mjs +659 -0
- package/dist/config-BLrAd7Of.mjs.map +1 -0
- package/dist/config-CRk2vdSp.d.mts +268 -0
- package/dist/config-CRk2vdSp.d.mts.map +1 -0
- package/dist/config-juUyBlb1.cjs +772 -0
- package/dist/config-juUyBlb1.cjs.map +1 -0
- package/dist/config-oBgsbLip.d.cts +268 -0
- package/dist/config-oBgsbLip.d.cts.map +1 -0
- package/dist/config.cjs +11 -3
- package/dist/config.d.cts +4 -117
- package/dist/config.d.mts +4 -117
- package/dist/config.mjs +3 -3
- package/dist/credentialSchemas-BAklWDna.cjs +271 -0
- package/dist/credentialSchemas-BAklWDna.cjs.map +1 -0
- package/dist/credentialSchemas-mz9QZTYh.mjs +236 -0
- package/dist/credentialSchemas-mz9QZTYh.mjs.map +1 -0
- package/dist/credentials-B6ZwGsy-.cjs +2272 -0
- package/dist/credentials-B6ZwGsy-.cjs.map +1 -0
- package/dist/credentials-DRfP9aG7.mjs +1817 -0
- package/dist/credentials-DRfP9aG7.mjs.map +1 -0
- package/dist/databases-DawSdqBI.cjs +703 -0
- package/dist/databases-DawSdqBI.cjs.map +1 -0
- package/dist/databases-mzSUFBTw.mjs +588 -0
- package/dist/databases-mzSUFBTw.mjs.map +1 -0
- package/dist/define-6poNqm5O.mjs +106 -0
- package/dist/define-6poNqm5O.mjs.map +1 -0
- package/dist/define-crmMcXFS.cjs +153 -0
- package/dist/define-crmMcXFS.cjs.map +1 -0
- package/dist/deploy/public.cjs +211 -0
- package/dist/deploy/public.cjs.map +1 -0
- package/dist/deploy/public.d.cts +647 -0
- package/dist/deploy/public.d.cts.map +1 -0
- package/dist/deploy/public.d.mts +647 -0
- package/dist/deploy/public.d.mts.map +1 -0
- package/dist/deploy/public.mjs +144 -0
- package/dist/deploy/public.mjs.map +1 -0
- package/dist/deploy/sniffer-envparser-worker.cjs +54 -0
- package/dist/deploy/sniffer-envparser-worker.cjs.map +1 -0
- package/dist/deploy/sniffer-envparser-worker.d.cts +1 -0
- package/dist/deploy/sniffer-envparser-worker.d.mts +1 -0
- package/dist/deploy/sniffer-envparser-worker.mjs +55 -0
- package/dist/deploy/sniffer-envparser-worker.mjs.map +1 -0
- package/dist/deploy/sniffer-hooks.cjs +1 -1
- package/dist/deploy/sniffer-hooks.mjs +1 -1
- package/dist/deploy/sniffer-loader.cjs +2 -2
- package/dist/deploy/sniffer-loader.mjs +1 -1
- package/dist/deploy/sniffer-routes-worker.cjs +2 -2
- package/dist/deploy/sniffer-routes-worker.mjs +1 -1
- package/dist/deploy-BgOujGGL.mjs +3836 -0
- package/dist/deploy-BgOujGGL.mjs.map +1 -0
- package/dist/deploy-ciuNiVqo.cjs +3892 -0
- package/dist/deploy-ciuNiVqo.cjs.map +1 -0
- package/dist/discover-CRywE7yc.cjs +1085 -0
- package/dist/discover-CRywE7yc.cjs.map +1 -0
- package/dist/discover-DbDrCQ8h.mjs +940 -0
- package/dist/discover-DbDrCQ8h.mjs.map +1 -0
- package/dist/docker-74kvq2jQ.cjs +1514 -0
- package/dist/docker-74kvq2jQ.cjs.map +1 -0
- package/dist/docker-CXYz3W2U.mjs +1407 -0
- package/dist/docker-CXYz3W2U.mjs.map +1 -0
- package/dist/dokploy-CrxDMut1.cjs +38 -0
- package/dist/dokploy-CrxDMut1.cjs.map +1 -0
- package/dist/dokploy-tNy6ZU64.mjs +38 -0
- package/dist/dokploy-tNy6ZU64.mjs.map +1 -0
- package/dist/drivers-aM87NQJi.cjs +224 -0
- package/dist/drivers-aM87NQJi.cjs.map +1 -0
- package/dist/drivers-uxLBq3e3.mjs +195 -0
- package/dist/drivers-uxLBq3e3.mjs.map +1 -0
- package/dist/eas-B3yv_XVz.mjs +334 -0
- package/dist/eas-B3yv_XVz.mjs.map +1 -0
- package/dist/eas-CiORdzk0.cjs +337 -0
- package/dist/eas-CiORdzk0.cjs.map +1 -0
- package/dist/emit-Bj6XSivk.mjs +136 -0
- package/dist/emit-Bj6XSivk.mjs.map +1 -0
- package/dist/emit-CDC__ubE.cjs +147 -0
- package/dist/emit-CDC__ubE.cjs.map +1 -0
- package/dist/encryption-Birkm2_E.mjs +89 -0
- package/dist/encryption-Birkm2_E.mjs.map +1 -0
- package/dist/encryption-drgYmkGP.cjs +90 -0
- package/dist/encryption-drgYmkGP.cjs.map +1 -0
- package/dist/engine-CW78Wt8x.mjs +3217 -0
- package/dist/engine-CW78Wt8x.mjs.map +1 -0
- package/dist/engine-CfLaQ0bJ.cjs +3330 -0
- package/dist/engine-CfLaQ0bJ.cjs.map +1 -0
- package/dist/errors-D8Gwp5kU.mjs +23 -0
- package/dist/errors-D8Gwp5kU.mjs.map +1 -0
- package/dist/errors-DMC4Umsb.cjs +34 -0
- package/dist/errors-DMC4Umsb.cjs.map +1 -0
- package/dist/github-BfLlBWB5.cjs +901 -0
- package/dist/github-BfLlBWB5.cjs.map +1 -0
- package/dist/github-DphkHybE.mjs +900 -0
- package/dist/github-DphkHybE.mjs.map +1 -0
- package/dist/googlePlay-BWDhYvH_.cjs +931 -0
- package/dist/googlePlay-BWDhYvH_.cjs.map +1 -0
- package/dist/googlePlay-CjzqTF8t.mjs +931 -0
- package/dist/googlePlay-CjzqTF8t.mjs.map +1 -0
- package/dist/{index-D-iAVHx-.d.cts → index-B35vTdAW.d.cts} +39 -15
- package/dist/index-B35vTdAW.d.cts.map +1 -0
- package/dist/{index-Cd-qeOam.d.mts → index-Dv1Zj86i.d.mts} +39 -15
- package/dist/index-Dv1Zj86i.d.mts.map +1 -0
- package/dist/index.cjs +13594 -12347
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +13541 -12292
- package/dist/index.mjs.map +1 -1
- package/dist/local-Bt9jPziD.cjs +241 -0
- package/dist/local-Bt9jPziD.cjs.map +1 -0
- package/dist/local-DBtepRK5.mjs +224 -0
- package/dist/local-DBtepRK5.mjs.map +1 -0
- package/dist/migrate-2YESt4v9.mjs +267 -0
- package/dist/migrate-2YESt4v9.mjs.map +1 -0
- package/dist/migrate-B-_cASJt.cjs +272 -0
- package/dist/migrate-B-_cASJt.cjs.map +1 -0
- package/dist/migrate-BUhe0BuA.cjs +181 -0
- package/dist/migrate-BUhe0BuA.cjs.map +1 -0
- package/dist/migrate-Dp_Y2XGi.mjs +181 -0
- package/dist/migrate-Dp_Y2XGi.mjs.map +1 -0
- package/dist/notes-DHN4qThL.mjs +399 -0
- package/dist/notes-DHN4qThL.mjs.map +1 -0
- package/dist/notes-DUq6Bx1I.cjs +500 -0
- package/dist/notes-DUq6Bx1I.cjs.map +1 -0
- package/dist/openapi.cjs +213 -7
- package/dist/openapi.cjs.map +1 -0
- package/dist/openapi.d.cts +32 -8
- package/dist/openapi.d.cts.map +1 -1
- package/dist/openapi.d.mts +32 -8
- package/dist/openapi.d.mts.map +1 -1
- package/dist/openapi.mjs +208 -2
- package/dist/openapi.mjs.map +1 -0
- package/dist/projectBucket-CxsutB3D.cjs +263 -0
- package/dist/projectBucket-CxsutB3D.cjs.map +1 -0
- package/dist/projectBucket-DzLZlleB.mjs +222 -0
- package/dist/projectBucket-DzLZlleB.mjs.map +1 -0
- package/dist/provider-BqpjG9QM.cjs +57 -0
- package/dist/provider-BqpjG9QM.cjs.map +1 -0
- package/dist/provider-CEOKk8NS.mjs +46 -0
- package/dist/provider-CEOKk8NS.mjs.map +1 -0
- package/dist/publish-BVal0GFd.mjs +123 -0
- package/dist/publish-BVal0GFd.mjs.map +1 -0
- package/dist/publish-DmTJhVe8.cjs +124 -0
- package/dist/publish-DmTJhVe8.cjs.map +1 -0
- package/dist/ready-BNh3zsSn.cjs +404 -0
- package/dist/ready-BNh3zsSn.cjs.map +1 -0
- package/dist/ready-g25dcGzK.mjs +375 -0
- package/dist/ready-g25dcGzK.mjs.map +1 -0
- package/dist/reconcile/public.cjs +3 -5
- package/dist/reconcile/public.d.cts +31 -89
- package/dist/reconcile/public.d.cts.map +1 -1
- package/dist/reconcile/public.d.mts +31 -89
- package/dist/reconcile/public.d.mts.map +1 -1
- package/dist/reconcile/public.mjs +3 -3
- package/dist/{reconcile-DhQ00DpU.mjs → reconcile--I7V4Klj.mjs} +2 -2
- package/dist/{reconcile-DhQ00DpU.mjs.map → reconcile--I7V4Klj.mjs.map} +1 -1
- package/dist/{reconcile-Dd2iyILf.cjs → reconcile-CuCQBa5-.cjs} +3 -3
- package/dist/{reconcile-Dd2iyILf.cjs.map → reconcile-CuCQBa5-.cjs.map} +1 -1
- package/dist/resolve-BwTJI8K7.cjs +316 -0
- package/dist/resolve-BwTJI8K7.cjs.map +1 -0
- package/dist/resolve-UBq26cZc.mjs +263 -0
- package/dist/resolve-UBq26cZc.mjs.map +1 -0
- package/dist/rollback-BFKex9TO.cjs +165 -0
- package/dist/rollback-BFKex9TO.cjs.map +1 -0
- package/dist/rollback-DiOcLTRc.mjs +136 -0
- package/dist/rollback-DiOcLTRc.mjs.map +1 -0
- package/dist/runtime-CFvcLEJW.d.cts +82 -0
- package/dist/runtime-CFvcLEJW.d.cts.map +1 -0
- package/dist/runtime-dwsH6ddo.d.mts +82 -0
- package/dist/runtime-dwsH6ddo.d.mts.map +1 -0
- package/dist/s3-BgG_xW-D.cjs +215 -0
- package/dist/s3-BgG_xW-D.cjs.map +1 -0
- package/dist/s3-CkrerKdA.mjs +215 -0
- package/dist/s3-CkrerKdA.mjs.map +1 -0
- package/dist/sandbox/config-worker.cjs +43 -0
- package/dist/sandbox/config-worker.cjs.map +1 -0
- package/dist/sandbox/config-worker.d.cts +1 -0
- package/dist/sandbox/config-worker.d.mts +1 -0
- package/dist/sandbox/config-worker.mjs +44 -0
- package/dist/sandbox/config-worker.mjs.map +1 -0
- package/dist/sandbox/credentials-worker.cjs +53 -0
- package/dist/sandbox/credentials-worker.cjs.map +1 -0
- package/dist/sandbox/credentials-worker.d.cts +1 -0
- package/dist/sandbox/credentials-worker.d.mts +1 -0
- package/dist/sandbox/credentials-worker.mjs +54 -0
- package/dist/sandbox/credentials-worker.mjs.map +1 -0
- package/dist/sandbox/discover-worker.cjs +47 -0
- package/dist/sandbox/discover-worker.cjs.map +1 -0
- package/dist/sandbox/discover-worker.d.cts +1 -0
- package/dist/sandbox/discover-worker.d.mts +1 -0
- package/dist/sandbox/discover-worker.mjs +48 -0
- package/dist/sandbox/discover-worker.mjs.map +1 -0
- package/dist/sandbox/migrate-worker.cjs +75 -0
- package/dist/sandbox/migrate-worker.cjs.map +1 -0
- package/dist/sandbox/migrate-worker.d.cts +1 -0
- package/dist/sandbox/migrate-worker.d.mts +1 -0
- package/dist/sandbox/migrate-worker.mjs +76 -0
- package/dist/sandbox/migrate-worker.mjs.map +1 -0
- package/dist/{workspace-mFpI_ky_.cjs → schemas-BCwKKA42.mjs} +399 -1162
- package/dist/schemas-BCwKKA42.mjs.map +1 -0
- package/dist/{workspace-CgwmXEtc.mjs → schemas-BQ_v0lEX.cjs} +487 -971
- package/dist/schemas-BQ_v0lEX.cjs.map +1 -0
- package/dist/secretsManager-CQORubp9.mjs +97 -0
- package/dist/secretsManager-CQORubp9.mjs.map +1 -0
- package/dist/secretsManager-RAGcEDX1.cjs +108 -0
- package/dist/secretsManager-RAGcEDX1.cjs.map +1 -0
- package/dist/seeds-B3xvUAQf.cjs +363 -0
- package/dist/seeds-B3xvUAQf.cjs.map +1 -0
- package/dist/seeds-BCC8vAXR.mjs +298 -0
- package/dist/seeds-BCC8vAXR.mjs.map +1 -0
- package/dist/serverSetup-CUBu8_Mk.cjs +652 -0
- package/dist/serverSetup-CUBu8_Mk.cjs.map +1 -0
- package/dist/serverSetup-eh9MUdSN.mjs +652 -0
- package/dist/serverSetup-eh9MUdSN.mjs.map +1 -0
- package/dist/sniffer-CNTnUmhc.mjs +1824 -0
- package/dist/sniffer-CNTnUmhc.mjs.map +1 -0
- package/dist/sniffer-CaoQH_kk.cjs +1997 -0
- package/dist/sniffer-CaoQH_kk.cjs.map +1 -0
- package/dist/snsSubscriptions-DiqwM9Ms.cjs +1173 -0
- package/dist/snsSubscriptions-DiqwM9Ms.cjs.map +1 -0
- package/dist/snsSubscriptions-zOIIswN0.mjs +1048 -0
- package/dist/snsSubscriptions-zOIIswN0.mjs.map +1 -0
- package/dist/sst-D6Dvhr6H.mjs +462 -0
- package/dist/sst-D6Dvhr6H.mjs.map +1 -0
- package/dist/sst-DECRMgjv.cjs +485 -0
- package/dist/sst-DECRMgjv.cjs.map +1 -0
- package/dist/stack-BZG5HoVN.mjs +2206 -0
- package/dist/stack-BZG5HoVN.mjs.map +1 -0
- package/dist/stack-CLk9WojF.cjs +2381 -0
- package/dist/stack-CLk9WojF.cjs.map +1 -0
- package/dist/stage-Cl0DPJ7w.cjs +313 -0
- package/dist/stage-Cl0DPJ7w.cjs.map +1 -0
- package/dist/stage-DiLPb89O.mjs +302 -0
- package/dist/stage-DiLPb89O.mjs.map +1 -0
- package/dist/stages-Bs1THSy7.cjs +190 -0
- package/dist/stages-Bs1THSy7.cjs.map +1 -0
- package/dist/stages-_xCG4Ymu.mjs +190 -0
- package/dist/stages-_xCG4Ymu.mjs.map +1 -0
- package/dist/target/public.cjs +15 -0
- package/dist/target/public.d.cts +28 -0
- package/dist/target/public.d.cts.map +1 -0
- package/dist/target/public.d.mts +28 -0
- package/dist/target/public.d.mts.map +1 -0
- package/dist/target/public.mjs +4 -0
- package/dist/terminal-XQE106CG.cjs +85 -0
- package/dist/terminal-XQE106CG.cjs.map +1 -0
- package/dist/terminal-jGj9TtMQ.mjs +85 -0
- package/dist/terminal-jGj9TtMQ.mjs.map +1 -0
- package/dist/types-Bl_CwZC9.cjs +90 -0
- package/dist/types-Bl_CwZC9.cjs.map +1 -0
- package/dist/{types-BGo5TaNE.d.mts → types-Dk--xVOT.d.cts} +2234 -439
- package/dist/types-Dk--xVOT.d.cts.map +1 -0
- package/dist/{types-C5ZNpUad.d.cts → types-DwQYpd_0.d.mts} +2232 -439
- package/dist/types-DwQYpd_0.d.mts.map +1 -0
- package/dist/types-Y1NfWlyG.mjs +61 -0
- package/dist/types-Y1NfWlyG.mjs.map +1 -0
- package/dist/utils-D2Nk1Nv2.cjs +205 -0
- package/dist/utils-D2Nk1Nv2.cjs.map +1 -0
- package/dist/utils-D_fxUqvU.mjs +156 -0
- package/dist/utils-D_fxUqvU.mjs.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/workerRuntime-BXfhbe13.cjs +108 -0
- package/dist/workerRuntime-BXfhbe13.cjs.map +1 -0
- package/dist/workerRuntime-CsOyBRx2.mjs +79 -0
- package/dist/workerRuntime-CsOyBRx2.mjs.map +1 -0
- package/dist/workspace/index.cjs +6 -2
- package/dist/workspace/index.d.cts +3 -3
- package/dist/workspace/index.d.mts +3 -3
- package/dist/workspace/index.mjs +2 -2
- package/dist/workspace-1szcahj9.cjs +2916 -0
- package/dist/workspace-1szcahj9.cjs.map +1 -0
- package/dist/workspace-DFGsrjGD.mjs +2480 -0
- package/dist/workspace-DFGsrjGD.mjs.map +1 -0
- package/package.json +66 -14
- package/dist/HostingerProvider-BY26bWwB.mjs.map +0 -1
- package/dist/HostingerProvider-BZFGYYVA.cjs.map +0 -1
- package/dist/LocalStateProvider-7HR6SS2t.cjs +0 -48
- package/dist/LocalStateProvider-7HR6SS2t.cjs.map +0 -1
- package/dist/LocalStateProvider-D7QyJoLM.mjs +0 -48
- package/dist/LocalStateProvider-D7QyJoLM.mjs.map +0 -1
- package/dist/Route53Provider-Cvj40A8I.mjs.map +0 -1
- package/dist/Route53Provider-DVILBsvV.cjs.map +0 -1
- package/dist/SSMStateProvider-B0Hu1MKZ.mjs +0 -75
- package/dist/SSMStateProvider-B0Hu1MKZ.mjs.map +0 -1
- package/dist/SSMStateProvider-VrQ-yeqd.cjs +0 -74
- package/dist/SSMStateProvider-VrQ-yeqd.cjs.map +0 -1
- package/dist/backup-provisioner-BmhIO_Yr.cjs.map +0 -1
- package/dist/backup-provisioner-DIVCbfee.mjs.map +0 -1
- package/dist/bundler-BeNDZdHQ.cjs.map +0 -1
- package/dist/bundler-BodTL4kf.mjs.map +0 -1
- package/dist/config-Q1rvKHvw.cjs +0 -467
- package/dist/config-Q1rvKHvw.cjs.map +0 -1
- package/dist/config-pqGD3hF9.mjs +0 -414
- package/dist/config-pqGD3hF9.mjs.map +0 -1
- package/dist/config.d.cts.map +0 -1
- package/dist/config.d.mts.map +0 -1
- package/dist/credentials-BekkKtY_.mjs +0 -2780
- package/dist/credentials-BekkKtY_.mjs.map +0 -1
- package/dist/credentials-Q6F0uqJq.cjs +0 -2917
- package/dist/credentials-Q6F0uqJq.cjs.map +0 -1
- package/dist/discover-BERGFg8v.cjs +0 -288
- package/dist/discover-BERGFg8v.cjs.map +0 -1
- package/dist/discover-CK-n3w6b.mjs +0 -244
- package/dist/discover-CK-n3w6b.mjs.map +0 -1
- package/dist/emit-BdoPFjZf.cjs +0 -253
- package/dist/emit-BdoPFjZf.cjs.map +0 -1
- package/dist/emit-Bzq7JsMP.mjs +0 -224
- package/dist/emit-Bzq7JsMP.mjs.map +0 -1
- package/dist/fullstack-secrets-BET8gqwK.mjs +0 -81
- package/dist/fullstack-secrets-BET8gqwK.mjs.map +0 -1
- package/dist/fullstack-secrets-DXsWO-5m.cjs +0 -92
- package/dist/fullstack-secrets-DXsWO-5m.cjs.map +0 -1
- package/dist/generator-LfZU7NlU.mjs +0 -247
- package/dist/generator-LfZU7NlU.mjs.map +0 -1
- package/dist/generator-Wdfp0jCS.cjs +0 -282
- package/dist/generator-Wdfp0jCS.cjs.map +0 -1
- package/dist/github-BfflNPVe.cjs +0 -203
- package/dist/github-BfflNPVe.cjs.map +0 -1
- package/dist/github-CRwnxKmD.mjs +0 -203
- package/dist/github-CRwnxKmD.mjs.map +0 -1
- package/dist/index-Cd-qeOam.d.mts.map +0 -1
- package/dist/index-D-iAVHx-.d.cts.map +0 -1
- package/dist/keystore-B4PRlbgE.mjs +0 -81
- package/dist/keystore-B4PRlbgE.mjs.map +0 -1
- package/dist/keystore-DgGRj2Yy.cjs +0 -98
- package/dist/keystore-DgGRj2Yy.cjs.map +0 -1
- package/dist/openapi-Dcbme-Us.cjs +0 -2038
- package/dist/openapi-Dcbme-Us.cjs.map +0 -1
- package/dist/openapi-vy4JzhUv.mjs +0 -1991
- package/dist/openapi-vy4JzhUv.mjs.map +0 -1
- package/dist/storage-C-30BD1e.cjs +0 -272
- package/dist/storage-C-30BD1e.cjs.map +0 -1
- package/dist/storage-P_b3w7uj.mjs +0 -231
- package/dist/storage-P_b3w7uj.mjs.map +0 -1
- package/dist/sync-B3xxXtJT.mjs +0 -88
- package/dist/sync-B3xxXtJT.mjs.map +0 -1
- package/dist/sync-D7uTIIEi.cjs +0 -111
- package/dist/sync-D7uTIIEi.cjs.map +0 -1
- package/dist/types-BGo5TaNE.d.mts.map +0 -1
- package/dist/types-C5ZNpUad.d.cts.map +0 -1
- package/dist/workspace-CgwmXEtc.mjs.map +0 -1
- package/dist/workspace-mFpI_ky_.cjs.map +0 -1
|
@@ -0,0 +1,1407 @@
|
|
|
1
|
+
import { t as GkmError } from "./errors-D8Gwp5kU.mjs";
|
|
2
|
+
import { ot as run } from "./credentials-DRfP9aG7.mjs";
|
|
3
|
+
import { D as ORIGIN_VERIFY_HEADER, F as imageLayout, G as generateNodeWebDockerfile, H as generateDockerignore, I as PROCESSOR_PORT, J as generateWorkerDockerfile, K as generateProcessorDockerfile, M as appImageOptions, O as PROCESSOR_ORIGIN_SECRET_ENV, Pt as siteClientTelemetry, R as WORKER_PORT, U as generateEntryDockerfile, V as generateBackendDockerfile, Vt as PROCESSORS_DEV_PREFIX, W as generateNextjsDockerfile, X as resolveDockerConfig, at as processorUnitName, g as COMPOSE_PATH, i as dockerfileOf, m as reconcileWorkspace, ot as processorUnits, q as generateViteStaticDockerfile, st as workerUnits } from "./apps-BOgA6AcI.mjs";
|
|
4
|
+
import { rt as getPublicUrlArgNames } from "./compose-B3OOowfE.mjs";
|
|
5
|
+
import { t as SubscriberGenerator } from "./SubscriberGenerator-CzPrixYu.mjs";
|
|
6
|
+
import { g as appKey, p as loadWorkspaceConfig } from "./config-BLrAd7Of.mjs";
|
|
7
|
+
import { a as startTelemetryCode, n as runtimeFor, s as writeTelemetryModule } from "./EndpointGenerator-CusLH-9S.mjs";
|
|
8
|
+
import { v as ConstructGenerator, y as output } from "./discover-DbDrCQ8h.mjs";
|
|
9
|
+
import { dirname, join, relative } from "node:path";
|
|
10
|
+
import { existsSync } from "node:fs";
|
|
11
|
+
import { appendFile, mkdir, readFile, writeFile } from "node:fs/promises";
|
|
12
|
+
import { provideKey, publicEnvFor } from "@geekmidas/manifest";
|
|
13
|
+
import { Cron } from "@geekmidas/constructs/crons";
|
|
14
|
+
import { Processor } from "@geekmidas/constructs/processors";
|
|
15
|
+
import { Queue } from "@geekmidas/constructs/queue";
|
|
16
|
+
//#region src/docker/imageRef.ts
|
|
17
|
+
/**
|
|
18
|
+
* An image reference, checked before it reaches `docker`.
|
|
19
|
+
*
|
|
20
|
+
* The parts come from the workspace — a registry in `gkm.config.ts`, an image
|
|
21
|
+
* name from the project, a tag from `--tag` — and an argument array already
|
|
22
|
+
* keeps them out of a shell. What it cannot do is stop `docker` reading a value
|
|
23
|
+
* that starts with `-` as one of its own flags, so a ref is held to Docker's
|
|
24
|
+
* own grammar (distribution/reference) and anything else is refused by name
|
|
25
|
+
* before a build starts.
|
|
26
|
+
*/
|
|
27
|
+
const DOMAIN_COMPONENT = "(?:[a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9])";
|
|
28
|
+
const DOMAIN = `${DOMAIN_COMPONENT}(?:\\.${DOMAIN_COMPONENT})*(?::[0-9]+)?`;
|
|
29
|
+
const PATH_COMPONENT = "[a-z0-9]+(?:(?:[._]|__|-+)[a-z0-9]+)*";
|
|
30
|
+
const REFERENCE = new RegExp(`^(?:${DOMAIN}/)?${PATH_COMPONENT}(?:/${PATH_COMPONENT})*(?::[\\w][\\w.-]{0,127})?(?:@[A-Za-z][A-Za-z0-9]*(?:[-_+.][A-Za-z][A-Za-z0-9]*)*:[0-9a-fA-F]{32,})?$`);
|
|
31
|
+
/** Docker refuses a repository name longer than this. */
|
|
32
|
+
const MAX_NAME_LENGTH = 255;
|
|
33
|
+
/** A value that is not an image reference was about to be built or pushed. */
|
|
34
|
+
var ImageRefInvalid = class extends GkmError {
|
|
35
|
+
ref;
|
|
36
|
+
constructor(ref) {
|
|
37
|
+
super(`'${ref}' is not a valid image reference. An image is \`[registry/]name[:tag]\`: the name lowercase letters, digits and . _ - separators, the tag up to 128 of letters, digits, _ . and -, not starting with . or -. Check docker.registry in gkm.config.ts and the --tag passed.`);
|
|
38
|
+
this.ref = ref;
|
|
39
|
+
this.name = "ImageRefInvalid";
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
/** Throw {@link ImageRefInvalid} unless `ref` is a Docker image reference. */
|
|
43
|
+
function validateImageRef(ref) {
|
|
44
|
+
const name = ref.split("@")[0].replace(/:[\w][\w.-]*$/, "");
|
|
45
|
+
if (!REFERENCE.test(ref) || name.length > MAX_NAME_LENGTH) throw new ImageRefInvalid(ref);
|
|
46
|
+
return ref;
|
|
47
|
+
}
|
|
48
|
+
//#endregion
|
|
49
|
+
//#region src/generators/ProcessorGenerator.ts
|
|
50
|
+
/** Where a file server's processor entry lives, under an app's `.gkm/server`. */
|
|
51
|
+
function processorEntryDir(serverDir, fileServerId) {
|
|
52
|
+
return join(serverDir, "processors", processorUnitName(fileServerId));
|
|
53
|
+
}
|
|
54
|
+
/** The file its bundle is written to, beside the server's. */
|
|
55
|
+
function processorBundleName(fileServerId) {
|
|
56
|
+
return `${processorUnitName(fileServerId)}.mjs`;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* A file server's processors, as the build generates them.
|
|
60
|
+
*
|
|
61
|
+
* On AWS each is a Lambda behind a function URL — the CDN's origin for its
|
|
62
|
+
* pattern. On a server they are one process per file server, the processor
|
|
63
|
+
* unit (see {@link ProcessorGenerator.buildEntry}), so the `server` target
|
|
64
|
+
* generates nothing per processor here.
|
|
65
|
+
*/
|
|
66
|
+
var ProcessorGenerator = class extends ConstructGenerator {
|
|
67
|
+
isConstruct(value) {
|
|
68
|
+
return Processor.isProcessor(value);
|
|
69
|
+
}
|
|
70
|
+
async build(context, constructs, outputDir, options) {
|
|
71
|
+
if ((options?.target ?? "aws") !== "aws" || constructs.length === 0) return [];
|
|
72
|
+
const dir = join(outputDir, "processors");
|
|
73
|
+
await mkdir(dir, { recursive: true });
|
|
74
|
+
const infos = [];
|
|
75
|
+
for (const { key, construct, path } of constructs) {
|
|
76
|
+
const file = join(dir, `${key}.ts`);
|
|
77
|
+
const importPath = relative(dirname(file), path.relative).replace(/\.ts$/, ".js");
|
|
78
|
+
await writeFile(file, `import { AWSLambdaProcessor } from '@geekmidas/constructs/processors';
|
|
79
|
+
import { ${key} } from '${importPath}';
|
|
80
|
+
${context.storageDrivers?.imports ?? ""}
|
|
81
|
+
${context.storageDrivers?.setup ? `\n// The handler registers the drivers its target needs.\n${context.storageDrivers.setup}\n` : ""}
|
|
82
|
+
const adapter = new AWSLambdaProcessor(${key});
|
|
83
|
+
|
|
84
|
+
export const handler = adapter.handler;
|
|
85
|
+
`);
|
|
86
|
+
infos.push(await processorInfo(key, construct, relative(options?.root ?? process.cwd(), file).replace(/\.ts$/, ".handler"), context));
|
|
87
|
+
}
|
|
88
|
+
return infos;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* `gkm dev`'s half: `processors.ts` beside the dev server's app, mounting
|
|
92
|
+
* each file server's processors under `/__gkm/processors/<FileServer>`.
|
|
93
|
+
* The local edge sends each pattern on the file server's host there, so
|
|
94
|
+
* `processedUrl()` answers locally as it does deployed.
|
|
95
|
+
*
|
|
96
|
+
* In the dev server's own process rather than a unit of its own: locally
|
|
97
|
+
* there is no CPU to protect, and the dev server already reloads on change.
|
|
98
|
+
*/
|
|
99
|
+
async buildDev(outputDir, processors) {
|
|
100
|
+
await mkdir(outputDir, { recursive: true });
|
|
101
|
+
const file = join(outputDir, "processors.ts");
|
|
102
|
+
const imports = processors.map(({ key, path }) => {
|
|
103
|
+
const specifier = relative(outputDir, path.absolute).replace(/\.ts$/, ".js");
|
|
104
|
+
return `import { ${key} } from '${specifier.startsWith(".") ? specifier : `./${specifier}`}';`;
|
|
105
|
+
}).join("\n");
|
|
106
|
+
const byServer = /* @__PURE__ */ new Map();
|
|
107
|
+
for (const { key, construct } of processors) byServer.set(construct.surfaceId, [...byServer.get(construct.surfaceId) ?? [], key]);
|
|
108
|
+
const units = [...byServer.entries()].map(([id, keys]) => ` ${JSON.stringify(id)}: [${keys.join(", ")}],`).join("\n");
|
|
109
|
+
await writeFile(file, `/**
|
|
110
|
+
* Generated processors setup for \`gkm dev\`.
|
|
111
|
+
*
|
|
112
|
+
* Each file server's processors, under ${PROCESSORS_DEV_PREFIX}<FileServer>: the
|
|
113
|
+
* local edge rewrites each processor pattern on the file server's host here.
|
|
114
|
+
*/
|
|
115
|
+
import type { EnvironmentParser } from '@geekmidas/envkit';
|
|
116
|
+
import { processorServer } from '@geekmidas/constructs/processors';
|
|
117
|
+
${imports}
|
|
118
|
+
|
|
119
|
+
export function setupProcessors(
|
|
120
|
+
app: { all: (path: string, handler: (c: any) => unknown) => unknown },
|
|
121
|
+
envParser: EnvironmentParser<any>,
|
|
122
|
+
): void {
|
|
123
|
+
const units: Record<string, ReturnType<typeof processorServer>> = Object.fromEntries(
|
|
124
|
+
Object.entries({
|
|
125
|
+
${units}
|
|
126
|
+
}).map(([id, processors]) => [id, processorServer(processors, envParser)]),
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
app.all('${PROCESSORS_DEV_PREFIX}:server/*', async (c: any) => {
|
|
130
|
+
const server = c.req.param('server') as string;
|
|
131
|
+
const serve = units[server];
|
|
132
|
+
if (!serve) return c.notFound();
|
|
133
|
+
const path = c.req.path.slice(\`${PROCESSORS_DEV_PREFIX}\${server}\`.length) || '/';
|
|
134
|
+
const response = await serve({ method: c.req.method, path });
|
|
135
|
+
if (!response) {
|
|
136
|
+
return new Response(null, {
|
|
137
|
+
status: 404,
|
|
138
|
+
headers: { 'cache-control': 'public, max-age=60' },
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
return new Response(c.req.method === 'HEAD' ? null : response.body, {
|
|
142
|
+
status: response.status,
|
|
143
|
+
headers: response.headers,
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
`);
|
|
148
|
+
return file;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* A file server's processor unit: one process answering each of its
|
|
152
|
+
* processors' patterns, and `/health`. Returns its entry, `processors.ts`.
|
|
153
|
+
*
|
|
154
|
+
* Its own process because making a derivative is CPU-bound — a resize
|
|
155
|
+
* spike in the API's process would be every request's latency.
|
|
156
|
+
*/
|
|
157
|
+
async buildEntry(input) {
|
|
158
|
+
const { context, outputDir, processors } = input;
|
|
159
|
+
await mkdir(outputDir, { recursive: true });
|
|
160
|
+
await writeTelemetryModule(outputDir, input.telemetry);
|
|
161
|
+
const healthCheck = context.production?.healthCheck ?? "/health";
|
|
162
|
+
const imports = processors.map(({ key, path }) => {
|
|
163
|
+
const specifier = relative(outputDir, path.absolute).replace(/\.ts$/, ".js");
|
|
164
|
+
return `import { ${key} } from '${specifier.startsWith(".") ? specifier : `./${specifier}`}';`;
|
|
165
|
+
}).join("\n");
|
|
166
|
+
const entry = join(outputDir, "processors.ts");
|
|
167
|
+
await writeFile(entry, `#!/usr/bin/env node
|
|
168
|
+
/**
|
|
169
|
+
* Production entry for ${input.fileServerId}'s processors.
|
|
170
|
+
* Generated by 'gkm build --production'.
|
|
171
|
+
*
|
|
172
|
+
* Answers each processor's pattern, and ${healthCheck} on PORT. The edge
|
|
173
|
+
* routes only those patterns here; everything else on the file server's
|
|
174
|
+
* domain is the bucket.
|
|
175
|
+
*/
|
|
176
|
+
import { timingSafeEqual } from 'node:crypto';
|
|
177
|
+
import { createServer } from 'node:http';
|
|
178
|
+
import { runShutdownHooks } from '@geekmidas/constructs';
|
|
179
|
+
import { processorServer } from '@geekmidas/constructs/processors';
|
|
180
|
+
${context.storageDrivers?.imports ?? ""}
|
|
181
|
+
${imports}
|
|
182
|
+
|
|
183
|
+
${startTelemetryCode([healthCheck])}
|
|
184
|
+
${context.storageDrivers?.setup ? `// The entry point registers the drivers its target needs.\n${context.storageDrivers.setup}\n` : ""}
|
|
185
|
+
process.env.GKM_APP_NAME ??= ${JSON.stringify(processorUnitName(input.fileServerId))};
|
|
186
|
+
|
|
187
|
+
const processors = [${processors.map(({ key }) => key).join(", ")}];
|
|
188
|
+
const serve = processorServer(processors);
|
|
189
|
+
const port = Number(process.env.PORT) || 3000;
|
|
190
|
+
let stopping = false;
|
|
191
|
+
|
|
192
|
+
${input.telemetry ? REQUEST_SPANS : NO_REQUEST_SPANS}
|
|
193
|
+
// Where the CDN fronts this unit, the secret it adds to every request: one
|
|
194
|
+
// without it is refused here, whatever the edge in front did or could not.
|
|
195
|
+
const originSecret = process.env.${PROCESSOR_ORIGIN_SECRET_ENV}
|
|
196
|
+
? Buffer.from(process.env.${PROCESSOR_ORIGIN_SECRET_ENV})
|
|
197
|
+
: undefined;
|
|
198
|
+
const fromOrigin = (header: string | string[] | undefined) => {
|
|
199
|
+
if (!originSecret) return true;
|
|
200
|
+
const given = Buffer.from(typeof header === 'string' ? header : '');
|
|
201
|
+
return given.length === originSecret.length && timingSafeEqual(given, originSecret);
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
const server = createServer(async (req, res) => {
|
|
205
|
+
const method = req.method ?? 'GET';
|
|
206
|
+
const path = (req.url ?? '/').split('?')[0] ?? '/';
|
|
207
|
+
if (path === ${JSON.stringify(healthCheck)}) {
|
|
208
|
+
res.writeHead(stopping ? 503 : 200, { 'content-type': 'application/json' });
|
|
209
|
+
res.end(JSON.stringify({ status: stopping ? 'stopping' : 'ok' }));
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
if (!fromOrigin(req.headers[${JSON.stringify(ORIGIN_VERIFY_HEADER.toLowerCase())}])) {
|
|
213
|
+
res.writeHead(403, { 'cache-control': 'no-store' }).end();
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
await traced(method, path, async () => {
|
|
217
|
+
try {
|
|
218
|
+
const response = await serve({ method, path });
|
|
219
|
+
if (!response) {
|
|
220
|
+
res.writeHead(404, { 'cache-control': 'public, max-age=60' }).end();
|
|
221
|
+
return 404;
|
|
222
|
+
}
|
|
223
|
+
res.writeHead(response.status, response.headers);
|
|
224
|
+
res.end(method === 'HEAD' ? undefined : response.body);
|
|
225
|
+
return response.status;
|
|
226
|
+
} catch (error) {
|
|
227
|
+
console.error(error);
|
|
228
|
+
res.writeHead(500, { 'cache-control': 'no-store' }).end();
|
|
229
|
+
return 500;
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
});
|
|
233
|
+
server.listen(port);
|
|
234
|
+
|
|
235
|
+
const shutdown = async () => {
|
|
236
|
+
if (stopping) return;
|
|
237
|
+
stopping = true;
|
|
238
|
+
setTimeout(() => process.exit(1), Number(process.env.GKM_SHUTDOWN_TIMEOUT_MS) || 8000).unref();
|
|
239
|
+
server.close();
|
|
240
|
+
await runShutdownHooks((error) => console.error(error));
|
|
241
|
+
process.exit(0);
|
|
242
|
+
};
|
|
243
|
+
process.on('SIGTERM', shutdown);
|
|
244
|
+
process.on('SIGINT', shutdown);
|
|
245
|
+
`);
|
|
246
|
+
return entry;
|
|
247
|
+
}
|
|
248
|
+
};
|
|
249
|
+
/**
|
|
250
|
+
* A SERVER span per request, once telemetry has started — opened by the unit
|
|
251
|
+
* rather than by hooking node:http, which sees nothing inside a bundle. Named
|
|
252
|
+
* after the processor's pattern, never the key, which has no bound.
|
|
253
|
+
*
|
|
254
|
+
* Only in an entry whose file server has a `Telemetry` node: the bundle
|
|
255
|
+
* follows the import, and an app without one need not install the API.
|
|
256
|
+
*/
|
|
257
|
+
const REQUEST_SPANS = `const tracing = requestSpans ? await import('@opentelemetry/api') : undefined;
|
|
258
|
+
const routeOf = (path: string) =>
|
|
259
|
+
processors.find((processor) => path.startsWith(processor.prefix))?.pattern;
|
|
260
|
+
|
|
261
|
+
async function traced(
|
|
262
|
+
method: string,
|
|
263
|
+
path: string,
|
|
264
|
+
run: () => Promise<number>,
|
|
265
|
+
): Promise<void> {
|
|
266
|
+
if (!tracing) {
|
|
267
|
+
await run();
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
const route = routeOf(path);
|
|
271
|
+
await tracing.trace.getTracer('@geekmidas/processors').startActiveSpan(
|
|
272
|
+
route ? \`\${method} \${route}\` : method,
|
|
273
|
+
{
|
|
274
|
+
kind: tracing.SpanKind.SERVER,
|
|
275
|
+
attributes: {
|
|
276
|
+
'http.request.method': method,
|
|
277
|
+
'url.path': path,
|
|
278
|
+
...(route ? { 'http.route': route } : {}),
|
|
279
|
+
},
|
|
280
|
+
},
|
|
281
|
+
async (span) => {
|
|
282
|
+
try {
|
|
283
|
+
const status = await run();
|
|
284
|
+
span.setAttribute('http.response.status_code', status);
|
|
285
|
+
if (status >= 500) span.setStatus({ code: tracing.SpanStatusCode.ERROR });
|
|
286
|
+
} finally {
|
|
287
|
+
span.end();
|
|
288
|
+
}
|
|
289
|
+
},
|
|
290
|
+
);
|
|
291
|
+
}
|
|
292
|
+
`;
|
|
293
|
+
/** The same shape without telemetry: each request just runs. */
|
|
294
|
+
const NO_REQUEST_SPANS = `async function traced(
|
|
295
|
+
_method: string,
|
|
296
|
+
_path: string,
|
|
297
|
+
run: () => Promise<number>,
|
|
298
|
+
): Promise<void> {
|
|
299
|
+
await run();
|
|
300
|
+
}
|
|
301
|
+
`;
|
|
302
|
+
/** What the manifest records of one processor. */
|
|
303
|
+
async function processorInfo(name, processor, handler, context) {
|
|
304
|
+
return {
|
|
305
|
+
name,
|
|
306
|
+
handler,
|
|
307
|
+
fileServer: processor.surfaceId,
|
|
308
|
+
path: processor.pattern,
|
|
309
|
+
prefix: processor.prefix,
|
|
310
|
+
...processor.native.length ? { native: [...processor.native] } : {},
|
|
311
|
+
...processor.timeout !== void 0 ? { timeout: processor.timeout } : {},
|
|
312
|
+
...processor.memorySize !== void 0 ? { memorySize: processor.memorySize } : {},
|
|
313
|
+
environment: await processor.getEnvironment({ markOptional: context.markOptional }),
|
|
314
|
+
dependencies: processor.constructs
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
//#endregion
|
|
318
|
+
//#region src/generators/CronGenerator.ts
|
|
319
|
+
var CronGenerator = class extends ConstructGenerator {
|
|
320
|
+
async build(context, constructs, outputDir, options) {
|
|
321
|
+
const target = options?.target ?? "aws";
|
|
322
|
+
const logger = console;
|
|
323
|
+
const cronInfos = [];
|
|
324
|
+
if (target === "server") {
|
|
325
|
+
await this.generateServerCronsFile(outputDir, constructs);
|
|
326
|
+
logger.log(`Generated server crons file with ${constructs.length} crons`);
|
|
327
|
+
return cronInfos;
|
|
328
|
+
}
|
|
329
|
+
if (constructs.length === 0) return cronInfos;
|
|
330
|
+
const cronsDir = join(outputDir, "crons");
|
|
331
|
+
await mkdir(cronsDir, { recursive: true });
|
|
332
|
+
for (const { key, construct, path } of constructs) {
|
|
333
|
+
const handlerFile = await this.generateCronHandler(cronsDir, path.relative, key, context, construct.owner);
|
|
334
|
+
cronInfos.push({
|
|
335
|
+
name: key,
|
|
336
|
+
handler: relative(options?.root ?? process.cwd(), handlerFile).replace(/\.ts$/, ".handler"),
|
|
337
|
+
schedule: construct.schedule || "rate(1 hour)",
|
|
338
|
+
timeout: construct.timeout,
|
|
339
|
+
memorySize: construct.memorySize,
|
|
340
|
+
environment: await construct.getEnvironment({ markOptional: context.markOptional }),
|
|
341
|
+
dependencies: construct.constructs
|
|
342
|
+
});
|
|
343
|
+
logger.log(`Generated cron handler: ${key}`);
|
|
344
|
+
}
|
|
345
|
+
return cronInfos;
|
|
346
|
+
}
|
|
347
|
+
isConstruct(value) {
|
|
348
|
+
return Cron.isCron(value);
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* The crons file a server entry imports.
|
|
352
|
+
*
|
|
353
|
+
* Shaped after `generateServerSubscribersFile`: one module, every cron, a
|
|
354
|
+
* `setupCrons` the generated entry calls beside `setupSubscribers`.
|
|
355
|
+
*
|
|
356
|
+
* It picks its scheduler from what the process can reach. With a Postgres it
|
|
357
|
+
* uses pg-boss, whose schedules live in the database — so a deployment
|
|
358
|
+
* running four replicas fires each job once, which is the thing a timer in
|
|
359
|
+
* every process gets wrong and does not report. With no database it falls
|
|
360
|
+
* back to timers and says plainly that it is doing so.
|
|
361
|
+
*/
|
|
362
|
+
async generateServerCronsFile(outputDir, crons) {
|
|
363
|
+
await mkdir(outputDir, { recursive: true });
|
|
364
|
+
const cronsPath = join(outputDir, "crons.ts");
|
|
365
|
+
if (crons.length === 0) {
|
|
366
|
+
await writeFile(cronsPath, `/**
|
|
367
|
+
* Generated cron setup — this app declares none.
|
|
368
|
+
*/
|
|
369
|
+
import type { EnvironmentParser } from '@geekmidas/envkit';
|
|
370
|
+
import type { Logger } from '@geekmidas/logger';
|
|
371
|
+
|
|
372
|
+
export async function setupCrons(
|
|
373
|
+
_envParser: EnvironmentParser<any>,
|
|
374
|
+
_logger: Logger,
|
|
375
|
+
): Promise<void> {}
|
|
376
|
+
|
|
377
|
+
export function cronsStatus(): { failed: string[]; connections: unknown[] } {
|
|
378
|
+
return { failed: [], connections: [] };
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
export async function stopCrons(): Promise<void> {}
|
|
382
|
+
`);
|
|
383
|
+
return cronsPath;
|
|
384
|
+
}
|
|
385
|
+
const importsByFile = /* @__PURE__ */ new Map();
|
|
386
|
+
for (const { path, key } of crons) {
|
|
387
|
+
const importPath = relative(dirname(cronsPath), path.relative).replace(/\.ts$/, ".js");
|
|
388
|
+
if (!importsByFile.has(importPath)) importsByFile.set(importPath, []);
|
|
389
|
+
importsByFile.get(importPath)?.push(key);
|
|
390
|
+
}
|
|
391
|
+
const content = `/**
|
|
392
|
+
* Generated cron setup.
|
|
393
|
+
*
|
|
394
|
+
* Schedules every cron this app declares, in the process that serves it.
|
|
395
|
+
*
|
|
396
|
+
* The schedule lives in Postgres, through pg-boss, in the database the worker
|
|
397
|
+
* named with \`.database(db)\`. That is what makes running several replicas
|
|
398
|
+
* safe: each job fires once, where a timer in every process fires it once per
|
|
399
|
+
* replica and reports nothing.
|
|
400
|
+
*
|
|
401
|
+
* No connection string appears here. The construct that owns the database is
|
|
402
|
+
* the only thing that knows its key, and it is resolved through service
|
|
403
|
+
* discovery like any other dependency.
|
|
404
|
+
*/
|
|
405
|
+
import type { EnvironmentParser } from '@geekmidas/envkit';
|
|
406
|
+
import type { Logger } from '@geekmidas/logger';
|
|
407
|
+
import { runCron, scheduleInProcess, toCronExpression } from '@geekmidas/constructs/crons';
|
|
408
|
+
import { ServiceDiscovery } from '@geekmidas/services';
|
|
409
|
+
${Array.from(importsByFile.entries()).map(([importPath, exports]) => `import { ${exports.join(", ")} } from '${importPath}';`).join("\n")}
|
|
410
|
+
|
|
411
|
+
const crons = [
|
|
412
|
+
${crons.map(({ key }) => ` { name: '${key}', cron: ${key} }`).join(",\n")}
|
|
413
|
+
];
|
|
414
|
+
|
|
415
|
+
type Stoppable = { stop: () => Promise<void> | void };
|
|
416
|
+
const running: Stoppable[] = [];
|
|
417
|
+
// What a worker's health check reads: the crons that cannot be scheduled, and
|
|
418
|
+
// the broker connection the schedule is kept through.
|
|
419
|
+
const failed: string[] = [];
|
|
420
|
+
const connections: import('@geekmidas/events').EventConnection[] = [];
|
|
421
|
+
|
|
422
|
+
export async function setupCrons(
|
|
423
|
+
envParser: EnvironmentParser<any>,
|
|
424
|
+
logger: Logger,
|
|
425
|
+
): Promise<void> {
|
|
426
|
+
if (crons.length === 0) {
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
const serviceDiscovery = ServiceDiscovery.getInstance(envParser);
|
|
431
|
+
|
|
432
|
+
// Resolved once per cron rather than per firing: registering services on
|
|
433
|
+
// every tick would reconnect a database every minute.
|
|
434
|
+
const prepared = [];
|
|
435
|
+
for (const { name, cron } of crons) {
|
|
436
|
+
try {
|
|
437
|
+
const schedule = toCronExpression(cron.schedule);
|
|
438
|
+
const services = cron.services.length > 0
|
|
439
|
+
? await serviceDiscovery.register(cron.services)
|
|
440
|
+
: {};
|
|
441
|
+
|
|
442
|
+
prepared.push({ name, cron, schedule, services });
|
|
443
|
+
} catch (error) {
|
|
444
|
+
// An unrepresentable schedule is a build-time mistake, and failing the
|
|
445
|
+
// process for it would take the HTTP server down with it.
|
|
446
|
+
logger.error({ err: error, cron: name }, 'Cron has no runnable schedule, skipping');
|
|
447
|
+
failed.push(name);
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
const run = async (entry: (typeof prepared)[number]) => {
|
|
452
|
+
try {
|
|
453
|
+
// The cron's own function, the way its Lambda would run it — services,
|
|
454
|
+
// the worker's database as \`db\`, its events. It used to call a
|
|
455
|
+
// \`handler\` a Cron does not have, so every firing logged a failure.
|
|
456
|
+
await runCron(entry.cron, serviceDiscovery, entry.name);
|
|
457
|
+
} catch (error) {
|
|
458
|
+
logger.error({ err: error, cron: entry.name }, 'Cron failed');
|
|
459
|
+
}
|
|
460
|
+
};
|
|
461
|
+
|
|
462
|
+
// The app's one pg-boss: the events broker's, as the broker's role, in the
|
|
463
|
+
// broker's schema. A server fires its own crons, and a process scheduling in
|
|
464
|
+
// memory fires each job once per replica — so the schedule lives in
|
|
465
|
+
// Postgres. It used to be a second pg-boss on the worker's database, as the
|
|
466
|
+
// runtime role, which can neither create a schema nor use the broker's.
|
|
467
|
+
const { url, devPid } = envParser
|
|
468
|
+
.create((get) => ({
|
|
469
|
+
url: get('EVENT_PUBLISHER_CONNECTION_STRING').string().optional(),
|
|
470
|
+
// Set by \`gkm dev\` on the server it starts, and by nothing deployed.
|
|
471
|
+
devPid: get('GKM_DEV_PID').string().optional(),
|
|
472
|
+
}))
|
|
473
|
+
.parse();
|
|
474
|
+
|
|
475
|
+
if (!url?.startsWith('pgboss://')) {
|
|
476
|
+
// \`gkm dev\` on a target whose crons are infrastructure once deployed —
|
|
477
|
+
// EventBridge rules on AWS — has no broker to keep a schedule in. It is one
|
|
478
|
+
// process, so a timer fires each job once, which is all pg-boss is for
|
|
479
|
+
// here. Only there: a deployed server firing by timer fires once per
|
|
480
|
+
// replica, so outside dev this stays the error below.
|
|
481
|
+
if (devPid) {
|
|
482
|
+
for (const entry of prepared) {
|
|
483
|
+
running.push(scheduleInProcess(entry.schedule, () => run(entry)));
|
|
484
|
+
logger.info({ cron: entry.name, schedule: entry.schedule }, 'Cron scheduled in this process');
|
|
485
|
+
}
|
|
486
|
+
return;
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
logger.error(
|
|
490
|
+
{ crons: prepared.map(({ name }) => name) },
|
|
491
|
+
'These crons have nowhere to keep their schedule. On a server they are ' +
|
|
492
|
+
'scheduled through the pg-boss events broker ' +
|
|
493
|
+
'(EVENT_PUBLISHER_CONNECTION_STRING), and ' +
|
|
494
|
+
(url ? 'the broker configured is not pg-boss.' : 'none is configured.'),
|
|
495
|
+
);
|
|
496
|
+
failed.push(...prepared.map(({ name }) => name));
|
|
497
|
+
return;
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
// Through the registered pg-boss driver, which the entry registers for a
|
|
501
|
+
// server whose broker is pg-boss. Naming \`@geekmidas/events/pgboss\` here
|
|
502
|
+
// made every bundle with a cron resolve pg-boss, whatever its broker.
|
|
503
|
+
const { EventConnectionFactory } = await import('@geekmidas/events');
|
|
504
|
+
const connection = (await EventConnectionFactory.fromConnectionString(
|
|
505
|
+
url,
|
|
506
|
+
)) as import('@geekmidas/events').EventConnection & { instance?: any };
|
|
507
|
+
const boss = connection.instance!;
|
|
508
|
+
|
|
509
|
+
// What this app declares now. Anything else under the prefix belonged to a
|
|
510
|
+
// cron since renamed or deleted, and would keep firing at a handler that has
|
|
511
|
+
// gone.
|
|
512
|
+
//
|
|
513
|
+
// The prefix is \`cron.\` rather than \`cron:\`: pg-boss accepts
|
|
514
|
+
// alphanumerics, underscores, hyphens, periods and slashes in a queue name,
|
|
515
|
+
// and rejects a colon outright.
|
|
516
|
+
const declared = new Set(prepared.map(({ name }) => \`cron.\${name}\`));
|
|
517
|
+
for (const existing of await boss.getSchedules()) {
|
|
518
|
+
if (existing.name.startsWith('cron.') && !declared.has(existing.name)) {
|
|
519
|
+
await boss.unschedule(existing.name);
|
|
520
|
+
logger.info({ cron: existing.name }, 'Removed a schedule nothing declares');
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
for (const entry of prepared) {
|
|
525
|
+
const queue = \`cron.\${entry.name}\`;
|
|
526
|
+
await boss.createQueue(queue);
|
|
527
|
+
// UTC, so this agrees with the schedule a deploy target would have made.
|
|
528
|
+
await boss.schedule(queue, entry.schedule, undefined, { tz: 'UTC' });
|
|
529
|
+
await boss.work(queue, () => run(entry));
|
|
530
|
+
|
|
531
|
+
logger.info({ cron: entry.name, schedule: entry.schedule }, 'Cron scheduled');
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
running.push({ stop: () => connection.close() });
|
|
535
|
+
connections.push(connection);
|
|
536
|
+
logger.info({ count: prepared.length }, 'Crons scheduled');
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
/** The crons that cannot be scheduled, and the connection that schedules the rest. */
|
|
540
|
+
export function cronsStatus(): {
|
|
541
|
+
failed: string[];
|
|
542
|
+
connections: import('@geekmidas/events').EventConnection[];
|
|
543
|
+
} {
|
|
544
|
+
return { failed: [...failed], connections: [...connections] };
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
/**
|
|
548
|
+
* Stop scheduling, let a firing in flight finish, and close the broker
|
|
549
|
+
* connection — pg-boss's graceful stop does all three. The caller bounds it.
|
|
550
|
+
*/
|
|
551
|
+
export async function stopCrons(): Promise<void> {
|
|
552
|
+
const open = [...running];
|
|
553
|
+
running.length = 0;
|
|
554
|
+
connections.length = 0;
|
|
555
|
+
await Promise.all(open.map((r) => r.stop()));
|
|
556
|
+
}
|
|
557
|
+
`;
|
|
558
|
+
await writeFile(cronsPath, content);
|
|
559
|
+
return cronsPath;
|
|
560
|
+
}
|
|
561
|
+
async generateCronHandler(outputDir, sourceFile, exportName, context, owner) {
|
|
562
|
+
const handlerFileName = `${exportName}.ts`;
|
|
563
|
+
const handlerPath = join(outputDir, handlerFileName);
|
|
564
|
+
const importPath = relative(dirname(handlerPath), sourceFile).replace(/\.ts$/, ".js");
|
|
565
|
+
const runtime = runtimeFor(context, dirname(handlerPath), owner);
|
|
566
|
+
const content = `import { AWSScheduledFunction } from '@geekmidas/constructs/aws';
|
|
567
|
+
import { ${exportName} } from '${importPath}';
|
|
568
|
+
${runtime.imports}
|
|
569
|
+
${context.storageDrivers?.imports ?? ""}
|
|
570
|
+
${runtime.bindings}
|
|
571
|
+
${context.storageDrivers?.setup ? `\n// The handler registers the drivers its target needs.\n${context.storageDrivers.setup}\n` : ""}
|
|
572
|
+
const adapter = new AWSScheduledFunction(envParser, ${exportName});
|
|
573
|
+
|
|
574
|
+
export const handler = adapter.handler;
|
|
575
|
+
`;
|
|
576
|
+
await writeFile(handlerPath, content);
|
|
577
|
+
return handlerPath;
|
|
578
|
+
}
|
|
579
|
+
};
|
|
580
|
+
//#endregion
|
|
581
|
+
//#region src/generators/QueueGenerator.ts
|
|
582
|
+
/**
|
|
583
|
+
* Generates the runtime for queue consumers (`worker.queue(…)`).
|
|
584
|
+
*
|
|
585
|
+
* - **server** (`gkm dev`): a single `queues.ts` exposing `setupQueues()` that
|
|
586
|
+
* polls each queue in-process, alongside the Hono server, through the queue's
|
|
587
|
+
* own connection string — pg-boss by default, SQS on the AWS emulator.
|
|
588
|
+
* - **aws-lambda**: one handler file per queue wrapping `AWSLambdaQueue`, backed
|
|
589
|
+
* by an SQS event-source mapping.
|
|
590
|
+
*/
|
|
591
|
+
var QueueGenerator = class extends ConstructGenerator {
|
|
592
|
+
isConstruct(value) {
|
|
593
|
+
return Queue.isQueue(value);
|
|
594
|
+
}
|
|
595
|
+
async build(context, constructs, outputDir, options) {
|
|
596
|
+
const target = options?.target ?? "aws";
|
|
597
|
+
const logger = console;
|
|
598
|
+
const queueInfos = [];
|
|
599
|
+
if (target === "server") {
|
|
600
|
+
await this.generateServerQueuesFile(outputDir, constructs);
|
|
601
|
+
logger.log(`Generated server queues file with ${constructs.length} queues (polling mode)`);
|
|
602
|
+
return queueInfos;
|
|
603
|
+
}
|
|
604
|
+
if (constructs.length === 0) return queueInfos;
|
|
605
|
+
const queuesDir = join(outputDir, "queues");
|
|
606
|
+
await mkdir(queuesDir, { recursive: true });
|
|
607
|
+
for (const { key, construct, path } of constructs) {
|
|
608
|
+
const handlerFile = await this.generateQueueHandler(queuesDir, path.relative, key, context, construct.owner);
|
|
609
|
+
queueInfos.push({
|
|
610
|
+
name: construct.name,
|
|
611
|
+
handler: relative(options?.root ?? process.cwd(), handlerFile).replace(/\.ts$/, ".handler"),
|
|
612
|
+
batchSize: construct.batchSize,
|
|
613
|
+
fifo: construct.fifo,
|
|
614
|
+
timeout: construct.timeout,
|
|
615
|
+
environment: await construct.getEnvironment({ markOptional: context.markOptional }),
|
|
616
|
+
dependencies: construct.constructs
|
|
617
|
+
});
|
|
618
|
+
logger.log(`Generated queue handler: ${key}`);
|
|
619
|
+
}
|
|
620
|
+
return queueInfos;
|
|
621
|
+
}
|
|
622
|
+
async generateQueueHandler(outputDir, sourceFile, exportName, context, owner) {
|
|
623
|
+
const handlerPath = join(outputDir, `${exportName}.ts`);
|
|
624
|
+
const importPath = relative(dirname(handlerPath), sourceFile).replace(/\.ts$/, ".js");
|
|
625
|
+
const runtime = runtimeFor(context, dirname(handlerPath), owner);
|
|
626
|
+
const content = `import { AWSLambdaQueue } from '@geekmidas/constructs/aws';
|
|
627
|
+
import { ${exportName} } from '${importPath}';
|
|
628
|
+
${runtime.imports}
|
|
629
|
+
${context.storageDrivers?.imports ?? ""}
|
|
630
|
+
${runtime.bindings}
|
|
631
|
+
${context.storageDrivers?.setup ? `\n// The handler registers the drivers its target needs.\n${context.storageDrivers.setup}\n` : ""}
|
|
632
|
+
const adapter = new AWSLambdaQueue(envParser, ${exportName});
|
|
633
|
+
|
|
634
|
+
export const handler = adapter.handler;
|
|
635
|
+
`;
|
|
636
|
+
await writeFile(handlerPath, content);
|
|
637
|
+
return handlerPath;
|
|
638
|
+
}
|
|
639
|
+
async generateServerQueuesFile(outputDir, queues) {
|
|
640
|
+
await mkdir(outputDir, { recursive: true });
|
|
641
|
+
const queuesPath = join(outputDir, "queues.ts");
|
|
642
|
+
if (queues.length === 0) {
|
|
643
|
+
await writeFile(queuesPath, `/**
|
|
644
|
+
* Generated queues setup — this app declares none.
|
|
645
|
+
*/
|
|
646
|
+
import type { EnvironmentParser } from '@geekmidas/envkit';
|
|
647
|
+
import type { Logger } from '@geekmidas/logger';
|
|
648
|
+
|
|
649
|
+
export async function setupQueues(
|
|
650
|
+
_envParser: EnvironmentParser<any>,
|
|
651
|
+
_logger: Logger,
|
|
652
|
+
): Promise<void> {}
|
|
653
|
+
|
|
654
|
+
export function queuesStatus(): { failed: string[]; connections: unknown[] } {
|
|
655
|
+
return { failed: [], connections: [] };
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
export async function stopQueues(): Promise<void> {}
|
|
659
|
+
`);
|
|
660
|
+
return queuesPath;
|
|
661
|
+
}
|
|
662
|
+
const importsByFile = /* @__PURE__ */ new Map();
|
|
663
|
+
for (const { path, key } of queues) {
|
|
664
|
+
const importPath = relative(dirname(queuesPath), path.relative).replace(/\.ts$/, ".js");
|
|
665
|
+
if (!importsByFile.has(importPath)) importsByFile.set(importPath, []);
|
|
666
|
+
importsByFile.get(importPath)?.push(key);
|
|
667
|
+
}
|
|
668
|
+
const content = `/**
|
|
669
|
+
* Generated queue consumers setup.
|
|
670
|
+
*
|
|
671
|
+
* Each queue's one consumer polls its own queue, through the queue's own
|
|
672
|
+
* connection string — the one its producers publish on. SQS cannot push, so
|
|
673
|
+
* this is a poller on every transport: pg-boss locally by default, the SQS
|
|
674
|
+
* queue on the AWS emulator.
|
|
675
|
+
*
|
|
676
|
+
* Deployed on Lambda, a queue's consumer is an SQS event source instead.
|
|
677
|
+
*/
|
|
678
|
+
import type { EnvironmentParser } from '@geekmidas/envkit';
|
|
679
|
+
import type { Logger } from '@geekmidas/logger';
|
|
680
|
+
import { EventConnectionFactory, Subscriber } from '@geekmidas/events';
|
|
681
|
+
import type { EventConnection } from '@geekmidas/events';
|
|
682
|
+
import { ServiceDiscovery } from '@geekmidas/services';
|
|
683
|
+
${Array.from(importsByFile.entries()).map(([importPath, exports]) => `import { ${exports.join(", ")} } from '${importPath}';`).join("\n")}
|
|
684
|
+
|
|
685
|
+
const queues = [
|
|
686
|
+
${queues.map(({ key, construct }) => ` { queue: ${key}, connectionKey: '${provideKey(construct.id, "publisherConnectionString")}' },`).join("\n")}
|
|
687
|
+
];
|
|
688
|
+
|
|
689
|
+
// What was opened, and what could not be: a worker's health check reads both,
|
|
690
|
+
// and its shutdown closes what was opened.
|
|
691
|
+
const connections = new Map<string, EventConnection>();
|
|
692
|
+
const failed: string[] = [];
|
|
693
|
+
|
|
694
|
+
export async function setupQueues(
|
|
695
|
+
envParser: EnvironmentParser<any>,
|
|
696
|
+
logger: Logger,
|
|
697
|
+
): Promise<void> {
|
|
698
|
+
const serviceDiscovery = ServiceDiscovery.getInstance(envParser);
|
|
699
|
+
|
|
700
|
+
for (const { queue, connectionKey } of queues) {
|
|
701
|
+
const connectionString = process.env[connectionKey];
|
|
702
|
+
if (!connectionString) {
|
|
703
|
+
logger.error({ queue: queue.name, connectionKey }, 'No connection string for this queue');
|
|
704
|
+
failed.push(queue.name);
|
|
705
|
+
continue;
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
try {
|
|
709
|
+
let connection = connections.get(connectionString);
|
|
710
|
+
if (!connection) {
|
|
711
|
+
connection = await EventConnectionFactory.fromConnectionString(connectionString);
|
|
712
|
+
connections.set(connectionString, connection);
|
|
713
|
+
}
|
|
714
|
+
const eventSubscriber = await Subscriber.fromConnection(connection);
|
|
715
|
+
const services = queue.services.length > 0
|
|
716
|
+
? await serviceDiscovery.register(queue.services)
|
|
717
|
+
: {};
|
|
718
|
+
// The queue's database — the worker's, or its own — handed over as \`db\`.
|
|
719
|
+
const db = queue.databaseService
|
|
720
|
+
? (await serviceDiscovery.register([queue.databaseService]))[
|
|
721
|
+
queue.databaseService.serviceName
|
|
722
|
+
]
|
|
723
|
+
: undefined;
|
|
724
|
+
|
|
725
|
+
// A queue's messages carry one type — its own name.
|
|
726
|
+
await eventSubscriber.subscribe([queue.name], async (message) => {
|
|
727
|
+
try {
|
|
728
|
+
const validation = await queue.messageSchema['~standard'].validate(message.payload);
|
|
729
|
+
if (validation.issues) {
|
|
730
|
+
logger.error({ issues: validation.issues, queue: queue.name }, 'Queue message failed validation');
|
|
731
|
+
return;
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
await queue.handler({
|
|
735
|
+
messages: [validation.value],
|
|
736
|
+
services: services,
|
|
737
|
+
logger: queue.logger,
|
|
738
|
+
db,
|
|
739
|
+
} as any);
|
|
740
|
+
} catch (error) {
|
|
741
|
+
logger.error({ err: error, queue: queue.name }, 'Failed to process queue message');
|
|
742
|
+
// Rethrown so the transport keeps the message for a retry.
|
|
743
|
+
throw error;
|
|
744
|
+
}
|
|
745
|
+
});
|
|
746
|
+
logger.info({ queue: queue.name }, 'Queue consumer started polling');
|
|
747
|
+
} catch (error) {
|
|
748
|
+
logger.error({ err: error, queue: queue.name }, 'Failed to set up queue consumer');
|
|
749
|
+
failed.push(queue.name);
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
/** The consumers that could not start, and the connections that did. */
|
|
755
|
+
export function queuesStatus(): { failed: string[]; connections: EventConnection[] } {
|
|
756
|
+
return { failed: [...failed], connections: [...connections.values()] };
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
/**
|
|
760
|
+
* Stop polling, let the messages in flight finish, and close each broker
|
|
761
|
+
* connection — pg-boss's graceful stop does all three. The caller bounds it.
|
|
762
|
+
*/
|
|
763
|
+
export async function stopQueues(): Promise<void> {
|
|
764
|
+
const open = [...connections.values()];
|
|
765
|
+
connections.clear();
|
|
766
|
+
await Promise.all(open.map((connection) => connection.close()));
|
|
767
|
+
}
|
|
768
|
+
`;
|
|
769
|
+
await writeFile(queuesPath, content);
|
|
770
|
+
return queuesPath;
|
|
771
|
+
}
|
|
772
|
+
};
|
|
773
|
+
//#endregion
|
|
774
|
+
//#region src/generators/WorkerGenerator.ts
|
|
775
|
+
/**
|
|
776
|
+
* A worker whose topic subscribers would have to be pushed to over HTTP.
|
|
777
|
+
*
|
|
778
|
+
* On SNS a subscriber is an HTTP endpoint SNS delivers to, and a worker's
|
|
779
|
+
* process serves nothing but its health check. A server target's broker is
|
|
780
|
+
* pg-boss, where each subscriber polls a queue of its own, so this is only
|
|
781
|
+
* reached by building server images for a project that deploys to AWS — where
|
|
782
|
+
* a subscriber is a Lambda instead.
|
|
783
|
+
*/
|
|
784
|
+
var WorkerSubscribersNeedPush = class extends GkmError {
|
|
785
|
+
worker;
|
|
786
|
+
subscribers;
|
|
787
|
+
constructor(worker, subscribers) {
|
|
788
|
+
super(`The worker '${worker}' runs topic subscribers (${subscribers.join(", ")}), and this build's broker is SNS, which pushes each event to its subscriber over HTTP. A worker image serves only its health check. Deploy to a server target, whose broker is pg-boss and whose subscribers poll, or to AWS, where each subscriber is a Lambda.`);
|
|
789
|
+
this.worker = worker;
|
|
790
|
+
this.subscribers = subscribers;
|
|
791
|
+
this.name = "WorkerSubscribersNeedPush";
|
|
792
|
+
}
|
|
793
|
+
};
|
|
794
|
+
/** Where a worker's generated entry lives, under an app's `.gkm/server`. */
|
|
795
|
+
function workerEntryDir(serverDir, workerId) {
|
|
796
|
+
return join(serverDir, "workers", appKey(workerId));
|
|
797
|
+
}
|
|
798
|
+
/** The file a worker's bundle is written to, beside the server's. */
|
|
799
|
+
function workerBundleName(workerId) {
|
|
800
|
+
return `worker-${appKey(workerId)}.mjs`;
|
|
801
|
+
}
|
|
802
|
+
/**
|
|
803
|
+
* A Worker's production entry: the process that runs its crons, its queue
|
|
804
|
+
* consumers and its topic subscribers, and answers nothing but a health check.
|
|
805
|
+
*
|
|
806
|
+
* It is the server's runtime without the server. The `crons.ts`, `queues.ts`
|
|
807
|
+
* and `subscribers.ts` it starts are the files `gkm dev` starts — written by
|
|
808
|
+
* the same generators, given only this worker's constructs — so a consumer
|
|
809
|
+
* runs the same code in development and in the image. What it adds is the
|
|
810
|
+
* process around them: drivers, a health check that says when a consumer or
|
|
811
|
+
* the broker is down, and a shutdown that drains.
|
|
812
|
+
*/
|
|
813
|
+
var WorkerGenerator = class {
|
|
814
|
+
generators;
|
|
815
|
+
constructor(generators = {
|
|
816
|
+
cron: new CronGenerator(),
|
|
817
|
+
queue: new QueueGenerator(),
|
|
818
|
+
subscriber: new SubscriberGenerator()
|
|
819
|
+
}) {
|
|
820
|
+
this.generators = generators;
|
|
821
|
+
}
|
|
822
|
+
/** Write the worker's files; returns its entry, `worker.ts`. */
|
|
823
|
+
async build(input) {
|
|
824
|
+
const { context, workerId, outputDir } = input;
|
|
825
|
+
if (input.subscribers.length > 0 && context.eventsBackends?.includes("sns")) throw new WorkerSubscribersNeedPush(workerId, input.subscribers.map(({ key }) => key));
|
|
826
|
+
await mkdir(outputDir, { recursive: true });
|
|
827
|
+
const options = { target: "server" };
|
|
828
|
+
await Promise.all([
|
|
829
|
+
this.generators.cron.build(context, input.crons, outputDir, options),
|
|
830
|
+
this.generators.queue.build(context, input.queues, outputDir, options),
|
|
831
|
+
this.generators.subscriber.build(context, input.subscribers, outputDir, options)
|
|
832
|
+
]);
|
|
833
|
+
await writeFile(join(outputDir, "app.ts"), workerApp(context, workerId, outputDir));
|
|
834
|
+
await writeTelemetryModule(outputDir, input.telemetry);
|
|
835
|
+
const entry = join(outputDir, "worker.ts");
|
|
836
|
+
await writeFile(entry, workerEntry(context.production?.healthCheck ?? "/health"));
|
|
837
|
+
return entry;
|
|
838
|
+
}
|
|
839
|
+
};
|
|
840
|
+
/**
|
|
841
|
+
* `app.ts`: the worker's runtime — its logger and environment parser off the
|
|
842
|
+
* Worker construct, the drivers its target needs, and a `startWorker` that
|
|
843
|
+
* starts every cron, consumer and subscriber it owns.
|
|
844
|
+
*/
|
|
845
|
+
function workerApp(context, workerId, outputDir) {
|
|
846
|
+
const runtime = runtimeFor(context, outputDir, workerId);
|
|
847
|
+
return `/**
|
|
848
|
+
* Generated worker runtime for ${workerId}.
|
|
849
|
+
* Generated by 'gkm build --production'.
|
|
850
|
+
*/
|
|
851
|
+
import { setupCrons, cronsStatus, stopCrons } from './crons.js';
|
|
852
|
+
import { setupQueues, queuesStatus, stopQueues } from './queues.js';
|
|
853
|
+
import { setupSubscribers, subscribersStatus, stopSubscribers } from './subscribers.js';
|
|
854
|
+
${runtime.imports}
|
|
855
|
+
${context.storageDrivers?.imports ?? ""}
|
|
856
|
+
|
|
857
|
+
${runtime.bindings}
|
|
858
|
+
|
|
859
|
+
${context.storageDrivers?.setup ? `// The entry point registers the drivers its target needs.
|
|
860
|
+
${context.storageDrivers.setup}
|
|
861
|
+
` : ""}
|
|
862
|
+
// Who this worker is to Postgres: application_name on every connection.
|
|
863
|
+
process.env.GKM_APP_NAME ??= ${JSON.stringify(workerId)};
|
|
864
|
+
|
|
865
|
+
export { logger };
|
|
866
|
+
|
|
867
|
+
/** What the health check answers, and why. */
|
|
868
|
+
export interface WorkerHealth {
|
|
869
|
+
healthy: boolean;
|
|
870
|
+
/** The crons, queues and subscribers that could not start. */
|
|
871
|
+
failed: string[];
|
|
872
|
+
/** How many broker connections did not answer. */
|
|
873
|
+
down: number;
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
/** Whether one broker connection answers: open, and — on pg-boss — a query. */
|
|
877
|
+
async function answers(connection: unknown): Promise<boolean> {
|
|
878
|
+
const c = connection as {
|
|
879
|
+
isConnected?: () => boolean;
|
|
880
|
+
instance?: { getDb?: () => { executeSql: (sql: string) => Promise<unknown> } };
|
|
881
|
+
};
|
|
882
|
+
if (c.isConnected && !c.isConnected()) return false;
|
|
883
|
+
const db = c.instance?.getDb?.();
|
|
884
|
+
if (!db) return true;
|
|
885
|
+
try {
|
|
886
|
+
await Promise.race([
|
|
887
|
+
db.executeSql('select 1'),
|
|
888
|
+
new Promise((_, reject) => setTimeout(() => reject(new Error('timeout')), 2000).unref()),
|
|
889
|
+
]);
|
|
890
|
+
return true;
|
|
891
|
+
} catch {
|
|
892
|
+
return false;
|
|
893
|
+
}
|
|
894
|
+
}
|
|
895
|
+
|
|
896
|
+
/** A request to a route this worker mounted, and what it answered. */
|
|
897
|
+
export interface WorkerRequest {
|
|
898
|
+
headers: Record<string, string | string[] | undefined>;
|
|
899
|
+
body: string;
|
|
900
|
+
/** The request's query — Mailpit's webhook carries its token there. */
|
|
901
|
+
query?: URLSearchParams;
|
|
902
|
+
}
|
|
903
|
+
export interface WorkerAnswer {
|
|
904
|
+
status: number;
|
|
905
|
+
body: unknown;
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
// The routes something pushes to: an SNS subscriber's, and the one a local
|
|
909
|
+
// object store posts a bucket's events to. Mounted by the subscribers, served
|
|
910
|
+
// by the entry's HTTP server beside the health check.
|
|
911
|
+
const routes = new Map<string, (c: any) => unknown>();
|
|
912
|
+
const app = {
|
|
913
|
+
post: (path: string, handler: (c: any) => unknown) => {
|
|
914
|
+
routes.set(path, handler);
|
|
915
|
+
},
|
|
916
|
+
};
|
|
917
|
+
|
|
918
|
+
/** Run one mounted route, as the subscribers' handlers expect to be called. */
|
|
919
|
+
async function route(path: string, request: WorkerRequest): Promise<WorkerAnswer | undefined> {
|
|
920
|
+
const handler = routes.get(path);
|
|
921
|
+
if (!handler) return undefined;
|
|
922
|
+
let answer: WorkerAnswer | undefined;
|
|
923
|
+
const c = {
|
|
924
|
+
req: {
|
|
925
|
+
text: async () => request.body,
|
|
926
|
+
query: (name: string) => request.query?.get(name) ?? undefined,
|
|
927
|
+
header: (name: string) => {
|
|
928
|
+
const value = request.headers[name.toLowerCase()];
|
|
929
|
+
return Array.isArray(value) ? value[0] : value;
|
|
930
|
+
},
|
|
931
|
+
},
|
|
932
|
+
json: (body: unknown, status = 200) => {
|
|
933
|
+
answer = { status, body };
|
|
934
|
+
return answer;
|
|
935
|
+
},
|
|
936
|
+
};
|
|
937
|
+
await handler(c);
|
|
938
|
+
return answer ?? { status: 204, body: null };
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
/** Start everything this worker runs. */
|
|
942
|
+
export async function startWorker(): Promise<{
|
|
943
|
+
health: () => Promise<WorkerHealth>;
|
|
944
|
+
stop: () => Promise<void>;
|
|
945
|
+
route: typeof route;
|
|
946
|
+
/** Subscribe the pushed routes, once the server answers on \`port\`. */
|
|
947
|
+
subscribeForPush: (port: number) => Promise<void>;
|
|
948
|
+
}> {
|
|
949
|
+
const subscribeForPush = await setupSubscribers(app, envParser, logger).catch((error) => {
|
|
950
|
+
logger.error({ err: error }, 'Failed to start subscribers');
|
|
951
|
+
return async (_port: number) => {};
|
|
952
|
+
});
|
|
953
|
+
await setupQueues(envParser, logger).catch((error) => {
|
|
954
|
+
logger.error({ err: error }, 'Failed to start queue consumers');
|
|
955
|
+
});
|
|
956
|
+
await setupCrons(envParser, logger).catch((error) => {
|
|
957
|
+
logger.error({ err: error }, 'Failed to schedule crons');
|
|
958
|
+
});
|
|
959
|
+
|
|
960
|
+
const statuses = () => [subscribersStatus(), queuesStatus(), cronsStatus()];
|
|
961
|
+
|
|
962
|
+
return {
|
|
963
|
+
route,
|
|
964
|
+
subscribeForPush,
|
|
965
|
+
async health() {
|
|
966
|
+
const all = statuses();
|
|
967
|
+
const failed = all.flatMap((s) => s.failed);
|
|
968
|
+
const alive = await Promise.all(
|
|
969
|
+
all.flatMap((s) => s.connections as unknown[]).map(answers),
|
|
970
|
+
);
|
|
971
|
+
const down = alive.filter((ok) => !ok).length;
|
|
972
|
+
return { healthy: failed.length === 0 && down === 0, failed, down };
|
|
973
|
+
},
|
|
974
|
+
// Each stops pulling, waits for what it has in flight, and closes its
|
|
975
|
+
// broker connection. Together, so one slow handler does not hold the
|
|
976
|
+
// others' connections open.
|
|
977
|
+
async stop() {
|
|
978
|
+
await Promise.all([stopSubscribers(), stopQueues(), stopCrons()]);
|
|
979
|
+
},
|
|
980
|
+
};
|
|
981
|
+
}
|
|
982
|
+
`;
|
|
983
|
+
}
|
|
984
|
+
/**
|
|
985
|
+
* `worker.ts`: the process. Health first, so the container answers while the
|
|
986
|
+
* consumers connect; then the worker; then a shutdown that drains.
|
|
987
|
+
*/
|
|
988
|
+
function workerEntry(healthCheck) {
|
|
989
|
+
return `#!/usr/bin/env node
|
|
990
|
+
/**
|
|
991
|
+
* Production worker entry point.
|
|
992
|
+
* Generated by 'gkm build --production'.
|
|
993
|
+
*
|
|
994
|
+
* Runs this worker's crons, queue consumers and topic subscribers, and serves
|
|
995
|
+
* its health check: ${healthCheck}, on PORT — 200 when every consumer started
|
|
996
|
+
* and every broker connection answers, 503 otherwise. Beside it, on the same
|
|
997
|
+
* port, the POST routes its subscribers mounted: where a local object store
|
|
998
|
+
* posts a bucket's events.
|
|
999
|
+
*
|
|
1000
|
+
* On SIGTERM it stops pulling messages and scheduling crons, lets the handlers
|
|
1001
|
+
* in flight finish, closes its broker connections and database pools, and
|
|
1002
|
+
* exits 0 — or 1, at GKM_SHUTDOWN_TIMEOUT_MS (8s by default, under Docker's
|
|
1003
|
+
* 10s stop timeout).
|
|
1004
|
+
*/
|
|
1005
|
+
import { createServer } from 'node:http';
|
|
1006
|
+
import { runShutdownHooks } from '@geekmidas/constructs';
|
|
1007
|
+
|
|
1008
|
+
${startTelemetryCode([healthCheck])}
|
|
1009
|
+
const { startWorker, logger } = await import('./app.js');
|
|
1010
|
+
|
|
1011
|
+
const port = Number(process.env.PORT) || 3000;
|
|
1012
|
+
|
|
1013
|
+
let worker: Awaited<ReturnType<typeof startWorker>> | undefined;
|
|
1014
|
+
let stopping = false;
|
|
1015
|
+
|
|
1016
|
+
const server = createServer((req, res) => {
|
|
1017
|
+
// Parsed once: the path routes, the query goes to the route.
|
|
1018
|
+
const url = new URL(req.url ?? '/', 'http://localhost');
|
|
1019
|
+
const path = url.pathname;
|
|
1020
|
+
const answer = (status: number, body: unknown) => {
|
|
1021
|
+
res.writeHead(status, { 'content-type': 'application/json' });
|
|
1022
|
+
res.end(JSON.stringify(body));
|
|
1023
|
+
};
|
|
1024
|
+
|
|
1025
|
+
// A route a subscriber mounted: what SNS pushes to, or what a local object
|
|
1026
|
+
// store posts a bucket's events to. Refused while starting or stopping, so
|
|
1027
|
+
// the sender keeps the message and sends it again.
|
|
1028
|
+
if (req.method === 'POST') {
|
|
1029
|
+
let body = '';
|
|
1030
|
+
req.setEncoding('utf8');
|
|
1031
|
+
req.on('data', (chunk) => {
|
|
1032
|
+
body += chunk;
|
|
1033
|
+
});
|
|
1034
|
+
req.on('end', () => {
|
|
1035
|
+
if (stopping) return answer(503, { status: 'stopping' });
|
|
1036
|
+
if (!worker) return answer(503, { status: 'starting' });
|
|
1037
|
+
worker.route(path, { headers: req.headers, body, query: url.searchParams }).then(
|
|
1038
|
+
(routed) => (routed ? answer(routed.status, routed.body) : answer(404, { status: 'not found' })),
|
|
1039
|
+
(error) => {
|
|
1040
|
+
logger.error({ err: error, path }, 'Route failed');
|
|
1041
|
+
answer(500, { status: 'failed' });
|
|
1042
|
+
},
|
|
1043
|
+
);
|
|
1044
|
+
});
|
|
1045
|
+
return;
|
|
1046
|
+
}
|
|
1047
|
+
|
|
1048
|
+
if (path !== ${JSON.stringify(healthCheck)} || (req.method !== 'GET' && req.method !== 'HEAD')) {
|
|
1049
|
+
res.writeHead(404).end();
|
|
1050
|
+
return;
|
|
1051
|
+
}
|
|
1052
|
+
if (stopping) return answer(503, { status: 'stopping' });
|
|
1053
|
+
if (!worker) return answer(503, { status: 'starting' });
|
|
1054
|
+
worker.health().then(
|
|
1055
|
+
(health) => answer(health.healthy ? 200 : 503, { status: health.healthy ? 'ok' : 'unhealthy', ...health }),
|
|
1056
|
+
(error) => answer(503, { status: 'unhealthy', error: String(error) }),
|
|
1057
|
+
);
|
|
1058
|
+
});
|
|
1059
|
+
server.listen(port);
|
|
1060
|
+
|
|
1061
|
+
const shutdown = async () => {
|
|
1062
|
+
if (stopping) return;
|
|
1063
|
+
stopping = true;
|
|
1064
|
+
const deadline = Number(process.env.GKM_SHUTDOWN_TIMEOUT_MS) || 8000;
|
|
1065
|
+
logger.info({ deadline }, 'Graceful shutdown initiated');
|
|
1066
|
+
setTimeout(() => {
|
|
1067
|
+
logger.warn({ deadline }, 'Shutdown deadline reached, exiting');
|
|
1068
|
+
process.exit(1);
|
|
1069
|
+
}, deadline).unref();
|
|
1070
|
+
|
|
1071
|
+
// Nothing new is pulled or scheduled; what is in flight finishes.
|
|
1072
|
+
await worker?.stop().catch((error) => logger.error({ err: error }, 'Failed to stop the worker'));
|
|
1073
|
+
// Then what the handlers used: database pools.
|
|
1074
|
+
await runShutdownHooks((error) => logger.error({ err: error }, 'Shutdown hook failed'));
|
|
1075
|
+
server.close();
|
|
1076
|
+
logger.info('Worker stopped');
|
|
1077
|
+
process.exit(0);
|
|
1078
|
+
};
|
|
1079
|
+
|
|
1080
|
+
process.on('SIGTERM', shutdown);
|
|
1081
|
+
process.on('SIGINT', shutdown);
|
|
1082
|
+
|
|
1083
|
+
worker = await startWorker();
|
|
1084
|
+
logger.info({ port }, 'Worker started');
|
|
1085
|
+
await worker.subscribeForPush(port).catch((error) => {
|
|
1086
|
+
logger.error({ err: error }, 'Failed to subscribe for push');
|
|
1087
|
+
});
|
|
1088
|
+
`;
|
|
1089
|
+
}
|
|
1090
|
+
//#endregion
|
|
1091
|
+
//#region src/docker/index.ts
|
|
1092
|
+
const logger = output;
|
|
1093
|
+
/** `docker build` failed; what docker printed above says why. */
|
|
1094
|
+
var DockerBuildFailed = class extends Error {
|
|
1095
|
+
imageRef;
|
|
1096
|
+
constructor(imageRef, cause) {
|
|
1097
|
+
super(`Failed to build Docker image: ${cause instanceof Error ? cause.message : String(cause)}`, { cause });
|
|
1098
|
+
this.imageRef = imageRef;
|
|
1099
|
+
this.name = "DockerBuildFailed";
|
|
1100
|
+
}
|
|
1101
|
+
};
|
|
1102
|
+
/** `docker push` failed — usually the registry login or its permissions. */
|
|
1103
|
+
var DockerPushFailed = class extends Error {
|
|
1104
|
+
imageRef;
|
|
1105
|
+
constructor(imageRef, cause) {
|
|
1106
|
+
super(`Failed to push Docker image: ${cause instanceof Error ? cause.message : String(cause)}`, { cause });
|
|
1107
|
+
this.imageRef = imageRef;
|
|
1108
|
+
this.name = "DockerPushFailed";
|
|
1109
|
+
}
|
|
1110
|
+
};
|
|
1111
|
+
/** `gkm docker --push` was asked for with nowhere to push to. */
|
|
1112
|
+
var PushNeedsRegistry = class extends GkmError {
|
|
1113
|
+
imageName;
|
|
1114
|
+
constructor(imageName) {
|
|
1115
|
+
super(`Registry is required to push Docker image '${imageName}'. Use --registry or configure docker.registry in gkm.config.ts`);
|
|
1116
|
+
this.imageName = imageName;
|
|
1117
|
+
this.name = "PushNeedsRegistry";
|
|
1118
|
+
}
|
|
1119
|
+
};
|
|
1120
|
+
/**
|
|
1121
|
+
* Docker command implementation: one Dockerfile per deployable app, each
|
|
1122
|
+
* building its image inside Docker from a turbo-pruned slice of the build
|
|
1123
|
+
* root — nothing is built on the host — plus the build root's
|
|
1124
|
+
* `.dockerignore` and `docker-compose.constructs.yml`.
|
|
1125
|
+
*/
|
|
1126
|
+
async function dockerCommand(options) {
|
|
1127
|
+
const cwd = options.cwd ?? process.cwd();
|
|
1128
|
+
const loaded = await loadWorkspaceConfig(cwd);
|
|
1129
|
+
const names = loaded.type === "single" ? Object.fromEntries(Object.keys(loaded.workspace.apps).map((name) => [name, resolveDockerConfig(loaded.raw).imageName])) : {};
|
|
1130
|
+
const result = await workspaceDockerCommand(loaded.workspace, loaded.manifest, names, loaded.background, options.stage);
|
|
1131
|
+
if (options.build) for (const app of result.apps) await buildDockerImage(app, result.buildRoot, options);
|
|
1132
|
+
if (options.push) for (const app of result.apps) await pushDockerImage(app.imageName, options, result.buildRoot);
|
|
1133
|
+
return result;
|
|
1134
|
+
}
|
|
1135
|
+
/**
|
|
1136
|
+
* Build one app's image, from the build root.
|
|
1137
|
+
* Uses BuildKit for cache mount support
|
|
1138
|
+
*/
|
|
1139
|
+
async function buildDockerImage(app, buildRoot, options) {
|
|
1140
|
+
const tag = options.tag ?? "latest";
|
|
1141
|
+
const registry = options.registry;
|
|
1142
|
+
const fullImageName = validateImageRef(registry ? `${registry}/${app.imageName}:${tag}` : `${app.imageName}:${tag}`);
|
|
1143
|
+
logger.log(`\n🐳 Building Docker image: ${fullImageName}`);
|
|
1144
|
+
try {
|
|
1145
|
+
await run("docker", [
|
|
1146
|
+
"build",
|
|
1147
|
+
`--file=${relative(buildRoot, app.dockerfile)}`,
|
|
1148
|
+
`--tag=${fullImageName}`,
|
|
1149
|
+
"."
|
|
1150
|
+
], {
|
|
1151
|
+
cwd: buildRoot,
|
|
1152
|
+
env: {
|
|
1153
|
+
...process.env,
|
|
1154
|
+
DOCKER_BUILDKIT: "1"
|
|
1155
|
+
}
|
|
1156
|
+
});
|
|
1157
|
+
logger.log(`✅ Docker image built: ${fullImageName}`);
|
|
1158
|
+
} catch (error) {
|
|
1159
|
+
throw new DockerBuildFailed(fullImageName, error);
|
|
1160
|
+
}
|
|
1161
|
+
}
|
|
1162
|
+
/**
|
|
1163
|
+
* Push Docker image to registry
|
|
1164
|
+
*/
|
|
1165
|
+
async function pushDockerImage(imageName, options, cwd) {
|
|
1166
|
+
const tag = options.tag ?? "latest";
|
|
1167
|
+
const registry = options.registry;
|
|
1168
|
+
if (!registry) throw new PushNeedsRegistry(imageName);
|
|
1169
|
+
const fullImageName = validateImageRef(`${registry}/${imageName}:${tag}`);
|
|
1170
|
+
logger.log(`\n🚀 Pushing Docker image: ${fullImageName}`);
|
|
1171
|
+
try {
|
|
1172
|
+
await run("docker", ["push", fullImageName], { cwd });
|
|
1173
|
+
logger.log(`✅ Docker image pushed: ${fullImageName}`);
|
|
1174
|
+
} catch (error) {
|
|
1175
|
+
throw new DockerPushFailed(fullImageName, error);
|
|
1176
|
+
}
|
|
1177
|
+
}
|
|
1178
|
+
/**
|
|
1179
|
+
* Generate Dockerfiles for all apps in a workspace.
|
|
1180
|
+
* @internal Exported for testing
|
|
1181
|
+
*/
|
|
1182
|
+
async function workspaceDockerCommand(workspace, manifest, imageNames = {}, background = {}, stage) {
|
|
1183
|
+
const results = [];
|
|
1184
|
+
const layout = imageLayout(workspace);
|
|
1185
|
+
logger.log(`\n🐳 Generating Dockerfiles for workspace: ${workspace.name}`);
|
|
1186
|
+
logger.log(` Build root: ${layout.buildRoot}`);
|
|
1187
|
+
logger.log(` Package manager: ${layout.tools.packageManager}${layout.tools.packageManagerVersion ? `@${layout.tools.packageManagerVersion}` : ""}, turbo@${layout.tools.turboVersion}`);
|
|
1188
|
+
for (const [appName, app] of Object.entries(workspace.apps)) {
|
|
1189
|
+
if (app.type === "mobile") {
|
|
1190
|
+
logger.log(`\n 📱 Skipping Docker for ${appName} (mobile app — deploy via framework toolchain)`);
|
|
1191
|
+
continue;
|
|
1192
|
+
}
|
|
1193
|
+
const buildType = app.entry ? "entry" : app.type;
|
|
1194
|
+
logger.log(`\n 📄 Generating Dockerfile for ${appName} (${buildType})`);
|
|
1195
|
+
const dockerfile = appDockerfile(appName, app, {
|
|
1196
|
+
layout,
|
|
1197
|
+
workspaceRoot: workspace.root,
|
|
1198
|
+
apps: workspace.apps,
|
|
1199
|
+
...manifest ? { manifest } : {},
|
|
1200
|
+
workspace,
|
|
1201
|
+
...stage ? { stage } : {}
|
|
1202
|
+
});
|
|
1203
|
+
const path = dockerfileOf(appName, app.path);
|
|
1204
|
+
const dockerfilePath = join(workspace.root, path);
|
|
1205
|
+
await mkdir(dirname(dockerfilePath), { recursive: true });
|
|
1206
|
+
await writeFile(dockerfilePath, dockerfile);
|
|
1207
|
+
logger.log(` Generated: ${path}`);
|
|
1208
|
+
results.push({
|
|
1209
|
+
appName,
|
|
1210
|
+
type: app.type,
|
|
1211
|
+
dockerfile: dockerfilePath,
|
|
1212
|
+
imageName: imageNames[appName] ?? appName
|
|
1213
|
+
});
|
|
1214
|
+
}
|
|
1215
|
+
for (const worker of manifest ? workerUnits(workspace, manifest, background) : []) {
|
|
1216
|
+
logger.log(`\n 📄 Generating Dockerfile for ${worker.name} (worker ${worker.id}, built from ${worker.app})`);
|
|
1217
|
+
const dockerfile = workerDockerfile(worker, workspace.apps[worker.app], {
|
|
1218
|
+
layout,
|
|
1219
|
+
workspaceRoot: workspace.root
|
|
1220
|
+
});
|
|
1221
|
+
const path = workerDockerfileOf(worker.name);
|
|
1222
|
+
const dockerfilePath = join(workspace.root, path);
|
|
1223
|
+
await mkdir(dirname(dockerfilePath), { recursive: true });
|
|
1224
|
+
await writeFile(dockerfilePath, dockerfile);
|
|
1225
|
+
logger.log(` Generated: ${path}`);
|
|
1226
|
+
results.push({
|
|
1227
|
+
appName: worker.name,
|
|
1228
|
+
type: "backend",
|
|
1229
|
+
dockerfile: dockerfilePath,
|
|
1230
|
+
imageName: imageNames[worker.name] ?? worker.name
|
|
1231
|
+
});
|
|
1232
|
+
}
|
|
1233
|
+
for (const unit of manifest ? processorUnits(workspace, manifest) : []) {
|
|
1234
|
+
logger.log(`\n 📄 Generating Dockerfile for ${unit.name} (processors of ${unit.id}, built from ${unit.app})`);
|
|
1235
|
+
const dockerfile = processorDockerfile(unit, workspace.apps[unit.app], {
|
|
1236
|
+
layout,
|
|
1237
|
+
workspaceRoot: workspace.root
|
|
1238
|
+
});
|
|
1239
|
+
const path = workerDockerfileOf(unit.name);
|
|
1240
|
+
const dockerfilePath = join(workspace.root, path);
|
|
1241
|
+
await mkdir(dirname(dockerfilePath), { recursive: true });
|
|
1242
|
+
await writeFile(dockerfilePath, dockerfile);
|
|
1243
|
+
logger.log(` Generated: ${path}`);
|
|
1244
|
+
results.push({
|
|
1245
|
+
appName: unit.name,
|
|
1246
|
+
type: "backend",
|
|
1247
|
+
dockerfile: dockerfilePath,
|
|
1248
|
+
imageName: imageNames[unit.name] ?? unit.name
|
|
1249
|
+
});
|
|
1250
|
+
}
|
|
1251
|
+
const dockerignorePath = await ensureDockerignore(layout.buildRoot);
|
|
1252
|
+
logger.log(`\n Ensured: ${dockerignorePath}`);
|
|
1253
|
+
const composePath = await writeConstructsCompose(workspace);
|
|
1254
|
+
logger.log(`\n✅ Generated ${results.length} Dockerfile(s) + ${COMPOSE_PATH}`);
|
|
1255
|
+
logger.log(`\n📋 Build commands (from ${layout.buildRoot}):`);
|
|
1256
|
+
for (const result of results) {
|
|
1257
|
+
const icon = result.type === "backend" ? "⚙️" : result.type === "mobile" ? "📱" : "🌐";
|
|
1258
|
+
logger.log(` ${icon} docker build -f ${relative(layout.buildRoot, result.dockerfile)} -t ${result.imageName} .`);
|
|
1259
|
+
}
|
|
1260
|
+
printRunInstructions(workspace);
|
|
1261
|
+
return {
|
|
1262
|
+
apps: results,
|
|
1263
|
+
dockerCompose: composePath,
|
|
1264
|
+
dockerignore: dockerignorePath,
|
|
1265
|
+
buildRoot: layout.buildRoot
|
|
1266
|
+
};
|
|
1267
|
+
}
|
|
1268
|
+
/**
|
|
1269
|
+
* One app's Dockerfile, by what it is: a gkm backend bundled by `gkm build`,
|
|
1270
|
+
* a backend with its own entry bundled by esbuild, or a site by its
|
|
1271
|
+
* framework. The one choice every builder of images makes.
|
|
1272
|
+
*/
|
|
1273
|
+
function appDockerfile(appName, app, options) {
|
|
1274
|
+
const image = appImageOptions(options.layout, appName, app, options.workspaceRoot, options.apps, app.type === "web" && options.manifest && options.workspace ? siteClientTelemetry(options.manifest, appName, options.workspace, options.stage) : void 0);
|
|
1275
|
+
if (app.type === "web") return siteDockerfile(appName, app, {
|
|
1276
|
+
image,
|
|
1277
|
+
...options.manifest ? { manifest: options.manifest } : {},
|
|
1278
|
+
...options.publicUrlArgs ? { publicUrlArgs: options.publicUrlArgs } : {}
|
|
1279
|
+
});
|
|
1280
|
+
if (app.entry) return generateEntryDockerfile({
|
|
1281
|
+
...image,
|
|
1282
|
+
entry: app.entry,
|
|
1283
|
+
healthCheckPath: "/health"
|
|
1284
|
+
});
|
|
1285
|
+
return generateBackendDockerfile({
|
|
1286
|
+
...image,
|
|
1287
|
+
healthCheckPath: "/health",
|
|
1288
|
+
...options.cache ? { cache: options.cache } : {}
|
|
1289
|
+
});
|
|
1290
|
+
}
|
|
1291
|
+
/** Where `gkm docker` writes a worker's Dockerfile. */
|
|
1292
|
+
function workerDockerfileOf(worker) {
|
|
1293
|
+
return `.gkm/docker/Dockerfile.${worker}`;
|
|
1294
|
+
}
|
|
1295
|
+
/**
|
|
1296
|
+
* A Worker's Dockerfile: its host app's build, and the worker's bundle as the
|
|
1297
|
+
* runner — see `generateWorkerDockerfile`.
|
|
1298
|
+
*/
|
|
1299
|
+
function workerDockerfile(worker, host, options) {
|
|
1300
|
+
const image = appImageOptions(options.layout, worker.app, host, options.workspaceRoot);
|
|
1301
|
+
return generateWorkerDockerfile({
|
|
1302
|
+
...image,
|
|
1303
|
+
imageName: worker.name,
|
|
1304
|
+
port: WORKER_PORT,
|
|
1305
|
+
worker: worker.id,
|
|
1306
|
+
bundle: workerBundleName(worker.id),
|
|
1307
|
+
healthCheckPath: "/health",
|
|
1308
|
+
...options.cache ? { cache: options.cache } : {}
|
|
1309
|
+
});
|
|
1310
|
+
}
|
|
1311
|
+
/**
|
|
1312
|
+
* A file server's processor unit's Dockerfile: its host app's build, and the
|
|
1313
|
+
* unit's bundle as the runner, with its processors' native packages
|
|
1314
|
+
* installed beside it — see `generateProcessorDockerfile`.
|
|
1315
|
+
*/
|
|
1316
|
+
function processorDockerfile(unit, host, options) {
|
|
1317
|
+
const image = appImageOptions(options.layout, unit.app, host, options.workspaceRoot);
|
|
1318
|
+
return generateProcessorDockerfile({
|
|
1319
|
+
...image,
|
|
1320
|
+
imageName: unit.name,
|
|
1321
|
+
port: PROCESSOR_PORT,
|
|
1322
|
+
fileServer: unit.id,
|
|
1323
|
+
bundle: processorBundleName(unit.id),
|
|
1324
|
+
healthCheckPath: "/health",
|
|
1325
|
+
...options.cache ? { cache: options.cache } : {}
|
|
1326
|
+
});
|
|
1327
|
+
}
|
|
1328
|
+
/**
|
|
1329
|
+
* A site's Dockerfile, with an `ARG` for every key its bundler inlines.
|
|
1330
|
+
*
|
|
1331
|
+
* The keys come from the site's declaration where there is one — every
|
|
1332
|
+
* public key its edges give it, `VITE_UPLOADS_SERVER_URL` included — and an
|
|
1333
|
+
* `ARG` the Dockerfile does not declare is a build argument the build drops,
|
|
1334
|
+
* leaving the bundle with an empty URL.
|
|
1335
|
+
*/
|
|
1336
|
+
function siteDockerfile(appName, app, options) {
|
|
1337
|
+
const declared = options.manifest ? Object.entries(options.manifest).find(([id, d]) => d.kind === "site" && appKey(id) === appName)?.[1] : void 0;
|
|
1338
|
+
const publicUrlArgs = options.publicUrlArgs ?? (declared?.kind === "site" && options.manifest ? [provideKey(declared.id, "url"), ...Object.keys(publicEnvFor(declared, options.manifest))] : getPublicUrlArgNames(app));
|
|
1339
|
+
const webOpts = {
|
|
1340
|
+
...options.image,
|
|
1341
|
+
publicUrlArgs
|
|
1342
|
+
};
|
|
1343
|
+
switch (app.framework) {
|
|
1344
|
+
case "vite": return generateViteStaticDockerfile(webOpts);
|
|
1345
|
+
case "tanstack-start":
|
|
1346
|
+
case "remix": return generateNodeWebDockerfile(webOpts);
|
|
1347
|
+
default: return generateNextjsDockerfile(webOpts);
|
|
1348
|
+
}
|
|
1349
|
+
}
|
|
1350
|
+
/**
|
|
1351
|
+
* What a build root's `.dockerignore` must leave out of every image's
|
|
1352
|
+
* context: dependencies installed for another platform, anything built on the
|
|
1353
|
+
* host (every image builds from source), git, and gkm's own output —
|
|
1354
|
+
* `.gkm/compose`'s env files hold a stage's secrets.
|
|
1355
|
+
*/
|
|
1356
|
+
const REQUIRED_IGNORES = [
|
|
1357
|
+
"**/node_modules",
|
|
1358
|
+
".git",
|
|
1359
|
+
"**/dist",
|
|
1360
|
+
"**/.next",
|
|
1361
|
+
"**/.turbo",
|
|
1362
|
+
"**/.gkm",
|
|
1363
|
+
"**/.gkm/compose"
|
|
1364
|
+
];
|
|
1365
|
+
/**
|
|
1366
|
+
* Make sure the build root's `.dockerignore` leaves out what no image may
|
|
1367
|
+
* hold: written whole where there is none, and each missing line appended to
|
|
1368
|
+
* one the project keeps.
|
|
1369
|
+
*/
|
|
1370
|
+
async function ensureDockerignore(buildRoot) {
|
|
1371
|
+
const path = join(buildRoot, ".dockerignore");
|
|
1372
|
+
if (!existsSync(path)) {
|
|
1373
|
+
await writeFile(path, generateDockerignore());
|
|
1374
|
+
return path;
|
|
1375
|
+
}
|
|
1376
|
+
const current = await readFile(path, "utf-8");
|
|
1377
|
+
const lines = new Set(current.split(/\r?\n/).map((line) => line.trim()));
|
|
1378
|
+
const missing = REQUIRED_IGNORES.filter((line) => !lines.has(line));
|
|
1379
|
+
if (missing.length === 0) return path;
|
|
1380
|
+
await appendFile(path, `${current.endsWith("\n") || current === "" ? "" : "\n"}\n# gkm: images build from source, and a stack's env files hold its secrets\n${missing.join("\n")}\n`);
|
|
1381
|
+
return path;
|
|
1382
|
+
}
|
|
1383
|
+
/**
|
|
1384
|
+
* Write `docker-compose.constructs.yml` — the same file `gkm dev` writes, with
|
|
1385
|
+
* the apps beside the containers their constructs derive.
|
|
1386
|
+
*
|
|
1387
|
+
* Through reconcile rather than a second generator, so what `gkm docker`
|
|
1388
|
+
* describes and what `gkm dev` runs cannot disagree. Nothing is started.
|
|
1389
|
+
*/
|
|
1390
|
+
async function writeConstructsCompose(workspace) {
|
|
1391
|
+
await reconcileWorkspace(workspace, {
|
|
1392
|
+
stage: workspace.stages.local,
|
|
1393
|
+
start: false
|
|
1394
|
+
});
|
|
1395
|
+
logger.log(` Generated: ${COMPOSE_PATH} (project root)`);
|
|
1396
|
+
return join(workspace.root, COMPOSE_PATH);
|
|
1397
|
+
}
|
|
1398
|
+
function printRunInstructions(workspace) {
|
|
1399
|
+
const project = existsSync(join(workspace.root, "docker-compose.yml")) ? " -f docker-compose.yml" : "";
|
|
1400
|
+
logger.log("\n📋 Run everything (the apps sit behind the \"apps\" profile):");
|
|
1401
|
+
logger.log(" gkm setup # starts the containers and creates what they hold");
|
|
1402
|
+
logger.log(` docker compose -f ${COMPOSE_PATH}${project} --profile apps up --build`);
|
|
1403
|
+
}
|
|
1404
|
+
//#endregion
|
|
1405
|
+
export { processorInfo as _, ensureDockerignore as a, workerDockerfileOf as c, workerEntryDir as d, QueueGenerator as f, processorEntryDir as g, processorBundleName as h, dockerCommand as i, WorkerGenerator as l, ProcessorGenerator as m, DockerPushFailed as n, processorDockerfile as o, CronGenerator as p, appDockerfile as r, workerDockerfile as s, DockerBuildFailed as t, workerBundleName as u, validateImageRef as v };
|
|
1406
|
+
|
|
1407
|
+
//# sourceMappingURL=docker-CXYz3W2U.mjs.map
|