@geekmidas/cli 10.0.0-alpha.16 → 10.0.0-alpha.160
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 +323 -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-B5BKAoLz.mjs +1039 -0
- package/dist/EndpointGenerator-B5BKAoLz.mjs.map +1 -0
- package/dist/EndpointGenerator-DxrRqfJ3.cjs +1098 -0
- package/dist/EndpointGenerator-DxrRqfJ3.cjs.map +1 -0
- package/dist/GoDaddyProvider-C9dDlH9I.mjs +412 -0
- package/dist/GoDaddyProvider-C9dDlH9I.mjs.map +1 -0
- package/dist/GoDaddyProvider-DkUMcMYy.cjs +412 -0
- package/dist/GoDaddyProvider-DkUMcMYy.cjs.map +1 -0
- package/dist/{HostingerProvider-BZFGYYVA.cjs → HostingerProvider-9faYOQnQ.cjs} +23 -9
- package/dist/HostingerProvider-9faYOQnQ.cjs.map +1 -0
- package/dist/{HostingerProvider-BY26bWwB.mjs → HostingerProvider-BEuKG2gz.mjs} +23 -9
- package/dist/HostingerProvider-BEuKG2gz.mjs.map +1 -0
- package/dist/LegacyStateStore-C44jUnMH.cjs +124 -0
- package/dist/LegacyStateStore-C44jUnMH.cjs.map +1 -0
- package/dist/LegacyStateStore-DPKhjUR6.mjs +124 -0
- package/dist/LegacyStateStore-DPKhjUR6.mjs.map +1 -0
- package/dist/LocalStateStore-B95WE99i.cjs +178 -0
- package/dist/LocalStateStore-B95WE99i.cjs.map +1 -0
- package/dist/LocalStateStore-BU3fWkcT.mjs +167 -0
- package/dist/LocalStateStore-BU3fWkcT.mjs.map +1 -0
- package/dist/OpenApiTsGenerator-DOTLKBFf.cjs +539 -0
- package/dist/OpenApiTsGenerator-DOTLKBFf.cjs.map +1 -0
- package/dist/OpenApiTsGenerator-Vaf0pI8u.mjs +534 -0
- package/dist/OpenApiTsGenerator-Vaf0pI8u.mjs.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-Cpbeijr5.mjs +223 -0
- package/dist/S3StateStore-Cpbeijr5.mjs.map +1 -0
- package/dist/S3StateStore-zU5kClhd.cjs +222 -0
- package/dist/S3StateStore-zU5kClhd.cjs.map +1 -0
- package/dist/SSMStateStore-BxkKMBi_.mjs +205 -0
- package/dist/SSMStateStore-BxkKMBi_.mjs.map +1 -0
- package/dist/SSMStateStore-D9uviQ3T.cjs +204 -0
- package/dist/SSMStateStore-D9uviQ3T.cjs.map +1 -0
- package/dist/SubscriberGenerator-BybB6uez.mjs +783 -0
- package/dist/SubscriberGenerator-BybB6uez.mjs.map +1 -0
- package/dist/SubscriberGenerator-mZpSuSU7.cjs +848 -0
- package/dist/SubscriberGenerator-mZpSuSU7.cjs.map +1 -0
- package/dist/add-Bb2IL3Yq.cjs +713 -0
- package/dist/add-Bb2IL3Yq.cjs.map +1 -0
- package/dist/add-Dj-gtqTO.mjs +711 -0
- package/dist/add-Dj-gtqTO.mjs.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-0vc4Oz9_.cjs +6247 -0
- package/dist/apps-0vc4Oz9_.cjs.map +1 -0
- package/dist/apps-FRNlECwi.mjs +5621 -0
- package/dist/apps-FRNlECwi.mjs.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-BodTL4kf.mjs → bundler-9EM4ZHcu.mjs} +59 -14
- package/dist/bundler-9EM4ZHcu.mjs.map +1 -0
- package/dist/{bundler-BeNDZdHQ.cjs → bundler-Bg2eEFEh.cjs} +59 -14
- package/dist/bundler-Bg2eEFEh.cjs.map +1 -0
- package/dist/cli-CmoSOzNq.mjs +80 -0
- package/dist/cli-CmoSOzNq.mjs.map +1 -0
- package/dist/cli-YtLjcAZT.cjs +80 -0
- package/dist/cli-YtLjcAZT.cjs.map +1 -0
- package/dist/compose-3AtZF7ul.mjs +1560 -0
- package/dist/compose-3AtZF7ul.mjs.map +1 -0
- package/dist/compose-CW1DGfYc.cjs +1919 -0
- package/dist/compose-CW1DGfYc.cjs.map +1 -0
- package/dist/compose-CnXZAYNM.mjs +3068 -0
- package/dist/compose-CnXZAYNM.mjs.map +1 -0
- package/dist/compose-D7gOSspy.cjs +3157 -0
- package/dist/compose-D7gOSspy.cjs.map +1 -0
- package/dist/config-B5Hi3mLK.cjs +821 -0
- package/dist/config-B5Hi3mLK.cjs.map +1 -0
- package/dist/config-BNmLn0dw.d.mts +291 -0
- package/dist/config-BNmLn0dw.d.mts.map +1 -0
- package/dist/config-CkuiD9Jv.d.cts +291 -0
- package/dist/config-CkuiD9Jv.d.cts.map +1 -0
- package/dist/config-DWTUVGRE.mjs +696 -0
- package/dist/config-DWTUVGRE.mjs.map +1 -0
- package/dist/config.cjs +13 -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-CjFtNBVH.mjs +1834 -0
- package/dist/credentials-CjFtNBVH.mjs.map +1 -0
- package/dist/credentials-DwIRfeBL.cjs +2289 -0
- package/dist/credentials-DwIRfeBL.cjs.map +1 -0
- package/dist/databases-C1qqNxTu.mjs +588 -0
- package/dist/databases-C1qqNxTu.mjs.map +1 -0
- package/dist/databases-CrKh5jw6.cjs +703 -0
- package/dist/databases-CrKh5jw6.cjs.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 +658 -0
- package/dist/deploy/public.d.cts.map +1 -0
- package/dist/deploy/public.d.mts +658 -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-3bsiWJxj.cjs +3925 -0
- package/dist/deploy-3bsiWJxj.cjs.map +1 -0
- package/dist/deploy-BI3fHnyb.mjs +3869 -0
- package/dist/deploy-BI3fHnyb.mjs.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-CwayjAF2.cjs +1515 -0
- package/dist/docker-CwayjAF2.cjs.map +1 -0
- package/dist/docker-DPdn7tYJ.mjs +1408 -0
- package/dist/docker-DPdn7tYJ.mjs.map +1 -0
- package/dist/dokploy-BMBL-_Xu.cjs +38 -0
- package/dist/dokploy-BMBL-_Xu.cjs.map +1 -0
- package/dist/dokploy-tmnH0Du_.mjs +38 -0
- package/dist/dokploy-tmnH0Du_.mjs.map +1 -0
- package/dist/drivers-BhdC9Efj.cjs +248 -0
- package/dist/drivers-BhdC9Efj.cjs.map +1 -0
- package/dist/drivers-wcDnzf7l.mjs +213 -0
- package/dist/drivers-wcDnzf7l.mjs.map +1 -0
- package/dist/eas-BVGQAUDc.mjs +334 -0
- package/dist/eas-BVGQAUDc.mjs.map +1 -0
- package/dist/eas-meN1xady.cjs +337 -0
- package/dist/eas-meN1xady.cjs.map +1 -0
- package/dist/emit-C4KSXOeS.mjs +153 -0
- package/dist/emit-C4KSXOeS.mjs.map +1 -0
- package/dist/emit-DiW0kbue.cjs +164 -0
- package/dist/emit-DiW0kbue.cjs.map +1 -0
- package/dist/encryption-C8AMbomA.mjs +89 -0
- package/dist/encryption-C8AMbomA.mjs.map +1 -0
- package/dist/encryption-DvFVZdGz.cjs +90 -0
- package/dist/encryption-DvFVZdGz.cjs.map +1 -0
- package/dist/engine-BbWj0w3F.mjs +3217 -0
- package/dist/engine-BbWj0w3F.mjs.map +1 -0
- package/dist/engine-BmiIUVWa.cjs +3330 -0
- package/dist/engine-BmiIUVWa.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-BWqQr8q6.cjs +901 -0
- package/dist/github-BWqQr8q6.cjs.map +1 -0
- package/dist/github-Dc1daUbH.mjs +900 -0
- package/dist/github-Dc1daUbH.mjs.map +1 -0
- package/dist/googlePlay-ByaFUly7.mjs +931 -0
- package/dist/googlePlay-ByaFUly7.mjs.map +1 -0
- package/dist/googlePlay-CdVCdfU8.cjs +931 -0
- package/dist/googlePlay-CdVCdfU8.cjs.map +1 -0
- package/dist/{index-C-VLwB_Y.d.mts → index-B35vTdAW.d.cts} +38 -14
- package/dist/index-B35vTdAW.d.cts.map +1 -0
- package/dist/{index-C-HkOEBt.d.cts → index-Dv1Zj86i.d.mts} +38 -14
- package/dist/index-Dv1Zj86i.d.mts.map +1 -0
- package/dist/index.cjs +13730 -12325
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +13771 -12364
- package/dist/index.mjs.map +1 -1
- package/dist/local-CnVFHJjS.mjs +224 -0
- package/dist/local-CnVFHJjS.mjs.map +1 -0
- package/dist/local-qevrV6dZ.cjs +241 -0
- package/dist/local-qevrV6dZ.cjs.map +1 -0
- package/dist/migrate-BEuCcCwN.mjs +267 -0
- package/dist/migrate-BEuCcCwN.mjs.map +1 -0
- package/dist/migrate-CRRps1i6.cjs +272 -0
- package/dist/migrate-CRRps1i6.cjs.map +1 -0
- package/dist/migrate-CU8_ZWP1.cjs +181 -0
- package/dist/migrate-CU8_ZWP1.cjs.map +1 -0
- package/dist/migrate-DgfKZB41.mjs +181 -0
- package/dist/migrate-DgfKZB41.mjs.map +1 -0
- package/dist/notes-BrBnyZz5.cjs +500 -0
- package/dist/notes-BrBnyZz5.cjs.map +1 -0
- package/dist/notes-CIzrdBKE.mjs +399 -0
- package/dist/notes-CIzrdBKE.mjs.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-CDJd3prK.mjs +222 -0
- package/dist/projectBucket-CDJd3prK.mjs.map +1 -0
- package/dist/projectBucket-CKr_zObJ.cjs +263 -0
- package/dist/projectBucket-CKr_zObJ.cjs.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-Bq96_QnK.mjs +123 -0
- package/dist/publish-Bq96_QnK.mjs.map +1 -0
- package/dist/publish-DMKXh1Tb.cjs +124 -0
- package/dist/publish-DMKXh1Tb.cjs.map +1 -0
- package/dist/ready-BjFMu_1J.mjs +375 -0
- package/dist/ready-BjFMu_1J.mjs.map +1 -0
- package/dist/ready-eVMJIcWn.cjs +404 -0
- package/dist/ready-eVMJIcWn.cjs.map +1 -0
- package/dist/reconcile/public.cjs +3 -5
- package/dist/reconcile/public.d.cts +33 -89
- package/dist/reconcile/public.d.cts.map +1 -1
- package/dist/reconcile/public.d.mts +33 -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-CSsE7frp.mjs +263 -0
- package/dist/resolve-CSsE7frp.mjs.map +1 -0
- package/dist/resolve-DF9GrosZ.cjs +316 -0
- package/dist/resolve-DF9GrosZ.cjs.map +1 -0
- package/dist/rollback-BBFGGmMa.cjs +165 -0
- package/dist/rollback-BBFGGmMa.cjs.map +1 -0
- package/dist/rollback-CZthwqus.mjs +136 -0
- package/dist/rollback-CZthwqus.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-BBRkezf7.mjs +215 -0
- package/dist/s3-BBRkezf7.mjs.map +1 -0
- package/dist/s3-CI2QYgXH.cjs +215 -0
- package/dist/s3-CI2QYgXH.cjs.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-C4iAABtI.mjs +685 -0
- package/dist/serverSetup-C4iAABtI.mjs.map +1 -0
- package/dist/serverSetup-Dt2DTlwa.cjs +685 -0
- package/dist/serverSetup-Dt2DTlwa.cjs.map +1 -0
- package/dist/sniffer-C2Ot1IbK.mjs +1824 -0
- package/dist/sniffer-C2Ot1IbK.mjs.map +1 -0
- package/dist/sniffer-bTrGuu9z.cjs +1997 -0
- package/dist/sniffer-bTrGuu9z.cjs.map +1 -0
- package/dist/snsSubscriptions-CFKb7fv0.cjs +1173 -0
- package/dist/snsSubscriptions-CFKb7fv0.cjs.map +1 -0
- package/dist/snsSubscriptions-QDDDn9Qi.mjs +1048 -0
- package/dist/snsSubscriptions-QDDDn9Qi.mjs.map +1 -0
- package/dist/sst-DDRWlXdv.mjs +478 -0
- package/dist/sst-DDRWlXdv.mjs.map +1 -0
- package/dist/sst-iRdMlGKd.cjs +501 -0
- package/dist/sst-iRdMlGKd.cjs.map +1 -0
- package/dist/stack-B9iDYMrq.cjs +2431 -0
- package/dist/stack-B9iDYMrq.cjs.map +1 -0
- package/dist/stack-CIOY44aC.mjs +2256 -0
- package/dist/stack-CIOY44aC.mjs.map +1 -0
- package/dist/stage-DA74aD_V.mjs +302 -0
- package/dist/stage-DA74aD_V.mjs.map +1 -0
- package/dist/stage-ycFS9mVn.cjs +313 -0
- package/dist/stage-ycFS9mVn.cjs.map +1 -0
- package/dist/stages-B0yOikgt.cjs +190 -0
- package/dist/stages-B0yOikgt.cjs.map +1 -0
- package/dist/stages-yA9bhStl.mjs +190 -0
- package/dist/stages-yA9bhStl.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-DX22WLvT.mjs +85 -0
- package/dist/terminal-DX22WLvT.mjs.map +1 -0
- package/dist/terminal-RxfbNUwl.cjs +85 -0
- package/dist/terminal-RxfbNUwl.cjs.map +1 -0
- package/dist/types-Bl_CwZC9.cjs +90 -0
- package/dist/types-Bl_CwZC9.cjs.map +1 -0
- package/dist/{types-kvBQjpPo.d.mts → types-Dk--xVOT.d.cts} +2159 -364
- package/dist/types-Dk--xVOT.d.cts.map +1 -0
- package/dist/{types-RhXmHR-e.d.cts → types-DwQYpd_0.d.mts} +2157 -364
- 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 +65 -13
- 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-C-HkOEBt.d.cts.map +0 -1
- package/dist/index-C-VLwB_Y.d.mts.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-RhXmHR-e.d.cts.map +0 -1
- package/dist/types-kvBQjpPo.d.mts.map +0 -1
- package/dist/workspace-CgwmXEtc.mjs.map +0 -1
- package/dist/workspace-mFpI_ky_.cjs.map +0 -1
|
@@ -0,0 +1,3068 @@
|
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-BhDjJH2R.mjs";
|
|
2
|
+
import { t as GkmError } from "./errors-D8Gwp5kU.mjs";
|
|
3
|
+
import { F as toEmbeddableSecrets, M as initStageSecrets, Q as imageRef, a as findRootDomain, m as createComposeState, o as normalizeDnsConfig, ot as run, st as runOutput, v as recordRelease } from "./credentials-CjFtNBVH.mjs";
|
|
4
|
+
import { L as resolveStageTelemetry, ct as ComposeTlsFileMissing, gt as SERVER_IPV4_KEY, yt as isReservedStageKey } from "./workspace-DFGsrjGD.mjs";
|
|
5
|
+
import { C as ensureLocalCertificate, Dt as envFor, E as readLocalAuthority, F as imageLayout, H as findBuildRoot, P as fromBuildRoot, S as ensureLocalAuthority, T as localCertificateNames, Z as nextPrerenderManifest, _t as applyLifecycles, b as bucketClient, bt as applyPostgres, d as backendsOf, f as constructGlobs, gt as applyBuckets, kt as stageEnv, l as workerEnvKeys, pt as backupsRoleStatements, t as appEnvKeys, ut as BACKUPS_SERVICE, v as LEGACY_LOCAL_LOGIN, vt as applyNotifications, wt as postgresStatements, x as pgClient, y as ensurePostgresLogin, yt as applyPolicies, zt as usesTelemetry } from "./apps-FRNlECwi.mjs";
|
|
6
|
+
import { t as defineTarget } from "./define-6poNqm5O.mjs";
|
|
7
|
+
import { E as withRedisPassword, W as primaryPortKey, X as LOGS_SERVICE, Z as logsAccess, m as loadLocalCredentials, tt as withLogsPassword, w as runsRedis, x as REDIS_SERVICE, y as withGeneratedSecrets } from "./compose-3AtZF7ul.mjs";
|
|
8
|
+
import { i as discover } from "./discover-DbDrCQ8h.mjs";
|
|
9
|
+
import { C as traefikStaticFile, E as assertImagesExist, O as pinImages, S as readEdgeClaims, T as RegistryRequired, _ as EDGE_NETWORK, a as composeProject, b as claimsOverlap, d as stackDir, g as EDGE_DYNAMIC_DIR, h as EDGE_CERTS_DIR, i as LOOPBACK_SERVICES, l as envFile, m as EDGE_AWS_CREDENTIALS, n as LOGS_PORT_ENV, o as composeStack, p as withCaddyConfigs, r as LOG_ROTATION, t as EDGE_PORT_ENV, u as replicaNames, v as EDGE_PROJECT, x as edgeComposeFile, y as EDGE_SERVICE } from "./stack-CIOY44aC.mjs";
|
|
10
|
+
import { a as ensureDockerignore } from "./docker-DPdn7tYJ.mjs";
|
|
11
|
+
import { a as subscriptionKey, c as HostNotPointingAtServer, f as requiredServerAddress, g as stageDns, h as stackHosts, i as recordedPushSubscriptions, n as SUBSCRIPTION_TYPE, o as subscriptionResource, p as serverAddressHint, r as confirmPendingSubscriptions, s as topicConnection, t as PushSubscriptionsUnconfirmed, u as isLocalHost, v as systemLookup } from "./snsSubscriptions-QDDDn9Qi.mjs";
|
|
12
|
+
import { i as installedFrom } from "./drivers-wcDnzf7l.mjs";
|
|
13
|
+
import { a as dnsResources, c as currentActor, d as DeployJournal, n as reportDatabaseRuns, o as forgetDnsResource, r as reportPlannedSeeds, s as recordDnsChanges, t as DeploySeedsFailed } from "./seeds-BCC8vAXR.mjs";
|
|
14
|
+
import { f as plannedSeeds, o as SeedFailed, p as seedDatabases, u as migrateDatabases } from "./databases-C1qqNxTu.mjs";
|
|
15
|
+
import { dirname, join, relative } from "node:path";
|
|
16
|
+
import { existsSync } from "node:fs";
|
|
17
|
+
import { chmod, mkdir, readFile, readdir, rm, writeFile } from "node:fs/promises";
|
|
18
|
+
import { hostname, userInfo } from "node:os";
|
|
19
|
+
import { spawn } from "node:child_process";
|
|
20
|
+
import { createConnection, createServer } from "node:net";
|
|
21
|
+
import { createHash } from "node:crypto";
|
|
22
|
+
import { provideKey } from "@geekmidas/manifest";
|
|
23
|
+
import { stringify } from "yaml";
|
|
24
|
+
import { request } from "node:http";
|
|
25
|
+
import { request as request$1 } from "node:https";
|
|
26
|
+
//#region src/compose/docker.ts
|
|
27
|
+
/**
|
|
28
|
+
* The Docker operations `gkm compose` needs, behind an interface.
|
|
29
|
+
*
|
|
30
|
+
* Small on purpose, like reconcile's: the rules about *when* each runs — the
|
|
31
|
+
* registry is asked before anything is pulled, nothing is started for a tag
|
|
32
|
+
* that is missing — are asserted against a fake, and this file is only the
|
|
33
|
+
* wiring to the real CLI.
|
|
34
|
+
*
|
|
35
|
+
* Every call is an argument array. Image refs, tags and paths come from the
|
|
36
|
+
* workspace, and none of them reaches a shell.
|
|
37
|
+
*/
|
|
38
|
+
/** `output` as `spawn` reads it. */
|
|
39
|
+
const STDIO = {
|
|
40
|
+
inherit: "inherit",
|
|
41
|
+
stderr: [
|
|
42
|
+
"ignore",
|
|
43
|
+
2,
|
|
44
|
+
2
|
|
45
|
+
],
|
|
46
|
+
ignore: "ignore"
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* The environment a docker command for `engine` runs with: this process's,
|
|
50
|
+
* with `DOCKER_HOST` pointing at the stack's engine when it is a server's.
|
|
51
|
+
*/
|
|
52
|
+
function engineEnv(engine, extra = {}) {
|
|
53
|
+
if (!engine.host && Object.keys(extra).length === 0) return void 0;
|
|
54
|
+
return {
|
|
55
|
+
...process.env,
|
|
56
|
+
...extra,
|
|
57
|
+
...engine.host ? { DOCKER_HOST: engine.host } : {}
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
/** How a stack's docker commands run: where it is, where output goes. */
|
|
61
|
+
function runOptions(stack, extra) {
|
|
62
|
+
const env = engineEnv(stack, extra);
|
|
63
|
+
return {
|
|
64
|
+
cwd: stack.cwd,
|
|
65
|
+
stdio: STDIO[stack.output ?? "inherit"],
|
|
66
|
+
...env ? { env } : {},
|
|
67
|
+
...stack.signal ? { signal: stack.signal } : {}
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
/** The network compose puts a project's services on. */
|
|
71
|
+
function projectNetwork(project) {
|
|
72
|
+
return `${project}_default`;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* The host ports a `docker ps` Ports column publishes: `0.0.0.0:443->443/tcp,
|
|
76
|
+
* [::]:443->443/tcp, 0.0.0.0:9000-9001->9000-9001/tcp`.
|
|
77
|
+
*/
|
|
78
|
+
function publishedPorts(column) {
|
|
79
|
+
const ports = /* @__PURE__ */ new Set();
|
|
80
|
+
for (const match of column.matchAll(/(?:[\d.]+|\[[^\]]*\]):(\d+)(?:-(\d+))?->/g)) {
|
|
81
|
+
const first = Number(match[1]);
|
|
82
|
+
const last = match[2] ? Number(match[2]) : first;
|
|
83
|
+
for (let port = first; port <= last; port++) ports.add(port);
|
|
84
|
+
}
|
|
85
|
+
return [...ports];
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* The host port a `docker ps` Ports column publishes for `inside`:
|
|
89
|
+
* `127.0.0.1:54321->5432/tcp` is 54321.
|
|
90
|
+
*/
|
|
91
|
+
function publishedPort(column, inside) {
|
|
92
|
+
const match = new RegExp(`(?:[\\d.]+|\\[[^\\]]*\\]):(\\d+)->${inside}/tcp`).exec(column);
|
|
93
|
+
return match ? Number(match[1]) : void 0;
|
|
94
|
+
}
|
|
95
|
+
/** Each line `docker ps` printed, as the containers holding `port`. */
|
|
96
|
+
function portHolders(output, port) {
|
|
97
|
+
return output.split("\n").filter(Boolean).map((line) => line.split(" ")).filter(([, , , column = ""]) => publishedPorts(column).includes(port)).map(([container = "", project, service]) => ({
|
|
98
|
+
container,
|
|
99
|
+
...project ? { project } : {},
|
|
100
|
+
...service ? { service } : {}
|
|
101
|
+
}));
|
|
102
|
+
}
|
|
103
|
+
/** How long a stack has to pass its health checks. */
|
|
104
|
+
const WAIT_TIMEOUT_S = 180;
|
|
105
|
+
/** `docker` itself failed, before it could say anything about a service. */
|
|
106
|
+
var DockerUnreachable = class extends GkmError {
|
|
107
|
+
engine;
|
|
108
|
+
stderr;
|
|
109
|
+
constructor(engine, stderr) {
|
|
110
|
+
super(`Could not ask Docker on ${engine} which ports its services publish (docker said: ${stderr.trim() || "nothing"}). Check that \`DOCKER_HOST=${engine} docker ps\` works from here.`);
|
|
111
|
+
this.engine = engine;
|
|
112
|
+
this.stderr = stderr;
|
|
113
|
+
this.name = "DockerUnreachable";
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
/** `docker compose port` printed nothing a port can be read from. */
|
|
117
|
+
var ServicePortUnknown = class extends GkmError {
|
|
118
|
+
service;
|
|
119
|
+
inside;
|
|
120
|
+
output;
|
|
121
|
+
constructor(service, inside, output) {
|
|
122
|
+
super(`'${service}' publishes no host port for ${inside} (docker said: ${output.trim() || "nothing"}). Is it running? \`docker compose ps\` shows the stack.`);
|
|
123
|
+
this.service = service;
|
|
124
|
+
this.inside = inside;
|
|
125
|
+
this.output = output;
|
|
126
|
+
this.name = "ServicePortUnknown";
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
/**
|
|
130
|
+
* Whether `ref` names a registry on this machine's loopback — which the
|
|
131
|
+
* daemon pulls from and pushes to over plain HTTP by default, and `docker
|
|
132
|
+
* manifest inspect` reaches only when told `--insecure` (without it, a local
|
|
133
|
+
* registry's image is reported as no such manifest).
|
|
134
|
+
*/
|
|
135
|
+
function isLoopbackRegistry(ref) {
|
|
136
|
+
const first = ref.split("/")[0];
|
|
137
|
+
if (!ref.includes("/") || !/[.:]|^localhost$/.test(first)) return false;
|
|
138
|
+
const host = first.replace(/:\d+$/, "");
|
|
139
|
+
return host === "localhost" || /^127(?:\.\d{1,3}){3}$/.test(host);
|
|
140
|
+
}
|
|
141
|
+
/** `docker push` finished without saying what digest the registry stored. */
|
|
142
|
+
var PushDigestUnknown = class extends GkmError {
|
|
143
|
+
ref;
|
|
144
|
+
output;
|
|
145
|
+
constructor(ref, output) {
|
|
146
|
+
super(`Pushed ${ref}, but docker did not say which digest the registry stored (it said: ${output.trim().split("\n").slice(-3).join(" / ") || "nothing"}). Check the push with \`docker buildx imagetools inspect ${ref}\`.`);
|
|
147
|
+
this.ref = ref;
|
|
148
|
+
this.output = output;
|
|
149
|
+
this.name = "PushDigestUnknown";
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
/** The digest `docker push` reports last: `<tag>: digest: sha256:… size: …`. */
|
|
153
|
+
function pushedDigest(output) {
|
|
154
|
+
return [...output.matchAll(/digest: (sha256:[0-9a-f]{64})/g)].at(-1)?.[1];
|
|
155
|
+
}
|
|
156
|
+
function compose(stack, args) {
|
|
157
|
+
return [
|
|
158
|
+
"compose",
|
|
159
|
+
"-p",
|
|
160
|
+
stack.project,
|
|
161
|
+
"-f",
|
|
162
|
+
stack.file,
|
|
163
|
+
...(stack.overrides ?? []).flatMap((file) => ["-f", file]),
|
|
164
|
+
...args
|
|
165
|
+
];
|
|
166
|
+
}
|
|
167
|
+
/** Run a program and keep everything it said, whatever it exits with. */
|
|
168
|
+
function capture(command, args, options = {}) {
|
|
169
|
+
const { timeoutMs = 6e4 } = options;
|
|
170
|
+
return new Promise((resolve, reject) => {
|
|
171
|
+
const child = spawn(command, [...args], {
|
|
172
|
+
stdio: [
|
|
173
|
+
options.input === void 0 ? "ignore" : "pipe",
|
|
174
|
+
"pipe",
|
|
175
|
+
"pipe"
|
|
176
|
+
],
|
|
177
|
+
shell: false,
|
|
178
|
+
...options.env ? { env: options.env } : {}
|
|
179
|
+
});
|
|
180
|
+
if (options.input !== void 0) child.stdin?.end(options.input);
|
|
181
|
+
let stdout = "";
|
|
182
|
+
let stderr = "";
|
|
183
|
+
child.stdout?.on("data", (chunk) => {
|
|
184
|
+
stdout += chunk.toString();
|
|
185
|
+
});
|
|
186
|
+
child.stderr?.on("data", (chunk) => {
|
|
187
|
+
stderr += chunk.toString();
|
|
188
|
+
});
|
|
189
|
+
const timer = setTimeout(() => child.kill("SIGKILL"), timeoutMs);
|
|
190
|
+
timer.unref?.();
|
|
191
|
+
child.on("error", (error) => {
|
|
192
|
+
clearTimeout(timer);
|
|
193
|
+
reject(error);
|
|
194
|
+
});
|
|
195
|
+
child.on("close", (code) => {
|
|
196
|
+
clearTimeout(timer);
|
|
197
|
+
resolve({
|
|
198
|
+
code,
|
|
199
|
+
stdout,
|
|
200
|
+
stderr
|
|
201
|
+
});
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Whether a failed `docker manifest inspect` means the tag is not there, as
|
|
207
|
+
* opposed to the registry not answering.
|
|
208
|
+
*
|
|
209
|
+
* Read off the message because that is all the CLI gives. Anything not
|
|
210
|
+
* recognisably "no such tag" is treated as the registry being unreachable:
|
|
211
|
+
* a registry that refused credentials must not be reported as a tag that was
|
|
212
|
+
* never pushed, or the fix offered would be the wrong one.
|
|
213
|
+
*/
|
|
214
|
+
function isMissingManifest(output) {
|
|
215
|
+
return /no such manifest|manifest unknown|manifest for .* not found|not found: manifest/i.test(output);
|
|
216
|
+
}
|
|
217
|
+
const dockerCompose = {
|
|
218
|
+
async lookup(ref) {
|
|
219
|
+
const { code, stdout, stderr } = await capture("docker", [
|
|
220
|
+
"manifest",
|
|
221
|
+
"inspect",
|
|
222
|
+
...isLoopbackRegistry(ref) ? ["--insecure"] : [],
|
|
223
|
+
ref
|
|
224
|
+
]);
|
|
225
|
+
if (code === 0) return {
|
|
226
|
+
ref,
|
|
227
|
+
status: "found"
|
|
228
|
+
};
|
|
229
|
+
const output = `${stderr}\n${stdout}`.trim();
|
|
230
|
+
return isMissingManifest(output) ? {
|
|
231
|
+
ref,
|
|
232
|
+
status: "missing"
|
|
233
|
+
} : {
|
|
234
|
+
ref,
|
|
235
|
+
status: "unreachable",
|
|
236
|
+
detail: output
|
|
237
|
+
};
|
|
238
|
+
},
|
|
239
|
+
async build(stack, services) {
|
|
240
|
+
await run("docker", compose(stack, ["build", ...services]), runOptions(stack, {
|
|
241
|
+
...process.env,
|
|
242
|
+
DOCKER_BUILDKIT: "1"
|
|
243
|
+
}));
|
|
244
|
+
},
|
|
245
|
+
async pull(stack, services) {
|
|
246
|
+
await run("docker", compose(stack, ["pull", ...services]), runOptions(stack));
|
|
247
|
+
},
|
|
248
|
+
async up(stack, services) {
|
|
249
|
+
await run("docker", compose(stack, [
|
|
250
|
+
"up",
|
|
251
|
+
"-d",
|
|
252
|
+
"--wait",
|
|
253
|
+
`--wait-timeout=${WAIT_TIMEOUT_S}`,
|
|
254
|
+
...services ? [] : ["--remove-orphans"],
|
|
255
|
+
...services ?? []
|
|
256
|
+
]), runOptions(stack));
|
|
257
|
+
},
|
|
258
|
+
async down(stack) {
|
|
259
|
+
await run("docker", compose(stack, ["down"]), runOptions(stack));
|
|
260
|
+
},
|
|
261
|
+
async port(stack, service, inside) {
|
|
262
|
+
const env = engineEnv(stack);
|
|
263
|
+
const output = await runOutput("docker", compose(stack, [
|
|
264
|
+
"port",
|
|
265
|
+
service,
|
|
266
|
+
String(inside)
|
|
267
|
+
]), {
|
|
268
|
+
cwd: stack.cwd,
|
|
269
|
+
...env ? { env } : {},
|
|
270
|
+
...stack.signal ? { signal: stack.signal } : {}
|
|
271
|
+
});
|
|
272
|
+
const port = Number(output.trim().split(":").pop());
|
|
273
|
+
if (!Number.isInteger(port) || port <= 0) throw new ServicePortUnknown(service, inside, output);
|
|
274
|
+
return port;
|
|
275
|
+
},
|
|
276
|
+
async health(stack, service) {
|
|
277
|
+
const env = engineEnv(stack);
|
|
278
|
+
const { code, stdout } = await capture("docker", compose(stack, [
|
|
279
|
+
"ps",
|
|
280
|
+
"--format",
|
|
281
|
+
"{{.Health}}",
|
|
282
|
+
service
|
|
283
|
+
]), env ? { env } : {});
|
|
284
|
+
if (code !== 0) return void 0;
|
|
285
|
+
return stdout.trim().split("\n")[0] || void 0;
|
|
286
|
+
},
|
|
287
|
+
async push(stack, ref) {
|
|
288
|
+
const output = await runOutput("docker", ["push", ref], {
|
|
289
|
+
cwd: stack.cwd,
|
|
290
|
+
...stack.signal ? { signal: stack.signal } : {}
|
|
291
|
+
});
|
|
292
|
+
const digest = pushedDigest(output);
|
|
293
|
+
if (!digest) throw new PushDigestUnknown(ref, output);
|
|
294
|
+
return digest;
|
|
295
|
+
},
|
|
296
|
+
async digest(engine, ref) {
|
|
297
|
+
const env = engineEnv(engine);
|
|
298
|
+
const { code, stdout } = await capture("docker", [
|
|
299
|
+
"image",
|
|
300
|
+
"inspect",
|
|
301
|
+
"--format={{json .RepoDigests}} {{.Id}}",
|
|
302
|
+
ref
|
|
303
|
+
], env ? { env } : {});
|
|
304
|
+
if (code !== 0) return void 0;
|
|
305
|
+
const [json = "[]", id] = stdout.trim().split(" ");
|
|
306
|
+
const repository = ref.split("@")[0].replace(/:[\w][\w.-]*$/, "");
|
|
307
|
+
try {
|
|
308
|
+
const digests = JSON.parse(json);
|
|
309
|
+
const match = Array.isArray(digests) ? digests.find((entry) => typeof entry === "string" && entry.startsWith(`${repository}@`)) : void 0;
|
|
310
|
+
if (match) return match.slice(repository.length + 1);
|
|
311
|
+
} catch {}
|
|
312
|
+
return id || void 0;
|
|
313
|
+
},
|
|
314
|
+
async ensureNetwork(engine, name) {
|
|
315
|
+
const env = engineEnv(engine);
|
|
316
|
+
const options = env ? { env } : {};
|
|
317
|
+
const { code } = await capture("docker", [
|
|
318
|
+
"network",
|
|
319
|
+
"inspect",
|
|
320
|
+
name
|
|
321
|
+
], options);
|
|
322
|
+
if (code === 0) return;
|
|
323
|
+
const created = await capture("docker", [
|
|
324
|
+
"network",
|
|
325
|
+
"create",
|
|
326
|
+
name
|
|
327
|
+
], options);
|
|
328
|
+
if (created.code !== 0 && !/already exists/.test(created.stderr)) throw new NetworkCreateFailed(name, created.stderr);
|
|
329
|
+
},
|
|
330
|
+
async publishers(engine, port) {
|
|
331
|
+
const env = engineEnv(engine);
|
|
332
|
+
const { stdout } = await capture("docker", [
|
|
333
|
+
"ps",
|
|
334
|
+
"--format",
|
|
335
|
+
"{{.Names}} {{.Label \"com.docker.compose.project\"}} {{.Label \"com.docker.compose.service\"}} {{.Ports}}"
|
|
336
|
+
], env ? { env } : {});
|
|
337
|
+
return portHolders(stdout, port);
|
|
338
|
+
},
|
|
339
|
+
async exec(stack, service, command, input) {
|
|
340
|
+
const env = engineEnv(stack);
|
|
341
|
+
const options = env ? { env } : {};
|
|
342
|
+
const { stdout: ids } = await capture("docker", [
|
|
343
|
+
"ps",
|
|
344
|
+
"-q",
|
|
345
|
+
"--filter",
|
|
346
|
+
`label=com.docker.compose.project=${stack.project}`,
|
|
347
|
+
"--filter",
|
|
348
|
+
`label=com.docker.compose.service=${service}`
|
|
349
|
+
], options);
|
|
350
|
+
const container = ids.trim().split("\n")[0];
|
|
351
|
+
if (!container) return {
|
|
352
|
+
code: null,
|
|
353
|
+
stdout: "",
|
|
354
|
+
stderr: `${service} is not running`
|
|
355
|
+
};
|
|
356
|
+
return capture("docker", [
|
|
357
|
+
"exec",
|
|
358
|
+
...input === void 0 ? [] : ["-i"],
|
|
359
|
+
container,
|
|
360
|
+
...command
|
|
361
|
+
], {
|
|
362
|
+
...options,
|
|
363
|
+
...input === void 0 ? {} : { input }
|
|
364
|
+
});
|
|
365
|
+
},
|
|
366
|
+
async container(engine, project, service) {
|
|
367
|
+
const env = engineEnv(engine);
|
|
368
|
+
const { stdout } = await capture("docker", [
|
|
369
|
+
"ps",
|
|
370
|
+
"--filter",
|
|
371
|
+
`label=com.docker.compose.project=${project}`,
|
|
372
|
+
"--filter",
|
|
373
|
+
`label=com.docker.compose.service=${service}`,
|
|
374
|
+
"--format",
|
|
375
|
+
"{{.ID}} {{.Image}}"
|
|
376
|
+
], env ? { env } : {});
|
|
377
|
+
const [id, image] = stdout.trim().split("\n")[0]?.split(" ") ?? [];
|
|
378
|
+
return id && image ? {
|
|
379
|
+
id,
|
|
380
|
+
image
|
|
381
|
+
} : void 0;
|
|
382
|
+
},
|
|
383
|
+
async published(engine, project, service, inside) {
|
|
384
|
+
const env = engineEnv(engine);
|
|
385
|
+
const { code, stdout, stderr } = await capture("docker", [
|
|
386
|
+
"ps",
|
|
387
|
+
"--filter",
|
|
388
|
+
`label=com.docker.compose.project=${project}`,
|
|
389
|
+
"--filter",
|
|
390
|
+
`label=com.docker.compose.service=${service}`,
|
|
391
|
+
"--format",
|
|
392
|
+
"{{.Ports}}"
|
|
393
|
+
], env ? { env } : {});
|
|
394
|
+
if (code !== 0) throw new DockerUnreachable(engine.host ?? "this machine", stderr);
|
|
395
|
+
return publishedPort(stdout, inside);
|
|
396
|
+
},
|
|
397
|
+
runOnce(engine, options) {
|
|
398
|
+
return dockerExit([
|
|
399
|
+
"run",
|
|
400
|
+
"--rm",
|
|
401
|
+
...options.stdin ? ["-i"] : [],
|
|
402
|
+
"--network",
|
|
403
|
+
options.network,
|
|
404
|
+
...Object.keys(options.env ?? {}).flatMap((name) => ["-e", name]),
|
|
405
|
+
"--entrypoint",
|
|
406
|
+
"",
|
|
407
|
+
options.image,
|
|
408
|
+
...options.command
|
|
409
|
+
], {
|
|
410
|
+
env: engineEnv(engine, { ...options.env }) ?? process.env,
|
|
411
|
+
...options.stdin ? { stdin: options.stdin } : {},
|
|
412
|
+
...options.output ? { output: options.output } : {}
|
|
413
|
+
});
|
|
414
|
+
}
|
|
415
|
+
};
|
|
416
|
+
/** Spawn `docker`, its output where `output` says; resolve with the exit code. */
|
|
417
|
+
function dockerExit(args, options = {}) {
|
|
418
|
+
const output = STDIO[options.output ?? "inherit"];
|
|
419
|
+
const out = Array.isArray(output) ? output : [
|
|
420
|
+
output,
|
|
421
|
+
output,
|
|
422
|
+
output
|
|
423
|
+
];
|
|
424
|
+
return new Promise((resolve, reject) => {
|
|
425
|
+
const child = spawn("docker", [...args], {
|
|
426
|
+
stdio: [
|
|
427
|
+
options.stdin ? "pipe" : "ignore",
|
|
428
|
+
out[1],
|
|
429
|
+
out[2]
|
|
430
|
+
],
|
|
431
|
+
env: options.env ?? process.env,
|
|
432
|
+
shell: false
|
|
433
|
+
});
|
|
434
|
+
if (options.stdin && child.stdin) {
|
|
435
|
+
options.stdin.on("error", (error) => child.stdin?.destroy(error));
|
|
436
|
+
child.stdin.on("error", () => {});
|
|
437
|
+
options.stdin.pipe(child.stdin);
|
|
438
|
+
}
|
|
439
|
+
child.on("error", reject);
|
|
440
|
+
child.on("close", (code) => resolve(code ?? 1));
|
|
441
|
+
});
|
|
442
|
+
}
|
|
443
|
+
/** `docker network create` failed. */
|
|
444
|
+
var NetworkCreateFailed = class extends GkmError {
|
|
445
|
+
network;
|
|
446
|
+
output;
|
|
447
|
+
constructor(network, output) {
|
|
448
|
+
super(`Could not create the Docker network '${network}' (docker said: ${output.trim() || "nothing"}). Create it by hand with \`docker network create ${network}\` and run again.`);
|
|
449
|
+
this.network = network;
|
|
450
|
+
this.output = output;
|
|
451
|
+
this.name = "NetworkCreateFailed";
|
|
452
|
+
}
|
|
453
|
+
};
|
|
454
|
+
//#endregion
|
|
455
|
+
//#region src/compose/server.ts
|
|
456
|
+
/**
|
|
457
|
+
* Where a deployed compose stage runs: its server, reached over SSH.
|
|
458
|
+
*
|
|
459
|
+
* gkm never runs on the server. It runs where the deploy is started — a CI
|
|
460
|
+
* runner, a developer's machine — and drives the server's Docker engine over
|
|
461
|
+
* SSH (`DOCKER_HOST=ssh://user@host`), so the server holds Docker, an SSH
|
|
462
|
+
* login and nothing else: no gkm, no checkout, no cloud credentials.
|
|
463
|
+
*
|
|
464
|
+
* ```ts
|
|
465
|
+
* deploy: { compose: { server: { production: { user: 'deploy' } } } }
|
|
466
|
+
* ```
|
|
467
|
+
*
|
|
468
|
+
* The host is the stage's `GKM_SERVER_IPV4` secret — the address its DNS
|
|
469
|
+
* records already point at — unless `host` names another. The local stage is
|
|
470
|
+
* never given one: it runs on this machine's Docker.
|
|
471
|
+
*
|
|
472
|
+
* What the deploy needs from inside the server — Postgres and MinIO, published
|
|
473
|
+
* on the server's loopback alone — it reaches through an SSH tunnel on the same
|
|
474
|
+
* login, so neither is ever published publicly.
|
|
475
|
+
*/
|
|
476
|
+
/** A deployed compose stage with nowhere to run. */
|
|
477
|
+
var ComposeServerMissing = class extends GkmError {
|
|
478
|
+
stage;
|
|
479
|
+
missing;
|
|
480
|
+
constructor(stage, missing) {
|
|
481
|
+
super(missing === "config" ? `'${stage}' is a deployed stage, and gkm deploys it to its server's Docker over SSH — it never starts a deployed stage on this machine's Docker. Name the login in gkm.config.ts: deploy: { compose: { server: { ${stage}: { user: 'deploy' } } } } — the host is the stage's ${SERVER_IPV4_KEY} secret (gkm secrets:set ${SERVER_IPV4_KEY} '<ip>' --stage ${stage}), or set host there too.` : `deploy.compose.server.${stage} names no host, and '${stage}' has no ${SERVER_IPV4_KEY} secret to default to. Set it: gkm secrets:set ${SERVER_IPV4_KEY} '<ip>' --stage ${stage} — or set deploy.compose.server.${stage}.host.`);
|
|
482
|
+
this.stage = stage;
|
|
483
|
+
this.missing = missing;
|
|
484
|
+
this.name = "ComposeServerMissing";
|
|
485
|
+
}
|
|
486
|
+
};
|
|
487
|
+
/** SSH to the stage's server failed before anything was changed there. */
|
|
488
|
+
var ComposeServerUnreachable = class extends GkmError {
|
|
489
|
+
target;
|
|
490
|
+
stderr;
|
|
491
|
+
constructor(target, stderr) {
|
|
492
|
+
super(`Could not reach Docker on ${target} over SSH (ssh said: ${stderr.trim() || "nothing"}). Check that \`ssh ${target} docker version\` works from here: the host key in ~/.ssh/known_hosts, the key in your agent or ~/.ssh/config, and the user in the server's docker group.`);
|
|
493
|
+
this.target = target;
|
|
494
|
+
this.stderr = stderr;
|
|
495
|
+
this.name = "ComposeServerUnreachable";
|
|
496
|
+
}
|
|
497
|
+
};
|
|
498
|
+
/** An SSH tunnel to a port on the server's loopback did not open. */
|
|
499
|
+
var ComposeTunnelFailed = class extends GkmError {
|
|
500
|
+
target;
|
|
501
|
+
remotePort;
|
|
502
|
+
stderr;
|
|
503
|
+
constructor(target, remotePort, stderr) {
|
|
504
|
+
super(`Could not open an SSH tunnel to 127.0.0.1:${remotePort} on ${target} (ssh said: ${stderr.trim() || "nothing"}). The server's sshd must allow TCP forwarding for the deploy user (AllowTcpForwarding yes, the default, or local), and its key in ~/.ssh/authorized_keys must too: a key installed with \`restrict\` refuses forwarding unless it also says \`port-forwarding\` (\`restrict,port-forwarding ssh-ed25519 …\`).`);
|
|
505
|
+
this.target = target;
|
|
506
|
+
this.remotePort = remotePort;
|
|
507
|
+
this.stderr = stderr;
|
|
508
|
+
this.name = "ComposeTunnelFailed";
|
|
509
|
+
}
|
|
510
|
+
};
|
|
511
|
+
/**
|
|
512
|
+
* The stage's server: its login from `deploy.compose.server.<stage>`, its
|
|
513
|
+
* host from there or the stage's `GKM_SERVER_IPV4`. Undefined for the local
|
|
514
|
+
* stage, which runs on this machine.
|
|
515
|
+
*
|
|
516
|
+
* @throws {ComposeServerMissing} for a deployed stage with no login or host
|
|
517
|
+
*/
|
|
518
|
+
function composeServer(options) {
|
|
519
|
+
const { stage } = options;
|
|
520
|
+
if (options.local) return void 0;
|
|
521
|
+
const config = options.config?.[stage];
|
|
522
|
+
if (!config) throw new ComposeServerMissing(stage, "config");
|
|
523
|
+
const host = config.host ?? options.custom?.["GKM_SERVER_IPV4"]?.trim();
|
|
524
|
+
if (!host) throw new ComposeServerMissing(stage, "host");
|
|
525
|
+
return {
|
|
526
|
+
user: config.user,
|
|
527
|
+
host,
|
|
528
|
+
port: config.port ?? 22
|
|
529
|
+
};
|
|
530
|
+
}
|
|
531
|
+
/** `user@host`, as a person types it after `ssh`. */
|
|
532
|
+
function sshTarget(server) {
|
|
533
|
+
return `${server.user}@${server.host}`;
|
|
534
|
+
}
|
|
535
|
+
/** The server's Docker engine, as `DOCKER_HOST` names it. */
|
|
536
|
+
function dockerHost(server) {
|
|
537
|
+
const host = server.host.includes(":") ? `[${server.host}]` : server.host;
|
|
538
|
+
return `ssh://${server.user}@${host}${server.port === 22 ? "" : `:${server.port}`}`;
|
|
539
|
+
}
|
|
540
|
+
/** The arguments every `ssh` gkm runs starts with: no prompt, ever. */
|
|
541
|
+
function sshArgs(server) {
|
|
542
|
+
return [
|
|
543
|
+
"-o",
|
|
544
|
+
"BatchMode=yes",
|
|
545
|
+
"-o",
|
|
546
|
+
"ConnectTimeout=20",
|
|
547
|
+
"-p",
|
|
548
|
+
String(server.port),
|
|
549
|
+
sshTarget(server)
|
|
550
|
+
];
|
|
551
|
+
}
|
|
552
|
+
async function freeLocalPort() {
|
|
553
|
+
const server = createServer();
|
|
554
|
+
await new Promise((resolve, reject) => {
|
|
555
|
+
server.once("error", reject);
|
|
556
|
+
server.listen(0, "127.0.0.1", resolve);
|
|
557
|
+
});
|
|
558
|
+
const address = server.address();
|
|
559
|
+
await new Promise((resolve) => server.close(resolve));
|
|
560
|
+
if (!address || typeof address === "string") return 0;
|
|
561
|
+
return address.port;
|
|
562
|
+
}
|
|
563
|
+
function connects(port) {
|
|
564
|
+
return new Promise((resolve) => {
|
|
565
|
+
const socket = createConnection({
|
|
566
|
+
host: "127.0.0.1",
|
|
567
|
+
port
|
|
568
|
+
});
|
|
569
|
+
socket.once("connect", () => {
|
|
570
|
+
socket.destroy();
|
|
571
|
+
resolve(true);
|
|
572
|
+
});
|
|
573
|
+
socket.once("error", () => resolve(false));
|
|
574
|
+
});
|
|
575
|
+
}
|
|
576
|
+
/** The real one: the system's `ssh`, with the user's keys and known hosts. */
|
|
577
|
+
const sshAccess = {
|
|
578
|
+
check(server) {
|
|
579
|
+
return new Promise((resolve, reject) => {
|
|
580
|
+
const child = spawn("ssh", [
|
|
581
|
+
...sshArgs(server),
|
|
582
|
+
"docker",
|
|
583
|
+
"version",
|
|
584
|
+
"--format",
|
|
585
|
+
"{{.Server.Version}}"
|
|
586
|
+
], { stdio: [
|
|
587
|
+
"ignore",
|
|
588
|
+
"ignore",
|
|
589
|
+
"pipe"
|
|
590
|
+
] });
|
|
591
|
+
let stderr = "";
|
|
592
|
+
child.stderr.on("data", (chunk) => {
|
|
593
|
+
stderr += chunk.toString();
|
|
594
|
+
});
|
|
595
|
+
child.on("error", (error) => reject(new ComposeServerUnreachable(sshTarget(server), error.message)));
|
|
596
|
+
child.on("close", (code) => code === 0 ? resolve() : reject(new ComposeServerUnreachable(sshTarget(server), stderr)));
|
|
597
|
+
});
|
|
598
|
+
},
|
|
599
|
+
async tunnel(server, remotePort) {
|
|
600
|
+
const port = await freeLocalPort();
|
|
601
|
+
const child = spawn("ssh", [
|
|
602
|
+
"-N",
|
|
603
|
+
"-o",
|
|
604
|
+
"ExitOnForwardFailure=yes",
|
|
605
|
+
"-o",
|
|
606
|
+
"ControlPath=none",
|
|
607
|
+
"-L",
|
|
608
|
+
`127.0.0.1:${port}:127.0.0.1:${remotePort}`,
|
|
609
|
+
...sshArgs(server)
|
|
610
|
+
], { stdio: [
|
|
611
|
+
"ignore",
|
|
612
|
+
"ignore",
|
|
613
|
+
"pipe"
|
|
614
|
+
] });
|
|
615
|
+
let stderr = "";
|
|
616
|
+
let exited = false;
|
|
617
|
+
child.stderr.on("data", (chunk) => {
|
|
618
|
+
stderr += chunk.toString();
|
|
619
|
+
});
|
|
620
|
+
child.on("exit", () => {
|
|
621
|
+
exited = true;
|
|
622
|
+
});
|
|
623
|
+
child.on("error", (error) => {
|
|
624
|
+
exited = true;
|
|
625
|
+
stderr += error.message;
|
|
626
|
+
});
|
|
627
|
+
const close = async () => {
|
|
628
|
+
if (exited) return;
|
|
629
|
+
const gone = new Promise((resolve) => child.once("exit", resolve));
|
|
630
|
+
child.kill("SIGTERM");
|
|
631
|
+
await gone;
|
|
632
|
+
};
|
|
633
|
+
for (let attempt = 0; attempt < 150; attempt++) {
|
|
634
|
+
if (exited) break;
|
|
635
|
+
if (await connects(port)) return {
|
|
636
|
+
port,
|
|
637
|
+
close
|
|
638
|
+
};
|
|
639
|
+
await new Promise((resolve) => setTimeout(resolve, 200));
|
|
640
|
+
}
|
|
641
|
+
await close();
|
|
642
|
+
throw new ComposeTunnelFailed(sshTarget(server), remotePort, stderr);
|
|
643
|
+
}
|
|
644
|
+
};
|
|
645
|
+
//#endregion
|
|
646
|
+
//#region src/compose/edge.ts
|
|
647
|
+
/**
|
|
648
|
+
* The server's shared Traefik edge, in Docker: started when a stack needs it,
|
|
649
|
+
* and each stack's routes written to — and removed from — the directory it
|
|
650
|
+
* watches.
|
|
651
|
+
*
|
|
652
|
+
* Everything goes through the server's Docker engine, never its filesystem:
|
|
653
|
+
* the edge's static configuration is handed to it inline, and the directories
|
|
654
|
+
* it watches are volumes each stack writes into with `docker exec`. So the
|
|
655
|
+
* deploy runs anywhere that reaches the engine — a CI runner over SSH — and
|
|
656
|
+
* nothing it writes depends on a path on that machine.
|
|
657
|
+
*
|
|
658
|
+
* gkm-edge (compose project — `GKM_EDGE_PROJECT` renames it)
|
|
659
|
+
* traefik.yml its static configuration (inline config)
|
|
660
|
+
* dynamic/<project>.yml one per stack: routers, services, middlewares
|
|
661
|
+
* certs/<project>.crt|.key a stack's own certificate, where it has one
|
|
662
|
+
*/
|
|
663
|
+
/** The edge's compose project, as docker is asked about it. */
|
|
664
|
+
function edgeRef(file, options = {}) {
|
|
665
|
+
return {
|
|
666
|
+
project: EDGE_PROJECT,
|
|
667
|
+
file,
|
|
668
|
+
cwd: dirname(file),
|
|
669
|
+
...options
|
|
670
|
+
};
|
|
671
|
+
}
|
|
672
|
+
/** Writing to or removing from the edge's volumes failed. */
|
|
673
|
+
var EdgeWriteFailed = class extends GkmError {
|
|
674
|
+
path;
|
|
675
|
+
output;
|
|
676
|
+
constructor(path, output) {
|
|
677
|
+
super(`Could not write ${path} in the shared edge (${EDGE_PROJECT}): ${output.trim() || "it is not running"}. Check it with \`docker compose -p ${EDGE_PROJECT} ps\` on the server, and run gkm compose again.`);
|
|
678
|
+
this.path = path;
|
|
679
|
+
this.output = output;
|
|
680
|
+
this.name = "EdgeWriteFailed";
|
|
681
|
+
}
|
|
682
|
+
};
|
|
683
|
+
/**
|
|
684
|
+
* Something other than the proxy a stack is set to holds the edge's ports.
|
|
685
|
+
*
|
|
686
|
+
* With `proxy: 'traefik'`, the stack's own Caddy — still running from before
|
|
687
|
+
* the switch — or any other container; with `proxy: 'caddy'`, the shared
|
|
688
|
+
* edge, or another stack's Caddy. Refused before anything is started, so the
|
|
689
|
+
* stack is never left half on one proxy and half on the other.
|
|
690
|
+
*/
|
|
691
|
+
var ComposeProxyClash = class extends GkmError {
|
|
692
|
+
project;
|
|
693
|
+
proxy;
|
|
694
|
+
port;
|
|
695
|
+
holder;
|
|
696
|
+
constructor(project, proxy, port, holder) {
|
|
697
|
+
const by = holder.project ? `${holder.container} (compose project ${holder.project})` : holder.container;
|
|
698
|
+
const fix = proxy === "traefik" ? holder.project === project && holder.service === "caddy" ? `That is this stack's own Caddy, from before it was switched to proxy: 'traefik'. Move it once: stop it (docker compose -p ${project} stop caddy), then run gkm compose again — the shared edge takes 80/443 and the stack registers with it.` : `The shared edge needs ports 80 and 443. Stop ${holder.container}${holder.project ? ` (docker compose -p ${holder.project} down, or its own gkm compose --down)` : ""}, or move the edge with GKM_COMPOSE_HTTPS_PORT/GKM_COMPOSE_HTTP_PORT.` : holder.project === EDGE_PROJECT ? `That is the server's shared Traefik edge, which other stacks register with. Set deploy.compose.proxy to 'traefik' for this stage so the stack registers with it too, or stop the edge once nothing uses it (docker compose -p ${EDGE_PROJECT} down).` : `Stop ${holder.container}, or publish this stack's Caddy elsewhere with GKM_COMPOSE_HTTPS_PORT/GKM_COMPOSE_HTTP_PORT.`;
|
|
699
|
+
super(`${project} is set to proxy: '${proxy}', and port ${port} is held by ${by}. ${fix}`);
|
|
700
|
+
this.project = project;
|
|
701
|
+
this.proxy = proxy;
|
|
702
|
+
this.port = port;
|
|
703
|
+
this.holder = holder;
|
|
704
|
+
this.name = "ComposeProxyClash";
|
|
705
|
+
}
|
|
706
|
+
};
|
|
707
|
+
/**
|
|
708
|
+
* Refuse a stack whose edge ports are held by anything but its own proxy:
|
|
709
|
+
* the shared edge for `'traefik'`, the stack's own Caddy for `'caddy'`.
|
|
710
|
+
*/
|
|
711
|
+
async function assertEdgePorts(docker, options) {
|
|
712
|
+
const { project, proxy, ports } = options;
|
|
713
|
+
for (const port of [ports.https, ports.http]) for (const holder of await docker.publishers(options.engine, port)) if (!(proxy === "traefik" ? holder.project === EDGE_PROJECT : holder.project === project && holder.service === "caddy")) throw new ComposeProxyClash(project, proxy, port, holder);
|
|
714
|
+
}
|
|
715
|
+
/**
|
|
716
|
+
* Write a file into the edge's running container whole or not at all: a
|
|
717
|
+
* temporary name, then a rename. Not `.yml`: the edge reads only `.yml`,
|
|
718
|
+
* `.yaml` and `.toml` files, so it never sees one half written.
|
|
719
|
+
*/
|
|
720
|
+
async function put(docker, edge, path, content, mode = "644") {
|
|
721
|
+
const result = await docker.exec(edge, EDGE_SERVICE, [
|
|
722
|
+
"sh",
|
|
723
|
+
"-c",
|
|
724
|
+
"set -e; t=\"$1.tmp\"; cat > \"$t\"; chmod \"$2\" \"$t\"; mv \"$t\" \"$1\"",
|
|
725
|
+
"sh",
|
|
726
|
+
path,
|
|
727
|
+
mode
|
|
728
|
+
], content);
|
|
729
|
+
if (result.code !== 0) throw new EdgeWriteFailed(path, `${result.stderr}${result.stdout}`);
|
|
730
|
+
}
|
|
731
|
+
/** Remove files from the edge's container; whether the first was there. */
|
|
732
|
+
async function remove(docker, edge, paths) {
|
|
733
|
+
return (await docker.exec(edge, EDGE_SERVICE, [
|
|
734
|
+
"sh",
|
|
735
|
+
"-c",
|
|
736
|
+
"e=1; [ -f \"$1\" ] && e=0; rm -f \"$@\"; exit $e",
|
|
737
|
+
"sh",
|
|
738
|
+
...paths
|
|
739
|
+
])).code === 0;
|
|
740
|
+
}
|
|
741
|
+
/**
|
|
742
|
+
* The edge, up: its network and its container — started when it is not
|
|
743
|
+
* running, and recreated when its configuration changed. Idempotent: on a
|
|
744
|
+
* server where it already runs as configured, `up` changes nothing. Its
|
|
745
|
+
* compose file is written to `file`, on this machine: compose reads it here.
|
|
746
|
+
*/
|
|
747
|
+
async function ensureEdge(docker, options) {
|
|
748
|
+
const { file, ports } = options;
|
|
749
|
+
const staticConfig = traefikStaticFile(ports);
|
|
750
|
+
const content = edgeComposeFile({
|
|
751
|
+
ports,
|
|
752
|
+
staticConfig,
|
|
753
|
+
logging: options.logging
|
|
754
|
+
});
|
|
755
|
+
await mkdir(dirname(file), { recursive: true });
|
|
756
|
+
if (await readFile(file, "utf-8").catch(() => void 0) !== content) await writeFile(file, content);
|
|
757
|
+
const ref = edgeRef(file, {
|
|
758
|
+
...options.host ? { host: options.host } : {},
|
|
759
|
+
...options.output ? { output: options.output } : {},
|
|
760
|
+
...options.signal ? { signal: options.signal } : {}
|
|
761
|
+
});
|
|
762
|
+
await docker.ensureNetwork(ref, EDGE_NETWORK);
|
|
763
|
+
await docker.up(ref, [EDGE_SERVICE]);
|
|
764
|
+
return [file];
|
|
765
|
+
}
|
|
766
|
+
/** A file inside the edge's running container, or undefined where there is none. */
|
|
767
|
+
async function readEdgeFile(docker, edge, path) {
|
|
768
|
+
const result = await docker.exec(edge, EDGE_SERVICE, ["cat", path]);
|
|
769
|
+
return result.code === 0 ? result.stdout : void 0;
|
|
770
|
+
}
|
|
771
|
+
/** A file written into the edge's running container, whole, readable by it alone. */
|
|
772
|
+
async function writeEdgeSecret(docker, edge, path, content) {
|
|
773
|
+
await put(docker, edge, path, content, "600");
|
|
774
|
+
}
|
|
775
|
+
/**
|
|
776
|
+
* The edge restarted — what it reads once and keeps, a key among them, read
|
|
777
|
+
* again — and waited on until it is healthy. Its own restart policy brings
|
|
778
|
+
* it back; `up` waits for it.
|
|
779
|
+
*/
|
|
780
|
+
async function restartEdge(docker, edge) {
|
|
781
|
+
await docker.exec(edge, EDGE_SERVICE, ["kill", "1"]);
|
|
782
|
+
await docker.up(edge, [EDGE_SERVICE]);
|
|
783
|
+
}
|
|
784
|
+
/** A stack's routes, inside the edge's container. */
|
|
785
|
+
function routesPath(project) {
|
|
786
|
+
return `${EDGE_DYNAMIC_DIR}/${project}.yml`;
|
|
787
|
+
}
|
|
788
|
+
/**
|
|
789
|
+
* A host this stack routes is already routed through the shared edge by
|
|
790
|
+
* another project: two routers for one host, and which stack serves it — and
|
|
791
|
+
* which gets its certificate — would be the edge's choice.
|
|
792
|
+
*/
|
|
793
|
+
var EdgeHostClaimed = class extends GkmError {
|
|
794
|
+
host;
|
|
795
|
+
owner;
|
|
796
|
+
project;
|
|
797
|
+
edge;
|
|
798
|
+
constructor(host, owner, project, edge = EDGE_PROJECT) {
|
|
799
|
+
super(`${project} routes ${host}, and ${owner} already routes it through the shared edge (${edge}) on this server. A host is served by one stack only. Give ${project} another domain, or take ${owner} off the edge first: gkm compose --stage <stage> --down in its workspace (or remove ${routesPath(owner)} from the edge).`);
|
|
800
|
+
this.host = host;
|
|
801
|
+
this.owner = owner;
|
|
802
|
+
this.project = project;
|
|
803
|
+
this.edge = edge;
|
|
804
|
+
this.name = "EdgeHostClaimed";
|
|
805
|
+
}
|
|
806
|
+
};
|
|
807
|
+
/**
|
|
808
|
+
* Every other stack's claims on the edge, by project: each `dynamic/*.yml`
|
|
809
|
+
* but this project's, read through the engine. None where the edge is not
|
|
810
|
+
* running — nothing is routed through it.
|
|
811
|
+
*/
|
|
812
|
+
async function edgeClaimsByProject(docker, edge, project) {
|
|
813
|
+
const claimed = /* @__PURE__ */ new Map();
|
|
814
|
+
const listed = await docker.exec(edge, EDGE_SERVICE, [
|
|
815
|
+
"ls",
|
|
816
|
+
"-1",
|
|
817
|
+
EDGE_DYNAMIC_DIR
|
|
818
|
+
]);
|
|
819
|
+
if (listed.code !== 0) return claimed;
|
|
820
|
+
for (const name of listed.stdout.split("\n").map((line) => line.trim())) {
|
|
821
|
+
if (!name.endsWith(".yml")) continue;
|
|
822
|
+
const owner = name.slice(0, -4);
|
|
823
|
+
if (!owner || owner === project) continue;
|
|
824
|
+
const file = await readEdgeFile(docker, edge, routesPath(owner));
|
|
825
|
+
if (file === void 0) continue;
|
|
826
|
+
const claims = readEdgeClaims(file);
|
|
827
|
+
if (claims.length > 0) claimed.set(owner, claims);
|
|
828
|
+
}
|
|
829
|
+
return claimed;
|
|
830
|
+
}
|
|
831
|
+
/**
|
|
832
|
+
* Refuse a stack's routes when a host in them is routed through the edge by
|
|
833
|
+
* another project — checked before a deploy changes anything, and again
|
|
834
|
+
* before its routes are written. Its own file, from its last deploy, is
|
|
835
|
+
* replaced, never a clash.
|
|
836
|
+
*/
|
|
837
|
+
async function assertEdgeHostsFree(docker, edge, project, routes) {
|
|
838
|
+
const mine = readEdgeClaims(routes);
|
|
839
|
+
if (mine.length === 0) return;
|
|
840
|
+
const others = await edgeClaimsByProject(docker, edge, project);
|
|
841
|
+
for (const [owner, theirs] of [...others].sort(([a], [b]) => a.localeCompare(b))) for (const claim of mine) for (const other of theirs) {
|
|
842
|
+
const host = claimsOverlap(claim, other);
|
|
843
|
+
if (host !== void 0) throw new EdgeHostClaimed(host, owner, project, edge.project);
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
function certificatePaths(project) {
|
|
847
|
+
return [`${EDGE_CERTS_DIR}/${project}.crt`, `${EDGE_CERTS_DIR}/${project}.key`];
|
|
848
|
+
}
|
|
849
|
+
/**
|
|
850
|
+
* Register a stack with the edge — refused, before anything is written, when
|
|
851
|
+
* another project routes one of its hosts: its certificate first, where it has one,
|
|
852
|
+
* so the routes that need it never load without it — then its routes, in one
|
|
853
|
+
* rename the edge picks up whole. The certificate — the stage's own, or the
|
|
854
|
+
* one gkm's local CA issued the local stage — is PEM read on this machine and
|
|
855
|
+
* written through the engine. The paths written, inside the edge.
|
|
856
|
+
*/
|
|
857
|
+
async function writeEdgeRoutes(docker, edge, project, routes, certificate) {
|
|
858
|
+
await assertEdgeHostsFree(docker, edge, project, routes);
|
|
859
|
+
const written = [];
|
|
860
|
+
const [crt, key] = certificatePaths(project);
|
|
861
|
+
if (certificate) {
|
|
862
|
+
await put(docker, edge, crt, certificate.cert);
|
|
863
|
+
await put(docker, edge, key, certificate.key, "600");
|
|
864
|
+
written.push(crt, key);
|
|
865
|
+
} else await remove(docker, edge, [crt, key]);
|
|
866
|
+
await put(docker, edge, routesPath(project), routes);
|
|
867
|
+
written.push(routesPath(project));
|
|
868
|
+
return written;
|
|
869
|
+
}
|
|
870
|
+
/** What a stack's file holds for the moment between emptying and removal. */
|
|
871
|
+
const UNREGISTERED = "# Unregistered by gkm compose --down.\n";
|
|
872
|
+
/**
|
|
873
|
+
* Unregister a stack: its routes, then its certificate. Whether there was
|
|
874
|
+
* anything to remove — false, too, when the edge is not running.
|
|
875
|
+
*/
|
|
876
|
+
async function removeEdgeRoutes(docker, edge, project) {
|
|
877
|
+
const file = routesPath(project);
|
|
878
|
+
if ((await docker.exec(edge, "traefik", [
|
|
879
|
+
"test",
|
|
880
|
+
"-f",
|
|
881
|
+
file
|
|
882
|
+
])).code !== 0) return false;
|
|
883
|
+
await put(docker, edge, file, UNREGISTERED);
|
|
884
|
+
await remove(docker, edge, [file, ...certificatePaths(project)]);
|
|
885
|
+
return true;
|
|
886
|
+
}
|
|
887
|
+
//#endregion
|
|
888
|
+
//#region src/compose/acmeDns.ts
|
|
889
|
+
/**
|
|
890
|
+
* The key the server's shared Traefik edge answers Let's Encrypt's DNS
|
|
891
|
+
* challenge with, for a stage with a wildcard site.
|
|
892
|
+
*
|
|
893
|
+
* A wildcard certificate is issued only over the DNS challenge: the edge
|
|
894
|
+
* proves it holds `<domain>` by writing a TXT record at
|
|
895
|
+
* `_acme-challenge.<domain>`. So it needs a key that can write that record —
|
|
896
|
+
* and nothing else, because it lives on the server.
|
|
897
|
+
*
|
|
898
|
+
* - **The user**: one per server, under `/gkm/`, tagged with the server it
|
|
899
|
+
* is for. One that exists without that tag is someone else's, and is
|
|
900
|
+
* refused rather than taken over.
|
|
901
|
+
* - **Its policies**: one per stack on the server, named for its compose
|
|
902
|
+
* project, allowing `ChangeResourceRecordSets` on the stage's hosted zone
|
|
903
|
+
* for TXT records named `_acme-challenge.<domain>` alone — plus what
|
|
904
|
+
* finding the zone and waiting for the change take, which read and write
|
|
905
|
+
* nothing. Put back on every deploy.
|
|
906
|
+
* - **Its key**: written into the edge's container, never into the stage's
|
|
907
|
+
* secrets or onto the machine running the deploy. Issued when the edge
|
|
908
|
+
* has none, or holds one IAM no longer knows — and then the edge is
|
|
909
|
+
* restarted, since it keeps the key it first read.
|
|
910
|
+
*/
|
|
911
|
+
/** Where gkm's IAM users live. */
|
|
912
|
+
const USER_PATH = "/gkm/";
|
|
913
|
+
/** The tag a server's edge user is found by. */
|
|
914
|
+
const TAG_EDGE = "gkm:edge";
|
|
915
|
+
/** The edge user's name for a server: stable, and safe for IAM. */
|
|
916
|
+
function edgeAcmeUser(server) {
|
|
917
|
+
return `gkm-edge-acme-${createHash("sha256").update(server).digest("hex").slice(0, 12)}`;
|
|
918
|
+
}
|
|
919
|
+
/**
|
|
920
|
+
* What one stage's wildcard certificate needs: its challenge record written
|
|
921
|
+
* in its zone, the change waited on, and the zone found by name — which is
|
|
922
|
+
* how the edge's ACME client finds it.
|
|
923
|
+
*/
|
|
924
|
+
function acmeDnsPolicy(zoneId, domain) {
|
|
925
|
+
return JSON.stringify({
|
|
926
|
+
Version: "2012-10-17",
|
|
927
|
+
Statement: [
|
|
928
|
+
{
|
|
929
|
+
Effect: "Allow",
|
|
930
|
+
Action: "route53:ChangeResourceRecordSets",
|
|
931
|
+
Resource: `arn:aws:route53:::hostedzone/${zoneId}`,
|
|
932
|
+
Condition: { "ForAllValues:StringEquals": {
|
|
933
|
+
"route53:ChangeResourceRecordSetsNormalizedRecordNames": [`_acme-challenge.${domain.toLowerCase()}`],
|
|
934
|
+
"route53:ChangeResourceRecordSetsRecordTypes": ["TXT"]
|
|
935
|
+
} }
|
|
936
|
+
},
|
|
937
|
+
{
|
|
938
|
+
Effect: "Allow",
|
|
939
|
+
Action: "route53:ListResourceRecordSets",
|
|
940
|
+
Resource: `arn:aws:route53:::hostedzone/${zoneId}`
|
|
941
|
+
},
|
|
942
|
+
{
|
|
943
|
+
Effect: "Allow",
|
|
944
|
+
Action: "route53:GetChange",
|
|
945
|
+
Resource: "arn:aws:route53:::change/*"
|
|
946
|
+
},
|
|
947
|
+
{
|
|
948
|
+
Effect: "Allow",
|
|
949
|
+
Action: "route53:ListHostedZonesByName",
|
|
950
|
+
Resource: "*"
|
|
951
|
+
}
|
|
952
|
+
]
|
|
953
|
+
});
|
|
954
|
+
}
|
|
955
|
+
/** An IAM user by the edge user's name that gkm did not create for this server. */
|
|
956
|
+
var EdgeAcmeUserNotOwned = class extends GkmError {
|
|
957
|
+
user;
|
|
958
|
+
server;
|
|
959
|
+
constructor(user, server) {
|
|
960
|
+
super(`The IAM user ${user} exists but is not tagged ${TAG_EDGE}=${server}, so gkm will not take it over to write the shared edge's DNS challenge records. Delete it, or tag it ${TAG_EDGE}=${server} if it is the one gkm created for this server.`);
|
|
961
|
+
this.user = user;
|
|
962
|
+
this.server = server;
|
|
963
|
+
this.name = "EdgeAcmeUserNotOwned";
|
|
964
|
+
}
|
|
965
|
+
};
|
|
966
|
+
/** A wildcard site's domain with no Route 53 hosted zone to answer it in. */
|
|
967
|
+
var AcmeHostedZoneMissing = class extends GkmError {
|
|
968
|
+
domain;
|
|
969
|
+
constructor(domain) {
|
|
970
|
+
super(`No Route 53 hosted zone holds ${domain}, so the shared edge cannot answer the DNS challenge for its wildcard certificate. Create the zone, or set hostedZoneId in its dns entry.`);
|
|
971
|
+
this.domain = domain;
|
|
972
|
+
this.name = "AcmeHostedZoneMissing";
|
|
973
|
+
}
|
|
974
|
+
};
|
|
975
|
+
/**
|
|
976
|
+
* The edge's key for `domain`'s challenge record: its user, this stack's
|
|
977
|
+
* policy on it, and a key in the edge that IAM knows.
|
|
978
|
+
*
|
|
979
|
+
* @throws {EdgeAcmeUserNotOwned} when the user is someone else's
|
|
980
|
+
* @throws {AcmeHostedZoneMissing} when no hosted zone holds the domain
|
|
981
|
+
*/
|
|
982
|
+
async function ensureEdgeAcmeKey(docker, options) {
|
|
983
|
+
const { clients, edge, server, project, domain } = options;
|
|
984
|
+
const log = options.log ?? ((line) => console.log(line));
|
|
985
|
+
const IAM = await import("@aws-sdk/client-iam");
|
|
986
|
+
const user = edgeAcmeUser(server);
|
|
987
|
+
const zoneId = options.hostedZoneId ?? await hostedZoneId(clients.route53, options.zone);
|
|
988
|
+
if (!zoneId) throw new AcmeHostedZoneMissing(domain);
|
|
989
|
+
if (options.dryRun) {
|
|
990
|
+
log(`🔑 Would let ${EDGE_PROJECT} write _acme-challenge.${domain} TXT records in ${zoneId}, as IAM user ${user} (dry run — nothing is written)`);
|
|
991
|
+
return {
|
|
992
|
+
user,
|
|
993
|
+
zoneId,
|
|
994
|
+
issued: false
|
|
995
|
+
};
|
|
996
|
+
}
|
|
997
|
+
if (!(await clients.iam.send(new IAM.GetUserCommand({ UserName: user })).catch((error) => {
|
|
998
|
+
if (error?.name === "NoSuchEntity" || error?.name === "NoSuchEntityException") return;
|
|
999
|
+
throw error;
|
|
1000
|
+
}))?.User) await clients.iam.send(new IAM.CreateUserCommand({
|
|
1001
|
+
UserName: user,
|
|
1002
|
+
Path: USER_PATH,
|
|
1003
|
+
Tags: [{
|
|
1004
|
+
Key: TAG_EDGE,
|
|
1005
|
+
Value: server
|
|
1006
|
+
}]
|
|
1007
|
+
}));
|
|
1008
|
+
else {
|
|
1009
|
+
const { Tags = [] } = await clients.iam.send(new IAM.ListUserTagsCommand({ UserName: user }));
|
|
1010
|
+
if (!Tags.some((t) => t.Key === "gkm:edge" && t.Value === server)) throw new EdgeAcmeUserNotOwned(user, server);
|
|
1011
|
+
}
|
|
1012
|
+
await clients.iam.send(new IAM.PutUserPolicyCommand({
|
|
1013
|
+
UserName: user,
|
|
1014
|
+
PolicyName: project,
|
|
1015
|
+
PolicyDocument: acmeDnsPolicy(zoneId, domain)
|
|
1016
|
+
}));
|
|
1017
|
+
log(`🔑 ${EDGE_PROJECT} may write _acme-challenge.${domain} TXT records in ${zoneId}, and nothing else there, as IAM user ${user}`);
|
|
1018
|
+
const written = await readEdgeFile(docker, edge, EDGE_AWS_CREDENTIALS);
|
|
1019
|
+
const held = written?.match(/aws_access_key_id\s*=\s*(\S+)/)?.[1];
|
|
1020
|
+
const { AccessKeyMetadata = [] } = await clients.iam.send(new IAM.ListAccessKeysCommand({ UserName: user }));
|
|
1021
|
+
if (held && AccessKeyMetadata.some((k) => k.AccessKeyId === held)) return {
|
|
1022
|
+
user,
|
|
1023
|
+
zoneId,
|
|
1024
|
+
issued: false
|
|
1025
|
+
};
|
|
1026
|
+
for (const key of AccessKeyMetadata) {
|
|
1027
|
+
if (!key.AccessKeyId) continue;
|
|
1028
|
+
await clients.iam.send(new IAM.DeleteAccessKeyCommand({
|
|
1029
|
+
UserName: user,
|
|
1030
|
+
AccessKeyId: key.AccessKeyId
|
|
1031
|
+
}));
|
|
1032
|
+
}
|
|
1033
|
+
const { AccessKey } = await clients.iam.send(new IAM.CreateAccessKeyCommand({ UserName: user }));
|
|
1034
|
+
await writeEdgeSecret(docker, edge, EDGE_AWS_CREDENTIALS, `# Written by gkm compose — the key ${EDGE_PROJECT} answers DNS challenges with.
|
|
1035
|
+
[default]
|
|
1036
|
+
aws_access_key_id = ${AccessKey?.AccessKeyId}
|
|
1037
|
+
aws_secret_access_key = ${AccessKey?.SecretAccessKey}
|
|
1038
|
+
`);
|
|
1039
|
+
log(`🔑 Wrote a new key for ${user} to ${EDGE_PROJECT} (${EDGE_AWS_CREDENTIALS})`);
|
|
1040
|
+
if (written !== void 0) await restartEdge(docker, edge);
|
|
1041
|
+
return {
|
|
1042
|
+
user,
|
|
1043
|
+
zoneId,
|
|
1044
|
+
issued: true
|
|
1045
|
+
};
|
|
1046
|
+
}
|
|
1047
|
+
/** The id of the hosted zone named exactly `zone`, if there is one. */
|
|
1048
|
+
async function hostedZoneId(route53, zone) {
|
|
1049
|
+
const { ListHostedZonesByNameCommand } = await import("@aws-sdk/client-route-53");
|
|
1050
|
+
const name = zone.endsWith(".") ? zone : `${zone}.`;
|
|
1051
|
+
const { HostedZones = [] } = await route53.send(new ListHostedZonesByNameCommand({
|
|
1052
|
+
DNSName: name,
|
|
1053
|
+
MaxItems: 1
|
|
1054
|
+
}));
|
|
1055
|
+
return HostedZones.find((z) => z.Name === name)?.Id?.replace("/hostedzone/", "");
|
|
1056
|
+
}
|
|
1057
|
+
//#endregion
|
|
1058
|
+
//#region src/compose/secrets.ts
|
|
1059
|
+
function deployedStackSecrets(workspace, stage, stored, manifest) {
|
|
1060
|
+
const withSeed = withGeneratedSecrets(stored ?? initStageSecrets(stage), manifest);
|
|
1061
|
+
const withLogs = resolveStageTelemetry({
|
|
1062
|
+
...workspace.deploy?.telemetry ? { telemetry: workspace.deploy.telemetry } : {},
|
|
1063
|
+
stage,
|
|
1064
|
+
local: false,
|
|
1065
|
+
target: "compose",
|
|
1066
|
+
runtime: "server",
|
|
1067
|
+
selfHosted: true,
|
|
1068
|
+
used: usesTelemetry(manifest)
|
|
1069
|
+
})?.provider === "self-hosted" ? withLogsPassword(withSeed.secrets) : {
|
|
1070
|
+
secrets: withSeed.secrets,
|
|
1071
|
+
generated: []
|
|
1072
|
+
};
|
|
1073
|
+
const withRedis = runsRedis(manifest, withLogs.secrets.custom ?? {}) ? withRedisPassword(withLogs.secrets) : {
|
|
1074
|
+
secrets: withLogs.secrets,
|
|
1075
|
+
generated: []
|
|
1076
|
+
};
|
|
1077
|
+
return {
|
|
1078
|
+
secrets: withRedis.secrets,
|
|
1079
|
+
generated: [
|
|
1080
|
+
...withSeed.generated,
|
|
1081
|
+
...withLogs.generated,
|
|
1082
|
+
...withRedis.generated
|
|
1083
|
+
]
|
|
1084
|
+
};
|
|
1085
|
+
}
|
|
1086
|
+
//#endregion
|
|
1087
|
+
//#region src/target/compose/health.ts
|
|
1088
|
+
/**
|
|
1089
|
+
* Asking each app of a stack whether it answers — through Caddy, over HTTPS,
|
|
1090
|
+
* the way a browser reaches it.
|
|
1091
|
+
*
|
|
1092
|
+
* `docker compose up --wait` already knows each container passed its own
|
|
1093
|
+
* health check, asked on 127.0.0.1 inside it. What that cannot say is whether
|
|
1094
|
+
* the stack is reachable: whether the edge routes the host to the app, and
|
|
1095
|
+
* whether the certificate it presents is one a client accepts. So the check
|
|
1096
|
+
* goes through the edge, by hostname, and verifies the certificate.
|
|
1097
|
+
*/
|
|
1098
|
+
/** A request that got no answer in time. */
|
|
1099
|
+
var HealthRequestTimedOut = class extends GkmError {
|
|
1100
|
+
url;
|
|
1101
|
+
timeoutMs;
|
|
1102
|
+
constructor(url, timeoutMs) {
|
|
1103
|
+
super(`${url} did not answer within ${timeoutMs}ms. Check the stack is up with \`docker compose ps\`.`);
|
|
1104
|
+
this.url = url;
|
|
1105
|
+
this.timeoutMs = timeoutMs;
|
|
1106
|
+
this.name = "HealthRequestTimedOut";
|
|
1107
|
+
}
|
|
1108
|
+
};
|
|
1109
|
+
/** The most of a body read — a sitemap may be 50 MB, and none needs to be. */
|
|
1110
|
+
const EDGE_BODY_LIMIT = 10485760;
|
|
1111
|
+
/** A body larger than {@link EDGE_BODY_LIMIT}. */
|
|
1112
|
+
var EdgeResponseTooLarge = class extends GkmError {
|
|
1113
|
+
url;
|
|
1114
|
+
limit;
|
|
1115
|
+
constructor(url, limit) {
|
|
1116
|
+
super(`${url} answered with more than ${limit} bytes, which is more than gkm reads. Split it — a sitemap index can list several sitemaps.`);
|
|
1117
|
+
this.url = url;
|
|
1118
|
+
this.limit = limit;
|
|
1119
|
+
this.name = "EdgeResponseTooLarge";
|
|
1120
|
+
}
|
|
1121
|
+
};
|
|
1122
|
+
/**
|
|
1123
|
+
* The real request: one GET to the edge — over HTTPS, the certificate
|
|
1124
|
+
* verified, for an `https:` URL, and plain HTTP for an `http:` one — with
|
|
1125
|
+
* the URL's host as SNI and `Host` wherever it connects.
|
|
1126
|
+
*/
|
|
1127
|
+
const edgeFetch = ({ url, ca, connectTo, connectPort, authorization, timeoutMs, signal, read, headers }) => {
|
|
1128
|
+
const target = new URL(url);
|
|
1129
|
+
const secure = target.protocol === "https:";
|
|
1130
|
+
const request$2 = secure ? request$1 : request;
|
|
1131
|
+
return new Promise((resolve, reject) => {
|
|
1132
|
+
const req = request$2({
|
|
1133
|
+
host: connectTo ?? target.hostname,
|
|
1134
|
+
port: connectPort ?? (target.port || (secure ? 443 : 80)),
|
|
1135
|
+
...secure ? { servername: target.hostname } : {},
|
|
1136
|
+
path: `${target.pathname}${target.search}`,
|
|
1137
|
+
method: "GET",
|
|
1138
|
+
headers: {
|
|
1139
|
+
...headers,
|
|
1140
|
+
host: target.host,
|
|
1141
|
+
...authorization ? { authorization } : {}
|
|
1142
|
+
},
|
|
1143
|
+
...secure && ca ? { ca } : {},
|
|
1144
|
+
...signal ? { signal } : {},
|
|
1145
|
+
timeout: timeoutMs
|
|
1146
|
+
}, (res) => {
|
|
1147
|
+
const answered = {
|
|
1148
|
+
status: res.statusCode ?? 0,
|
|
1149
|
+
headers: res.headers
|
|
1150
|
+
};
|
|
1151
|
+
if (!read) {
|
|
1152
|
+
res.resume();
|
|
1153
|
+
res.on("end", () => resolve({
|
|
1154
|
+
...answered,
|
|
1155
|
+
body: ""
|
|
1156
|
+
}));
|
|
1157
|
+
res.on("error", reject);
|
|
1158
|
+
return;
|
|
1159
|
+
}
|
|
1160
|
+
const chunks = [];
|
|
1161
|
+
let size = 0;
|
|
1162
|
+
res.on("data", (chunk) => {
|
|
1163
|
+
size += chunk.length;
|
|
1164
|
+
if (size > 10485760) {
|
|
1165
|
+
req.destroy(new EdgeResponseTooLarge(url, EDGE_BODY_LIMIT));
|
|
1166
|
+
return;
|
|
1167
|
+
}
|
|
1168
|
+
chunks.push(chunk);
|
|
1169
|
+
});
|
|
1170
|
+
res.on("end", () => resolve({
|
|
1171
|
+
...answered,
|
|
1172
|
+
body: Buffer.concat(chunks).toString("utf-8")
|
|
1173
|
+
}));
|
|
1174
|
+
res.on("error", reject);
|
|
1175
|
+
});
|
|
1176
|
+
req.on("timeout", () => req.destroy(new HealthRequestTimedOut(url, timeoutMs)));
|
|
1177
|
+
req.on("error", reject);
|
|
1178
|
+
req.end();
|
|
1179
|
+
});
|
|
1180
|
+
};
|
|
1181
|
+
/** The real probe: one GET through the edge, answered by its status. */
|
|
1182
|
+
const httpsProbe = (request) => edgeFetch(request).then(({ status }) => status);
|
|
1183
|
+
/** Whether a status means the app answered as it should. */
|
|
1184
|
+
function isHealthy(status) {
|
|
1185
|
+
return status >= 200 && status < 400;
|
|
1186
|
+
}
|
|
1187
|
+
/**
|
|
1188
|
+
* Apps that are not healthy. `via` says which check said so:
|
|
1189
|
+
* - `edge`: verify asked each app through the edge, by its host, and it did
|
|
1190
|
+
* not answer as it should (a worker, with no route, by its container's
|
|
1191
|
+
* health);
|
|
1192
|
+
* - `docker`: `up --wait` failed, and these containers' own health checks
|
|
1193
|
+
* had not passed — the rest of the stack was released and routed first.
|
|
1194
|
+
* One class either way, so a caller matches one failure: apps not healthy.
|
|
1195
|
+
*/
|
|
1196
|
+
var ComposeAppsUnhealthy = class extends GkmError {
|
|
1197
|
+
project;
|
|
1198
|
+
apps;
|
|
1199
|
+
proxy;
|
|
1200
|
+
via;
|
|
1201
|
+
constructor(project, apps, proxy = "caddy", via = "edge") {
|
|
1202
|
+
const names = apps.map((a) => a.app).join(" ");
|
|
1203
|
+
super(via === "docker" ? `${project} started, but ${apps.length === 1 ? "this container's health check has" : "these containers' health checks have"} not passed. The rest of the stack is up and routed:\n` + apps.map(({ app, last }) => ` - ${app}: Docker reports it ${last}`).join("\n") + `\nSee why with \`docker compose -p ${project} ps ${names}\` and \`docker compose -p ${project} logs ${names}\`, fix the app, and deploy again.` : `${project} started, but ${apps.length === 1 ? "this app does" : "these apps do"} not answer through ${proxy === "caddy" ? "Caddy" : "the shared Traefik edge"}:\n` + apps.map(({ url, last }) => ` - ${url}: ${last}`).join("\n") + (proxy === "caddy" ? `\nSee why with \`docker compose -p ${project} logs caddy ${names}\`.` : `\nSee why with \`docker compose -p ${EDGE_PROJECT} logs traefik\` and \`docker compose -p ${project} logs ${names}\`.`));
|
|
1204
|
+
this.project = project;
|
|
1205
|
+
this.apps = apps;
|
|
1206
|
+
this.proxy = proxy;
|
|
1207
|
+
this.via = via;
|
|
1208
|
+
this.name = "ComposeAppsUnhealthy";
|
|
1209
|
+
}
|
|
1210
|
+
};
|
|
1211
|
+
//#endregion
|
|
1212
|
+
//#region src/target/compose/topicSubscriptions.ts
|
|
1213
|
+
/**
|
|
1214
|
+
* Every topic subscriber the stack pushes to: a subscriber whose connection
|
|
1215
|
+
* key is a topic's publisher string — a bucket's events key is not — and
|
|
1216
|
+
* whose value on this stage is an SNS one.
|
|
1217
|
+
*/
|
|
1218
|
+
function topicPushes(stack, manifest) {
|
|
1219
|
+
const topicKeys = new Set(Object.values(manifest).filter((declaration) => declaration.kind === "topic").map((topic) => provideKey(topic.id, "publisherConnectionString")));
|
|
1220
|
+
const pushes = [];
|
|
1221
|
+
for (const worker of stack.workers) for (const subscriber of worker.push?.subscribers ?? []) {
|
|
1222
|
+
if (!topicKeys.has(subscriber.connectionKey)) continue;
|
|
1223
|
+
const connectionString = worker.env?.[subscriber.connectionKey];
|
|
1224
|
+
if (!connectionString?.startsWith("sns:")) continue;
|
|
1225
|
+
pushes.push({
|
|
1226
|
+
worker: worker.id,
|
|
1227
|
+
name: subscriber.name,
|
|
1228
|
+
endpoint: subscriber.endpoint,
|
|
1229
|
+
connectionKey: subscriber.connectionKey,
|
|
1230
|
+
connectionString,
|
|
1231
|
+
...subscriber.events ? { events: subscriber.events } : {}
|
|
1232
|
+
});
|
|
1233
|
+
}
|
|
1234
|
+
return pushes;
|
|
1235
|
+
}
|
|
1236
|
+
/** The subscriptions recorded for hand-set topics: those with a key. */
|
|
1237
|
+
function recordedTopicSubscriptions(resources) {
|
|
1238
|
+
return Object.values(resources ?? {}).filter((record) => record.type === "sns-subscription" && typeof record.data?.connectionKey === "string");
|
|
1239
|
+
}
|
|
1240
|
+
/**
|
|
1241
|
+
* Converge each hand-set topic's subscriptions on the subscribers pushed to:
|
|
1242
|
+
* subscribe, bring filters up to date, unsubscribe a route on the worker's
|
|
1243
|
+
* host no subscriber wants any more — and record each ARN, forgetting what
|
|
1244
|
+
* was removed.
|
|
1245
|
+
*
|
|
1246
|
+
* @returns each worker's subscriptions, by export — what it is handed
|
|
1247
|
+
*/
|
|
1248
|
+
async function ensureTopicSubscriptions(input) {
|
|
1249
|
+
const { snsUrl, reconcileHttpSubscriptions } = await import("@geekmidas/events/sns");
|
|
1250
|
+
const groups = /* @__PURE__ */ new Map();
|
|
1251
|
+
const group = (topicArn, host, connectionKey) => {
|
|
1252
|
+
const id = `${topicArn}|${host}`;
|
|
1253
|
+
const found = groups.get(id);
|
|
1254
|
+
if (found) return found;
|
|
1255
|
+
const created = {
|
|
1256
|
+
topicArn,
|
|
1257
|
+
host,
|
|
1258
|
+
connectionKey,
|
|
1259
|
+
pushes: [],
|
|
1260
|
+
recorded: []
|
|
1261
|
+
};
|
|
1262
|
+
groups.set(id, created);
|
|
1263
|
+
return created;
|
|
1264
|
+
};
|
|
1265
|
+
for (const push of input.pushes) {
|
|
1266
|
+
const { topicArn } = snsUrl.parse(push.connectionString);
|
|
1267
|
+
const into = group(topicArn, new URL(push.endpoint).host, push.connectionKey);
|
|
1268
|
+
into.connectionString = push.connectionString;
|
|
1269
|
+
into.pushes.push(push);
|
|
1270
|
+
}
|
|
1271
|
+
for (const record of recordedTopicSubscriptions(input.recorded)) group(String(record.data?.topicArn), new URL(String(record.data?.endpoint)).host, String(record.data?.connectionKey)).recorded.push(record);
|
|
1272
|
+
const wanted = new Set(input.pushes.map(({ worker, name }) => subscriptionKey(worker, name)));
|
|
1273
|
+
const arns = {};
|
|
1274
|
+
for (const { topicArn, host, connectionKey, ...members } of groups.values()) {
|
|
1275
|
+
const stale = members.recorded.filter((r) => !wanted.has(r.key));
|
|
1276
|
+
const named = members.connectionString ?? input.secrets[connectionKey];
|
|
1277
|
+
if (!named?.startsWith("sns:")) {
|
|
1278
|
+
for (const record of stale) {
|
|
1279
|
+
input.log(` – forgot ${record.data?.endpoint}: '${connectionKey}' no longer names an SNS topic to unsubscribe it from`);
|
|
1280
|
+
await input.forget(record.key);
|
|
1281
|
+
}
|
|
1282
|
+
continue;
|
|
1283
|
+
}
|
|
1284
|
+
const address = new URL(named);
|
|
1285
|
+
address.searchParams.set("topicArn", topicArn);
|
|
1286
|
+
const connection = await topicConnection({
|
|
1287
|
+
connectionKey,
|
|
1288
|
+
connectionString: address.toString(),
|
|
1289
|
+
stage: input.stage,
|
|
1290
|
+
env: input.env
|
|
1291
|
+
});
|
|
1292
|
+
const result = await reconcileHttpSubscriptions(connection, {
|
|
1293
|
+
endpoints: members.pushes.map((push) => ({
|
|
1294
|
+
name: push.name,
|
|
1295
|
+
endpoint: push.endpoint,
|
|
1296
|
+
...push.events ? { events: push.events } : {}
|
|
1297
|
+
})),
|
|
1298
|
+
ownedHost: host
|
|
1299
|
+
});
|
|
1300
|
+
await connection.close();
|
|
1301
|
+
for (const push of members.pushes) {
|
|
1302
|
+
const arn = result.subscriptions[push.name];
|
|
1303
|
+
const key = subscriptionKey(push.worker, push.name);
|
|
1304
|
+
if (input.recorded?.[key]?.id !== arn) input.log(` ✓ '${push.name}' subscribed to ${topicArn.split(":").pop()} at ${push.endpoint}`);
|
|
1305
|
+
await input.record(subscriptionResource({
|
|
1306
|
+
worker: push.worker,
|
|
1307
|
+
name: push.name,
|
|
1308
|
+
topicArn,
|
|
1309
|
+
endpoint: push.endpoint,
|
|
1310
|
+
connectionKey: push.connectionKey,
|
|
1311
|
+
pending: result.pending.includes(push.name),
|
|
1312
|
+
...push.events ? { events: push.events } : {}
|
|
1313
|
+
}, arn));
|
|
1314
|
+
arns[push.worker] = {
|
|
1315
|
+
...arns[push.worker],
|
|
1316
|
+
[push.name]: arn
|
|
1317
|
+
};
|
|
1318
|
+
}
|
|
1319
|
+
for (const arn of result.removed) input.log(` – unsubscribed ${arn}: no subscriber wants it any more`);
|
|
1320
|
+
for (const record of stale) await input.forget(record.key);
|
|
1321
|
+
}
|
|
1322
|
+
return arns;
|
|
1323
|
+
}
|
|
1324
|
+
/**
|
|
1325
|
+
* How long one page has to answer: a first render fetches from the site's
|
|
1326
|
+
* APIs, so it is given longer than a health check is.
|
|
1327
|
+
*/
|
|
1328
|
+
const WARMUP_TIMEOUT_MS = 3e4;
|
|
1329
|
+
/**
|
|
1330
|
+
* Next's on-demand revalidation header: a request carrying the build's
|
|
1331
|
+
* preview-mode id is rendered afresh whatever the page's cache says.
|
|
1332
|
+
*/
|
|
1333
|
+
const NEXT_REVALIDATE_HEADER = "x-prerender-revalidate";
|
|
1334
|
+
/**
|
|
1335
|
+
* What Next answered a request from: `HIT` and `STALE` are a cached copy —
|
|
1336
|
+
* on a fresh deploy, the build's — and the request rendered nothing.
|
|
1337
|
+
*/
|
|
1338
|
+
const NEXT_CACHE_HEADER = "x-nextjs-cache";
|
|
1339
|
+
const FROM_CACHE = /* @__PURE__ */ new Set(["HIT", "STALE"]);
|
|
1340
|
+
/**
|
|
1341
|
+
* Asks the site for its `/sitemap.xml` — a sitemap index's sitemaps followed
|
|
1342
|
+
* one level — then for `/` and every page it lists, up to `maxUrls` pages in
|
|
1343
|
+
* all, `concurrency` at a time. The sitemap comes first so that, rendered
|
|
1344
|
+
* again with `headers`, it lists what the deployed APIs hold. Only pages on
|
|
1345
|
+
* the site's own origin are asked: a sitemap may list another's, which this
|
|
1346
|
+
* deploy did not start.
|
|
1347
|
+
*/
|
|
1348
|
+
async function warmSite(options) {
|
|
1349
|
+
const { fetch, edge = {}, maxUrls = 500, concurrency = 4, timeoutMs = WARMUP_TIMEOUT_MS, headers } = options;
|
|
1350
|
+
const origin = new URL(options.url).origin;
|
|
1351
|
+
const result = {
|
|
1352
|
+
warmed: [],
|
|
1353
|
+
cached: [],
|
|
1354
|
+
warnings: [],
|
|
1355
|
+
leftOut: 0
|
|
1356
|
+
};
|
|
1357
|
+
/** One GET; a failure is a warning, and `undefined`. */
|
|
1358
|
+
const get = async (url, read) => {
|
|
1359
|
+
try {
|
|
1360
|
+
const response = await fetch({
|
|
1361
|
+
url,
|
|
1362
|
+
...edge,
|
|
1363
|
+
...headers ? { headers } : {},
|
|
1364
|
+
timeoutMs,
|
|
1365
|
+
read
|
|
1366
|
+
});
|
|
1367
|
+
const cache = response.headers?.[NEXT_CACHE_HEADER];
|
|
1368
|
+
if (typeof cache === "string" && FROM_CACHE.has(cache.toUpperCase())) result.cached.push(url);
|
|
1369
|
+
return response;
|
|
1370
|
+
} catch (error) {
|
|
1371
|
+
if (edge.signal?.aborted) throw error;
|
|
1372
|
+
result.warnings.push({
|
|
1373
|
+
url,
|
|
1374
|
+
reason: error instanceof HealthRequestTimedOut ? `no answer within ${error.timeoutMs}ms` : error instanceof Error ? error.message : String(error)
|
|
1375
|
+
});
|
|
1376
|
+
return;
|
|
1377
|
+
}
|
|
1378
|
+
};
|
|
1379
|
+
const warm = async (url) => {
|
|
1380
|
+
const response = await get(url, false);
|
|
1381
|
+
if (!response) return;
|
|
1382
|
+
if (isHealthy(response.status)) result.warmed.push(url);
|
|
1383
|
+
else result.warnings.push({
|
|
1384
|
+
url,
|
|
1385
|
+
reason: `HTTP ${response.status}`
|
|
1386
|
+
});
|
|
1387
|
+
};
|
|
1388
|
+
/** A sitemap's `<loc>`s, or none where it has none — or did not answer. */
|
|
1389
|
+
const sitemap = async (url) => {
|
|
1390
|
+
const response = await get(url, true);
|
|
1391
|
+
if (!response) return void 0;
|
|
1392
|
+
if (response.status >= 400 && response.status < 500) return void 0;
|
|
1393
|
+
if (!isHealthy(response.status)) {
|
|
1394
|
+
result.warnings.push({
|
|
1395
|
+
url,
|
|
1396
|
+
reason: `HTTP ${response.status}`
|
|
1397
|
+
});
|
|
1398
|
+
return;
|
|
1399
|
+
}
|
|
1400
|
+
return readSitemap(response.body);
|
|
1401
|
+
};
|
|
1402
|
+
const root = `${origin}/`;
|
|
1403
|
+
const pages = /* @__PURE__ */ new Set([root]);
|
|
1404
|
+
const sameOrigin = (loc) => {
|
|
1405
|
+
if (!URL.canParse(loc, root)) return void 0;
|
|
1406
|
+
const url = new URL(loc, root);
|
|
1407
|
+
url.hash = "";
|
|
1408
|
+
return url.origin === origin ? url.href : void 0;
|
|
1409
|
+
};
|
|
1410
|
+
const list = (locs) => {
|
|
1411
|
+
for (const loc of locs) {
|
|
1412
|
+
const url = sameOrigin(loc);
|
|
1413
|
+
if (url) pages.add(url);
|
|
1414
|
+
}
|
|
1415
|
+
};
|
|
1416
|
+
const top = await sitemap(`${origin}/sitemap.xml`);
|
|
1417
|
+
if (top?.kind === "index") {
|
|
1418
|
+
const read = await pool([...new Set(top.locs.map(sameOrigin).filter((u) => u !== void 0))], concurrency, sitemap);
|
|
1419
|
+
for (const child of read) if (child?.kind === "urlset") list(child.locs);
|
|
1420
|
+
} else if (top) list(top.locs);
|
|
1421
|
+
await warm(root);
|
|
1422
|
+
const listed = [...pages].slice(1);
|
|
1423
|
+
const room = Math.max(0, maxUrls - 1);
|
|
1424
|
+
result.leftOut = Math.max(0, listed.length - room);
|
|
1425
|
+
await pool(listed.slice(0, room), concurrency, warm);
|
|
1426
|
+
return result;
|
|
1427
|
+
}
|
|
1428
|
+
/**
|
|
1429
|
+
* Prints the preview-mode id of the prerender manifest at `argv[1]`, and
|
|
1430
|
+
* nothing else of it: the manifest's signing and encryption keys never leave
|
|
1431
|
+
* the container. Exit 3 when the manifest has no id.
|
|
1432
|
+
*/
|
|
1433
|
+
const PRINT_PREVIEW_MODE_ID = [
|
|
1434
|
+
"let m;",
|
|
1435
|
+
"try { m = JSON.parse(require('fs').readFileSync(process.argv[1], 'utf8')); }",
|
|
1436
|
+
"catch (e) { process.stderr.write(String(e && e.message)); process.exit(2); }",
|
|
1437
|
+
"const id = m && m.preview && m.preview.previewModeId;",
|
|
1438
|
+
"if (typeof id !== 'string' || id === '') process.exit(3);",
|
|
1439
|
+
"process.stdout.write(id);"
|
|
1440
|
+
].join(" ");
|
|
1441
|
+
/**
|
|
1442
|
+
* The preview-mode id of a running Next site, from the prerender manifest
|
|
1443
|
+
* of its image — `manifest`, a path inside the container — by running the
|
|
1444
|
+
* image's own `node` in it through `exec` (`docker exec`, on whichever
|
|
1445
|
+
* engine runs the stack). Never read from this machine's disk: the image
|
|
1446
|
+
* that runs is the one whose id counts.
|
|
1447
|
+
*
|
|
1448
|
+
* The id is a secret of the site's: it is returned to the warm-up and
|
|
1449
|
+
* nowhere else — never logged, never written.
|
|
1450
|
+
*/
|
|
1451
|
+
async function nextPreviewModeId(exec, manifest) {
|
|
1452
|
+
const { code, stdout, stderr } = await exec([
|
|
1453
|
+
"node",
|
|
1454
|
+
"-e",
|
|
1455
|
+
PRINT_PREVIEW_MODE_ID,
|
|
1456
|
+
manifest
|
|
1457
|
+
]);
|
|
1458
|
+
if (code === 0 && stdout) return { id: stdout };
|
|
1459
|
+
if (code === 3 || code === 0) return { reason: `${manifest} has no preview.previewModeId, which this version of Next may not write` };
|
|
1460
|
+
const said = stderr.trim().split("\n")[0];
|
|
1461
|
+
if (code === null) return { reason: said || "its container is not running" };
|
|
1462
|
+
return { reason: `could not read ${manifest} in its container (${said || `exit ${code}`})` };
|
|
1463
|
+
}
|
|
1464
|
+
/**
|
|
1465
|
+
* Reads a sitemap (sitemaps.org): each entry's `<loc>`, entity-decoded or
|
|
1466
|
+
* from CDATA. Only an unprefixed `<loc>` is an entry's — an `<image:loc>` is
|
|
1467
|
+
* an image on a page, not a page.
|
|
1468
|
+
*/
|
|
1469
|
+
function readSitemap(xml) {
|
|
1470
|
+
const kind = /<(?:[\w-]+:)?sitemapindex[\s>]/.test(xml) ? "index" : "urlset";
|
|
1471
|
+
const locs = [];
|
|
1472
|
+
for (const match of xml.matchAll(/<loc>\s*(?:<!\[CDATA\[([\s\S]*?)\]\]>|([\s\S]*?))\s*<\/loc>/g)) {
|
|
1473
|
+
const loc = match[1] ?? decodeEntities(match[2] ?? "");
|
|
1474
|
+
if (loc.trim()) locs.push(loc.trim());
|
|
1475
|
+
}
|
|
1476
|
+
return {
|
|
1477
|
+
kind,
|
|
1478
|
+
locs
|
|
1479
|
+
};
|
|
1480
|
+
}
|
|
1481
|
+
const ENTITIES = {
|
|
1482
|
+
amp: "&",
|
|
1483
|
+
lt: "<",
|
|
1484
|
+
gt: ">",
|
|
1485
|
+
quot: "\"",
|
|
1486
|
+
apos: "'"
|
|
1487
|
+
};
|
|
1488
|
+
function decodeEntities(text) {
|
|
1489
|
+
return text.replace(/&(#x[\da-f]+|#\d+|amp|lt|gt|quot|apos);/gi, (whole, entity) => {
|
|
1490
|
+
if (entity[0] === "#") {
|
|
1491
|
+
const code = entity[1] === "x" || entity[1] === "X" ? Number.parseInt(entity.slice(2), 16) : Number.parseInt(entity.slice(1), 10);
|
|
1492
|
+
return Number.isFinite(code) ? String.fromCodePoint(code) : whole;
|
|
1493
|
+
}
|
|
1494
|
+
return ENTITIES[entity.toLowerCase()] ?? whole;
|
|
1495
|
+
});
|
|
1496
|
+
}
|
|
1497
|
+
/** Each item through `run`, at most `size` at once, results in order. */
|
|
1498
|
+
async function pool(items, size, run) {
|
|
1499
|
+
const results = new Array(items.length);
|
|
1500
|
+
let next = 0;
|
|
1501
|
+
const worker = async () => {
|
|
1502
|
+
while (next < items.length) {
|
|
1503
|
+
const index = next++;
|
|
1504
|
+
results[index] = await run(items[index]);
|
|
1505
|
+
}
|
|
1506
|
+
};
|
|
1507
|
+
await Promise.all(Array.from({ length: Math.min(size, items.length) }, worker));
|
|
1508
|
+
return results;
|
|
1509
|
+
}
|
|
1510
|
+
//#endregion
|
|
1511
|
+
//#region src/target/compose/phases.ts
|
|
1512
|
+
/**
|
|
1513
|
+
* The compose target's phases: a stage as one Docker Compose stack behind
|
|
1514
|
+
* Caddy — the local stage on this machine's Docker, a deployed stage on its
|
|
1515
|
+
* server's, driven over SSH (`compose/server.ts`) from wherever the deploy
|
|
1516
|
+
* runs.
|
|
1517
|
+
*
|
|
1518
|
+
* The order is the point of this file, and the rules it keeps are these:
|
|
1519
|
+
*
|
|
1520
|
+
* - A tag is checked before anything happens (`validate`). Every app's image
|
|
1521
|
+
* is asked of the registry first; one missing image stops the run naming
|
|
1522
|
+
* them all, and nothing is written, pulled or started.
|
|
1523
|
+
* - The databases exist before the apps do (`provision`). Postgres comes up
|
|
1524
|
+
* alone, its databases, roles and grants are created, its migrations
|
|
1525
|
+
* applied and its seeds run from this machine — through an SSH tunnel to a
|
|
1526
|
+
* server's loopback — and only then do the apps
|
|
1527
|
+
* start — so an app
|
|
1528
|
+
* never boots against a schema that is not there yet.
|
|
1529
|
+
* - What a stage runs is recorded (`release`). Each app's image, the tag it
|
|
1530
|
+
* was released under and the digest it resolved to are written to the
|
|
1531
|
+
* stage's state, so "what is this stage running" has an exact answer.
|
|
1532
|
+
* - What was started answers (`verify`): each app is asked through Caddy,
|
|
1533
|
+
* over HTTPS, with the certificate verified. Then each server-rendered site
|
|
1534
|
+
* is warmed (`warmup.ts`): a page that fails to warm is said, never failed.
|
|
1535
|
+
*
|
|
1536
|
+
* Every image is built inside Docker from a pruned slice of the build root —
|
|
1537
|
+
* the same Dockerfiles `gkm docker` writes — so nothing is built on this
|
|
1538
|
+
* machine before `docker compose build`.
|
|
1539
|
+
*
|
|
1540
|
+
* Docker, the registry, Postgres and the health probe are
|
|
1541
|
+
* injected, so the rules are asserted without a daemon; the defaults are the
|
|
1542
|
+
* real ones.
|
|
1543
|
+
*/
|
|
1544
|
+
/** `--push` without `--build`: there is nothing built here to push. */
|
|
1545
|
+
var ComposePushNeedsBuild = class extends GkmError {
|
|
1546
|
+
constructor() {
|
|
1547
|
+
super("--push pushes the images this checkout builds, so it needs --build (and never --pull): gkm compose --stage <stage> --build --push --tag <tag>.");
|
|
1548
|
+
this.name = "ComposePushNeedsBuild";
|
|
1549
|
+
}
|
|
1550
|
+
};
|
|
1551
|
+
/** Digests to run by, on a run that pulls nothing. */
|
|
1552
|
+
var ComposePinNeedsPull = class extends GkmError {
|
|
1553
|
+
constructor() {
|
|
1554
|
+
super("--digests-file pins the images a release pulls, so it needs --tag (or --pull) — or, with --build --push, it is where the pushed digests are written.");
|
|
1555
|
+
this.name = "ComposePinNeedsPull";
|
|
1556
|
+
}
|
|
1557
|
+
};
|
|
1558
|
+
/** A port variable that does not hold a port. */
|
|
1559
|
+
var EdgePortInvalid = class extends GkmError {
|
|
1560
|
+
variable;
|
|
1561
|
+
value;
|
|
1562
|
+
constructor(variable, value) {
|
|
1563
|
+
super(`${variable}=${value} is not a port. Set it to a number between 1 and 65535, or unset it for the default.`);
|
|
1564
|
+
this.variable = variable;
|
|
1565
|
+
this.value = value;
|
|
1566
|
+
this.name = "EdgePortInvalid";
|
|
1567
|
+
}
|
|
1568
|
+
};
|
|
1569
|
+
/**
|
|
1570
|
+
* A site that pre-renders against its stage (`prerender: 'stage'`) whose
|
|
1571
|
+
* APIs do not answer, so it is not built: pages built without their data
|
|
1572
|
+
* would ship, and nothing at runtime could fill them.
|
|
1573
|
+
*/
|
|
1574
|
+
var SitePrerenderApisDown = class extends GkmError {
|
|
1575
|
+
site;
|
|
1576
|
+
apis;
|
|
1577
|
+
via;
|
|
1578
|
+
constructor(site, apis, via) {
|
|
1579
|
+
const lines = apis.map(({ app, url, last }) => via === "docker" ? ` - ${app}: Docker reports it ${last}` : ` - ${url}: ${last}`).join("\n");
|
|
1580
|
+
super(`'${site}' pre-renders from its stage's APIs (prerender: 'stage'), and ${apis.length === 1 ? "this one does" : "these do"} not answer, so it was not built:\n${lines}\n` + (via === "push" ? "An image pushed for it is built against the stage as it runs now: deploy the stage first, then build and push the site." : "Fix the API and deploy again."));
|
|
1581
|
+
this.site = site;
|
|
1582
|
+
this.apis = apis;
|
|
1583
|
+
this.via = via;
|
|
1584
|
+
this.name = "SitePrerenderApisDown";
|
|
1585
|
+
}
|
|
1586
|
+
};
|
|
1587
|
+
/** A build with no commit to tag its images with. */
|
|
1588
|
+
var NoGitRevision = class extends GkmError {
|
|
1589
|
+
root;
|
|
1590
|
+
constructor(root) {
|
|
1591
|
+
super(`Images built here are tagged with the commit they were built from, and ${root} is not in a git repository with a commit. Commit, or pass --tag to name the images yourself.`);
|
|
1592
|
+
this.root = root;
|
|
1593
|
+
this.name = "NoGitRevision";
|
|
1594
|
+
}
|
|
1595
|
+
};
|
|
1596
|
+
/**
|
|
1597
|
+
* The project's own file merged over a stage's stack: `docker-compose.<stage>.yml`
|
|
1598
|
+
* at the workspace root. What the generated file cannot know — a port bound
|
|
1599
|
+
* to a tailnet address, another log driver — goes there, and is never
|
|
1600
|
+
* overwritten.
|
|
1601
|
+
*/
|
|
1602
|
+
function stackOverrideFile(root, stage) {
|
|
1603
|
+
return join(root, `docker-compose.${stage}.yml`);
|
|
1604
|
+
}
|
|
1605
|
+
/** The commit HEAD is at, short — and `-dirty` when the tree has changes. */
|
|
1606
|
+
async function gitRevision(root) {
|
|
1607
|
+
let sha;
|
|
1608
|
+
try {
|
|
1609
|
+
sha = (await runOutput("git", [
|
|
1610
|
+
"rev-parse",
|
|
1611
|
+
"--short",
|
|
1612
|
+
"HEAD"
|
|
1613
|
+
], { cwd: root })).trim();
|
|
1614
|
+
} catch {
|
|
1615
|
+
throw new NoGitRevision(root);
|
|
1616
|
+
}
|
|
1617
|
+
if (!sha) throw new NoGitRevision(root);
|
|
1618
|
+
return (await runOutput("git", ["status", "--porcelain"], { cwd: root }).catch(() => "")).trim() ? `${sha}-dirty` : sha;
|
|
1619
|
+
}
|
|
1620
|
+
/** The edge's ports, from the environment — 443 and 80 when unset. */
|
|
1621
|
+
function edgePorts(env = process.env) {
|
|
1622
|
+
const read = (variable, fallback) => {
|
|
1623
|
+
const value = env[variable];
|
|
1624
|
+
if (value === void 0 || value === "") return fallback;
|
|
1625
|
+
const port = Number(value);
|
|
1626
|
+
if (!Number.isInteger(port) || port < 1 || port > 65535) throw new EdgePortInvalid(variable, value);
|
|
1627
|
+
return port;
|
|
1628
|
+
};
|
|
1629
|
+
const logs = env["GKM_COMPOSE_LOGS_PORT"] ? read(LOGS_PORT_ENV, 0) : void 0;
|
|
1630
|
+
return {
|
|
1631
|
+
https: read(EDGE_PORT_ENV.https, 443),
|
|
1632
|
+
http: read(EDGE_PORT_ENV.http, 80),
|
|
1633
|
+
...logs ? { logs } : {}
|
|
1634
|
+
};
|
|
1635
|
+
}
|
|
1636
|
+
/**
|
|
1637
|
+
* The real ones. Each app is asked for three minutes before it counts as
|
|
1638
|
+
* down: a deployed stage's first ACME certificate can take that long.
|
|
1639
|
+
*/
|
|
1640
|
+
const defaultDeps = {
|
|
1641
|
+
docker: dockerCompose,
|
|
1642
|
+
revision: gitRevision,
|
|
1643
|
+
sql: pgClient,
|
|
1644
|
+
buckets: bucketClient,
|
|
1645
|
+
logins: ensurePostgresLogin,
|
|
1646
|
+
migrate: migrateDatabases,
|
|
1647
|
+
seed: seedDatabases,
|
|
1648
|
+
probe: httpsProbe,
|
|
1649
|
+
fetch: edgeFetch,
|
|
1650
|
+
healthAttempts: 90,
|
|
1651
|
+
healthIntervalMs: 2e3,
|
|
1652
|
+
env: process.env,
|
|
1653
|
+
lookup: systemLookup,
|
|
1654
|
+
server: sshAccess
|
|
1655
|
+
};
|
|
1656
|
+
/**
|
|
1657
|
+
* The stack the stage would run, and — for a tag — the registry's word that
|
|
1658
|
+
* every image it names exists. Nothing is written: a missing image stops the
|
|
1659
|
+
* run here, before a file, a secret or a container is touched.
|
|
1660
|
+
*/
|
|
1661
|
+
async function validateCompose(ctx, deps, options = {}) {
|
|
1662
|
+
const { workspace, stage, identity, tag } = ctx;
|
|
1663
|
+
const root = workspace.root;
|
|
1664
|
+
const mode = options.mode ?? (ctx.tagGiven ? "pull" : "build");
|
|
1665
|
+
const push = options.push === true;
|
|
1666
|
+
if (push && mode !== "build") throw new ComposePushNeedsBuild();
|
|
1667
|
+
if (options.pin && mode !== "pull") throw new ComposePinNeedsPull();
|
|
1668
|
+
const registry = workspace.deploy?.registry;
|
|
1669
|
+
if (!registry && (push || mode === "pull")) throw new RegistryRequired(push ? "push" : "pull", imageRef(identity, ctx.apps[0] ?? workspace.name, void 0, tag));
|
|
1670
|
+
const background = {};
|
|
1671
|
+
const subscribers = {};
|
|
1672
|
+
const manifest = await discover({
|
|
1673
|
+
patterns: constructGlobs(workspace),
|
|
1674
|
+
cwd: root,
|
|
1675
|
+
background,
|
|
1676
|
+
subscribers
|
|
1677
|
+
});
|
|
1678
|
+
const { secrets, generated } = await stageSecrets(ctx, manifest);
|
|
1679
|
+
const recorded = push ? void 0 : await ctx.state.read(stage);
|
|
1680
|
+
const layout = mode === "build" ? imageLayout(workspace) : void 0;
|
|
1681
|
+
const input = {
|
|
1682
|
+
workspace,
|
|
1683
|
+
manifest,
|
|
1684
|
+
background,
|
|
1685
|
+
subscribers,
|
|
1686
|
+
stage,
|
|
1687
|
+
identity,
|
|
1688
|
+
images: {
|
|
1689
|
+
mode,
|
|
1690
|
+
tag,
|
|
1691
|
+
...registry ? { registry } : {}
|
|
1692
|
+
},
|
|
1693
|
+
secrets,
|
|
1694
|
+
...stage === workspace.stages.local ? { localCredentials: (await loadLocalCredentials(workspace)).credentials } : {},
|
|
1695
|
+
allowDevServices: ctx.allowDevServices,
|
|
1696
|
+
ports: edgePorts(deps.env),
|
|
1697
|
+
...layout ? { layout } : {},
|
|
1698
|
+
...push ? { buildOnly: true } : {},
|
|
1699
|
+
...mode === "build" ? { prerenderRun: (/* @__PURE__ */ new Date()).toISOString() } : {}
|
|
1700
|
+
};
|
|
1701
|
+
const recordedArns = recordedPushSubscriptions(recorded?.resources);
|
|
1702
|
+
const planned = push ? void 0 : composeStack({
|
|
1703
|
+
...input,
|
|
1704
|
+
recordingSubscriptions: true
|
|
1705
|
+
});
|
|
1706
|
+
const pushes = planned ? topicPushes(planned, manifest) : [];
|
|
1707
|
+
const topics = planned && (pushes.length > 0 || recordedTopicSubscriptions(recorded?.resources).length > 0) ? {
|
|
1708
|
+
pushes,
|
|
1709
|
+
recorded: recorded?.resources
|
|
1710
|
+
} : void 0;
|
|
1711
|
+
const composed = topics && planned ? planned : composeStack({
|
|
1712
|
+
...input,
|
|
1713
|
+
pushSubscriptions: recordedArns
|
|
1714
|
+
});
|
|
1715
|
+
if (mode === "build") assertRedisClient(workspace, composed, manifest);
|
|
1716
|
+
const pinned = (unpinned) => options.pin ? withPinnedImages(unpinned, options.pin.file, options.pin.digests) : unpinned;
|
|
1717
|
+
const stack = pinned(composed);
|
|
1718
|
+
if (mode === "pull" && !ctx.dryRun) await assertImagesExist(deps.docker, tag, [
|
|
1719
|
+
...stack.apps,
|
|
1720
|
+
...stack.workers,
|
|
1721
|
+
...stack.processors
|
|
1722
|
+
]);
|
|
1723
|
+
if (stack.redis && !stack.local) ctx.secrets.mask(stack.redis.password);
|
|
1724
|
+
if (stack.logs && (!stack.local || stack.logs.passwordFromSecrets)) {
|
|
1725
|
+
ctx.secrets.mask(stack.logs.password);
|
|
1726
|
+
ctx.secrets.mask(stack.logs.appEnv.OTEL_EXPORTER_OTLP_HEADERS);
|
|
1727
|
+
}
|
|
1728
|
+
if (!push && !stack.local) requiredServerAddress(stage, workspace.domains?.[stage], secrets?.custom);
|
|
1729
|
+
const server = push ? void 0 : composeServer({
|
|
1730
|
+
stage,
|
|
1731
|
+
local: stack.local,
|
|
1732
|
+
config: workspace.deploy?.compose?.server,
|
|
1733
|
+
custom: secrets?.custom
|
|
1734
|
+
});
|
|
1735
|
+
const dir = join(root, stackDir(stage));
|
|
1736
|
+
const override = stackOverrideFile(root, stage);
|
|
1737
|
+
const overrides = existsSync(override) ? [override] : [];
|
|
1738
|
+
if (overrides.length > 0) ctx.logger.info(`🧩 Merging docker-compose.${stage}.yml over the generated stack`);
|
|
1739
|
+
const previous = Object.fromEntries(Object.entries(recorded?.state.releases ?? {}).map(([name, releases]) => {
|
|
1740
|
+
const { ref, tag, digest } = releases.current;
|
|
1741
|
+
return [name, {
|
|
1742
|
+
ref,
|
|
1743
|
+
...tag ? { tag } : {},
|
|
1744
|
+
...digest ? { digest } : {}
|
|
1745
|
+
}];
|
|
1746
|
+
}));
|
|
1747
|
+
return {
|
|
1748
|
+
mode,
|
|
1749
|
+
push,
|
|
1750
|
+
stack,
|
|
1751
|
+
...topics ? { topicSubscriptions: {
|
|
1752
|
+
...topics,
|
|
1753
|
+
restack: (arns) => {
|
|
1754
|
+
const merged = { ...recordedArns };
|
|
1755
|
+
for (const [worker, own] of Object.entries(arns)) merged[worker] = {
|
|
1756
|
+
...merged[worker],
|
|
1757
|
+
...own
|
|
1758
|
+
};
|
|
1759
|
+
return pinned(composeStack({
|
|
1760
|
+
...input,
|
|
1761
|
+
pushSubscriptions: merged
|
|
1762
|
+
}));
|
|
1763
|
+
}
|
|
1764
|
+
} } : {},
|
|
1765
|
+
...server ? { server } : {},
|
|
1766
|
+
dir,
|
|
1767
|
+
ref: {
|
|
1768
|
+
project: composeProject(identity),
|
|
1769
|
+
file: join(dir, "docker-compose.yml"),
|
|
1770
|
+
...overrides.length > 0 ? { overrides } : {},
|
|
1771
|
+
cwd: root,
|
|
1772
|
+
...server ? { host: dockerHost(server) } : {},
|
|
1773
|
+
output: ctx.childOutput,
|
|
1774
|
+
signal: ctx.signal
|
|
1775
|
+
},
|
|
1776
|
+
secrets,
|
|
1777
|
+
generated,
|
|
1778
|
+
previous,
|
|
1779
|
+
files: [],
|
|
1780
|
+
images: {},
|
|
1781
|
+
changes: []
|
|
1782
|
+
};
|
|
1783
|
+
}
|
|
1784
|
+
/**
|
|
1785
|
+
* What only a compose deploy checks before it changes anything, once the
|
|
1786
|
+
* stage's own keys are: the stage's own certificate is there, and every
|
|
1787
|
+
* public host points at the stage's server — its records written where a
|
|
1788
|
+
* provider holds them, then confirmed — before Caddy or Traefik ask Let's
|
|
1789
|
+
* Encrypt for a certificate it could not issue. A build-only run never asks.
|
|
1790
|
+
*/
|
|
1791
|
+
async function readyCompose(ctx, run, deps) {
|
|
1792
|
+
const { stack } = run;
|
|
1793
|
+
if (stack.tls) {
|
|
1794
|
+
const { certFile, keyFile, caFile } = stack.tls;
|
|
1795
|
+
for (const file of [
|
|
1796
|
+
certFile,
|
|
1797
|
+
keyFile,
|
|
1798
|
+
...caFile ? [caFile] : []
|
|
1799
|
+
]) if (!existsSync(file)) throw new ComposeTlsFileMissing(ctx.stage, file);
|
|
1800
|
+
}
|
|
1801
|
+
if (stack.local) {
|
|
1802
|
+
await edgeHostsFree(ctx, run, deps);
|
|
1803
|
+
return;
|
|
1804
|
+
}
|
|
1805
|
+
if (run.server && !ctx.dryRun && !run.push) await deps.server.check(run.server);
|
|
1806
|
+
await edgeHostsFree(ctx, run, deps);
|
|
1807
|
+
const prune = await stageHostsDns(ctx, deps, stackHosts(stack).filter((host) => !isLocalHost(host)), run.secrets?.custom, stack.wildcard?.host);
|
|
1808
|
+
if (prune) run.pruneDns = prune;
|
|
1809
|
+
}
|
|
1810
|
+
/**
|
|
1811
|
+
* No host the stack routes through the shared edge is routed there by another
|
|
1812
|
+
* project — asked of the edge on the stage's engine before a record, a
|
|
1813
|
+
* secret, an image or a container is touched, so a clash fails the deploy
|
|
1814
|
+
* with nothing changed. Asked again as the routes are written
|
|
1815
|
+
* (`writeEdgeRoutes`), for an edge that was not running yet.
|
|
1816
|
+
*/
|
|
1817
|
+
async function edgeHostsFree(ctx, run, deps) {
|
|
1818
|
+
const { stack, ref } = run;
|
|
1819
|
+
if (ctx.dryRun || run.push) return;
|
|
1820
|
+
if (stack.proxy !== "traefik" || !stack.traefik) return;
|
|
1821
|
+
await assertEdgeHostsFree(deps.docker, edgeRef(edgeFile(run), {
|
|
1822
|
+
...ref.host ? { host: ref.host } : {},
|
|
1823
|
+
...ref.output ? { output: ref.output } : {}
|
|
1824
|
+
}), stack.project, stack.traefik);
|
|
1825
|
+
}
|
|
1826
|
+
/** A stack whose caches are in Redis, built for an app that has no client. */
|
|
1827
|
+
var RedisClientMissing = class extends GkmError {
|
|
1828
|
+
apps;
|
|
1829
|
+
constructor(apps) {
|
|
1830
|
+
super(`The stack keeps every cache in Redis, and ${apps.join(", ")} ${apps.length === 1 ? "does" : "do"} not depend on ioredis, the client the generated server reaches it with. Add it to the workspace: pnpm add ioredis`);
|
|
1831
|
+
this.apps = apps;
|
|
1832
|
+
this.name = "RedisClientMissing";
|
|
1833
|
+
}
|
|
1834
|
+
};
|
|
1835
|
+
/**
|
|
1836
|
+
* Every backend and worker image whose process reaches a cache can resolve
|
|
1837
|
+
* `ioredis` — listed by its app or a directory above it, the way Node and
|
|
1838
|
+
* the image's install find it. A process that reaches no cache registers no
|
|
1839
|
+
* cache driver, so it needs no client.
|
|
1840
|
+
*/
|
|
1841
|
+
function assertRedisClient(workspace, stack, manifest) {
|
|
1842
|
+
if (!stack.plan.resources.some((r) => r.kind === "cache")) return;
|
|
1843
|
+
const cacheKeys = Object.values(manifest).filter((d) => d.kind === "cache").flatMap((d) => d.provides ?? []);
|
|
1844
|
+
const reachesCache = (keys) => cacheKeys.some((key) => keys?.has(key));
|
|
1845
|
+
const missing = [.../* @__PURE__ */ new Set([...stack.apps.filter((app) => (app.kind === "rest-api" || app.kind === "websocket-api") && reachesCache(appEnvKeys(manifest, app.name))).map((a) => a.name), ...stack.workers.filter((worker) => reachesCache(workerEnvKeys(manifest, worker.id))).map((worker) => worker.host)])].filter((name) => {
|
|
1846
|
+
const app = workspace.apps[name];
|
|
1847
|
+
return app && !installedFrom(join(workspace.root, app.path), "ioredis");
|
|
1848
|
+
}).sort();
|
|
1849
|
+
if (missing.length > 0) throw new RedisClientMissing(missing);
|
|
1850
|
+
}
|
|
1851
|
+
/**
|
|
1852
|
+
* The deploy's DNS step, for a deployed stage: its server's address — required
|
|
1853
|
+
* where it serves a real domain — then its own hosts written through each
|
|
1854
|
+
* domain's provider in `dns` where they differ, read back from it, and
|
|
1855
|
+
* recorded in the stage's state; hosts no provider writes resolved with the
|
|
1856
|
+
* system resolver. A dry run prints the plan and writes nothing, and warns
|
|
1857
|
+
* rather than stops. Returns the prune of the records gkm wrote for hosts the
|
|
1858
|
+
* stage no longer serves — which a dry run prints there and then.
|
|
1859
|
+
*
|
|
1860
|
+
* @throws {ServerAddressMissing} when the stage has a domain and no address
|
|
1861
|
+
* @throws {ServerAddressInvalid} for a value that is not an address
|
|
1862
|
+
* @throws {HostNotPointingAtServer} when a host is not the server
|
|
1863
|
+
*/
|
|
1864
|
+
async function stageHostsDns(ctx, deps, hosts, custom, wildcard) {
|
|
1865
|
+
const { workspace, stage } = ctx;
|
|
1866
|
+
const server = requiredServerAddress(stage, workspace.domains?.[stage], custom);
|
|
1867
|
+
if (hosts.length === 0) return;
|
|
1868
|
+
if (ctx.skipDns) {
|
|
1869
|
+
ctx.logger.info("🌐 DNS skipped (--skip-dns): no record is written or checked");
|
|
1870
|
+
return;
|
|
1871
|
+
}
|
|
1872
|
+
if (!server) {
|
|
1873
|
+
ctx.logger.info(`🌐 DNS skipped: no ${SERVER_IPV4_KEY} in '${stage}''s secrets — ${serverAddressHint(stage)}`);
|
|
1874
|
+
return;
|
|
1875
|
+
}
|
|
1876
|
+
const log = (line) => ctx.logger.info(line);
|
|
1877
|
+
if (workspace.dns) log(`🌐 DNS for '${stage}' → ${server.ipv4}${server.ipv6 ? ` / ${server.ipv6}` : ""}${ctx.dryRun ? " (dry run — nothing is written)" : ""}`);
|
|
1878
|
+
try {
|
|
1879
|
+
const stored = await ctx.state.read(stage);
|
|
1880
|
+
const result = await stageDns({
|
|
1881
|
+
stage,
|
|
1882
|
+
hosts,
|
|
1883
|
+
server,
|
|
1884
|
+
dns: workspace.dns,
|
|
1885
|
+
recorded: dnsResources(stored?.resources ?? {}),
|
|
1886
|
+
...wildcard ? { wildcard } : {},
|
|
1887
|
+
credentials: ctx.credentials,
|
|
1888
|
+
log,
|
|
1889
|
+
lookup: deps.lookup ?? systemLookup,
|
|
1890
|
+
...ctx.dryRun ? { dryRun: true } : {},
|
|
1891
|
+
...deps.dnsProviderFor ? { providerFor: deps.dnsProviderFor } : {}
|
|
1892
|
+
});
|
|
1893
|
+
if (!ctx.dryRun) {
|
|
1894
|
+
const journal = await DeployJournal.open(ctx.state, stage, () => createComposeState(stage));
|
|
1895
|
+
const providers = new Map(result.plan.domains.map((d) => [d.domain, d.provider]));
|
|
1896
|
+
await recordDnsChanges(journal, result.changes, (domain) => providers.get(domain));
|
|
1897
|
+
}
|
|
1898
|
+
const parts = [result.confirmed.length > 0 ? `${result.confirmed.length} host${result.confirmed.length === 1 ? "" : "s"} confirmed by the DNS provider` : "", result.resolved.length > 0 ? `${result.resolved.length} host${result.resolved.length === 1 ? "" : "s"} resolve${result.resolved.length === 1 ? "s" : ""} to ${server.ipv4}` : ""].filter(Boolean);
|
|
1899
|
+
if (parts.length > 0) log(`🌐 ${parts.join(", ")}`);
|
|
1900
|
+
if (ctx.dryRun) {
|
|
1901
|
+
await result.prune();
|
|
1902
|
+
return;
|
|
1903
|
+
}
|
|
1904
|
+
return result.recorded.stale.length > 0 ? result.prune : void 0;
|
|
1905
|
+
} catch (error) {
|
|
1906
|
+
if (ctx.dryRun && error instanceof HostNotPointingAtServer) {
|
|
1907
|
+
ctx.logger.warn(`⚠ ${error.message}`);
|
|
1908
|
+
return;
|
|
1909
|
+
}
|
|
1910
|
+
throw error;
|
|
1911
|
+
}
|
|
1912
|
+
}
|
|
1913
|
+
/**
|
|
1914
|
+
* The records gkm wrote for hosts the stage no longer serves, deleted once it
|
|
1915
|
+
* answers on its new ones — and forgotten from its state, deleted or not:
|
|
1916
|
+
* none is gkm's to manage any more.
|
|
1917
|
+
*/
|
|
1918
|
+
async function pruneStageDns(ctx, run) {
|
|
1919
|
+
if (!run.pruneDns) return;
|
|
1920
|
+
const pruned = await run.pruneDns();
|
|
1921
|
+
const journal = await DeployJournal.open(ctx.state, ctx.stage, () => createComposeState(ctx.stage));
|
|
1922
|
+
for (const { record } of pruned) await forgetDnsResource(journal, record);
|
|
1923
|
+
const deleted = pruned.filter((p) => p.action === "delete").length;
|
|
1924
|
+
if (deleted > 0) ctx.logger.info(`🌐 ${deleted} record${deleted === 1 ? "" : "s"} deleted`);
|
|
1925
|
+
}
|
|
1926
|
+
/**
|
|
1927
|
+
* The stage's secrets — and, for a deployed stage, everything it generates
|
|
1928
|
+
* once: its seed, and each declared secret and keyring. Kept only once the
|
|
1929
|
+
* run goes ahead (`provision`), so a dry run, or a tag that is not there,
|
|
1930
|
+
* leaves the stage's secrets as it found them.
|
|
1931
|
+
*/
|
|
1932
|
+
async function stageSecrets(ctx, manifest) {
|
|
1933
|
+
const stored = await ctx.secrets.read();
|
|
1934
|
+
if (ctx.stage === ctx.workspace.stages.local) return {
|
|
1935
|
+
secrets: stored,
|
|
1936
|
+
generated: []
|
|
1937
|
+
};
|
|
1938
|
+
const { secrets, generated } = deployedStackSecrets(ctx.workspace, ctx.stage, stored, manifest);
|
|
1939
|
+
if (secrets.seed) ctx.secrets.mask(secrets.seed);
|
|
1940
|
+
for (const [key, value] of Object.entries(secrets.custom ?? {})) if (!isReservedStageKey(key)) ctx.secrets.mask(value);
|
|
1941
|
+
return {
|
|
1942
|
+
secrets,
|
|
1943
|
+
generated
|
|
1944
|
+
};
|
|
1945
|
+
}
|
|
1946
|
+
/**
|
|
1947
|
+
* The stack with each app's and worker's image pinned to the digest the file
|
|
1948
|
+
* names: the refs it is checked, pulled and recorded by, and the image each
|
|
1949
|
+
* compose service runs.
|
|
1950
|
+
*/
|
|
1951
|
+
function withPinnedImages(stack, file, digests) {
|
|
1952
|
+
const apps = pinImages(file, digests, stack.apps);
|
|
1953
|
+
const workers = pinImages(file, digests, stack.workers);
|
|
1954
|
+
const processors = pinImages(file, digests, stack.processors);
|
|
1955
|
+
const services = { ...stack.compose.services };
|
|
1956
|
+
for (const image of [
|
|
1957
|
+
...apps,
|
|
1958
|
+
...workers,
|
|
1959
|
+
...processors
|
|
1960
|
+
]) services[image.name] = {
|
|
1961
|
+
...services[image.name],
|
|
1962
|
+
image: image.ref
|
|
1963
|
+
};
|
|
1964
|
+
return {
|
|
1965
|
+
...stack,
|
|
1966
|
+
apps,
|
|
1967
|
+
workers,
|
|
1968
|
+
processors,
|
|
1969
|
+
compose: {
|
|
1970
|
+
...stack.compose,
|
|
1971
|
+
services
|
|
1972
|
+
}
|
|
1973
|
+
};
|
|
1974
|
+
}
|
|
1975
|
+
/**
|
|
1976
|
+
* A dry run: the stack's files, written so they can be read, and what a real
|
|
1977
|
+
* run would do — no image is built or pulled, no container touched, nothing
|
|
1978
|
+
* recorded and no secret kept.
|
|
1979
|
+
*/
|
|
1980
|
+
async function planCompose(ctx, run) {
|
|
1981
|
+
if (run.generated.length > 0) ctx.logger.info(`🔑 "${ctx.stage}" has no ${run.generated.join(", ")} yet; this dry run used values it did not keep.`);
|
|
1982
|
+
run.files = await writeStack(ctx.cwd, run.dir, run.stack);
|
|
1983
|
+
printPlan(ctx, run);
|
|
1984
|
+
if (!run.push && run.stack.infra.includes("postgres")) reportPlannedSeeds((await plannedSeeds({
|
|
1985
|
+
root: ctx.workspace.root,
|
|
1986
|
+
manifest: ctx.manifest
|
|
1987
|
+
})).map(({ target, seeds }) => ({
|
|
1988
|
+
folder: target.seeds,
|
|
1989
|
+
seeds
|
|
1990
|
+
})), (line) => ctx.logger.info(line));
|
|
1991
|
+
const planned = (change) => {
|
|
1992
|
+
run.changes.push(change);
|
|
1993
|
+
ctx.emit({
|
|
1994
|
+
type: "resource.planned",
|
|
1995
|
+
...change
|
|
1996
|
+
});
|
|
1997
|
+
};
|
|
1998
|
+
for (const service of run.push ? [] : run.stack.infra) planned({
|
|
1999
|
+
key: `service:${service}`,
|
|
2000
|
+
resourceType: "service",
|
|
2001
|
+
action: "ensure"
|
|
2002
|
+
});
|
|
2003
|
+
for (const app of run.stack.apps) {
|
|
2004
|
+
planned({
|
|
2005
|
+
key: `image:${app.name}`,
|
|
2006
|
+
resourceType: "image",
|
|
2007
|
+
action: run.mode === "build" ? "build" : "reuse",
|
|
2008
|
+
id: app.ref
|
|
2009
|
+
});
|
|
2010
|
+
if (run.push) continue;
|
|
2011
|
+
planned({
|
|
2012
|
+
key: `service:${app.name}`,
|
|
2013
|
+
resourceType: "service",
|
|
2014
|
+
action: run.previous[app.name] ? "reuse" : "create"
|
|
2015
|
+
});
|
|
2016
|
+
}
|
|
2017
|
+
for (const worker of [...run.stack.workers, ...run.stack.processors]) {
|
|
2018
|
+
planned({
|
|
2019
|
+
key: `image:${worker.name}`,
|
|
2020
|
+
resourceType: "image",
|
|
2021
|
+
action: run.mode === "build" ? "build" : "reuse",
|
|
2022
|
+
id: worker.ref
|
|
2023
|
+
});
|
|
2024
|
+
if (run.push) continue;
|
|
2025
|
+
planned({
|
|
2026
|
+
key: `service:${worker.name}`,
|
|
2027
|
+
resourceType: "service",
|
|
2028
|
+
action: run.previous[worker.name] ? "reuse" : "create"
|
|
2029
|
+
});
|
|
2030
|
+
}
|
|
2031
|
+
for (const push of run.topicSubscriptions?.pushes ?? []) {
|
|
2032
|
+
const key = subscriptionKey(push.worker, push.name);
|
|
2033
|
+
const id = run.topicSubscriptions?.recorded?.[key]?.id;
|
|
2034
|
+
planned({
|
|
2035
|
+
key,
|
|
2036
|
+
resourceType: SUBSCRIPTION_TYPE,
|
|
2037
|
+
action: id ? "reuse" : "create",
|
|
2038
|
+
...id ? { id } : {}
|
|
2039
|
+
});
|
|
2040
|
+
}
|
|
2041
|
+
if (!run.push) planned({
|
|
2042
|
+
key: run.stack.proxy === "caddy" ? "service:caddy" : `service:${EDGE_PROJECT}/${EDGE_SERVICE}`,
|
|
2043
|
+
resourceType: "service",
|
|
2044
|
+
action: "ensure"
|
|
2045
|
+
});
|
|
2046
|
+
}
|
|
2047
|
+
/**
|
|
2048
|
+
* The shared edge's key for the stage's wildcard certificate: the DNS
|
|
2049
|
+
* challenge's record, and nothing else, through the stage domain's Route 53
|
|
2050
|
+
* entry — before the stack's routes ask for the certificate.
|
|
2051
|
+
*/
|
|
2052
|
+
async function edgeAcmeKey(ctx, run, deps) {
|
|
2053
|
+
const { workspace, stage } = ctx;
|
|
2054
|
+
const domain = workspace.domains?.[stage];
|
|
2055
|
+
const dns = workspace.dns ? normalizeDnsConfig(workspace.dns) : {};
|
|
2056
|
+
const zone = domain ? findRootDomain(domain, dns) : null;
|
|
2057
|
+
const config = zone ? dns[zone] : void 0;
|
|
2058
|
+
if (!domain || !zone || config?.provider !== "route53") return;
|
|
2059
|
+
const route53 = config;
|
|
2060
|
+
const server = requiredServerAddress(stage, domain, run.secrets?.custom)?.ipv4 ?? run.server?.host ?? "local";
|
|
2061
|
+
const clients = await (deps.acmeClients ?? defaultAcmeClients)(route53);
|
|
2062
|
+
await ensureEdgeAcmeKey(deps.docker, {
|
|
2063
|
+
clients,
|
|
2064
|
+
edge: edgeRef(edgeFile(run), {
|
|
2065
|
+
...run.ref.host ? { host: run.ref.host } : {},
|
|
2066
|
+
...run.ref.output ? { output: run.ref.output } : {}
|
|
2067
|
+
}),
|
|
2068
|
+
server,
|
|
2069
|
+
project: run.stack.project,
|
|
2070
|
+
domain,
|
|
2071
|
+
zone,
|
|
2072
|
+
...route53.hostedZoneId ? { hostedZoneId: route53.hostedZoneId } : {},
|
|
2073
|
+
...ctx.dryRun ? { dryRun: true } : {},
|
|
2074
|
+
log: (line) => ctx.logger.info(line)
|
|
2075
|
+
});
|
|
2076
|
+
}
|
|
2077
|
+
/** IAM and Route 53 through the AWS SDK's own chain, or the entry's profile. */
|
|
2078
|
+
async function defaultAcmeClients(config) {
|
|
2079
|
+
const [{ IAMClient }, { Route53Client }, { fromIni }] = await Promise.all([
|
|
2080
|
+
import("@aws-sdk/client-iam"),
|
|
2081
|
+
import("@aws-sdk/client-route-53"),
|
|
2082
|
+
import("@aws-sdk/credential-providers")
|
|
2083
|
+
]);
|
|
2084
|
+
const options = {
|
|
2085
|
+
region: config.region ?? "us-east-1",
|
|
2086
|
+
...config.profile ? { credentials: fromIni({ profile: config.profile }) } : {}
|
|
2087
|
+
};
|
|
2088
|
+
return {
|
|
2089
|
+
iam: new IAMClient(options),
|
|
2090
|
+
route53: new Route53Client(options)
|
|
2091
|
+
};
|
|
2092
|
+
}
|
|
2093
|
+
/**
|
|
2094
|
+
* What the apps run on: the stage's generated secrets kept, the stack's files
|
|
2095
|
+
* written, its infrastructure started, and its databases, roles, grants and
|
|
2096
|
+
* migrations applied.
|
|
2097
|
+
*/
|
|
2098
|
+
async function provisionCompose(ctx, run, deps) {
|
|
2099
|
+
const { ref } = run;
|
|
2100
|
+
if (run.push) return;
|
|
2101
|
+
if (run.generated.length > 0 && run.secrets) {
|
|
2102
|
+
await ctx.secrets.write(run.secrets);
|
|
2103
|
+
ctx.logger.info(`🔑 Generated for "${ctx.stage}" (${ctx.secrets.store}): ${run.generated.join(", ")}`);
|
|
2104
|
+
}
|
|
2105
|
+
const ports = edgePorts(deps.env);
|
|
2106
|
+
await assertEdgePorts(deps.docker, {
|
|
2107
|
+
project: run.stack.project,
|
|
2108
|
+
proxy: run.stack.proxy,
|
|
2109
|
+
ports,
|
|
2110
|
+
engine: ref
|
|
2111
|
+
});
|
|
2112
|
+
if (run.topicSubscriptions) await subscribeTopics(ctx, run, deps);
|
|
2113
|
+
const { stack } = run;
|
|
2114
|
+
run.files = await writeStack(ctx.cwd, run.dir, stack);
|
|
2115
|
+
printPlan(ctx, run);
|
|
2116
|
+
if (stack.proxy === "traefik") {
|
|
2117
|
+
ctx.logger.info(`\n🌐 Starting the shared edge (${EDGE_PROJECT})…`);
|
|
2118
|
+
run.files.push(...await ensureEdge(deps.docker, {
|
|
2119
|
+
file: edgeFile(run),
|
|
2120
|
+
ports,
|
|
2121
|
+
...ref.host ? { host: ref.host } : {},
|
|
2122
|
+
logging: {
|
|
2123
|
+
driver: LOG_ROTATION.driver,
|
|
2124
|
+
options: { ...LOG_ROTATION.options }
|
|
2125
|
+
},
|
|
2126
|
+
...ref.output ? { output: ref.output } : {},
|
|
2127
|
+
...ref.signal ? { signal: ref.signal } : {}
|
|
2128
|
+
}));
|
|
2129
|
+
applied(ctx, run, {
|
|
2130
|
+
key: `service:${EDGE_PROJECT}/${EDGE_SERVICE}`,
|
|
2131
|
+
resourceType: "service",
|
|
2132
|
+
action: "ensure",
|
|
2133
|
+
id: `${EDGE_PROJECT}/${EDGE_SERVICE}`,
|
|
2134
|
+
via: "found"
|
|
2135
|
+
});
|
|
2136
|
+
if (stack.wildcard?.tls === "dns") await edgeAcmeKey(ctx, run, deps);
|
|
2137
|
+
}
|
|
2138
|
+
if (stack.infra.length > 0) {
|
|
2139
|
+
ctx.logger.info(`\n🗄️ Starting ${stack.infra.join(", ")}…`);
|
|
2140
|
+
await deps.docker.up(ref, stack.infra);
|
|
2141
|
+
for (const service of stack.infra) applied(ctx, run, {
|
|
2142
|
+
key: `service:${service}`,
|
|
2143
|
+
resourceType: "service",
|
|
2144
|
+
action: "ensure",
|
|
2145
|
+
id: `${stack.project}/${service}`,
|
|
2146
|
+
via: Object.keys(run.previous).length > 0 ? "recorded" : "created"
|
|
2147
|
+
});
|
|
2148
|
+
}
|
|
2149
|
+
if (stack.storage && stack.infra.includes("minio")) await prepareBuckets(ctx, run, deps);
|
|
2150
|
+
if (stack.infra.includes("postgres")) await prepareDatabases(ctx, run, deps);
|
|
2151
|
+
}
|
|
2152
|
+
/**
|
|
2153
|
+
* Subscribe each topic subscriber SNS pushes to — for a topic the stage set
|
|
2154
|
+
* to SNS by hand — record the ARNs, and compose the stack again with them,
|
|
2155
|
+
* before a file is written.
|
|
2156
|
+
*/
|
|
2157
|
+
async function subscribeTopics(ctx, run, deps) {
|
|
2158
|
+
const { pushes, recorded, restack } = run.topicSubscriptions;
|
|
2159
|
+
if (pushes.length > 0) ctx.logger.info("\n📮 SNS subscriptions for the stage's own topics");
|
|
2160
|
+
run.stack = restack(await ensureTopicSubscriptions({
|
|
2161
|
+
pushes,
|
|
2162
|
+
recorded,
|
|
2163
|
+
secrets: run.secrets?.custom ?? {},
|
|
2164
|
+
stage: ctx.stage,
|
|
2165
|
+
env: deps.env,
|
|
2166
|
+
record: async (resource) => {
|
|
2167
|
+
await ctx.state.putResource(ctx.stage, resource);
|
|
2168
|
+
applied(ctx, run, {
|
|
2169
|
+
key: resource.key,
|
|
2170
|
+
resourceType: SUBSCRIPTION_TYPE,
|
|
2171
|
+
action: "ensure",
|
|
2172
|
+
id: resource.id,
|
|
2173
|
+
via: recorded?.[resource.key]?.id === resource.id ? "recorded" : "created"
|
|
2174
|
+
});
|
|
2175
|
+
},
|
|
2176
|
+
forget: async (key) => {
|
|
2177
|
+
await ctx.state.deleteResource(ctx.stage, key);
|
|
2178
|
+
},
|
|
2179
|
+
log: (line) => ctx.logger.info(line)
|
|
2180
|
+
}));
|
|
2181
|
+
}
|
|
2182
|
+
/**
|
|
2183
|
+
* Create each bucket the stack's MinIO serves, and the open paths of each
|
|
2184
|
+
* one a file server fronts — from this machine, on MinIO's loopback port,
|
|
2185
|
+
* the way `gkm dev` creates them.
|
|
2186
|
+
*/
|
|
2187
|
+
async function prepareBuckets(ctx, run, deps) {
|
|
2188
|
+
const storage = run.stack.storage;
|
|
2189
|
+
if (storage.buckets.length === 0) return;
|
|
2190
|
+
const tunnel = await reach(run, deps, "minio", LOOPBACK_SERVICES.minio);
|
|
2191
|
+
let done;
|
|
2192
|
+
try {
|
|
2193
|
+
const client = deps.buckets(tunnel.port, storage);
|
|
2194
|
+
done = [
|
|
2195
|
+
...await applyBuckets(client, storage.buckets),
|
|
2196
|
+
...await applyPolicies(client, storage.policies),
|
|
2197
|
+
...await applyLifecycles(client, storage.lifecycles),
|
|
2198
|
+
...await applyNotifications(client, storage.objects, new Set(storage.webhooks.map((hook) => hook.bucket)))
|
|
2199
|
+
];
|
|
2200
|
+
} finally {
|
|
2201
|
+
await tunnel.close();
|
|
2202
|
+
}
|
|
2203
|
+
const created = done.filter((entry) => entry.created).length;
|
|
2204
|
+
ctx.logger.info(`🪣 Buckets: ${storage.buckets.join(", ")}${created ? ` (${created} change(s))` : ""}`);
|
|
2205
|
+
}
|
|
2206
|
+
/**
|
|
2207
|
+
* Create what the plan names in the stack's Postgres, migrate it, then run
|
|
2208
|
+
* its seeds — every one, every time, as each construct's owner.
|
|
2209
|
+
*
|
|
2210
|
+
* Every service the stack publishes on its loopback is reached, not only
|
|
2211
|
+
* Postgres: a seed runs project code, and project code that uploads a file
|
|
2212
|
+
* reaches the stack's MinIO as well.
|
|
2213
|
+
*/
|
|
2214
|
+
async function prepareDatabases(ctx, run, deps) {
|
|
2215
|
+
const tunnels = [];
|
|
2216
|
+
try {
|
|
2217
|
+
const ports = {};
|
|
2218
|
+
for (const [service, inside] of Object.entries(LOOPBACK_SERVICES)) {
|
|
2219
|
+
if (!run.stack.infra.includes(service)) continue;
|
|
2220
|
+
const tunnel = await reach(run, deps, service, inside);
|
|
2221
|
+
tunnels.push(tunnel);
|
|
2222
|
+
ports[primaryPortKey(service)] = tunnel.port;
|
|
2223
|
+
}
|
|
2224
|
+
await migrateAndSeed(ctx, run, deps, ports);
|
|
2225
|
+
} finally {
|
|
2226
|
+
await Promise.all(tunnels.map((tunnel) => tunnel.close()));
|
|
2227
|
+
}
|
|
2228
|
+
}
|
|
2229
|
+
/**
|
|
2230
|
+
* A port a stack's service publishes on its engine's loopback, reachable
|
|
2231
|
+
* from this machine: the published port itself on the local stage, and on a
|
|
2232
|
+
* server an SSH tunnel to it over the deploy's own login — so Postgres and
|
|
2233
|
+
* MinIO are never published beyond the server's loopback.
|
|
2234
|
+
*
|
|
2235
|
+
* Migrations and seeds run here, in this process, with the project's own
|
|
2236
|
+
* Kysely — the way `gkm migrate` runs them — through that port. No image
|
|
2237
|
+
* needs to carry them, and nothing is run on the server but the stack.
|
|
2238
|
+
*/
|
|
2239
|
+
async function reach(run, deps, service, inside) {
|
|
2240
|
+
const published = await deps.docker.port(run.ref, service, inside);
|
|
2241
|
+
if (!run.server) return {
|
|
2242
|
+
port: published,
|
|
2243
|
+
close: async () => {}
|
|
2244
|
+
};
|
|
2245
|
+
return deps.server.tunnel(run.server, published);
|
|
2246
|
+
}
|
|
2247
|
+
async function migrateAndSeed(ctx, run, deps, ports) {
|
|
2248
|
+
const { stack } = run;
|
|
2249
|
+
const workspace = ctx.workspace;
|
|
2250
|
+
const port = ports[primaryPortKey("postgres")];
|
|
2251
|
+
const superuser = stack.credential.containers.postgres;
|
|
2252
|
+
const login = await deps.logins({
|
|
2253
|
+
port,
|
|
2254
|
+
login: superuser,
|
|
2255
|
+
legacy: [{
|
|
2256
|
+
user: LEGACY_LOCAL_LOGIN.user,
|
|
2257
|
+
password: superuser.password
|
|
2258
|
+
}, ...stack.local ? [LEGACY_LOCAL_LOGIN] : []]
|
|
2259
|
+
});
|
|
2260
|
+
if (login.notice) ctx.logger.info(login.notice);
|
|
2261
|
+
const statements = [...postgresStatements(stack.plan, workspace.name, stack.credential.seed), ...stack.backups ? backupsRoleStatements(stack.backups) : []];
|
|
2262
|
+
if (statements.length > 0) {
|
|
2263
|
+
ctx.logger.info("🗄️ Creating databases, roles and grants…");
|
|
2264
|
+
await applyPostgres(deps.sql(port, login.login), statements);
|
|
2265
|
+
}
|
|
2266
|
+
const sources = {};
|
|
2267
|
+
const manifest = await discover({
|
|
2268
|
+
patterns: constructGlobs(workspace),
|
|
2269
|
+
cwd: workspace.root,
|
|
2270
|
+
sources
|
|
2271
|
+
});
|
|
2272
|
+
const custom = run.secrets?.custom ?? {};
|
|
2273
|
+
const resolved = envFor(stack.plan, {
|
|
2274
|
+
...stack.resolution,
|
|
2275
|
+
ports,
|
|
2276
|
+
credentials: {
|
|
2277
|
+
...stack.resolution.credentials,
|
|
2278
|
+
postgres: login.login
|
|
2279
|
+
}
|
|
2280
|
+
});
|
|
2281
|
+
const env = stageEnv(run.secrets ? toEmbeddableSecrets(run.secrets) : {}, Object.fromEntries(Object.entries(resolved).filter(([key]) => custom[key] === void 0)));
|
|
2282
|
+
const options = {
|
|
2283
|
+
root: workspace.root,
|
|
2284
|
+
manifest,
|
|
2285
|
+
sources,
|
|
2286
|
+
env
|
|
2287
|
+
};
|
|
2288
|
+
const runs = await deps.migrate(options);
|
|
2289
|
+
const seeds = await deps.seed({
|
|
2290
|
+
...options,
|
|
2291
|
+
stage: ctx.stage,
|
|
2292
|
+
backends: backendsOf(workspace)
|
|
2293
|
+
}).catch((error) => {
|
|
2294
|
+
if (error instanceof SeedFailed) throw new DeploySeedsFailed(ctx.stage, error.construct, error.seed, error);
|
|
2295
|
+
throw error;
|
|
2296
|
+
});
|
|
2297
|
+
reportDatabaseRuns(runs.map(({ target, applied }) => ({
|
|
2298
|
+
construct: target.id,
|
|
2299
|
+
folder: target.migrations,
|
|
2300
|
+
applied
|
|
2301
|
+
})), seeds.map(({ target, seeded }) => ({
|
|
2302
|
+
construct: target.id,
|
|
2303
|
+
folder: target.seeds,
|
|
2304
|
+
seeded
|
|
2305
|
+
})), (line) => ctx.logger.info(line), (event) => ctx.emit(event));
|
|
2306
|
+
}
|
|
2307
|
+
/**
|
|
2308
|
+
* Each app's image: built from this checkout — inside Docker, every one of
|
|
2309
|
+
* them, from a pruned slice of the build root — or pulled at the tag. Nothing
|
|
2310
|
+
* live changes.
|
|
2311
|
+
*/
|
|
2312
|
+
async function buildCompose(ctx, run, deps) {
|
|
2313
|
+
const { stack, ref } = run;
|
|
2314
|
+
const images = [
|
|
2315
|
+
...stack.apps,
|
|
2316
|
+
...stack.workers,
|
|
2317
|
+
...stack.processors
|
|
2318
|
+
];
|
|
2319
|
+
const apps = images.map((image) => image.app);
|
|
2320
|
+
if (run.push) {
|
|
2321
|
+
run.files = await writeStack(ctx.cwd, run.dir, stack);
|
|
2322
|
+
printPlan(ctx, run);
|
|
2323
|
+
}
|
|
2324
|
+
const prerendered = prerenderedHere(run);
|
|
2325
|
+
if (run.push) await stageAnswers(ctx, run, deps, prerendered);
|
|
2326
|
+
const held = new Set(run.push ? [] : prerendered.map(({ app }) => app));
|
|
2327
|
+
const now = images.filter((image) => !held.has(image.app));
|
|
2328
|
+
if (run.mode === "build") {
|
|
2329
|
+
ctx.logger.info("\n🐳 Building images…");
|
|
2330
|
+
await deps.docker.build(ref, now.map((image) => image.app));
|
|
2331
|
+
} else {
|
|
2332
|
+
ctx.logger.info(`\n🐳 Pulling ${ctx.tag}…`);
|
|
2333
|
+
await deps.docker.pull(ref, apps);
|
|
2334
|
+
}
|
|
2335
|
+
if (run.push) ctx.logger.info("\n📤 Pushing images…");
|
|
2336
|
+
await recordBuilt(ctx, run, deps, now);
|
|
2337
|
+
}
|
|
2338
|
+
/**
|
|
2339
|
+
* Each image's tag as it resolved — the registry's digest for a pushed or
|
|
2340
|
+
* pulled image, or, for one built here and never pushed, its content id —
|
|
2341
|
+
* in the run, and said.
|
|
2342
|
+
*/
|
|
2343
|
+
async function recordBuilt(ctx, run, deps, images) {
|
|
2344
|
+
const { ref } = run;
|
|
2345
|
+
for (const image of images) {
|
|
2346
|
+
const digest = run.push ? await deps.docker.push(ref, image.ref) : await deps.docker.digest(ref, image.ref);
|
|
2347
|
+
if (run.push) ctx.logger.info(` ${image.app.padEnd(12)} ${image.ref}@${digest}`);
|
|
2348
|
+
run.images[image.app] = {
|
|
2349
|
+
ref: image.ref,
|
|
2350
|
+
tag: image.tag,
|
|
2351
|
+
...digest ? { digest } : {}
|
|
2352
|
+
};
|
|
2353
|
+
ctx.emit({
|
|
2354
|
+
type: "artifact.built",
|
|
2355
|
+
app: image.app,
|
|
2356
|
+
imageRef: image.ref,
|
|
2357
|
+
...digest ? { digest } : {}
|
|
2358
|
+
});
|
|
2359
|
+
run.changes.push({
|
|
2360
|
+
key: `image:${image.app}`,
|
|
2361
|
+
resourceType: "image",
|
|
2362
|
+
action: run.mode === "build" ? "build" : "reuse",
|
|
2363
|
+
id: digest ?? image.ref
|
|
2364
|
+
});
|
|
2365
|
+
}
|
|
2366
|
+
}
|
|
2367
|
+
/**
|
|
2368
|
+
* The whole stack up — anything it no longer defines removed — and each
|
|
2369
|
+
* app's image recorded in the stage's state.
|
|
2370
|
+
*/
|
|
2371
|
+
async function releaseCompose(ctx, run, deps) {
|
|
2372
|
+
const { stack, ref } = run;
|
|
2373
|
+
if (run.push) return;
|
|
2374
|
+
const edge = edgeRef(edgeFile(run), {
|
|
2375
|
+
...ref.host ? { host: ref.host } : {},
|
|
2376
|
+
...ref.output ? { output: ref.output } : {}
|
|
2377
|
+
});
|
|
2378
|
+
if (stack.proxy === "traefik" && stack.traefik) {
|
|
2379
|
+
const written = await writeEdgeRoutes(deps.docker, edge, stack.project, stack.traefik, await edgeCertificate(run.dir, stack));
|
|
2380
|
+
ctx.logger.info(`🌐 Registered ${stack.routes.length} route(s) with ${EDGE_PROJECT}: ${written.at(-1)}`);
|
|
2381
|
+
} else if (!stack.local || existsSync(edgeFile(run))) await removeEdgeRoutes(deps.docker, edge, stack.project);
|
|
2382
|
+
const prerendered = prerenderedHere(run);
|
|
2383
|
+
if (prerendered.length > 0) await buildAgainstStage(ctx, run, deps, prerendered);
|
|
2384
|
+
ctx.logger.info("\n🚀 Starting the stack…");
|
|
2385
|
+
const down = await deps.docker.up(ref).then(() => [], (error) => unhealthyAfterUp(ctx, run, deps, error));
|
|
2386
|
+
const isDown = new Set(down.map(({ app }) => app));
|
|
2387
|
+
await recordImages(ctx, run);
|
|
2388
|
+
for (const app of stack.apps) {
|
|
2389
|
+
if (isDown.has(app.name)) continue;
|
|
2390
|
+
const image = run.images[app.name];
|
|
2391
|
+
applied(ctx, run, {
|
|
2392
|
+
key: `service:${app.name}`,
|
|
2393
|
+
resourceType: "service",
|
|
2394
|
+
action: "ensure",
|
|
2395
|
+
id: `${stack.project}/${app.name}`,
|
|
2396
|
+
via: run.previous[app.name] ? "recorded" : "created"
|
|
2397
|
+
});
|
|
2398
|
+
ctx.emit({
|
|
2399
|
+
type: "app.deployed",
|
|
2400
|
+
app: app.name,
|
|
2401
|
+
applicationId: `${stack.project}/${app.name}`,
|
|
2402
|
+
imageRef: image?.ref ?? app.ref,
|
|
2403
|
+
url: app.url
|
|
2404
|
+
});
|
|
2405
|
+
}
|
|
2406
|
+
for (const worker of [...stack.workers, ...stack.processors]) {
|
|
2407
|
+
if (isDown.has(worker.name)) continue;
|
|
2408
|
+
applied(ctx, run, {
|
|
2409
|
+
key: `service:${worker.name}`,
|
|
2410
|
+
resourceType: "service",
|
|
2411
|
+
action: "ensure",
|
|
2412
|
+
id: `${stack.project}/${worker.name}`,
|
|
2413
|
+
via: run.previous[worker.name] ? "recorded" : "created"
|
|
2414
|
+
});
|
|
2415
|
+
}
|
|
2416
|
+
ctx.logger.info(`\n✅ ${stack.project} is running:`);
|
|
2417
|
+
for (const app of stack.apps) {
|
|
2418
|
+
if (isDown.has(app.name)) continue;
|
|
2419
|
+
ctx.logger.info(` ${app.name.padEnd(12)} ${app.url}${app.auth ? ` 🔒 user: ${app.auth.user}, password: gkm secrets:show --stage ${ctx.stage} --reveal → ${app.auth.key}` : ""}`);
|
|
2420
|
+
}
|
|
2421
|
+
if (stack.mailInbox) ctx.logger.info(` ${"mail".padEnd(12)} ${stack.mailInbox.url} (inbox)`);
|
|
2422
|
+
for (const worker of stack.workers) {
|
|
2423
|
+
if (isDown.has(worker.name)) continue;
|
|
2424
|
+
ctx.logger.info(` ${worker.name.padEnd(12)} worker ${worker.id}`);
|
|
2425
|
+
}
|
|
2426
|
+
for (const unit of stack.processors) {
|
|
2427
|
+
if (isDown.has(unit.name)) continue;
|
|
2428
|
+
ctx.logger.info(` ${unit.name.padEnd(12)} processors of ${unit.id}`);
|
|
2429
|
+
}
|
|
2430
|
+
if (stack.authority) ctx.logger.info(`\n🔐 Certificates are from gkm's local CA ("gkm trust" trusts it here): NODE_EXTRA_CA_CERTS=${stack.authority.certFile}`);
|
|
2431
|
+
else if (stack.local && stack.tls) ctx.logger.info(stack.tls.caFile ? `\n🔐 Certificates are the stage's own (deploy.compose.tls), from the CA in ${stack.tls.caFile}: NODE_EXTRA_CA_CERTS=${stack.tls.caFile}` : `\n🔐 Certificates are the stage's own (deploy.compose.tls): ${stack.tls.certFile}. Set its caFile to the root it chains to, so gkm and the stack's containers trust it.`);
|
|
2432
|
+
if (down.length > 0) throw new ComposeAppsUnhealthy(stack.project, down, stack.proxy, "docker");
|
|
2433
|
+
}
|
|
2434
|
+
/**
|
|
2435
|
+
* After `up --wait` failed: each app's and worker's service that is not
|
|
2436
|
+
* healthy once its health settles — waited on while it is still starting,
|
|
2437
|
+
* as `--wait` stops at the first that is not. None means the failure was not
|
|
2438
|
+
* health's, and it is thrown as it was.
|
|
2439
|
+
*/
|
|
2440
|
+
async function unhealthyAfterUp(ctx, run, deps, error, except = /* @__PURE__ */ new Set()) {
|
|
2441
|
+
const { stack } = run;
|
|
2442
|
+
const services = [
|
|
2443
|
+
...stack.apps.flatMap(replicaNames),
|
|
2444
|
+
...stack.workers.map((worker) => worker.name),
|
|
2445
|
+
...stack.processors.map((unit) => unit.name)
|
|
2446
|
+
].filter((service) => !except.has(service));
|
|
2447
|
+
const down = (await Promise.all(services.map(async (service) => {
|
|
2448
|
+
let last;
|
|
2449
|
+
for (let attempt = 1; attempt <= deps.healthAttempts; attempt++) {
|
|
2450
|
+
ctx.signal.throwIfAborted();
|
|
2451
|
+
last = await deps.docker.health(run.ref, service).catch(() => void 0);
|
|
2452
|
+
if (last !== "starting") break;
|
|
2453
|
+
if (attempt < deps.healthAttempts) await new Promise((resolve) => setTimeout(resolve, deps.healthIntervalMs));
|
|
2454
|
+
}
|
|
2455
|
+
return {
|
|
2456
|
+
app: service,
|
|
2457
|
+
url: `docker:${service}`,
|
|
2458
|
+
last
|
|
2459
|
+
};
|
|
2460
|
+
}))).filter(({ last }) => last !== "healthy").map(({ app, url, last }) => ({
|
|
2461
|
+
app,
|
|
2462
|
+
url,
|
|
2463
|
+
last: last ?? "not running"
|
|
2464
|
+
}));
|
|
2465
|
+
if (down.length === 0) throw error;
|
|
2466
|
+
ctx.logger.warn(`\n⚠️ ${down.map(({ app }) => app).join(", ")} did not turn healthy; the rest of the stack is released and routed.`);
|
|
2467
|
+
return down;
|
|
2468
|
+
}
|
|
2469
|
+
/**
|
|
2470
|
+
* Where a check through the edge connects: this machine for the local stage,
|
|
2471
|
+
* a deployed stage's server on its published port — or, for a push, which
|
|
2472
|
+
* has no server, wherever the host resolves.
|
|
2473
|
+
*/
|
|
2474
|
+
function edgeTarget(run, deps) {
|
|
2475
|
+
if (run.stack.local) return { connectTo: "127.0.0.1" };
|
|
2476
|
+
if (run.server) return {
|
|
2477
|
+
connectTo: run.server.host,
|
|
2478
|
+
connectPort: edgePorts(deps.env).https
|
|
2479
|
+
};
|
|
2480
|
+
}
|
|
2481
|
+
/**
|
|
2482
|
+
* The sites this run builds against their stage's running APIs
|
|
2483
|
+
* (`prerender: 'stage'`). None for a run that pulls: a pulled image was built
|
|
2484
|
+
* against the stage when it was pushed.
|
|
2485
|
+
*/
|
|
2486
|
+
function prerenderedHere(run) {
|
|
2487
|
+
if (run.mode !== "build") return [];
|
|
2488
|
+
return run.stack.apps.filter((app) => app.prerender && app.build);
|
|
2489
|
+
}
|
|
2490
|
+
/**
|
|
2491
|
+
* A site that pre-renders against its stage, built once its APIs answer:
|
|
2492
|
+
* every service of the stack started but those sites — `up --wait`, so each
|
|
2493
|
+
* is healthy by its own check — then each API the site depends on asked
|
|
2494
|
+
* through the edge, as a browser reaches it, and only then the site built.
|
|
2495
|
+
* The full `up` that follows starts it.
|
|
2496
|
+
*/
|
|
2497
|
+
async function buildAgainstStage(ctx, run, deps, sites) {
|
|
2498
|
+
const { stack, ref } = run;
|
|
2499
|
+
const held = new Set(sites.flatMap(replicaNames));
|
|
2500
|
+
const services = Object.keys(stack.compose.services).filter((service) => !held.has(service));
|
|
2501
|
+
ctx.logger.info(`\n🚀 Starting the stack, but ${listNames(sites)}, built once its APIs answer…`);
|
|
2502
|
+
const down = await deps.docker.up(ref, services).then(() => [], (error) => unhealthyAfterUp(ctx, run, deps, error, held));
|
|
2503
|
+
for (const site of sites) {
|
|
2504
|
+
const against = new Set(site.prerender?.against);
|
|
2505
|
+
const blocking = down.filter(({ app }) => against.has(app));
|
|
2506
|
+
if (blocking.length > 0) throw new SitePrerenderApisDown(site.name, blocking, "docker");
|
|
2507
|
+
}
|
|
2508
|
+
await stageAnswers(ctx, run, deps, sites);
|
|
2509
|
+
ctx.logger.info(`\n🐳 Building ${listNames(sites)} against the stage's APIs…`);
|
|
2510
|
+
await deps.docker.build(ref, sites.map((site) => site.app));
|
|
2511
|
+
await recordBuilt(ctx, run, deps, sites);
|
|
2512
|
+
}
|
|
2513
|
+
/** `web` — or `docs and web`. */
|
|
2514
|
+
function listNames(apps) {
|
|
2515
|
+
const names = apps.map(({ name }) => name);
|
|
2516
|
+
return names.length > 1 ? `${names.slice(0, -1).join(", ")} and ${names.at(-1)}` : names[0] ?? "";
|
|
2517
|
+
}
|
|
2518
|
+
/**
|
|
2519
|
+
* Each API a site pre-rendered against its stage depends on, asked through
|
|
2520
|
+
* the edge as `verify` asks it — the address the site's build fetches from.
|
|
2521
|
+
* Any that does not answer fails the run before the site is built: a build
|
|
2522
|
+
* that cannot reach them bakes in pages without their data.
|
|
2523
|
+
*/
|
|
2524
|
+
async function stageAnswers(ctx, run, deps, sites) {
|
|
2525
|
+
const { stack } = run;
|
|
2526
|
+
const names = new Set(sites.flatMap((site) => site.prerender?.against ?? []));
|
|
2527
|
+
const apps = stack.apps.filter((app) => names.has(app.name));
|
|
2528
|
+
if (apps.length === 0) return;
|
|
2529
|
+
ctx.logger.info(`\n🩺 Checking the APIs ${listNames(sites)} ${sites.length > 1 ? "pre-render" : "pre-renders"} from…`);
|
|
2530
|
+
const ca = await verifyAuthority(stack);
|
|
2531
|
+
const edge = edgeTarget(run, deps);
|
|
2532
|
+
const results = await Promise.all(apps.map((app) => app.id === stack.wildcard?.site && !run.push ? checkContainer(ctx, run, deps, app.name) : checkApp(ctx, app, deps, {
|
|
2533
|
+
ca,
|
|
2534
|
+
edge
|
|
2535
|
+
})));
|
|
2536
|
+
const down = new Map(results.filter((r) => !r.healthy).map((r) => [r.app, r]));
|
|
2537
|
+
for (const site of sites) {
|
|
2538
|
+
const blocking = (site.prerender?.against ?? []).flatMap((name) => {
|
|
2539
|
+
const result = down.get(name);
|
|
2540
|
+
return result ? [result] : [];
|
|
2541
|
+
});
|
|
2542
|
+
if (blocking.length > 0) throw new SitePrerenderApisDown(site.name, blocking, run.push ? "push" : "edge");
|
|
2543
|
+
}
|
|
2544
|
+
}
|
|
2545
|
+
/**
|
|
2546
|
+
* Each app's image in the stage's state — the same `images` a Dokploy deploy
|
|
2547
|
+
* records: the ref it runs, the tag it was released under, and the digest
|
|
2548
|
+
* the tag resolved to.
|
|
2549
|
+
*/
|
|
2550
|
+
async function recordImages(ctx, run) {
|
|
2551
|
+
const journal = await DeployJournal.open(ctx.state, ctx.stage, () => createComposeState(ctx.stage));
|
|
2552
|
+
const by = currentActor();
|
|
2553
|
+
for (const app of [
|
|
2554
|
+
...run.stack.apps,
|
|
2555
|
+
...run.stack.workers,
|
|
2556
|
+
...run.stack.processors
|
|
2557
|
+
]) {
|
|
2558
|
+
const image = run.images[app.app] ?? {
|
|
2559
|
+
ref: app.ref,
|
|
2560
|
+
tag: app.tag
|
|
2561
|
+
};
|
|
2562
|
+
recordRelease(journal.state, app.app, image, by);
|
|
2563
|
+
}
|
|
2564
|
+
journal.state.identity = ctx.identity.key;
|
|
2565
|
+
await journal.save();
|
|
2566
|
+
}
|
|
2567
|
+
/**
|
|
2568
|
+
* Each app asked through Caddy, over HTTPS, the certificate verified: an API
|
|
2569
|
+
* at `/health`, a site at `/`. On the local stage the edge is this machine and
|
|
2570
|
+
* its certificate is from gkm's local CA, so that root is the one trusted and
|
|
2571
|
+
* the request goes to 127.0.0.1.
|
|
2572
|
+
*/
|
|
2573
|
+
async function verifyCompose(ctx, run, deps) {
|
|
2574
|
+
const { stack } = run;
|
|
2575
|
+
if (run.push) return;
|
|
2576
|
+
const ca = await verifyAuthority(stack);
|
|
2577
|
+
ctx.logger.info(`\n🩺 Checking each app through ${stack.proxy === "caddy" ? "Caddy" : "the shared edge"}…`);
|
|
2578
|
+
const edge = edgeTarget(run, deps);
|
|
2579
|
+
const results = await Promise.all(stack.apps.map((app) => app.id === stack.wildcard?.site ? checkContainer(ctx, run, deps, app.name) : checkApp(ctx, app, deps, {
|
|
2580
|
+
ca,
|
|
2581
|
+
edge
|
|
2582
|
+
})));
|
|
2583
|
+
results.push(...await Promise.all([...stack.workers, ...stack.processors].map((worker) => checkContainer(ctx, run, deps, worker.name))));
|
|
2584
|
+
if (stack.logs) results.push(await checkContainer(ctx, run, deps, LOGS_SERVICE));
|
|
2585
|
+
const down = results.filter((result) => !result.healthy).map(({ app, url, last }) => ({
|
|
2586
|
+
app,
|
|
2587
|
+
url,
|
|
2588
|
+
last
|
|
2589
|
+
}));
|
|
2590
|
+
if (down.length > 0) throw new ComposeAppsUnhealthy(stack.project, down, stack.proxy);
|
|
2591
|
+
await pruneStageDns(ctx, run);
|
|
2592
|
+
await confirmSubscriptions(ctx, run, deps);
|
|
2593
|
+
await warmSites(ctx, run, deps, {
|
|
2594
|
+
ca,
|
|
2595
|
+
edge
|
|
2596
|
+
});
|
|
2597
|
+
if (stack.logs) reportLogs(ctx, stack.logs, stack.local, run.server);
|
|
2598
|
+
}
|
|
2599
|
+
/**
|
|
2600
|
+
* Each server-rendered site (`next`, `tanstack`) asked for its sitemap, its
|
|
2601
|
+
* `/` and every page the sitemap lists, through the edge as `checkApp` asks
|
|
2602
|
+
* it — see `warmup.ts`. Its image was built with no API reachable, so each
|
|
2603
|
+
* page renders on its first request: this is that request, made before any
|
|
2604
|
+
* visitor's. A Next site is asked with its on-demand revalidation header,
|
|
2605
|
+
* so a page its build cached (empty) is rendered again from the deployed
|
|
2606
|
+
* APIs rather than served from that cache.
|
|
2607
|
+
*
|
|
2608
|
+
* Only ever said, never failed on: every app is already healthy, and a page
|
|
2609
|
+
* that did not warm renders on the next request for it.
|
|
2610
|
+
*/
|
|
2611
|
+
async function warmSites(ctx, run, deps, options) {
|
|
2612
|
+
const { stack } = run;
|
|
2613
|
+
const sites = stack.apps.filter((app) => app.kind === "site" && (app.variant === "next" || app.variant === "tanstack"));
|
|
2614
|
+
if (sites.length === 0) return;
|
|
2615
|
+
ctx.logger.info("\n🔥 Warming each server-rendered site…");
|
|
2616
|
+
for (const app of sites) {
|
|
2617
|
+
if (app.id === stack.wildcard?.site) {
|
|
2618
|
+
ctx.logger.info(` – ${app.name.padEnd(12)} serves every subdomain: there is no one host to warm, so it is skipped`);
|
|
2619
|
+
continue;
|
|
2620
|
+
}
|
|
2621
|
+
try {
|
|
2622
|
+
const headers = app.variant === "next" ? await forceRender(ctx, run, deps, app) : {};
|
|
2623
|
+
const { warmed, cached, warnings, leftOut } = await warmSite({
|
|
2624
|
+
url: app.url,
|
|
2625
|
+
fetch: deps.fetch ?? edgeFetch,
|
|
2626
|
+
headers,
|
|
2627
|
+
edge: {
|
|
2628
|
+
...options.ca ? { ca: options.ca } : {},
|
|
2629
|
+
...app.auth ? { authorization: basicAuthorization(app.auth) } : {},
|
|
2630
|
+
...options.edge,
|
|
2631
|
+
signal: ctx.signal
|
|
2632
|
+
}
|
|
2633
|
+
});
|
|
2634
|
+
const said = `warmed ${warmed.length} page(s)${cached.length > 0 ? `, ${cached.length} served from the build cache` : ""}${warnings.length > 0 ? `, ${warnings.length} warning(s)` : ""}`;
|
|
2635
|
+
if (warnings.length === 0) ctx.logger.info(` ✓ ${app.name.padEnd(12)} ${said}${cached.length > 0 ? `: ${listed(cached)}` : ""}`);
|
|
2636
|
+
else {
|
|
2637
|
+
ctx.logger.warn(` ⚠ ${app.name.padEnd(12)} ${said}:`);
|
|
2638
|
+
for (const { url, reason } of warnings) ctx.logger.warn(` ${url}: ${reason}`);
|
|
2639
|
+
if (cached.length > 0) ctx.logger.warn(` served from the build cache: ${listed(cached)}`);
|
|
2640
|
+
}
|
|
2641
|
+
if (leftOut > 0) ctx.logger.info(` ${leftOut} more page(s) in its sitemap were not asked: at most 500 are warmed per site`);
|
|
2642
|
+
} catch (error) {
|
|
2643
|
+
if (ctx.signal.aborted) throw error;
|
|
2644
|
+
ctx.logger.warn(` ⚠ ${app.name.padEnd(12)} not warmed: ${error instanceof Error ? error.message : String(error)}`);
|
|
2645
|
+
}
|
|
2646
|
+
}
|
|
2647
|
+
}
|
|
2648
|
+
/** The most pages a summary names; the rest are counted. */
|
|
2649
|
+
const LISTED_PAGES = 10;
|
|
2650
|
+
/** Pages by path, `/about`, the first {@link LISTED_PAGES} of them. */
|
|
2651
|
+
function listed(urls) {
|
|
2652
|
+
const paths = urls.map((url) => {
|
|
2653
|
+
const { pathname, search } = new URL(url);
|
|
2654
|
+
return `${pathname}${search}`;
|
|
2655
|
+
});
|
|
2656
|
+
const shown = paths.slice(0, LISTED_PAGES).join(", ");
|
|
2657
|
+
return paths.length > LISTED_PAGES ? `${shown} and ${paths.length - LISTED_PAGES} more` : shown;
|
|
2658
|
+
}
|
|
2659
|
+
/**
|
|
2660
|
+
* The header that has a Next site render each warmed page whatever its
|
|
2661
|
+
* cache says: `x-prerender-revalidate` with the preview-mode id of the image
|
|
2662
|
+
* running — read in its container, through the stack's Docker engine, at
|
|
2663
|
+
* the path the generated Dockerfile puts the standalone output at. Where the
|
|
2664
|
+
* id cannot be read, said once, and the site is warmed with plain requests.
|
|
2665
|
+
*/
|
|
2666
|
+
async function forceRender(ctx, run, deps, app) {
|
|
2667
|
+
let reason;
|
|
2668
|
+
try {
|
|
2669
|
+
const root = ctx.workspace.root;
|
|
2670
|
+
const gkmRoot = relative(findBuildRoot(root), root) || ".";
|
|
2671
|
+
const lookup = await nextPreviewModeId((command) => deps.docker.exec(run.ref, app.name, command), nextPrerenderManifest(fromBuildRoot({ gkmRoot }, app.path)));
|
|
2672
|
+
if ("id" in lookup) return { [NEXT_REVALIDATE_HEADER]: lookup.id };
|
|
2673
|
+
reason = lookup.reason;
|
|
2674
|
+
} catch (error) {
|
|
2675
|
+
if (ctx.signal.aborted) throw error;
|
|
2676
|
+
reason = error instanceof Error ? error.message : String(error);
|
|
2677
|
+
}
|
|
2678
|
+
ctx.logger.warn(` ⚠ ${app.name.padEnd(12)} can't force ISR pages to render: ${reason}. Warming with plain requests; a page Next cached at build is served from that cache until its revalidate window ends.`);
|
|
2679
|
+
return {};
|
|
2680
|
+
}
|
|
2681
|
+
/**
|
|
2682
|
+
* The SNS subscriptions the stage's providers made before the workers were
|
|
2683
|
+
* up: each still pending is subscribed again, so SNS resends its
|
|
2684
|
+
* confirmation to a worker now there to answer it, and waited on. One still
|
|
2685
|
+
* pending after that is said, not failed on — every app is healthy, and
|
|
2686
|
+
* rolling them back would not confirm it.
|
|
2687
|
+
*/
|
|
2688
|
+
async function confirmSubscriptions(ctx, run, deps) {
|
|
2689
|
+
const stored = await ctx.state.read(ctx.stage);
|
|
2690
|
+
const left = await (deps.confirmSubscriptions ?? confirmPendingSubscriptions)({
|
|
2691
|
+
workspace: ctx.workspace,
|
|
2692
|
+
stage: ctx.stage,
|
|
2693
|
+
secrets: run.secrets?.custom ?? {},
|
|
2694
|
+
resources: stored?.resources,
|
|
2695
|
+
env: deps.env,
|
|
2696
|
+
log: (line) => ctx.logger.info(line),
|
|
2697
|
+
record: async (record) => {
|
|
2698
|
+
const { updatedAt: _, updatedBy: __, ...input } = record;
|
|
2699
|
+
await ctx.state.putResource(ctx.stage, input);
|
|
2700
|
+
}
|
|
2701
|
+
});
|
|
2702
|
+
if (left.length > 0) ctx.logger.warn(`⚠ ${new PushSubscriptionsUnconfirmed(left).message}`);
|
|
2703
|
+
}
|
|
2704
|
+
/**
|
|
2705
|
+
* A container's own health check, as Docker reports it: a worker's, which
|
|
2706
|
+
* has no route through the edge, and OpenObserve's — by default it has no
|
|
2707
|
+
* host there, and served publicly it answers only the addresses it allows,
|
|
2708
|
+
* which need not include this one.
|
|
2709
|
+
*/
|
|
2710
|
+
async function checkContainer(ctx, run, deps, service) {
|
|
2711
|
+
const url = `docker:${service}`;
|
|
2712
|
+
let last = "not asked";
|
|
2713
|
+
for (let attempt = 1; attempt <= deps.healthAttempts; attempt++) {
|
|
2714
|
+
ctx.signal.throwIfAborted();
|
|
2715
|
+
const health = await deps.docker.health(run.ref, service).catch((error) => error instanceof Error ? error.message : String(error));
|
|
2716
|
+
last = health ?? "not running";
|
|
2717
|
+
const healthy = health === "healthy";
|
|
2718
|
+
ctx.emit({
|
|
2719
|
+
type: "health.checked",
|
|
2720
|
+
app: service,
|
|
2721
|
+
url,
|
|
2722
|
+
healthy,
|
|
2723
|
+
attempt
|
|
2724
|
+
});
|
|
2725
|
+
if (healthy) {
|
|
2726
|
+
ctx.logger.info(` ✓ ${service.padEnd(12)} ${url} (${last})`);
|
|
2727
|
+
return {
|
|
2728
|
+
app: service,
|
|
2729
|
+
url,
|
|
2730
|
+
last,
|
|
2731
|
+
healthy
|
|
2732
|
+
};
|
|
2733
|
+
}
|
|
2734
|
+
if (attempt < deps.healthAttempts) await new Promise((resolve) => setTimeout(resolve, deps.healthIntervalMs));
|
|
2735
|
+
}
|
|
2736
|
+
ctx.logger.warn(` ✗ ${service.padEnd(12)} ${url} (${last})`);
|
|
2737
|
+
return {
|
|
2738
|
+
app: service,
|
|
2739
|
+
url,
|
|
2740
|
+
last,
|
|
2741
|
+
healthy: false
|
|
2742
|
+
};
|
|
2743
|
+
}
|
|
2744
|
+
/** A login, as the `Authorization` header that carries it. */
|
|
2745
|
+
function basicAuthorization(auth) {
|
|
2746
|
+
return `Basic ${Buffer.from(`${auth.user}:${auth.password}`).toString("base64")}`;
|
|
2747
|
+
}
|
|
2748
|
+
/** How to open the logs, printed — and as an event, for a headless caller. */
|
|
2749
|
+
function reportLogs(ctx, logs, local, server) {
|
|
2750
|
+
const lines = logsAccess(logs, {
|
|
2751
|
+
stage: ctx.stage,
|
|
2752
|
+
local,
|
|
2753
|
+
user: server?.user ?? currentUser(),
|
|
2754
|
+
hostname: server?.host ?? hostname(),
|
|
2755
|
+
...server ? { known: true } : {}
|
|
2756
|
+
});
|
|
2757
|
+
ctx.logger.info(`\n${lines.join("\n")}`);
|
|
2758
|
+
ctx.emit({
|
|
2759
|
+
type: "logs.ready",
|
|
2760
|
+
service: LOGS_SERVICE,
|
|
2761
|
+
access: logs.public ? "public" : "tunnel",
|
|
2762
|
+
url: logs.url,
|
|
2763
|
+
...logs.public ? { allow: [...logs.public.allow] } : { port: logs.port },
|
|
2764
|
+
email: logs.email
|
|
2765
|
+
});
|
|
2766
|
+
}
|
|
2767
|
+
/** This machine's user — a guess at who would SSH in. */
|
|
2768
|
+
function currentUser() {
|
|
2769
|
+
try {
|
|
2770
|
+
return userInfo().username;
|
|
2771
|
+
} catch {
|
|
2772
|
+
return process.env.USER ?? "user";
|
|
2773
|
+
}
|
|
2774
|
+
}
|
|
2775
|
+
async function checkApp(ctx, app, deps, options) {
|
|
2776
|
+
const url = `${app.url.replace(/^ws/, "http")}${app.kind === "site" ? "/" : "/health"}`;
|
|
2777
|
+
let last = "not asked";
|
|
2778
|
+
for (let attempt = 1; attempt <= deps.healthAttempts; attempt++) {
|
|
2779
|
+
ctx.signal.throwIfAborted();
|
|
2780
|
+
let status;
|
|
2781
|
+
try {
|
|
2782
|
+
status = await deps.probe({
|
|
2783
|
+
url,
|
|
2784
|
+
...options.ca ? { ca: options.ca } : {},
|
|
2785
|
+
...app.auth ? { authorization: basicAuthorization(app.auth) } : {},
|
|
2786
|
+
...options.edge,
|
|
2787
|
+
timeoutMs: 1e4,
|
|
2788
|
+
signal: ctx.signal
|
|
2789
|
+
});
|
|
2790
|
+
last = `HTTP ${status}`;
|
|
2791
|
+
} catch (error) {
|
|
2792
|
+
last = error instanceof Error ? error.message : String(error);
|
|
2793
|
+
}
|
|
2794
|
+
const healthy = status !== void 0 && isHealthy(status);
|
|
2795
|
+
ctx.emit({
|
|
2796
|
+
type: "health.checked",
|
|
2797
|
+
app: app.name,
|
|
2798
|
+
url,
|
|
2799
|
+
healthy,
|
|
2800
|
+
...status !== void 0 ? { status } : {},
|
|
2801
|
+
attempt
|
|
2802
|
+
});
|
|
2803
|
+
if (healthy) {
|
|
2804
|
+
ctx.logger.info(` ✓ ${app.name.padEnd(12)} ${url} (${last})`);
|
|
2805
|
+
return {
|
|
2806
|
+
app: app.name,
|
|
2807
|
+
url,
|
|
2808
|
+
last,
|
|
2809
|
+
healthy
|
|
2810
|
+
};
|
|
2811
|
+
}
|
|
2812
|
+
if (attempt < deps.healthAttempts) await new Promise((resolve) => setTimeout(resolve, deps.healthIntervalMs));
|
|
2813
|
+
}
|
|
2814
|
+
ctx.logger.warn(` ✗ ${app.name.padEnd(12)} ${url} (${last})`);
|
|
2815
|
+
return {
|
|
2816
|
+
app: app.name,
|
|
2817
|
+
url,
|
|
2818
|
+
last,
|
|
2819
|
+
healthy: false
|
|
2820
|
+
};
|
|
2821
|
+
}
|
|
2822
|
+
function composeResult(ctx, run) {
|
|
2823
|
+
const apps = [...run.stack.apps.map((app) => {
|
|
2824
|
+
const image = run.images[app.name];
|
|
2825
|
+
return {
|
|
2826
|
+
appName: app.name,
|
|
2827
|
+
type: app.kind === "site" ? "web" : "backend",
|
|
2828
|
+
success: !ctx.dryRun,
|
|
2829
|
+
applicationId: `${run.stack.project}/${app.name}`,
|
|
2830
|
+
imageRef: image?.ref ?? app.ref,
|
|
2831
|
+
...image?.digest ? { digest: image.digest } : {},
|
|
2832
|
+
url: app.url
|
|
2833
|
+
};
|
|
2834
|
+
}), ...[...run.stack.workers, ...run.stack.processors].map((worker) => {
|
|
2835
|
+
const image = run.images[worker.name];
|
|
2836
|
+
return {
|
|
2837
|
+
appName: worker.name,
|
|
2838
|
+
type: "backend",
|
|
2839
|
+
success: !ctx.dryRun,
|
|
2840
|
+
applicationId: `${run.stack.project}/${worker.name}`,
|
|
2841
|
+
imageRef: image?.ref ?? worker.ref,
|
|
2842
|
+
...image?.digest ? { digest: image.digest } : {}
|
|
2843
|
+
};
|
|
2844
|
+
})];
|
|
2845
|
+
return {
|
|
2846
|
+
apps,
|
|
2847
|
+
projectId: run.stack.project,
|
|
2848
|
+
successCount: ctx.dryRun ? 0 : apps.length,
|
|
2849
|
+
failedCount: 0,
|
|
2850
|
+
stage: ctx.stage,
|
|
2851
|
+
identity: ctx.identity.key,
|
|
2852
|
+
tag: ctx.tag,
|
|
2853
|
+
dryRun: ctx.dryRun,
|
|
2854
|
+
environmentId: "",
|
|
2855
|
+
skipped: [...ctx.skipped],
|
|
2856
|
+
urls: Object.fromEntries(run.stack.apps.map((app) => [app.name, app.url])),
|
|
2857
|
+
changes: run.changes
|
|
2858
|
+
};
|
|
2859
|
+
}
|
|
2860
|
+
/** The shared edge's compose file, as this machine hands it to compose. */
|
|
2861
|
+
function edgeFile(run) {
|
|
2862
|
+
return join(run.dir, `${EDGE_PROJECT}.yml`);
|
|
2863
|
+
}
|
|
2864
|
+
function applied(ctx, run, change) {
|
|
2865
|
+
const { via, ...rest } = change;
|
|
2866
|
+
run.changes.push(rest);
|
|
2867
|
+
ctx.emit({
|
|
2868
|
+
type: "resource.applied",
|
|
2869
|
+
...rest,
|
|
2870
|
+
via
|
|
2871
|
+
});
|
|
2872
|
+
}
|
|
2873
|
+
/**
|
|
2874
|
+
* The root the check after a start trusts, PEM: gkm's on the local stage that
|
|
2875
|
+
* set no certificate of its own, and otherwise the one the stage's own names
|
|
2876
|
+
* (`deploy.compose.tls.<stage>.caFile`). Undefined — Node's own roots, and
|
|
2877
|
+
* `NODE_EXTRA_CA_CERTS` — for a certificate that names none: a public CA's.
|
|
2878
|
+
*/
|
|
2879
|
+
async function verifyAuthority(stack) {
|
|
2880
|
+
if (stack.authority) return (await readLocalAuthority(stack.authority)).cert;
|
|
2881
|
+
if (stack.tls?.caFile) return readFile(stack.tls.caFile, "utf-8");
|
|
2882
|
+
}
|
|
2883
|
+
/**
|
|
2884
|
+
* The certificate the stack's proxy serves, PEM: the stage's own where it set
|
|
2885
|
+
* one, the one gkm's local CA issued the local stage otherwise, and none — a
|
|
2886
|
+
* deployed stage's comes from Let's Encrypt — when neither.
|
|
2887
|
+
*/
|
|
2888
|
+
async function edgeCertificate(dir, stack) {
|
|
2889
|
+
if (stack.tls) return {
|
|
2890
|
+
cert: await readFile(stack.tls.certFile, "utf-8"),
|
|
2891
|
+
key: await readFile(stack.tls.keyFile, "utf-8")
|
|
2892
|
+
};
|
|
2893
|
+
if (stack.authority) return localEdgeCertificate(dir, stack, stack.authority);
|
|
2894
|
+
}
|
|
2895
|
+
/** Where the local stage's edge certificate is kept, between runs. */
|
|
2896
|
+
const LOCAL_EDGE_CERTIFICATE = "local-edge.pem";
|
|
2897
|
+
/**
|
|
2898
|
+
* The local stage's edge certificate, from gkm's local CA: the one kept in
|
|
2899
|
+
* the stack's directory while it still covers every host, so an unchanged
|
|
2900
|
+
* stack does not recreate its Caddy for a new certificate each run.
|
|
2901
|
+
*/
|
|
2902
|
+
async function localEdgeCertificate(dir, stack, authority) {
|
|
2903
|
+
const { cert, key } = await ensureLocalCertificate(await ensureLocalAuthority(authority), localCertificateNames(stack.resolution.project ?? "", stackHosts(stack)), join(dir, LOCAL_EDGE_CERTIFICATE));
|
|
2904
|
+
return {
|
|
2905
|
+
cert,
|
|
2906
|
+
key
|
|
2907
|
+
};
|
|
2908
|
+
}
|
|
2909
|
+
/** Write the stack's files: owner-only, since the env files hold secrets. */
|
|
2910
|
+
async function writeStack(root, dir, stack) {
|
|
2911
|
+
await mkdir(dir, {
|
|
2912
|
+
recursive: true,
|
|
2913
|
+
mode: 448
|
|
2914
|
+
});
|
|
2915
|
+
await chmod(dir, 448);
|
|
2916
|
+
const files = [];
|
|
2917
|
+
const write = async (path, content, mode = 420) => {
|
|
2918
|
+
await mkdir(dirname(path), { recursive: true });
|
|
2919
|
+
await writeFile(path, content, { mode });
|
|
2920
|
+
await chmod(path, mode);
|
|
2921
|
+
files.push(path);
|
|
2922
|
+
};
|
|
2923
|
+
const issued = await edgeCertificate(dir, stack);
|
|
2924
|
+
const tls = stack.proxy === "caddy" ? issued : void 0;
|
|
2925
|
+
const compose = stack.caddyfile !== void 0 ? withCaddyConfigs(stack.compose, {
|
|
2926
|
+
caddyfile: stack.caddyfile,
|
|
2927
|
+
...tls ? { tls } : {}
|
|
2928
|
+
}) : stack.compose;
|
|
2929
|
+
await write(join(dir, "docker-compose.yml"), composeYaml(stack, compose), tls ? 384 : 420);
|
|
2930
|
+
if (stack.caddyfile !== void 0) {
|
|
2931
|
+
await write(join(dir, "Caddyfile"), stack.caddyfile);
|
|
2932
|
+
await rm(join(dir, "traefik.yml"), { force: true });
|
|
2933
|
+
} else await rm(join(dir, "Caddyfile"), { force: true });
|
|
2934
|
+
if (stack.traefik !== void 0) await write(join(dir, "traefik.yml"), stack.traefik);
|
|
2935
|
+
await rm(join(dir, "tls"), {
|
|
2936
|
+
recursive: true,
|
|
2937
|
+
force: true
|
|
2938
|
+
});
|
|
2939
|
+
for (const app of [
|
|
2940
|
+
...stack.apps,
|
|
2941
|
+
...stack.workers,
|
|
2942
|
+
...stack.processors
|
|
2943
|
+
]) if (app.env) await write(join(dir, `${app.name}.env`), envFile(app.env), 384);
|
|
2944
|
+
if (stack.logs && stack.compose.services["openobserve"]?.env_file) await write(join(dir, `${LOGS_SERVICE}.env`), envFile(stack.logs.env), 384);
|
|
2945
|
+
if (stack.redis && stack.compose.services["redis"]?.env_file) await write(join(dir, `${REDIS_SERVICE}.env`), envFile(stack.redis.env), 384);
|
|
2946
|
+
if (stack.backups) {
|
|
2947
|
+
for (const [name, content] of Object.entries(stack.backups.files)) await write(join(dir, BACKUPS_SERVICE, name), content);
|
|
2948
|
+
if (stack.compose.services["backups"]?.env_file) await write(join(dir, `${BACKUPS_SERVICE}.env`), envFile(stack.backups.env), 384);
|
|
2949
|
+
} else {
|
|
2950
|
+
await rm(join(dir, BACKUPS_SERVICE), {
|
|
2951
|
+
recursive: true,
|
|
2952
|
+
force: true
|
|
2953
|
+
});
|
|
2954
|
+
await rm(join(dir, `${BACKUPS_SERVICE}.env`), { force: true });
|
|
2955
|
+
}
|
|
2956
|
+
for (const entry of await readdir(dir)) if (entry.endsWith(".credentials")) await rm(join(dir, entry));
|
|
2957
|
+
for (const [path, content] of Object.entries(stack.dockerfiles)) await write(join(root, path), content);
|
|
2958
|
+
await ensureDockerignore(findBuildRoot(root));
|
|
2959
|
+
return files;
|
|
2960
|
+
}
|
|
2961
|
+
function composeYaml(stack, compose) {
|
|
2962
|
+
const stage = ` --stage ${stack.stage}`;
|
|
2963
|
+
return `# Generated by gkm compose from the construct manifest — do not edit.
|
|
2964
|
+
# The ${stack.stage} stage's APIs and sites behind ${stack.proxy === "caddy" ? "one Caddy" : `the shared Traefik edge (${EDGE_PROJECT})`}, and its workers.
|
|
2965
|
+
# Each backend and worker reads exactly the keys in its own env file beside
|
|
2966
|
+
# this one.
|
|
2967
|
+
#
|
|
2968
|
+
# gkm compose${stage} start or update it
|
|
2969
|
+
# gkm compose${stage} --down stop it
|
|
2970
|
+
${stringify(compose, {
|
|
2971
|
+
lineWidth: 0,
|
|
2972
|
+
aliasDuplicateObjects: false
|
|
2973
|
+
})}`;
|
|
2974
|
+
}
|
|
2975
|
+
function printPlan(ctx, run) {
|
|
2976
|
+
const { stack, mode, files } = run;
|
|
2977
|
+
ctx.logger.info(`\n🧱 ${stack.project} — stage ${stack.stage}`);
|
|
2978
|
+
if (run.server) ctx.logger.info(` → ${sshTarget(run.server)} (docker over ssh)`);
|
|
2979
|
+
for (const app of stack.apps) ctx.logger.info(` ${app.name.padEnd(12)} ${app.url.padEnd(40)} ${mode} ${app.ref}`);
|
|
2980
|
+
for (const worker of stack.workers) ctx.logger.info(` ${worker.name.padEnd(12)} ${`worker ${worker.id} (no route)`.padEnd(40)} ${mode} ${worker.ref}`);
|
|
2981
|
+
for (const unit of stack.processors) ctx.logger.info(` ${unit.name.padEnd(12)} ${`processors of ${unit.id}`.padEnd(40)} ${mode} ${unit.ref}`);
|
|
2982
|
+
if (stack.infra.length > 0) ctx.logger.info(` infrastructure: ${stack.infra.join(", ")}`);
|
|
2983
|
+
if (stack.backups) ctx.logger.info(` ${BACKUPS_SERVICE.padEnd(12)} ${stack.backups.databases.map((d) => d.file).join(", ")} — ${stack.backups.backups.describe}, to ${stack.backups.prefix}/`);
|
|
2984
|
+
ctx.logger.info(`\n📝 Wrote ${files.length} file(s) under ${stackDir(stack.stage)}/`);
|
|
2985
|
+
}
|
|
2986
|
+
//#endregion
|
|
2987
|
+
//#region src/target/compose/index.ts
|
|
2988
|
+
/**
|
|
2989
|
+
* The built-in `compose` target: a stage as one Docker Compose stack behind
|
|
2990
|
+
* Caddy — the local stage on the machine that runs the deploy, a deployed
|
|
2991
|
+
* stage on its server's Docker engine, over SSH (`deploy.compose.server`).
|
|
2992
|
+
*
|
|
2993
|
+
* ```bash
|
|
2994
|
+
* gkm deploy --target compose --stage production --tag v1.4.0 # what CI pushed
|
|
2995
|
+
* gkm deploy --target compose --stage production # built from here
|
|
2996
|
+
* gkm deploy --target compose --stage development # the local stage
|
|
2997
|
+
* ```
|
|
2998
|
+
*
|
|
2999
|
+
* - `validate`: the stack (`composeStack`, pure) and, for a tag, every image
|
|
3000
|
+
* looked up in the registry — `ImageTagNotFound` before anything changes
|
|
3001
|
+
* - `ready`: a deploy's own checks, after the stage's keys are — the stage's
|
|
3002
|
+
* certificate, its server's address, and every public host's DNS
|
|
3003
|
+
* - `plan`: the stack's files and what a run would create or reuse
|
|
3004
|
+
* - `provision`: generated secrets kept, files written, infrastructure up,
|
|
3005
|
+
* databases, roles, grants and migrations
|
|
3006
|
+
* - `build`: each backend bundled on the host and every image built — or, for
|
|
3007
|
+
* a tag, pulled. A site that pre-renders against its stage
|
|
3008
|
+
* (`prerender: 'stage'`) is held back, but for a push, which first asks the
|
|
3009
|
+
* running stage's APIs and builds it against them
|
|
3010
|
+
* - `release`: the stack's routes on the shared edge; a held-back site built
|
|
3011
|
+
* once the rest of the stack is up and its APIs answer through the edge;
|
|
3012
|
+
* then `up --wait
|
|
3013
|
+
* --remove-orphans`, and each app's image, tag and digest in the stage's
|
|
3014
|
+
* state — an app that never turns healthy fails it only once the rest is
|
|
3015
|
+
* released and routed
|
|
3016
|
+
* - `verify`: each app asked through Caddy over HTTPS, then each
|
|
3017
|
+
* server-rendered site warmed — its `/` and its sitemap's pages asked, a
|
|
3018
|
+
* failure only warned of
|
|
3019
|
+
*
|
|
3020
|
+
* With `push` (`gkm compose --build --push`), run with `buildOnly`, it builds
|
|
3021
|
+
* every image and pushes it to `deploy.registry`, and does nothing else: no
|
|
3022
|
+
* readiness check runs, so a stage whose keys the deploy has yet to write
|
|
3023
|
+
* still builds.
|
|
3024
|
+
*
|
|
3025
|
+
* `gkm compose` is this target with a few more switches (`--build`, `--pull`,
|
|
3026
|
+
* `--down`), run through the same `deploy()`.
|
|
3027
|
+
*/
|
|
3028
|
+
var compose_exports = /* @__PURE__ */ __exportAll({ composeTarget: () => composeTarget });
|
|
3029
|
+
/** The compose target, with its Docker, bundler and probe as given. */
|
|
3030
|
+
function composeTarget(options = {}) {
|
|
3031
|
+
const { mode, push, pin, report, ...given } = options;
|
|
3032
|
+
const deps = {
|
|
3033
|
+
...defaultDeps,
|
|
3034
|
+
...given
|
|
3035
|
+
};
|
|
3036
|
+
return defineTarget({
|
|
3037
|
+
name: "compose",
|
|
3038
|
+
runtime: "server",
|
|
3039
|
+
capabilities: {
|
|
3040
|
+
rollback: false,
|
|
3041
|
+
migrations: "target",
|
|
3042
|
+
images: true,
|
|
3043
|
+
localStage: true,
|
|
3044
|
+
selfHostedTelemetry: true
|
|
3045
|
+
},
|
|
3046
|
+
credentials: [],
|
|
3047
|
+
tag: ({ cwd }) => deps.revision(cwd),
|
|
3048
|
+
validate: (ctx) => validateCompose(ctx, deps, {
|
|
3049
|
+
...mode ? { mode } : {},
|
|
3050
|
+
...push ? { push } : {},
|
|
3051
|
+
...pin ? { pin } : {}
|
|
3052
|
+
}),
|
|
3053
|
+
ready: (ctx, run) => readyCompose(ctx, run, deps),
|
|
3054
|
+
plan: (ctx, run) => planCompose(ctx, run),
|
|
3055
|
+
provision: (ctx, run) => provisionCompose(ctx, run, deps),
|
|
3056
|
+
build: (ctx, run) => buildCompose(ctx, run, deps),
|
|
3057
|
+
release: (ctx, run) => releaseCompose(ctx, run, deps),
|
|
3058
|
+
verify: (ctx, run) => verifyCompose(ctx, run, deps),
|
|
3059
|
+
result: (ctx, run) => {
|
|
3060
|
+
report?.(run);
|
|
3061
|
+
return composeResult(ctx, run);
|
|
3062
|
+
}
|
|
3063
|
+
});
|
|
3064
|
+
}
|
|
3065
|
+
//#endregion
|
|
3066
|
+
export { edgePorts as a, edgeRef as c, dockerHost as d, sshAccess as f, projectNetwork as h, ComposePushNeedsBuild as i, removeEdgeRoutes as l, dockerCompose as m, compose_exports as n, stackOverrideFile as o, sshTarget as p, ComposePinNeedsPull as r, deployedStackSecrets as s, composeTarget as t, composeServer as u };
|
|
3067
|
+
|
|
3068
|
+
//# sourceMappingURL=compose-CnXZAYNM.mjs.map
|