@geekmidas/cli 10.0.0-alpha.146 → 10.0.0-alpha.147
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/dist/{GoDaddyProvider-BK5N6-fx.cjs → GoDaddyProvider-CpO8dFYC.cjs} +2 -2
- package/dist/{GoDaddyProvider-BK5N6-fx.cjs.map → GoDaddyProvider-CpO8dFYC.cjs.map} +1 -1
- package/dist/{GoDaddyProvider-BESq24p-.mjs → GoDaddyProvider-DXuPFufW.mjs} +2 -2
- package/dist/{GoDaddyProvider-BESq24p-.mjs.map → GoDaddyProvider-DXuPFufW.mjs.map} +1 -1
- package/dist/{HostingerProvider-BbQod5OB.cjs → HostingerProvider-Beu0Ciky.cjs} +2 -2
- package/dist/{HostingerProvider-BbQod5OB.cjs.map → HostingerProvider-Beu0Ciky.cjs.map} +1 -1
- package/dist/{HostingerProvider-BV30wTNI.mjs → HostingerProvider-Dum492dc.mjs} +2 -2
- package/dist/{HostingerProvider-BV30wTNI.mjs.map → HostingerProvider-Dum492dc.mjs.map} +1 -1
- package/dist/{LegacyStateStore-Ck3HI28A.mjs → LegacyStateStore-DZjph7ES.mjs} +2 -2
- package/dist/{LegacyStateStore-Ck3HI28A.mjs.map → LegacyStateStore-DZjph7ES.mjs.map} +1 -1
- package/dist/{LegacyStateStore-OEno6vIb.cjs → LegacyStateStore-V4R0llou.cjs} +2 -2
- package/dist/{LegacyStateStore-OEno6vIb.cjs.map → LegacyStateStore-V4R0llou.cjs.map} +1 -1
- package/dist/{LocalStateStore-Fa54CpLw.mjs → LocalStateStore-Bth8pBp-.mjs} +2 -2
- package/dist/{LocalStateStore-Fa54CpLw.mjs.map → LocalStateStore-Bth8pBp-.mjs.map} +1 -1
- package/dist/{LocalStateStore-ukDFg6GM.cjs → LocalStateStore-DuSotrd3.cjs} +2 -2
- package/dist/{LocalStateStore-ukDFg6GM.cjs.map → LocalStateStore-DuSotrd3.cjs.map} +1 -1
- package/dist/{S3StateStore-D53985SR.mjs → S3StateStore-DGlh3s2p.mjs} +4 -4
- package/dist/{S3StateStore-D53985SR.mjs.map → S3StateStore-DGlh3s2p.mjs.map} +1 -1
- package/dist/{S3StateStore-Cjuft2Lk.cjs → S3StateStore-DTPxQS3z.cjs} +4 -4
- package/dist/{S3StateStore-Cjuft2Lk.cjs.map → S3StateStore-DTPxQS3z.cjs.map} +1 -1
- package/dist/{SSMStateStore-CnJgw3_-.cjs → SSMStateStore-B9R317q0.cjs} +2 -2
- package/dist/{SSMStateStore-CnJgw3_-.cjs.map → SSMStateStore-B9R317q0.cjs.map} +1 -1
- package/dist/{SSMStateStore-CRjV2h2G.mjs → SSMStateStore-DCa85jhG.mjs} +2 -2
- package/dist/{SSMStateStore-CRjV2h2G.mjs.map → SSMStateStore-DCa85jhG.mjs.map} +1 -1
- package/dist/{add-D0-1UyFj.mjs → add-Bl33BvDW.mjs} +7 -7
- package/dist/{add-D0-1UyFj.mjs.map → add-Bl33BvDW.mjs.map} +1 -1
- package/dist/{add-CG_4mNir.cjs → add-Cr-9Ku0W.cjs} +7 -7
- package/dist/{add-CG_4mNir.cjs.map → add-Cr-9Ku0W.cjs.map} +1 -1
- package/dist/{apps-DHi6E_yH.cjs → apps-BIsxWYUo.cjs} +104 -8
- package/dist/apps-BIsxWYUo.cjs.map +1 -0
- package/dist/{apps-DWALM-8s.mjs → apps-DFzUuJ22.mjs} +87 -9
- package/dist/apps-DFzUuJ22.mjs.map +1 -0
- package/dist/{bundler-Cb5ynXXS.mjs → bundler-BagXzefF.mjs} +6 -6
- package/dist/{bundler-Cb5ynXXS.mjs.map → bundler-BagXzefF.mjs.map} +1 -1
- package/dist/{bundler-Co_7zpYC.cjs → bundler-Cael9EDc.cjs} +6 -6
- package/dist/{bundler-Co_7zpYC.cjs.map → bundler-Cael9EDc.cjs.map} +1 -1
- package/dist/{cli-C5M_7Kux.cjs → cli-B1A-cLy-.cjs} +4 -4
- package/dist/{cli-C5M_7Kux.cjs.map → cli-B1A-cLy-.cjs.map} +1 -1
- package/dist/{cli-D_9WqN6C.mjs → cli-BJRPsFq7.mjs} +4 -4
- package/dist/{cli-D_9WqN6C.mjs.map → cli-BJRPsFq7.mjs.map} +1 -1
- package/dist/{compose-7p0-3ogo.mjs → compose-C7izI7Eo.mjs} +5 -5
- package/dist/{compose-7p0-3ogo.mjs.map → compose-C7izI7Eo.mjs.map} +1 -1
- package/dist/{compose-DxmEMeTu.mjs → compose-CZU60dwb.mjs} +286 -31
- package/dist/compose-CZU60dwb.mjs.map +1 -0
- package/dist/{compose-C10hkeHU.cjs → compose-Cius-YHS.cjs} +5 -5
- package/dist/{compose-C10hkeHU.cjs.map → compose-Cius-YHS.cjs.map} +1 -1
- package/dist/{compose-BeQ01iYk.cjs → compose-CnNmDNph.cjs} +285 -30
- package/dist/compose-CnNmDNph.cjs.map +1 -0
- package/dist/{config-B-wza0Xk.mjs → config-BLrAd7Of.mjs} +2 -2
- package/dist/{config-B-wza0Xk.mjs.map → config-BLrAd7Of.mjs.map} +1 -1
- package/dist/{config-BcL1Fojs.d.cts → config-CRk2vdSp.d.mts} +3 -3
- package/dist/{config-BbivVpq0.d.mts.map → config-CRk2vdSp.d.mts.map} +1 -1
- package/dist/{config-CWExbDxA.cjs → config-juUyBlb1.cjs} +2 -2
- package/dist/{config-CWExbDxA.cjs.map → config-juUyBlb1.cjs.map} +1 -1
- package/dist/{config-BbivVpq0.d.mts → config-oBgsbLip.d.cts} +3 -3
- package/dist/{config-BcL1Fojs.d.cts.map → config-oBgsbLip.d.cts.map} +1 -1
- package/dist/config.cjs +2 -2
- package/dist/config.d.cts +3 -3
- package/dist/config.d.mts +3 -3
- package/dist/config.mjs +2 -2
- package/dist/{credentials-B5Oe4fLE.mjs → credentials-CJ_z0Nni.mjs} +7 -7
- package/dist/{credentials-B5Oe4fLE.mjs.map → credentials-CJ_z0Nni.mjs.map} +1 -1
- package/dist/{credentials-Csnd7M8M.cjs → credentials-D11xozSF.cjs} +7 -7
- package/dist/{credentials-Csnd7M8M.cjs.map → credentials-D11xozSF.cjs.map} +1 -1
- package/dist/deploy/public.cjs +12 -12
- package/dist/deploy/public.d.cts +3 -3
- package/dist/deploy/public.d.cts.map +1 -1
- package/dist/deploy/public.d.mts +3 -3
- package/dist/deploy/public.d.mts.map +1 -1
- package/dist/deploy/public.mjs +12 -12
- package/dist/{deploy-BwNxJ3ZI.cjs → deploy-Ch1wCsU1.cjs} +13 -13
- package/dist/{deploy-BwNxJ3ZI.cjs.map → deploy-Ch1wCsU1.cjs.map} +1 -1
- package/dist/{deploy-6DDEG4Ai.mjs → deploy-Dfn21QYG.mjs} +13 -13
- package/dist/{deploy-6DDEG4Ai.mjs.map → deploy-Dfn21QYG.mjs.map} +1 -1
- package/dist/{docker-BZnNUJCy.cjs → docker-BT6G7aJE.cjs} +5 -5
- package/dist/{docker-BZnNUJCy.cjs.map → docker-BT6G7aJE.cjs.map} +1 -1
- package/dist/{docker-Ch5aPQ04.mjs → docker-_W_CauBY.mjs} +5 -5
- package/dist/{docker-Ch5aPQ04.mjs.map → docker-_W_CauBY.mjs.map} +1 -1
- package/dist/{dokploy-CTWw3WSo.mjs → dokploy-CBgGuei3.mjs} +2 -2
- package/dist/{dokploy-CTWw3WSo.mjs.map → dokploy-CBgGuei3.mjs.map} +1 -1
- package/dist/{dokploy-Cn7dQqmE.cjs → dokploy-DaQbR_NH.cjs} +2 -2
- package/dist/{dokploy-Cn7dQqmE.cjs.map → dokploy-DaQbR_NH.cjs.map} +1 -1
- package/dist/{eas-D0B8H7hT.mjs → eas-3L1_yKhk.mjs} +3 -3
- package/dist/{eas-D0B8H7hT.mjs.map → eas-3L1_yKhk.mjs.map} +1 -1
- package/dist/{eas-IPjz0PWK.cjs → eas-YxDTJ3ql.cjs} +3 -3
- package/dist/{eas-IPjz0PWK.cjs.map → eas-YxDTJ3ql.cjs.map} +1 -1
- package/dist/{encryption-C9auXcSV.mjs → encryption-CRyFk5nu.mjs} +4 -4
- package/dist/{encryption-C9auXcSV.mjs.map → encryption-CRyFk5nu.mjs.map} +1 -1
- package/dist/{encryption-vK64UP4M.cjs → encryption-CVIu104e.cjs} +4 -4
- package/dist/{encryption-vK64UP4M.cjs.map → encryption-CVIu104e.cjs.map} +1 -1
- package/dist/{engine-C3N2WhbC.mjs → engine-DZnZy1R5.mjs} +17 -12
- package/dist/engine-DZnZy1R5.mjs.map +1 -0
- package/dist/{engine-Icqv5JI6.cjs → engine-XecwdLdj.cjs} +17 -12
- package/dist/engine-XecwdLdj.cjs.map +1 -0
- package/dist/{github-D24wTOe2.mjs → github-CDJXpBCT.mjs} +9 -9
- package/dist/{github-D24wTOe2.mjs.map → github-CDJXpBCT.mjs.map} +1 -1
- package/dist/{github-DUuNInc0.cjs → github-dnxU_tMp.cjs} +9 -9
- package/dist/{github-DUuNInc0.cjs.map → github-dnxU_tMp.cjs.map} +1 -1
- package/dist/{googlePlay-Cy-MaYr2.mjs → googlePlay-BYeXKpNE.mjs} +5 -5
- package/dist/{googlePlay-Cy-MaYr2.mjs.map → googlePlay-BYeXKpNE.mjs.map} +1 -1
- package/dist/{googlePlay-BGDKlnPx.cjs → googlePlay-CnIU3qIV.cjs} +5 -5
- package/dist/{googlePlay-BGDKlnPx.cjs.map → googlePlay-CnIU3qIV.cjs.map} +1 -1
- package/dist/{index-C1jffZ5_.d.cts → index-B35vTdAW.d.cts} +2 -2
- package/dist/{index-BZZeEWug.d.mts.map → index-B35vTdAW.d.cts.map} +1 -1
- package/dist/{index-BZZeEWug.d.mts → index-Dv1Zj86i.d.mts} +2 -2
- package/dist/{index-C1jffZ5_.d.cts.map → index-Dv1Zj86i.d.mts.map} +1 -1
- package/dist/index.cjs +64 -63
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +64 -63
- package/dist/index.mjs.map +1 -1
- package/dist/{local-CdpBgn3d.mjs → local-BIOpCtLE.mjs} +2 -2
- package/dist/{local-CdpBgn3d.mjs.map → local-BIOpCtLE.mjs.map} +1 -1
- package/dist/{local-B4xobzh-.cjs → local-qdNfjzxQ.cjs} +2 -2
- package/dist/{local-B4xobzh-.cjs.map → local-qdNfjzxQ.cjs.map} +1 -1
- package/dist/{migrate-DhZfvCkJ.mjs → migrate--VNdTWT7.mjs} +6 -6
- package/dist/{migrate-DhZfvCkJ.mjs.map → migrate--VNdTWT7.mjs.map} +1 -1
- package/dist/{migrate-DwQ-zaMy.cjs → migrate-CDEHWq-e.cjs} +6 -6
- package/dist/{migrate-DwQ-zaMy.cjs.map → migrate-CDEHWq-e.cjs.map} +1 -1
- package/dist/{migrate--hMBtpx-.cjs → migrate-CkHtNdre.cjs} +4 -4
- package/dist/{migrate--hMBtpx-.cjs.map → migrate-CkHtNdre.cjs.map} +1 -1
- package/dist/{migrate-DVrXTq58.mjs → migrate-svXhccrs.mjs} +4 -4
- package/dist/{migrate-DVrXTq58.mjs.map → migrate-svXhccrs.mjs.map} +1 -1
- package/dist/{notes-z5OOMqm4.mjs → notes-D9ofENLJ.mjs} +4 -4
- package/dist/{notes-z5OOMqm4.mjs.map → notes-D9ofENLJ.mjs.map} +1 -1
- package/dist/{notes-C2b5RzGl.cjs → notes-DBNPml4N.cjs} +4 -4
- package/dist/{notes-C2b5RzGl.cjs.map → notes-DBNPml4N.cjs.map} +1 -1
- package/dist/openapi.cjs +2 -2
- package/dist/openapi.d.cts +1 -1
- package/dist/openapi.d.mts +1 -1
- package/dist/openapi.mjs +2 -2
- package/dist/{projectBucket-Dk_aZ1cD.cjs → projectBucket-BtiC0Cn8.cjs} +2 -2
- package/dist/{projectBucket-Dk_aZ1cD.cjs.map → projectBucket-BtiC0Cn8.cjs.map} +1 -1
- package/dist/{projectBucket-DPD0_B8N.mjs → projectBucket-De0MQeNj.mjs} +2 -2
- package/dist/{projectBucket-DPD0_B8N.mjs.map → projectBucket-De0MQeNj.mjs.map} +1 -1
- package/dist/{publish-CDvh-9OG.cjs → publish-CohTrVKe.cjs} +2 -2
- package/dist/{publish-CDvh-9OG.cjs.map → publish-CohTrVKe.cjs.map} +1 -1
- package/dist/{publish-Bmc1Wfs3.mjs → publish-k38S418e.mjs} +2 -2
- package/dist/{publish-Bmc1Wfs3.mjs.map → publish-k38S418e.mjs.map} +1 -1
- package/dist/reconcile/public.d.cts +1 -1
- package/dist/reconcile/public.d.mts +1 -1
- package/dist/{resolve-CuxPZ3ga.cjs → resolve-Cr3Qj8ch.cjs} +4 -4
- package/dist/{resolve-CuxPZ3ga.cjs.map → resolve-Cr3Qj8ch.cjs.map} +1 -1
- package/dist/{resolve-DHARlMdl.mjs → resolve-YMxlYJtO.mjs} +4 -4
- package/dist/{resolve-DHARlMdl.mjs.map → resolve-YMxlYJtO.mjs.map} +1 -1
- package/dist/{rollback-DZq_dIbl.mjs → rollback-DIoyVrQI.mjs} +7 -7
- package/dist/{rollback-DZq_dIbl.mjs.map → rollback-DIoyVrQI.mjs.map} +1 -1
- package/dist/{rollback-DxHut8C-.cjs → rollback-eyqvtzW_.cjs} +7 -7
- package/dist/{rollback-DxHut8C-.cjs.map → rollback-eyqvtzW_.cjs.map} +1 -1
- package/dist/{runtime-Bvgyxm88.d.cts → runtime-CFvcLEJW.d.cts} +2 -2
- package/dist/{runtime-Bvgyxm88.d.cts.map → runtime-CFvcLEJW.d.cts.map} +1 -1
- package/dist/{runtime-CeAt1IJd.d.mts → runtime-dwsH6ddo.d.mts} +2 -2
- package/dist/{runtime-CeAt1IJd.d.mts.map → runtime-dwsH6ddo.d.mts.map} +1 -1
- package/dist/{s3-Dhy58V_y.cjs → s3-CegRM8Sa.cjs} +3 -3
- package/dist/{s3-Dhy58V_y.cjs.map → s3-CegRM8Sa.cjs.map} +1 -1
- package/dist/{s3-Cd7UK2y8.mjs → s3-Cl3tRemt.mjs} +3 -3
- package/dist/{s3-Cd7UK2y8.mjs.map → s3-Cl3tRemt.mjs.map} +1 -1
- package/dist/{serverSetup-DYiKHMVp.cjs → serverSetup-BwfMgz3W.cjs} +7 -7
- package/dist/{serverSetup-DYiKHMVp.cjs.map → serverSetup-BwfMgz3W.cjs.map} +1 -1
- package/dist/{serverSetup-qe5bdBhO.mjs → serverSetup-fQwkJ_EI.mjs} +7 -7
- package/dist/{serverSetup-qe5bdBhO.mjs.map → serverSetup-fQwkJ_EI.mjs.map} +1 -1
- package/dist/{sniffer-DFix2ORf.cjs → sniffer-BgdVvvzU.cjs} +7 -7
- package/dist/{sniffer-DFix2ORf.cjs.map → sniffer-BgdVvvzU.cjs.map} +1 -1
- package/dist/{sniffer-BNcLP8MO.mjs → sniffer-FF7mfuR8.mjs} +7 -7
- package/dist/{sniffer-BNcLP8MO.mjs.map → sniffer-FF7mfuR8.mjs.map} +1 -1
- package/dist/{snsSubscriptions-BwX28_Kl.mjs → snsSubscriptions-B_WH4o1S.mjs} +3 -3
- package/dist/{snsSubscriptions-BwX28_Kl.mjs.map → snsSubscriptions-B_WH4o1S.mjs.map} +1 -1
- package/dist/{snsSubscriptions-Dr-gJWtR.cjs → snsSubscriptions-DUY-Tu6J.cjs} +3 -3
- package/dist/{snsSubscriptions-Dr-gJWtR.cjs.map → snsSubscriptions-DUY-Tu6J.cjs.map} +1 -1
- package/dist/{sst-CoKFPW7f.cjs → sst-BEXeTgDQ.cjs} +5 -5
- package/dist/{sst-CoKFPW7f.cjs.map → sst-BEXeTgDQ.cjs.map} +1 -1
- package/dist/{sst-Bvtx6uZ9.mjs → sst-BkTtncop.mjs} +5 -5
- package/dist/{sst-Bvtx6uZ9.mjs.map → sst-BkTtncop.mjs.map} +1 -1
- package/dist/{stack-DbaKGKnI.cjs → stack-CcFgY4sJ.cjs} +29 -27
- package/dist/stack-CcFgY4sJ.cjs.map +1 -0
- package/dist/{stack-BeSbt_7k.mjs → stack-CqfBL5LA.mjs} +29 -27
- package/dist/stack-CqfBL5LA.mjs.map +1 -0
- package/dist/{stage-BblkSR2C.mjs → stage-4ZtteXz8.mjs} +7 -7
- package/dist/{stage-BblkSR2C.mjs.map → stage-4ZtteXz8.mjs.map} +1 -1
- package/dist/{stage-DI5mzoAi.cjs → stage-C19XRx7W.cjs} +7 -7
- package/dist/{stage-DI5mzoAi.cjs.map → stage-C19XRx7W.cjs.map} +1 -1
- package/dist/{stages-C-bVwvJZ.cjs → stages-Bs1THSy7.cjs} +3 -3
- package/dist/{stages-C-bVwvJZ.cjs.map → stages-Bs1THSy7.cjs.map} +1 -1
- package/dist/{stages-DBsDvEbo.mjs → stages-_xCG4Ymu.mjs} +3 -3
- package/dist/{stages-DBsDvEbo.mjs.map → stages-_xCG4Ymu.mjs.map} +1 -1
- package/dist/target/public.cjs +1 -1
- package/dist/target/public.d.cts +2 -2
- package/dist/target/public.d.mts +2 -2
- package/dist/target/public.mjs +1 -1
- package/dist/{terminal-Bxy_A8iP.cjs → terminal-BkyVVOb-.cjs} +2 -2
- package/dist/{terminal-Bxy_A8iP.cjs.map → terminal-BkyVVOb-.cjs.map} +1 -1
- package/dist/{terminal-DDqusYW0.mjs → terminal-KVX_MmCR.mjs} +2 -2
- package/dist/{terminal-DDqusYW0.mjs.map → terminal-KVX_MmCR.mjs.map} +1 -1
- package/dist/{types-Dy1eV7yc.d.cts → types-Dk--xVOT.d.cts} +31 -11
- package/dist/{types-Dy1eV7yc.d.cts.map → types-Dk--xVOT.d.cts.map} +1 -1
- package/dist/{types-C6hDCkV2.d.mts → types-DwQYpd_0.d.mts} +31 -11
- package/dist/{types-C6hDCkV2.d.mts.map → types-DwQYpd_0.d.mts.map} +1 -1
- package/dist/workspace/index.cjs +1 -1
- package/dist/workspace/index.d.cts +2 -2
- package/dist/workspace/index.d.mts +2 -2
- package/dist/workspace/index.mjs +1 -1
- package/dist/{workspace-BbbkJDUU.cjs → workspace-1szcahj9.cjs} +19 -27
- package/dist/workspace-1szcahj9.cjs.map +1 -0
- package/dist/{workspace-CZGJdcTs.mjs → workspace-DFGsrjGD.mjs} +19 -27
- package/dist/workspace-DFGsrjGD.mjs.map +1 -0
- package/package.json +15 -15
- package/dist/apps-DHi6E_yH.cjs.map +0 -1
- package/dist/apps-DWALM-8s.mjs.map +0 -1
- package/dist/compose-BeQ01iYk.cjs.map +0 -1
- package/dist/compose-DxmEMeTu.mjs.map +0 -1
- package/dist/engine-C3N2WhbC.mjs.map +0 -1
- package/dist/engine-Icqv5JI6.cjs.map +0 -1
- package/dist/stack-BeSbt_7k.mjs.map +0 -1
- package/dist/stack-DbaKGKnI.cjs.map +0 -1
- package/dist/workspace-BbbkJDUU.cjs.map +0 -1
- package/dist/workspace-CZGJdcTs.mjs.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compose-CZU60dwb.mjs","names":["request","httpsRequest","httpRequest"],"sources":["../src/compose/docker.ts","../src/compose/server.ts","../src/compose/edge.ts","../src/compose/acmeDns.ts","../src/compose/secrets.ts","../src/target/compose/health.ts","../src/target/compose/topicSubscriptions.ts","../src/target/compose/warmup.ts","../src/target/compose/phases.ts","../src/target/compose/index.ts"],"sourcesContent":["/**\n * The Docker operations `gkm compose` needs, behind an interface.\n *\n * Small on purpose, like reconcile's: the rules about *when* each runs — the\n * registry is asked before anything is pulled, nothing is started for a tag\n * that is missing — are asserted against a fake, and this file is only the\n * wiring to the real CLI.\n *\n * Every call is an argument array. Image refs, tags and paths come from the\n * workspace, and none of them reaches a shell.\n */\n\nimport { spawn } from 'node:child_process';\nimport { GkmError } from '../errors';\nimport { type RunOptions, run, runOutput } from '../run';\n\n/** Where one stack lives: its compose project and the file that defines it. */\nexport interface StackRef {\n\tproject: string;\n\tfile: string;\n\t/**\n\t * The project's own files merged over `file`, in order — its\n\t * `docker-compose.<stage>.yml`, where it has one.\n\t */\n\toverrides?: readonly string[];\n\t/** Where relative paths in the file resolve — the workspace root. */\n\tcwd: string;\n\t/**\n\t * The Docker engine the stack runs on, as `DOCKER_HOST` names it: a\n\t * deployed stage's server, `ssh://user@host`. Absent for this machine's\n\t * engine — the local stage — whose environment is left as it is.\n\t *\n\t * Compose is a client: it reads the compose file and every `env_file` here\n\t * and sends their values in the API calls that create each container. A\n\t * stage's secrets therefore never land on the server as a file — they are\n\t * in the container's configuration, which only the server's Docker group\n\t * can read.\n\t */\n\thost?: string;\n\t/**\n\t * Where docker's own output goes: the terminal (the default), stderr — so\n\t * a `--json` run's stdout carries only events — or nowhere.\n\t */\n\toutput?: 'inherit' | 'stderr' | 'ignore';\n\t/** Stops whatever docker is doing for the stack. */\n\tsignal?: AbortSignal;\n}\n\n/** `output` as `spawn` reads it. */\nconst STDIO: Record<NonNullable<StackRef['output']>, RunOptions['stdio']> = {\n\tinherit: 'inherit',\n\tstderr: ['ignore', 2, 2],\n\tignore: 'ignore',\n};\n\n/**\n * The environment a docker command for `engine` runs with: this process's,\n * with `DOCKER_HOST` pointing at the stack's engine when it is a server's.\n */\nexport function engineEnv(\n\tengine: Pick<StackRef, 'host'>,\n\textra: NodeJS.ProcessEnv = {},\n): NodeJS.ProcessEnv | undefined {\n\tif (!engine.host && Object.keys(extra).length === 0) return undefined;\n\treturn {\n\t\t...process.env,\n\t\t...extra,\n\t\t...(engine.host ? { DOCKER_HOST: engine.host } : {}),\n\t};\n}\n\n/** How a stack's docker commands run: where it is, where output goes. */\nfunction runOptions(stack: StackRef, extra?: NodeJS.ProcessEnv): RunOptions {\n\tconst env = engineEnv(stack, extra);\n\treturn {\n\t\tcwd: stack.cwd,\n\t\tstdio: STDIO[stack.output ?? 'inherit'],\n\t\t...(env ? { env } : {}),\n\t\t...(stack.signal ? { signal: stack.signal } : {}),\n\t};\n}\n\n/** What a command run in a container said, whatever it exited with. */\nexport interface ExecResult {\n\t/** Its exit code — null when the service has no running container. */\n\tcode: number | null;\n\tstdout: string;\n\tstderr: string;\n}\n\n/** The engine a call that is about no stack in particular is made against. */\nexport type DockerEngine = Pick<StackRef, 'host'>;\n\n/** What the registry said about one image ref. */\nexport type ImageLookup =\n\t| { ref: string; status: 'found' }\n\t| { ref: string; status: 'missing' }\n\t| { ref: string; status: 'unreachable'; detail: string };\n\n/** A running container that publishes a host port. */\nexport interface PortHolder {\n\t/** The container's name. */\n\tcontainer: string;\n\t/** Its compose project and service, when compose started it. */\n\tproject?: string;\n\tservice?: string;\n}\n\nexport interface ComposeDocker {\n\t/** Ask the registry whether `ref` exists, without pulling it. */\n\tlookup(ref: string): Promise<ImageLookup>;\n\t/** Build every service with a `build:` entry. */\n\tbuild(stack: StackRef, services: readonly string[]): Promise<void>;\n\t/** Pull the named services' images. */\n\tpull(stack: StackRef, services: readonly string[]): Promise<void>;\n\t/**\n\t * Start services, detached, and wait for their health checks. With no\n\t * services named, the whole stack — and anything it no longer defines is\n\t * removed.\n\t */\n\tup(stack: StackRef, services?: readonly string[]): Promise<void>;\n\t/** Stop the stack. Its volumes are kept. */\n\tdown(stack: StackRef): Promise<void>;\n\t/** The host port a running service publishes for `inside`. */\n\tport(stack: StackRef, service: string, inside: number): Promise<number>;\n\t/**\n\t * A running service's health, as its own check reports it — `healthy`,\n\t * `starting`, `unhealthy` — or undefined when it is not running.\n\t */\n\thealth(stack: StackRef, service: string): Promise<string | undefined>;\n\t/**\n\t * Push an image built here to its registry, and return the digest the\n\t * registry stored it under (`sha256:…`).\n\t */\n\tpush(stack: StackRef, ref: string): Promise<string>;\n\t/**\n\t * What an image resolved to on the stack's engine: the registry digest a\n\t * pulled image has, or the content id of one built and never pushed.\n\t */\n\tdigest(engine: DockerEngine, ref: string): Promise<string | undefined>;\n\t/** Create a network on the engine, unless one by that name is there. */\n\tensureNetwork(engine: DockerEngine, name: string): Promise<void>;\n\t/** Every running container publishing `port` on the engine's host. */\n\tpublishers(engine: DockerEngine, port: number): Promise<PortHolder[]>;\n\t/**\n\t * Run a command in a service's running container, `input` on its stdin —\n\t * how files reach a container on a server, through the engine alone.\n\t */\n\texec(\n\t\tstack: StackRef,\n\t\tservice: string,\n\t\tcommand: readonly string[],\n\t\tinput?: string,\n\t): Promise<ExecResult>;\n\t/**\n\t * A compose project's running container for `service` on the engine, by\n\t * its labels — found without the stack's compose file.\n\t */\n\tcontainer(\n\t\tengine: DockerEngine,\n\t\tproject: string,\n\t\tservice: string,\n\t): Promise<{ id: string; image: string } | undefined>;\n\t/**\n\t * The host port a compose project's running `service` publishes for\n\t * `inside` on the engine, by its labels — found without the stack's\n\t * compose file. Undefined when it is not running or publishes none.\n\t */\n\tpublished(\n\t\tengine: DockerEngine,\n\t\tproject: string,\n\t\tservice: string,\n\t\tinside: number,\n\t): Promise<number | undefined>;\n\t/**\n\t * Run `command` once on the engine, in a new container of `image` on\n\t * `network`, removed when it ends, with `stdin` streamed in. Each of `env`\n\t * is passed by name, never on the command line. Resolves with its exit\n\t * code.\n\t */\n\trunOnce(\n\t\tengine: DockerEngine,\n\t\toptions: {\n\t\t\timage: string;\n\t\t\tnetwork: string;\n\t\t\tcommand: readonly string[];\n\t\t\tenv?: Readonly<Record<string, string>>;\n\t\t\tstdin?: NodeJS.ReadableStream;\n\t\t\toutput?: StackRef['output'];\n\t\t},\n\t): Promise<number>;\n}\n\n/** The network compose puts a project's services on. */\nexport function projectNetwork(project: string): string {\n\treturn `${project}_default`;\n}\n\n/**\n * The host ports a `docker ps` Ports column publishes: `0.0.0.0:443->443/tcp,\n * [::]:443->443/tcp, 0.0.0.0:9000-9001->9000-9001/tcp`.\n */\nexport function publishedPorts(column: string): number[] {\n\tconst ports = new Set<number>();\n\tfor (const match of column.matchAll(\n\t\t/(?:[\\d.]+|\\[[^\\]]*\\]):(\\d+)(?:-(\\d+))?->/g,\n\t)) {\n\t\tconst first = Number(match[1]);\n\t\tconst last = match[2] ? Number(match[2]) : first;\n\t\tfor (let port = first; port <= last; port++) ports.add(port);\n\t}\n\treturn [...ports];\n}\n\n/**\n * The host port a `docker ps` Ports column publishes for `inside`:\n * `127.0.0.1:54321->5432/tcp` is 54321.\n */\nexport function publishedPort(\n\tcolumn: string,\n\tinside: number,\n): number | undefined {\n\tconst match = new RegExp(\n\t\t`(?:[\\\\d.]+|\\\\[[^\\\\]]*\\\\]):(\\\\d+)->${inside}/tcp`,\n\t).exec(column);\n\treturn match ? Number(match[1]) : undefined;\n}\n\n/** Each line `docker ps` printed, as the containers holding `port`. */\nexport function portHolders(output: string, port: number): PortHolder[] {\n\treturn output\n\t\t.split('\\n')\n\t\t.filter(Boolean)\n\t\t.map((line) => line.split('\\t'))\n\t\t.filter(([, , , column = '']) => publishedPorts(column).includes(port))\n\t\t.map(([container = '', project, service]) => ({\n\t\t\tcontainer,\n\t\t\t...(project ? { project } : {}),\n\t\t\t...(service ? { service } : {}),\n\t\t}));\n}\n\n/** How long a stack has to pass its health checks. */\nconst WAIT_TIMEOUT_S = 180;\n\n/** `docker` itself failed, before it could say anything about a service. */\nexport class DockerUnreachable extends GkmError {\n\tconstructor(\n\t\treadonly engine: string,\n\t\treadonly stderr: string,\n\t) {\n\t\tsuper(\n\t\t\t`Could not ask Docker on ${engine} which ports its services publish ` +\n\t\t\t\t`(docker said: ${stderr.trim() || 'nothing'}). Check that ` +\n\t\t\t\t`\\`DOCKER_HOST=${engine} docker ps\\` works from here.`,\n\t\t);\n\t\tthis.name = 'DockerUnreachable';\n\t}\n}\n\n/** `docker compose port` printed nothing a port can be read from. */\nexport class ServicePortUnknown extends GkmError {\n\tconstructor(\n\t\treadonly service: string,\n\t\treadonly inside: number,\n\t\treadonly output: string,\n\t) {\n\t\tsuper(\n\t\t\t`'${service}' publishes no host port for ${inside} (docker said: ${output.trim() || 'nothing'}). Is it running? \\`docker compose ps\\` shows the stack.`,\n\t\t);\n\t\tthis.name = 'ServicePortUnknown';\n\t}\n}\n\n/**\n * Whether `ref` names a registry on this machine's loopback — which the\n * daemon pulls from and pushes to over plain HTTP by default, and `docker\n * manifest inspect` reaches only when told `--insecure` (without it, a local\n * registry's image is reported as no such manifest).\n */\nexport function isLoopbackRegistry(ref: string): boolean {\n\tconst first = ref.split('/')[0]!;\n\tif (!ref.includes('/') || !/[.:]|^localhost$/.test(first)) return false;\n\tconst host = first.replace(/:\\d+$/, '');\n\treturn host === 'localhost' || /^127(?:\\.\\d{1,3}){3}$/.test(host);\n}\n\n/** `docker push` finished without saying what digest the registry stored. */\nexport class PushDigestUnknown extends GkmError {\n\tconstructor(\n\t\treadonly ref: string,\n\t\treadonly output: string,\n\t) {\n\t\tsuper(\n\t\t\t`Pushed ${ref}, but docker did not say which digest the registry stored ` +\n\t\t\t\t`(it said: ${output.trim().split('\\n').slice(-3).join(' / ') || 'nothing'}). ` +\n\t\t\t\t`Check the push with \\`docker buildx imagetools inspect ${ref}\\`.`,\n\t\t);\n\t\tthis.name = 'PushDigestUnknown';\n\t}\n}\n\n/** The digest `docker push` reports last: `<tag>: digest: sha256:… size: …`. */\nexport function pushedDigest(output: string): string | undefined {\n\tconst matches = [...output.matchAll(/digest: (sha256:[0-9a-f]{64})/g)];\n\treturn matches.at(-1)?.[1];\n}\n\nfunction compose(stack: StackRef, args: readonly string[]): string[] {\n\treturn [\n\t\t'compose',\n\t\t'-p',\n\t\tstack.project,\n\t\t'-f',\n\t\tstack.file,\n\t\t...(stack.overrides ?? []).flatMap((file) => ['-f', file]),\n\t\t...args,\n\t];\n}\n\n/** Run a program and keep everything it said, whatever it exits with. */\nfunction capture(\n\tcommand: string,\n\targs: readonly string[],\n\toptions: { env?: NodeJS.ProcessEnv; input?: string; timeoutMs?: number } = {},\n): Promise<{ code: number | null; stdout: string; stderr: string }> {\n\tconst { timeoutMs = 60_000 } = options;\n\treturn new Promise((resolve, reject) => {\n\t\tconst child = spawn(command, [...args], {\n\t\t\tstdio: [options.input === undefined ? 'ignore' : 'pipe', 'pipe', 'pipe'],\n\t\t\tshell: false,\n\t\t\t...(options.env ? { env: options.env } : {}),\n\t\t});\n\t\tif (options.input !== undefined) child.stdin?.end(options.input);\n\t\tlet stdout = '';\n\t\tlet stderr = '';\n\t\tchild.stdout?.on('data', (chunk: Buffer) => {\n\t\t\tstdout += chunk.toString();\n\t\t});\n\t\tchild.stderr?.on('data', (chunk: Buffer) => {\n\t\t\tstderr += chunk.toString();\n\t\t});\n\t\tconst timer = setTimeout(() => child.kill('SIGKILL'), timeoutMs);\n\t\ttimer.unref?.();\n\t\tchild.on('error', (error) => {\n\t\t\tclearTimeout(timer);\n\t\t\treject(error);\n\t\t});\n\t\tchild.on('close', (code) => {\n\t\t\tclearTimeout(timer);\n\t\t\tresolve({ code, stdout, stderr });\n\t\t});\n\t});\n}\n\n/**\n * Whether a failed `docker manifest inspect` means the tag is not there, as\n * opposed to the registry not answering.\n *\n * Read off the message because that is all the CLI gives. Anything not\n * recognisably \"no such tag\" is treated as the registry being unreachable:\n * a registry that refused credentials must not be reported as a tag that was\n * never pushed, or the fix offered would be the wrong one.\n */\nexport function isMissingManifest(output: string): boolean {\n\treturn /no such manifest|manifest unknown|manifest for .* not found|not found: manifest/i.test(\n\t\toutput,\n\t);\n}\n\nexport const dockerCompose: ComposeDocker = {\n\tasync lookup(ref) {\n\t\tconst { code, stdout, stderr } = await capture('docker', [\n\t\t\t'manifest',\n\t\t\t'inspect',\n\t\t\t...(isLoopbackRegistry(ref) ? ['--insecure'] : []),\n\t\t\tref,\n\t\t]);\n\t\tif (code === 0) return { ref, status: 'found' };\n\n\t\tconst output = `${stderr}\\n${stdout}`.trim();\n\t\treturn isMissingManifest(output)\n\t\t\t? { ref, status: 'missing' }\n\t\t\t: { ref, status: 'unreachable', detail: output };\n\t},\n\n\tasync build(stack, services) {\n\t\tawait run(\n\t\t\t'docker',\n\t\t\tcompose(stack, ['build', ...services]),\n\t\t\trunOptions(stack, { ...process.env, DOCKER_BUILDKIT: '1' }),\n\t\t);\n\t},\n\n\tasync pull(stack, services) {\n\t\tawait run(\n\t\t\t'docker',\n\t\t\tcompose(stack, ['pull', ...services]),\n\t\t\trunOptions(stack),\n\t\t);\n\t},\n\n\tasync up(stack, services) {\n\t\tawait run(\n\t\t\t'docker',\n\t\t\tcompose(stack, [\n\t\t\t\t'up',\n\t\t\t\t'-d',\n\t\t\t\t'--wait',\n\t\t\t\t`--wait-timeout=${WAIT_TIMEOUT_S}`,\n\t\t\t\t// Only when the whole stack is asked for: starting the databases\n\t\t\t\t// first must not remove the apps an earlier run left running.\n\t\t\t\t...(services ? [] : ['--remove-orphans']),\n\t\t\t\t...(services ?? []),\n\t\t\t]),\n\t\t\trunOptions(stack),\n\t\t);\n\t},\n\n\tasync down(stack) {\n\t\tawait run('docker', compose(stack, ['down']), runOptions(stack));\n\t},\n\n\tasync port(stack, service, inside) {\n\t\tconst env = engineEnv(stack);\n\t\tconst output = await runOutput(\n\t\t\t'docker',\n\t\t\tcompose(stack, ['port', service, String(inside)]),\n\t\t\t{\n\t\t\t\tcwd: stack.cwd,\n\t\t\t\t...(env ? { env } : {}),\n\t\t\t\t...(stack.signal ? { signal: stack.signal } : {}),\n\t\t\t},\n\t\t);\n\t\t// `127.0.0.1:54321` — the part after the last colon is the host port.\n\t\tconst port = Number(output.trim().split(':').pop());\n\t\tif (!Number.isInteger(port) || port <= 0) {\n\t\t\tthrow new ServicePortUnknown(service, inside, output);\n\t\t}\n\t\treturn port;\n\t},\n\n\tasync health(stack, service) {\n\t\tconst env = engineEnv(stack);\n\t\tconst { code, stdout } = await capture(\n\t\t\t'docker',\n\t\t\tcompose(stack, ['ps', '--format', '{{.Health}}', service]),\n\t\t\tenv ? { env } : {},\n\t\t);\n\t\tif (code !== 0) return undefined;\n\t\treturn stdout.trim().split('\\n')[0] || undefined;\n\t},\n\n\tasync push(stack, ref) {\n\t\t// What it printed is read back for the digest; its errors still reach\n\t\t// the terminal.\n\t\tconst output = await runOutput('docker', ['push', ref], {\n\t\t\tcwd: stack.cwd,\n\t\t\t...(stack.signal ? { signal: stack.signal } : {}),\n\t\t});\n\t\tconst digest = pushedDigest(output);\n\t\tif (!digest) throw new PushDigestUnknown(ref, output);\n\t\treturn digest;\n\t},\n\n\tasync digest(engine, ref) {\n\t\tconst env = engineEnv(engine);\n\t\tconst { code, stdout } = await capture(\n\t\t\t'docker',\n\t\t\t['image', 'inspect', '--format={{json .RepoDigests}} {{.Id}}', ref],\n\t\t\tenv ? { env } : {},\n\t\t);\n\t\tif (code !== 0) return undefined;\n\n\t\tconst [json = '[]', id] = stdout.trim().split(' ');\n\t\tconst repository = ref.split('@')[0]!.replace(/:[\\w][\\w.-]*$/, '');\n\t\ttry {\n\t\t\tconst digests = JSON.parse(json) as unknown;\n\t\t\tconst match = Array.isArray(digests)\n\t\t\t\t? digests.find(\n\t\t\t\t\t\t(entry): entry is string =>\n\t\t\t\t\t\t\ttypeof entry === 'string' && entry.startsWith(`${repository}@`),\n\t\t\t\t\t)\n\t\t\t\t: undefined;\n\t\t\tif (match) return match.slice(repository.length + 1);\n\t\t} catch {\n\t\t\t// Fall through to the content id.\n\t\t}\n\t\treturn id || undefined;\n\t},\n\n\tasync ensureNetwork(engine, name) {\n\t\tconst env = engineEnv(engine);\n\t\tconst options = env ? { env } : {};\n\t\tconst { code } = await capture(\n\t\t\t'docker',\n\t\t\t['network', 'inspect', name],\n\t\t\toptions,\n\t\t);\n\t\tif (code === 0) return;\n\t\tconst created = await capture(\n\t\t\t'docker',\n\t\t\t['network', 'create', name],\n\t\t\toptions,\n\t\t);\n\t\t// Another run may have created it between the two calls.\n\t\tif (created.code !== 0 && !/already exists/.test(created.stderr)) {\n\t\t\tthrow new NetworkCreateFailed(name, created.stderr);\n\t\t}\n\t},\n\n\tasync publishers(engine, port) {\n\t\tconst env = engineEnv(engine);\n\t\tconst { stdout } = await capture(\n\t\t\t'docker',\n\t\t\t[\n\t\t\t\t'ps',\n\t\t\t\t'--format',\n\t\t\t\t'{{.Names}}\\t{{.Label \"com.docker.compose.project\"}}\\t{{.Label \"com.docker.compose.service\"}}\\t{{.Ports}}',\n\t\t\t],\n\t\t\tenv ? { env } : {},\n\t\t);\n\t\treturn portHolders(stdout, port);\n\t},\n\n\tasync exec(stack, service, command, input) {\n\t\tconst env = engineEnv(stack);\n\t\tconst options = env ? { env } : {};\n\t\t// By its compose labels, so it needs no compose file: `--down` reaches\n\t\t// the shared edge with nothing but its project's name.\n\t\tconst { stdout: ids } = await capture(\n\t\t\t'docker',\n\t\t\t[\n\t\t\t\t'ps',\n\t\t\t\t'-q',\n\t\t\t\t'--filter',\n\t\t\t\t`label=com.docker.compose.project=${stack.project}`,\n\t\t\t\t'--filter',\n\t\t\t\t`label=com.docker.compose.service=${service}`,\n\t\t\t],\n\t\t\toptions,\n\t\t);\n\t\tconst container = ids.trim().split('\\n')[0];\n\t\tif (!container) {\n\t\t\treturn { code: null, stdout: '', stderr: `${service} is not running` };\n\t\t}\n\t\treturn capture(\n\t\t\t'docker',\n\t\t\t['exec', ...(input === undefined ? [] : ['-i']), container, ...command],\n\t\t\t{ ...options, ...(input === undefined ? {} : { input }) },\n\t\t);\n\t},\n\n\tasync container(engine, project, service) {\n\t\tconst env = engineEnv(engine);\n\t\tconst { stdout } = await capture(\n\t\t\t'docker',\n\t\t\t[\n\t\t\t\t'ps',\n\t\t\t\t'--filter',\n\t\t\t\t`label=com.docker.compose.project=${project}`,\n\t\t\t\t'--filter',\n\t\t\t\t`label=com.docker.compose.service=${service}`,\n\t\t\t\t'--format',\n\t\t\t\t'{{.ID}}\\t{{.Image}}',\n\t\t\t],\n\t\t\tenv ? { env } : {},\n\t\t);\n\t\tconst [id, image] = stdout.trim().split('\\n')[0]?.split('\\t') ?? [];\n\t\treturn id && image ? { id, image } : undefined;\n\t},\n\n\tasync published(engine, project, service, inside) {\n\t\tconst env = engineEnv(engine);\n\t\tconst { code, stdout, stderr } = await capture(\n\t\t\t'docker',\n\t\t\t[\n\t\t\t\t'ps',\n\t\t\t\t'--filter',\n\t\t\t\t`label=com.docker.compose.project=${project}`,\n\t\t\t\t'--filter',\n\t\t\t\t`label=com.docker.compose.service=${service}`,\n\t\t\t\t'--format',\n\t\t\t\t'{{.Ports}}',\n\t\t\t],\n\t\t\tenv ? { env } : {},\n\t\t);\n\t\t// Docker not answering is not a service that publishes nothing.\n\t\tif (code !== 0) {\n\t\t\tthrow new DockerUnreachable(engine.host ?? 'this machine', stderr);\n\t\t}\n\t\treturn publishedPort(stdout, inside);\n\t},\n\n\trunOnce(engine, options) {\n\t\treturn dockerExit(\n\t\t\t[\n\t\t\t\t'run',\n\t\t\t\t'--rm',\n\t\t\t\t...(options.stdin ? ['-i'] : []),\n\t\t\t\t'--network',\n\t\t\t\toptions.network,\n\t\t\t\t...Object.keys(options.env ?? {}).flatMap((name) => ['-e', name]),\n\t\t\t\t'--entrypoint',\n\t\t\t\t'',\n\t\t\t\toptions.image,\n\t\t\t\t...options.command,\n\t\t\t],\n\t\t\t{\n\t\t\t\tenv: engineEnv(engine, { ...options.env }) ?? process.env,\n\t\t\t\t...(options.stdin ? { stdin: options.stdin } : {}),\n\t\t\t\t...(options.output ? { output: options.output } : {}),\n\t\t\t},\n\t\t);\n\t},\n};\n\n/** Spawn `docker`, its output where `output` says; resolve with the exit code. */\nfunction dockerExit(\n\targs: readonly string[],\n\toptions: {\n\t\tenv?: NodeJS.ProcessEnv;\n\t\tstdin?: NodeJS.ReadableStream;\n\t\toutput?: StackRef['output'];\n\t} = {},\n): Promise<number> {\n\tconst output = STDIO[options.output ?? 'inherit'];\n\tconst out = Array.isArray(output) ? output : [output, output, output];\n\treturn new Promise((resolve, reject) => {\n\t\tconst child = spawn('docker', [...args], {\n\t\t\tstdio: [options.stdin ? 'pipe' : 'ignore', out[1], out[2]] as never,\n\t\t\tenv: options.env ?? process.env,\n\t\t\tshell: false,\n\t\t});\n\t\tif (options.stdin && child.stdin) {\n\t\t\toptions.stdin.on('error', (error) => child.stdin?.destroy(error));\n\t\t\tchild.stdin.on('error', () => {});\n\t\t\toptions.stdin.pipe(child.stdin);\n\t\t}\n\t\tchild.on('error', reject);\n\t\tchild.on('close', (code) => resolve(code ?? 1));\n\t});\n}\n\n/** `docker network create` failed. */\nexport class NetworkCreateFailed extends GkmError {\n\tconstructor(\n\t\treadonly network: string,\n\t\treadonly output: string,\n\t) {\n\t\tsuper(\n\t\t\t`Could not create the Docker network '${network}' (docker said: ${output.trim() || 'nothing'}). Create it by hand with \\`docker network create ${network}\\` and run again.`,\n\t\t);\n\t\tthis.name = 'NetworkCreateFailed';\n\t}\n}\n","/**\n * Where a deployed compose stage runs: its server, reached over SSH.\n *\n * gkm never runs on the server. It runs where the deploy is started — a CI\n * runner, a developer's machine — and drives the server's Docker engine over\n * SSH (`DOCKER_HOST=ssh://user@host`), so the server holds Docker, an SSH\n * login and nothing else: no gkm, no checkout, no cloud credentials.\n *\n * ```ts\n * deploy: { compose: { server: { production: { user: 'deploy' } } } }\n * ```\n *\n * The host is the stage's `GKM_SERVER_IPV4` secret — the address its DNS\n * records already point at — unless `host` names another. The local stage is\n * never given one: it runs on this machine's Docker.\n *\n * What the deploy needs from inside the server — Postgres and MinIO, published\n * on the server's loopback alone — it reaches through an SSH tunnel on the same\n * login, so neither is ever published publicly.\n */\n\nimport { spawn } from 'node:child_process';\nimport { createConnection, createServer } from 'node:net';\nimport { GkmError } from '../errors';\nimport type { ComposeServerConfig } from '../workspace/types.js';\nimport { SERVER_IPV4_KEY } from './dnsConfig';\n\n/** A stage's server, as SSH reaches it. */\nexport interface ComposeServer {\n\tuser: string;\n\thost: string;\n\tport: number;\n}\n\n/** A deployed compose stage with nowhere to run. */\nexport class ComposeServerMissing extends GkmError {\n\tconstructor(\n\t\treadonly stage: string,\n\t\treadonly missing: 'config' | 'host',\n\t) {\n\t\tsuper(\n\t\t\tmissing === 'config'\n\t\t\t\t? `'${stage}' is a deployed stage, and gkm deploys it to its server's ` +\n\t\t\t\t\t\t\"Docker over SSH — it never starts a deployed stage on this machine's \" +\n\t\t\t\t\t\t`Docker. Name the login in gkm.config.ts: deploy: { compose: { server: ` +\n\t\t\t\t\t\t`{ ${stage}: { user: 'deploy' } } } } — the host is the stage's ` +\n\t\t\t\t\t\t`${SERVER_IPV4_KEY} secret (gkm secrets:set ${SERVER_IPV4_KEY} '<ip>' ` +\n\t\t\t\t\t\t`--stage ${stage}), or set host there too.`\n\t\t\t\t: `deploy.compose.server.${stage} names no host, and '${stage}' has no ` +\n\t\t\t\t\t\t`${SERVER_IPV4_KEY} secret to default to. Set it: gkm secrets:set ` +\n\t\t\t\t\t\t`${SERVER_IPV4_KEY} '<ip>' --stage ${stage} — or set ` +\n\t\t\t\t\t\t`deploy.compose.server.${stage}.host.`,\n\t\t);\n\t\tthis.name = 'ComposeServerMissing';\n\t}\n}\n\n/** SSH to the stage's server failed before anything was changed there. */\nexport class ComposeServerUnreachable extends GkmError {\n\tconstructor(\n\t\treadonly target: string,\n\t\treadonly stderr: string,\n\t) {\n\t\tsuper(\n\t\t\t`Could not reach Docker on ${target} over SSH (ssh said: ${stderr.trim() || 'nothing'}). ` +\n\t\t\t\t`Check that \\`ssh ${target} docker version\\` works from here: the host key in ` +\n\t\t\t\t'~/.ssh/known_hosts, the key in your agent or ~/.ssh/config, and the user in ' +\n\t\t\t\t\"the server's docker group.\",\n\t\t);\n\t\tthis.name = 'ComposeServerUnreachable';\n\t}\n}\n\n/** An SSH tunnel to a port on the server's loopback did not open. */\nexport class ComposeTunnelFailed extends GkmError {\n\tconstructor(\n\t\treadonly target: string,\n\t\treadonly remotePort: number,\n\t\treadonly stderr: string,\n\t) {\n\t\tsuper(\n\t\t\t`Could not open an SSH tunnel to 127.0.0.1:${remotePort} on ${target} ` +\n\t\t\t\t`(ssh said: ${stderr.trim() || 'nothing'}). The server's sshd must allow ` +\n\t\t\t\t'TCP forwarding for the deploy user (AllowTcpForwarding yes, the default, ' +\n\t\t\t\t'or local), and its key in ~/.ssh/authorized_keys must too: a key ' +\n\t\t\t\t'installed with `restrict` refuses forwarding unless it also says ' +\n\t\t\t\t'`port-forwarding` (`restrict,port-forwarding ssh-ed25519 …`).',\n\t\t);\n\t\tthis.name = 'ComposeTunnelFailed';\n\t}\n}\n\n/**\n * The stage's server: its login from `deploy.compose.server.<stage>`, its\n * host from there or the stage's `GKM_SERVER_IPV4`. Undefined for the local\n * stage, which runs on this machine.\n *\n * @throws {ComposeServerMissing} for a deployed stage with no login or host\n */\nexport function composeServer(options: {\n\tstage: string;\n\tlocal: boolean;\n\tconfig: Readonly<Record<string, ComposeServerConfig>> | undefined;\n\tcustom: Readonly<Record<string, string>> | undefined;\n}): ComposeServer | undefined {\n\tconst { stage } = options;\n\tif (options.local) return undefined;\n\tconst config = options.config?.[stage];\n\tif (!config) throw new ComposeServerMissing(stage, 'config');\n\tconst host = config.host ?? options.custom?.[SERVER_IPV4_KEY]?.trim();\n\tif (!host) throw new ComposeServerMissing(stage, 'host');\n\treturn { user: config.user, host, port: config.port ?? 22 };\n}\n\n/** `user@host`, as a person types it after `ssh`. */\nexport function sshTarget(server: ComposeServer): string {\n\treturn `${server.user}@${server.host}`;\n}\n\n/** The server's Docker engine, as `DOCKER_HOST` names it. */\nexport function dockerHost(server: ComposeServer): string {\n\tconst host = server.host.includes(':') ? `[${server.host}]` : server.host;\n\treturn `ssh://${server.user}@${host}${server.port === 22 ? '' : `:${server.port}`}`;\n}\n\n/** The arguments every `ssh` gkm runs starts with: no prompt, ever. */\nfunction sshArgs(server: ComposeServer): string[] {\n\treturn [\n\t\t'-o',\n\t\t'BatchMode=yes',\n\t\t'-o',\n\t\t'ConnectTimeout=20',\n\t\t'-p',\n\t\tString(server.port),\n\t\tsshTarget(server),\n\t];\n}\n\n/** A local port forwarded to one on the server's loopback. */\nexport interface Tunnel {\n\t/** The port on this machine's loopback. */\n\tport: number;\n\tclose(): Promise<void>;\n}\n\n/** What the deploy does on a stage's server beyond Docker. */\nexport interface ServerAccess {\n\t/**\n\t * Whether SSH logs in and Docker answers there — read-only: `docker\n\t * version`, nothing else.\n\t */\n\tcheck(server: ComposeServer): Promise<void>;\n\t/** Forward a free local port to `remotePort` on the server's loopback. */\n\ttunnel(server: ComposeServer, remotePort: number): Promise<Tunnel>;\n}\n\nasync function freeLocalPort(): Promise<number> {\n\tconst server = createServer();\n\tawait new Promise<void>((resolve, reject) => {\n\t\tserver.once('error', reject);\n\t\tserver.listen(0, '127.0.0.1', resolve);\n\t});\n\tconst address = server.address();\n\tawait new Promise((resolve) => server.close(resolve));\n\tif (!address || typeof address === 'string') return 0;\n\treturn address.port;\n}\n\nfunction connects(port: number): Promise<boolean> {\n\treturn new Promise((resolve) => {\n\t\tconst socket = createConnection({ host: '127.0.0.1', port });\n\t\tsocket.once('connect', () => {\n\t\t\tsocket.destroy();\n\t\t\tresolve(true);\n\t\t});\n\t\tsocket.once('error', () => resolve(false));\n\t});\n}\n\n/** The real one: the system's `ssh`, with the user's keys and known hosts. */\nexport const sshAccess: ServerAccess = {\n\tcheck(server) {\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tconst child = spawn(\n\t\t\t\t'ssh',\n\t\t\t\t[\n\t\t\t\t\t...sshArgs(server),\n\t\t\t\t\t'docker',\n\t\t\t\t\t'version',\n\t\t\t\t\t'--format',\n\t\t\t\t\t'{{.Server.Version}}',\n\t\t\t\t],\n\t\t\t\t{ stdio: ['ignore', 'ignore', 'pipe'] },\n\t\t\t);\n\t\t\tlet stderr = '';\n\t\t\tchild.stderr.on('data', (chunk: Buffer) => {\n\t\t\t\tstderr += chunk.toString();\n\t\t\t});\n\t\t\tchild.on('error', (error) =>\n\t\t\t\treject(new ComposeServerUnreachable(sshTarget(server), error.message)),\n\t\t\t);\n\t\t\tchild.on('close', (code) =>\n\t\t\t\tcode === 0\n\t\t\t\t\t? resolve()\n\t\t\t\t\t: reject(new ComposeServerUnreachable(sshTarget(server), stderr)),\n\t\t\t);\n\t\t});\n\t},\n\n\tasync tunnel(server, remotePort) {\n\t\tconst port = await freeLocalPort();\n\t\tconst child = spawn(\n\t\t\t'ssh',\n\t\t\t[\n\t\t\t\t'-N',\n\t\t\t\t'-o',\n\t\t\t\t'ExitOnForwardFailure=yes',\n\t\t\t\t// A connection of its own: through a shared master (ControlMaster\n\t\t\t\t// in ~/.ssh/config) the forward would be the master's, and this\n\t\t\t\t// process — the tunnel's lifetime — would exit at once.\n\t\t\t\t'-o',\n\t\t\t\t'ControlPath=none',\n\t\t\t\t'-L',\n\t\t\t\t`127.0.0.1:${port}:127.0.0.1:${remotePort}`,\n\t\t\t\t...sshArgs(server),\n\t\t\t],\n\t\t\t{ stdio: ['ignore', 'ignore', 'pipe'] },\n\t\t);\n\t\tlet stderr = '';\n\t\tlet exited = false;\n\t\tchild.stderr.on('data', (chunk: Buffer) => {\n\t\t\tstderr += chunk.toString();\n\t\t});\n\t\tchild.on('exit', () => {\n\t\t\texited = true;\n\t\t});\n\t\tchild.on('error', (error) => {\n\t\t\texited = true;\n\t\t\tstderr += error.message;\n\t\t});\n\t\tconst close = async () => {\n\t\t\tif (exited) return;\n\t\t\tconst gone = new Promise((resolve) => child.once('exit', resolve));\n\t\t\tchild.kill('SIGTERM');\n\t\t\tawait gone;\n\t\t};\n\n\t\t// Open once a connection to it is accepted — ssh only listens once\n\t\t// it has logged in and set the forward up.\n\t\tfor (let attempt = 0; attempt < 150; attempt++) {\n\t\t\tif (exited) break;\n\t\t\tif (await connects(port)) return { port, close };\n\t\t\tawait new Promise((resolve) => setTimeout(resolve, 200));\n\t\t}\n\t\tawait close();\n\t\tthrow new ComposeTunnelFailed(sshTarget(server), remotePort, stderr);\n\t},\n};\n","/**\n * The server's shared Traefik edge, in Docker: started when a stack needs it,\n * and each stack's routes written to — and removed from — the directory it\n * watches.\n *\n * Everything goes through the server's Docker engine, never its filesystem:\n * the edge's static configuration is handed to it inline, and the directories\n * it watches are volumes each stack writes into with `docker exec`. So the\n * deploy runs anywhere that reaches the engine — a CI runner over SSH — and\n * nothing it writes depends on a path on that machine.\n *\n * gkm-edge (compose project)\n * traefik.yml its static configuration (inline config)\n * dynamic/<project>.yml one per stack: routers, services, middlewares\n * certs/<project>.crt|.key a stack's own certificate, where it has one\n */\n\nimport { mkdir, readFile, writeFile } from 'node:fs/promises';\nimport { dirname } from 'node:path';\nimport { GkmError } from '../errors';\nimport type {\n\tComposeDocker,\n\tDockerEngine,\n\tPortHolder,\n\tStackRef,\n} from './docker.js';\nimport type { ComposeProxy } from './routes.js';\nimport {\n\tEDGE_CERTS_DIR,\n\tEDGE_DYNAMIC_DIR,\n\tEDGE_NETWORK,\n\tEDGE_PROJECT,\n\tEDGE_SERVICE,\n\ttype EdgePorts,\n\tedgeComposeFile,\n\ttraefikStaticFile,\n} from './traefik.js';\n\n/** The edge's compose project, as docker is asked about it. */\nexport function edgeRef(\n\tfile: string,\n\toptions: Pick<StackRef, 'output' | 'signal' | 'host'> = {},\n): StackRef {\n\treturn {\n\t\tproject: EDGE_PROJECT,\n\t\tfile,\n\t\tcwd: dirname(file),\n\t\t...options,\n\t};\n}\n\n/** Writing to or removing from the edge's volumes failed. */\nexport class EdgeWriteFailed extends GkmError {\n\tconstructor(\n\t\treadonly path: string,\n\t\treadonly output: string,\n\t) {\n\t\tsuper(\n\t\t\t`Could not write ${path} in the shared edge (${EDGE_PROJECT}): ${output.trim() || 'it is not running'}. ` +\n\t\t\t\t`Check it with \\`docker compose -p ${EDGE_PROJECT} ps\\` on the server, and run gkm compose again.`,\n\t\t);\n\t\tthis.name = 'EdgeWriteFailed';\n\t}\n}\n\n/**\n * Something other than the proxy a stack is set to holds the edge's ports.\n *\n * With `proxy: 'traefik'`, the stack's own Caddy — still running from before\n * the switch — or any other container; with `proxy: 'caddy'`, the shared\n * edge, or another stack's Caddy. Refused before anything is started, so the\n * stack is never left half on one proxy and half on the other.\n */\nexport class ComposeProxyClash extends GkmError {\n\tconstructor(\n\t\treadonly project: string,\n\t\treadonly proxy: ComposeProxy,\n\t\treadonly port: number,\n\t\treadonly holder: PortHolder,\n\t) {\n\t\tconst by = holder.project\n\t\t\t? `${holder.container} (compose project ${holder.project})`\n\t\t\t: holder.container;\n\t\tconst fix =\n\t\t\tproxy === 'traefik'\n\t\t\t\t? holder.project === project && holder.service === 'caddy'\n\t\t\t\t\t? `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.`\n\t\t\t\t\t: `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.`\n\t\t\t\t: holder.project === EDGE_PROJECT\n\t\t\t\t\t? `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).`\n\t\t\t\t\t: `Stop ${holder.container}, or publish this stack's Caddy elsewhere with GKM_COMPOSE_HTTPS_PORT/GKM_COMPOSE_HTTP_PORT.`;\n\t\tsuper(\n\t\t\t`${project} is set to proxy: '${proxy}', and port ${port} is held by ${by}. ${fix}`,\n\t\t);\n\t\tthis.name = 'ComposeProxyClash';\n\t}\n}\n\n/**\n * Refuse a stack whose edge ports are held by anything but its own proxy:\n * the shared edge for `'traefik'`, the stack's own Caddy for `'caddy'`.\n */\nexport async function assertEdgePorts(\n\tdocker: ComposeDocker,\n\toptions: {\n\t\tproject: string;\n\t\tproxy: ComposeProxy;\n\t\tports: EdgePorts;\n\t\tengine: DockerEngine;\n\t},\n): Promise<void> {\n\tconst { project, proxy, ports } = options;\n\tfor (const port of [ports.https, ports.http]) {\n\t\tfor (const holder of await docker.publishers(options.engine, port)) {\n\t\t\tconst own =\n\t\t\t\tproxy === 'traefik'\n\t\t\t\t\t? holder.project === EDGE_PROJECT\n\t\t\t\t\t: holder.project === project && holder.service === 'caddy';\n\t\t\tif (!own) throw new ComposeProxyClash(project, proxy, port, holder);\n\t\t}\n\t}\n}\n\n/**\n * Write a file into the edge's running container whole or not at all: a\n * temporary name, then a rename. Not `.yml`: the edge reads only `.yml`,\n * `.yaml` and `.toml` files, so it never sees one half written.\n */\nasync function put(\n\tdocker: ComposeDocker,\n\tedge: StackRef,\n\tpath: string,\n\tcontent: string,\n\tmode: '600' | '644' = '644',\n): Promise<void> {\n\tconst result = await docker.exec(\n\t\tedge,\n\t\tEDGE_SERVICE,\n\t\t[\n\t\t\t'sh',\n\t\t\t'-c',\n\t\t\t'set -e; t=\"$1.tmp\"; cat > \"$t\"; chmod \"$2\" \"$t\"; mv \"$t\" \"$1\"',\n\t\t\t'sh',\n\t\t\tpath,\n\t\t\tmode,\n\t\t],\n\t\tcontent,\n\t);\n\tif (result.code !== 0) {\n\t\tthrow new EdgeWriteFailed(path, `${result.stderr}${result.stdout}`);\n\t}\n}\n\n/** Remove files from the edge's container; whether the first was there. */\nasync function remove(\n\tdocker: ComposeDocker,\n\tedge: StackRef,\n\tpaths: readonly string[],\n): Promise<boolean> {\n\tconst result = await docker.exec(edge, EDGE_SERVICE, [\n\t\t'sh',\n\t\t'-c',\n\t\t'e=1; [ -f \"$1\" ] && e=0; rm -f \"$@\"; exit $e',\n\t\t'sh',\n\t\t...paths,\n\t]);\n\treturn result.code === 0;\n}\n\n/**\n * The edge, up: its network and its container — started when it is not\n * running, and recreated when its configuration changed. Idempotent: on a\n * server where it already runs as configured, `up` changes nothing. Its\n * compose file is written to `file`, on this machine: compose reads it here.\n */\nexport async function ensureEdge(\n\tdocker: ComposeDocker,\n\toptions: {\n\t\tfile: string;\n\t\tports: EdgePorts;\n\t\tlogging: { driver: string; options: Record<string, string> };\n\t\thost?: string;\n\t\toutput?: StackRef['output'];\n\t\tsignal?: AbortSignal;\n\t},\n): Promise<string[]> {\n\tconst { file, ports } = options;\n\tconst staticConfig = traefikStaticFile(ports);\n\tconst content = edgeComposeFile({\n\t\tports,\n\t\tstaticConfig,\n\t\tlogging: options.logging,\n\t});\n\tawait mkdir(dirname(file), { recursive: true });\n\tif ((await readFile(file, 'utf-8').catch(() => undefined)) !== content) {\n\t\tawait writeFile(file, content);\n\t}\n\n\tconst ref = edgeRef(file, {\n\t\t...(options.host ? { host: options.host } : {}),\n\t\t...(options.output ? { output: options.output } : {}),\n\t\t...(options.signal ? { signal: options.signal } : {}),\n\t});\n\tawait docker.ensureNetwork(ref, EDGE_NETWORK);\n\tawait docker.up(ref, [EDGE_SERVICE]);\n\treturn [file];\n}\n\n/** A file inside the edge's running container, or undefined where there is none. */\nexport async function readEdgeFile(\n\tdocker: ComposeDocker,\n\tedge: StackRef,\n\tpath: string,\n): Promise<string | undefined> {\n\tconst result = await docker.exec(edge, EDGE_SERVICE, ['cat', path]);\n\treturn result.code === 0 ? result.stdout : undefined;\n}\n\n/** A file written into the edge's running container, whole, readable by it alone. */\nexport async function writeEdgeSecret(\n\tdocker: ComposeDocker,\n\tedge: StackRef,\n\tpath: string,\n\tcontent: string,\n): Promise<void> {\n\tawait put(docker, edge, path, content, '600');\n}\n\n/**\n * The edge restarted — what it reads once and keeps, a key among them, read\n * again — and waited on until it is healthy. Its own restart policy brings\n * it back; `up` waits for it.\n */\nexport async function restartEdge(\n\tdocker: ComposeDocker,\n\tedge: StackRef,\n): Promise<void> {\n\tawait docker.exec(edge, EDGE_SERVICE, ['kill', '1']);\n\tawait docker.up(edge, [EDGE_SERVICE]);\n}\n\n/** A stack's routes, inside the edge's container. */\nexport function routesPath(project: string): string {\n\treturn `${EDGE_DYNAMIC_DIR}/${project}.yml`;\n}\n\nfunction certificatePaths(project: string): [string, string] {\n\treturn [\n\t\t`${EDGE_CERTS_DIR}/${project}.crt`,\n\t\t`${EDGE_CERTS_DIR}/${project}.key`,\n\t];\n}\n\n/**\n * Register a stack with the edge: its certificate first, where it has one,\n * so the routes that need it never load without it — then its routes, in one\n * rename the edge picks up whole. The certificate — the stage's own, or the\n * one gkm's local CA issued the local stage — is PEM read on this machine and\n * written through the engine. The paths written, inside the edge.\n */\nexport async function writeEdgeRoutes(\n\tdocker: ComposeDocker,\n\tedge: StackRef,\n\tproject: string,\n\troutes: string,\n\tcertificate?: { cert: string; key: string },\n): Promise<string[]> {\n\tconst written: string[] = [];\n\tconst [crt, key] = certificatePaths(project);\n\tif (certificate) {\n\t\tawait put(docker, edge, crt, certificate.cert);\n\t\tawait put(docker, edge, key, certificate.key, '600');\n\t\twritten.push(crt, key);\n\t} else {\n\t\tawait remove(docker, edge, [crt, key]);\n\t}\n\tawait put(docker, edge, routesPath(project), routes);\n\twritten.push(routesPath(project));\n\treturn written;\n}\n\n/** What a stack's file holds for the moment between emptying and removal. */\nconst UNREGISTERED = '# Unregistered by gkm compose --down.\\n';\n\n/**\n * Unregister a stack: its routes, then its certificate. Whether there was\n * anything to remove — false, too, when the edge is not running.\n */\nexport async function removeEdgeRoutes(\n\tdocker: ComposeDocker,\n\tedge: StackRef,\n\tproject: string,\n): Promise<boolean> {\n\tconst file = routesPath(project);\n\tconst there = await docker.exec(edge, EDGE_SERVICE, ['test', '-f', file]);\n\tif (there.code !== 0) return false;\n\t// Emptied by a rename before it is removed: a watcher that misses the\n\t// removal has still seen the stack's routes go.\n\tawait put(docker, edge, file, UNREGISTERED);\n\tawait remove(docker, edge, [file, ...certificatePaths(project)]);\n\treturn true;\n}\n","/**\n * The key the server's shared Traefik edge answers Let's Encrypt's DNS\n * challenge with, for a stage with a wildcard site.\n *\n * A wildcard certificate is issued only over the DNS challenge: the edge\n * proves it holds `<domain>` by writing a TXT record at\n * `_acme-challenge.<domain>`. So it needs a key that can write that record —\n * and nothing else, because it lives on the server.\n *\n * - **The user**: one per server, under `/gkm/`, tagged with the server it\n * is for. One that exists without that tag is someone else's, and is\n * refused rather than taken over.\n * - **Its policies**: one per stack on the server, named for its compose\n * project, allowing `ChangeResourceRecordSets` on the stage's hosted zone\n * for TXT records named `_acme-challenge.<domain>` alone — plus what\n * finding the zone and waiting for the change take, which read and write\n * nothing. Put back on every deploy.\n * - **Its key**: written into the edge's container, never into the stage's\n * secrets or onto the machine running the deploy. Issued when the edge\n * has none, or holds one IAM no longer knows — and then the edge is\n * restarted, since it keeps the key it first read.\n */\n\nimport { createHash } from 'node:crypto';\nimport type { IAMClient } from '@aws-sdk/client-iam';\nimport type { Route53Client } from '@aws-sdk/client-route-53';\nimport { GkmError } from '../errors';\nimport type { ComposeDocker, StackRef } from './docker.js';\nimport { readEdgeFile, restartEdge, writeEdgeSecret } from './edge.js';\nimport { EDGE_AWS_CREDENTIALS, EDGE_PROJECT } from './traefik.js';\n\n/** Where gkm's IAM users live. */\nconst USER_PATH = '/gkm/';\n\n/** The tag a server's edge user is found by. */\nexport const TAG_EDGE = 'gkm:edge';\n\n/** What the key is issued and its zone found through. */\nexport interface AcmeDnsClients {\n\tiam: IAMClient;\n\troute53: Route53Client;\n}\n\n/** The edge user's name for a server: stable, and safe for IAM. */\nexport function edgeAcmeUser(server: string): string {\n\tconst hash = createHash('sha256').update(server).digest('hex').slice(0, 12);\n\treturn `gkm-edge-acme-${hash}`;\n}\n\n/**\n * What one stage's wildcard certificate needs: its challenge record written\n * in its zone, the change waited on, and the zone found by name — which is\n * how the edge's ACME client finds it.\n */\nexport function acmeDnsPolicy(zoneId: string, domain: string): string {\n\treturn JSON.stringify({\n\t\tVersion: '2012-10-17',\n\t\tStatement: [\n\t\t\t{\n\t\t\t\tEffect: 'Allow',\n\t\t\t\tAction: 'route53:ChangeResourceRecordSets',\n\t\t\t\tResource: `arn:aws:route53:::hostedzone/${zoneId}`,\n\t\t\t\tCondition: {\n\t\t\t\t\t'ForAllValues:StringEquals': {\n\t\t\t\t\t\t'route53:ChangeResourceRecordSetsNormalizedRecordNames': [\n\t\t\t\t\t\t\t`_acme-challenge.${domain.toLowerCase()}`,\n\t\t\t\t\t\t],\n\t\t\t\t\t\t'route53:ChangeResourceRecordSetsRecordTypes': ['TXT'],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tEffect: 'Allow',\n\t\t\t\tAction: 'route53:ListResourceRecordSets',\n\t\t\t\tResource: `arn:aws:route53:::hostedzone/${zoneId}`,\n\t\t\t},\n\t\t\t{\n\t\t\t\tEffect: 'Allow',\n\t\t\t\tAction: 'route53:GetChange',\n\t\t\t\tResource: 'arn:aws:route53:::change/*',\n\t\t\t},\n\t\t\t{\n\t\t\t\tEffect: 'Allow',\n\t\t\t\tAction: 'route53:ListHostedZonesByName',\n\t\t\t\tResource: '*',\n\t\t\t},\n\t\t],\n\t});\n}\n\n/** An IAM user by the edge user's name that gkm did not create for this server. */\nexport class EdgeAcmeUserNotOwned extends GkmError {\n\tconstructor(\n\t\treadonly user: string,\n\t\treadonly server: string,\n\t) {\n\t\tsuper(\n\t\t\t`The IAM user ${user} exists but is not tagged ${TAG_EDGE}=${server}, ` +\n\t\t\t\t`so gkm will not take it over to write the shared edge's DNS ` +\n\t\t\t\t`challenge records. Delete it, or tag it ${TAG_EDGE}=${server} if it ` +\n\t\t\t\t`is the one gkm created for this server.`,\n\t\t);\n\t\tthis.name = 'EdgeAcmeUserNotOwned';\n\t}\n}\n\n/** A wildcard site's domain with no Route 53 hosted zone to answer it in. */\nexport class AcmeHostedZoneMissing extends GkmError {\n\tconstructor(readonly domain: string) {\n\t\tsuper(\n\t\t\t`No Route 53 hosted zone holds ${domain}, so the shared edge cannot ` +\n\t\t\t\t`answer the DNS challenge for its wildcard certificate. Create the ` +\n\t\t\t\t`zone, or set hostedZoneId in its dns entry.`,\n\t\t);\n\t\tthis.name = 'AcmeHostedZoneMissing';\n\t}\n}\n\nexport interface EnsureEdgeAcmeKeyOptions {\n\tclients: AcmeDnsClients;\n\t/** The edge's compose project, as docker is asked about it. */\n\tedge: StackRef;\n\t/** What identifies the server: its public IPv4 address, or its SSH host. */\n\tserver: string;\n\t/** The stack's compose project: what its policy is named. */\n\tproject: string;\n\t/** The stage's domain, under which its tenants' hosts sit. */\n\tdomain: string;\n\t/** The root domain in `dns` — the zone's name. */\n\tzone: string;\n\t/** The zone's id, where its `dns` entry names one. */\n\thostedZoneId?: string;\n\tdryRun?: boolean;\n\tlog?: (line: string) => void;\n}\n\nexport interface EdgeAcmeKey {\n\tuser: string;\n\tzoneId: string;\n\t/** Whether a key was issued and written to the edge on this run. */\n\tissued: boolean;\n}\n\n/**\n * The edge's key for `domain`'s challenge record: its user, this stack's\n * policy on it, and a key in the edge that IAM knows.\n *\n * @throws {EdgeAcmeUserNotOwned} when the user is someone else's\n * @throws {AcmeHostedZoneMissing} when no hosted zone holds the domain\n */\nexport async function ensureEdgeAcmeKey(\n\tdocker: ComposeDocker,\n\toptions: EnsureEdgeAcmeKeyOptions,\n): Promise<EdgeAcmeKey> {\n\tconst { clients, edge, server, project, domain } = options;\n\tconst log = options.log ?? ((line: string) => console.log(line));\n\tconst IAM = await import('@aws-sdk/client-iam');\n\tconst user = edgeAcmeUser(server);\n\tconst zoneId =\n\t\toptions.hostedZoneId ?? (await hostedZoneId(clients.route53, options.zone));\n\tif (!zoneId) throw new AcmeHostedZoneMissing(domain);\n\n\tif (options.dryRun) {\n\t\tlog(\n\t\t\t`🔑 Would let ${EDGE_PROJECT} write _acme-challenge.${domain} TXT records in ${zoneId}, as IAM user ${user} (dry run — nothing is written)`,\n\t\t);\n\t\treturn { user, zoneId, issued: false };\n\t}\n\n\tconst existing = await clients.iam\n\t\t.send(new IAM.GetUserCommand({ UserName: user }))\n\t\t.catch((error: { name?: string }) => {\n\t\t\tif (\n\t\t\t\terror?.name === 'NoSuchEntity' ||\n\t\t\t\terror?.name === 'NoSuchEntityException'\n\t\t\t) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\tthrow error;\n\t\t});\n\tif (!existing?.User) {\n\t\tawait clients.iam.send(\n\t\t\tnew IAM.CreateUserCommand({\n\t\t\t\tUserName: user,\n\t\t\t\tPath: USER_PATH,\n\t\t\t\tTags: [{ Key: TAG_EDGE, Value: server }],\n\t\t\t}),\n\t\t);\n\t} else {\n\t\tconst { Tags = [] } = await clients.iam.send(\n\t\t\tnew IAM.ListUserTagsCommand({ UserName: user }),\n\t\t);\n\t\tconst owned = Tags.some((t) => t.Key === TAG_EDGE && t.Value === server);\n\t\tif (!owned) throw new EdgeAcmeUserNotOwned(user, server);\n\t}\n\n\tawait clients.iam.send(\n\t\tnew IAM.PutUserPolicyCommand({\n\t\t\tUserName: user,\n\t\t\tPolicyName: project,\n\t\t\tPolicyDocument: acmeDnsPolicy(zoneId, domain),\n\t\t}),\n\t);\n\tlog(\n\t\t`🔑 ${EDGE_PROJECT} may write _acme-challenge.${domain} TXT records in ${zoneId}, and nothing else there, as IAM user ${user}`,\n\t);\n\n\tconst written = await readEdgeFile(docker, edge, EDGE_AWS_CREDENTIALS);\n\tconst held = written?.match(/aws_access_key_id\\s*=\\s*(\\S+)/)?.[1];\n\tconst { AccessKeyMetadata = [] } = await clients.iam.send(\n\t\tnew IAM.ListAccessKeysCommand({ UserName: user }),\n\t);\n\tif (held && AccessKeyMetadata.some((k) => k.AccessKeyId === held)) {\n\t\treturn { user, zoneId, issued: false };\n\t}\n\n\t// The edge holds none, or one IAM no longer has: every key of the user is\n\t// retired — it is the edge's alone — and one issued in its place.\n\tfor (const key of AccessKeyMetadata) {\n\t\tif (!key.AccessKeyId) continue;\n\t\tawait clients.iam.send(\n\t\t\tnew IAM.DeleteAccessKeyCommand({\n\t\t\t\tUserName: user,\n\t\t\t\tAccessKeyId: key.AccessKeyId,\n\t\t\t}),\n\t\t);\n\t}\n\tconst { AccessKey } = await clients.iam.send(\n\t\tnew IAM.CreateAccessKeyCommand({ UserName: user }),\n\t);\n\tawait writeEdgeSecret(\n\t\tdocker,\n\t\tedge,\n\t\tEDGE_AWS_CREDENTIALS,\n\t\t`# Written by gkm compose — the key ${EDGE_PROJECT} answers DNS challenges with.\n[default]\naws_access_key_id = ${AccessKey?.AccessKeyId}\naws_secret_access_key = ${AccessKey?.SecretAccessKey}\n`,\n\t);\n\tlog(\n\t\t`🔑 Wrote a new key for ${user} to ${EDGE_PROJECT} (${EDGE_AWS_CREDENTIALS})`,\n\t);\n\t// It replaced one the edge may already have read and kept.\n\tif (written !== undefined) await restartEdge(docker, edge);\n\treturn { user, zoneId, issued: true };\n}\n\n/** The id of the hosted zone named exactly `zone`, if there is one. */\nasync function hostedZoneId(\n\troute53: Route53Client,\n\tzone: string,\n): Promise<string | undefined> {\n\tconst { ListHostedZonesByNameCommand } = await import(\n\t\t'@aws-sdk/client-route-53'\n\t);\n\tconst name = zone.endsWith('.') ? zone : `${zone}.`;\n\tconst { HostedZones = [] } = await route53.send(\n\t\tnew ListHostedZonesByNameCommand({ DNSName: name, MaxItems: 1 }),\n\t);\n\tconst found = HostedZones.find((z) => z.Name === name);\n\treturn found?.Id?.replace('/hostedzone/', '');\n}\n","/**\n * What a deployed stage's stack generates once and keeps: its seed, each\n * `secret` construct's value, the log UI's root password where its telemetry\n * is self-hosted, and the stack's Redis password where a cache lives in it.\n *\n * Pure: the compose target writes the result back to the stage's store.\n */\n\nimport type { ConstructManifest } from '@geekmidas/manifest';\nimport {\n\ttype GeneratedSecrets,\n\twithGeneratedSecrets,\n} from '../deploy/generated.js';\nimport { initStageSecrets } from '../secrets/storage.js';\nimport type { StageSecrets } from '../secrets/types.js';\nimport { resolveStageTelemetry } from '../telemetry/config';\nimport { usesTelemetry } from '../telemetry/edges';\nimport type { NormalizedWorkspace } from '../workspace/types.js';\nimport { withLogsPassword } from './logs';\nimport { runsRedis, withRedisPassword } from './redis';\n\nexport function deployedStackSecrets(\n\tworkspace: NormalizedWorkspace,\n\tstage: string,\n\tstored: StageSecrets | null,\n\tmanifest: ConstructManifest,\n): GeneratedSecrets {\n\tconst withSeed = withGeneratedSecrets(\n\t\tstored ?? initStageSecrets(stage),\n\t\tmanifest,\n\t);\n\t// The log UI's root password, generated once like the seed, where the\n\t// stage's telemetry is self-hosted and the stage set none.\n\tconst telemetry = resolveStageTelemetry({\n\t\t...(workspace.deploy?.telemetry\n\t\t\t? { telemetry: workspace.deploy.telemetry }\n\t\t\t: {}),\n\t\tstage,\n\t\tlocal: false,\n\t\ttarget: 'compose',\n\t\truntime: 'server',\n\t\tselfHosted: true,\n\t\tused: usesTelemetry(manifest),\n\t});\n\tconst withLogs =\n\t\ttelemetry?.provider === 'self-hosted'\n\t\t\t? withLogsPassword(withSeed.secrets)\n\t\t\t: { secrets: withSeed.secrets, generated: [] };\n\t// The stack's Redis password, the same way, where a cache lives in it.\n\tconst withRedis = runsRedis(manifest, withLogs.secrets.custom ?? {})\n\t\t? withRedisPassword(withLogs.secrets)\n\t\t: { secrets: withLogs.secrets, generated: [] };\n\treturn {\n\t\tsecrets: withRedis.secrets,\n\t\tgenerated: [\n\t\t\t...withSeed.generated,\n\t\t\t...withLogs.generated,\n\t\t\t...withRedis.generated,\n\t\t],\n\t};\n}\n","/**\n * Asking each app of a stack whether it answers — through Caddy, over HTTPS,\n * the way a browser reaches it.\n *\n * `docker compose up --wait` already knows each container passed its own\n * health check, asked on 127.0.0.1 inside it. What that cannot say is whether\n * the stack is reachable: whether the edge routes the host to the app, and\n * whether the certificate it presents is one a client accepts. So the check\n * goes through the edge, by hostname, and verifies the certificate.\n */\n\nimport { request as httpRequest } from 'node:http';\nimport { request as httpsRequest } from 'node:https';\nimport { GkmError } from '../../errors';\n\n/** One request to the edge. */\nexport interface HealthRequest {\n\t/** The app's public URL plus its health path. */\n\turl: string;\n\t/**\n\t * The certificate authority to verify against, PEM — gkm's local CA on\n\t * the local stage. The system's when absent.\n\t */\n\tca?: string;\n\t/**\n\t * Connect here instead of resolving the URL's host — the local edge, at\n\t * 127.0.0.1. The host is still sent as SNI and `Host`, so nothing depends\n\t * on how this machine resolves `*.localhost`.\n\t */\n\tconnectTo?: string;\n\t/**\n\t * With `connectTo`, the port to connect to, where it is not the URL's —\n\t * the shared edge's published port, asked for a deployed host.\n\t */\n\tconnectPort?: number;\n\t/**\n\t * The `Authorization` header to send — a site the stage puts behind a\n\t * password is asked with its login, which proves the login works too.\n\t */\n\tauthorization?: string;\n\ttimeoutMs: number;\n\tsignal?: AbortSignal;\n}\n\n/** Asks once, resolving with the HTTP status. Rejects when nothing answers. */\nexport type HealthProbe = (request: HealthRequest) => Promise<number>;\n\n/** A request that got no answer in time. */\nexport class HealthRequestTimedOut extends GkmError {\n\tconstructor(\n\t\treadonly url: string,\n\t\treadonly timeoutMs: number,\n\t) {\n\t\tsuper(\n\t\t\t`${url} did not answer within ${timeoutMs}ms. Check the stack is up with \\`docker compose ps\\`.`,\n\t\t);\n\t\tthis.name = 'HealthRequestTimedOut';\n\t}\n}\n\n/** What the edge answered: its status, and the body where it was asked for. */\nexport interface EdgeResponse {\n\tstatus: number;\n\t/** The body, as text — empty unless the request asked to `read` it. */\n\tbody: string;\n}\n\n/** A request to the edge, and whether its body is wanted. */\nexport interface EdgeRequest extends HealthRequest {\n\t/** Read the body, up to {@link EDGE_BODY_LIMIT} bytes; drained otherwise. */\n\tread?: boolean;\n}\n\n/** Asks once. Rejects when nothing answers. */\nexport type EdgeFetch = (request: EdgeRequest) => Promise<EdgeResponse>;\n\n/** The most of a body read — a sitemap may be 50 MB, and none needs to be. */\nexport const EDGE_BODY_LIMIT = 10 * 1024 * 1024;\n\n/** A body larger than {@link EDGE_BODY_LIMIT}. */\nexport class EdgeResponseTooLarge extends GkmError {\n\tconstructor(\n\t\treadonly url: string,\n\t\treadonly limit: number,\n\t) {\n\t\tsuper(\n\t\t\t`${url} answered with more than ${limit} bytes, which is more than gkm reads. Split it — a sitemap index can list several sitemaps.`,\n\t\t);\n\t\tthis.name = 'EdgeResponseTooLarge';\n\t}\n}\n\n/**\n * The real request: one GET to the edge — over HTTPS, the certificate\n * verified, for an `https:` URL, and plain HTTP for an `http:` one — with\n * the URL's host as SNI and `Host` wherever it connects.\n */\nexport const edgeFetch: EdgeFetch = ({\n\turl,\n\tca,\n\tconnectTo,\n\tconnectPort,\n\tauthorization,\n\ttimeoutMs,\n\tsignal,\n\tread,\n}) => {\n\tconst target = new URL(url);\n\tconst secure = target.protocol === 'https:';\n\tconst request = secure ? httpsRequest : httpRequest;\n\treturn new Promise((resolve, reject) => {\n\t\tconst req = request(\n\t\t\t{\n\t\t\t\thost: connectTo ?? target.hostname,\n\t\t\t\tport: connectPort ?? (target.port || (secure ? 443 : 80)),\n\t\t\t\t...(secure ? { servername: target.hostname } : {}),\n\t\t\t\tpath: `${target.pathname}${target.search}`,\n\t\t\t\tmethod: 'GET',\n\t\t\t\theaders: {\n\t\t\t\t\thost: target.host,\n\t\t\t\t\t...(authorization ? { authorization } : {}),\n\t\t\t\t},\n\t\t\t\t...(secure && ca ? { ca } : {}),\n\t\t\t\t...(signal ? { signal } : {}),\n\t\t\t\ttimeout: timeoutMs,\n\t\t\t},\n\t\t\t(res) => {\n\t\t\t\tconst status = res.statusCode ?? 0;\n\t\t\t\tif (!read) {\n\t\t\t\t\t// The status is the answer; the body is drained so the socket closes.\n\t\t\t\t\tres.resume();\n\t\t\t\t\tres.on('end', () => resolve({ status, body: '' }));\n\t\t\t\t\tres.on('error', reject);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst chunks: Buffer[] = [];\n\t\t\t\tlet size = 0;\n\t\t\t\tres.on('data', (chunk: Buffer) => {\n\t\t\t\t\tsize += chunk.length;\n\t\t\t\t\tif (size > EDGE_BODY_LIMIT) {\n\t\t\t\t\t\treq.destroy(new EdgeResponseTooLarge(url, EDGE_BODY_LIMIT));\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tchunks.push(chunk);\n\t\t\t\t});\n\t\t\t\tres.on('end', () =>\n\t\t\t\t\tresolve({ status, body: Buffer.concat(chunks).toString('utf-8') }),\n\t\t\t\t);\n\t\t\t\tres.on('error', reject);\n\t\t\t},\n\t\t);\n\t\treq.on('timeout', () =>\n\t\t\treq.destroy(new HealthRequestTimedOut(url, timeoutMs)),\n\t\t);\n\t\treq.on('error', reject);\n\t\treq.end();\n\t});\n};\n\n/** The real probe: one GET through the edge, answered by its status. */\nexport const httpsProbe: HealthProbe = (request) =>\n\tedgeFetch(request).then(({ status }) => status);\n\n/** Whether a status means the app answered as it should. */\nexport function isHealthy(status: number): boolean {\n\treturn status >= 200 && status < 400;\n}\n\n/**\n * Apps that are not healthy. `via` says which check said so:\n * - `edge`: verify asked each app through the edge, by its host, and it did\n * not answer as it should (a worker, with no route, by its container's\n * health);\n * - `docker`: `up --wait` failed, and these containers' own health checks\n * had not passed — the rest of the stack was released and routed first.\n * One class either way, so a caller matches one failure: apps not healthy.\n */\nexport class ComposeAppsUnhealthy extends GkmError {\n\tconstructor(\n\t\treadonly project: string,\n\t\t/**\n\t\t * Each app, and the last thing its check got: a status or an error —\n\t\t * for `docker`, the container's health as Docker reports it.\n\t\t */\n\t\treadonly apps: readonly { app: string; url: string; last: string }[],\n\t\t/** The proxy the stack is served through. */\n\t\treadonly proxy: 'caddy' | 'traefik' = 'caddy',\n\t\t/** Which check failed: through the edge, or Docker's own. */\n\t\treadonly via: 'edge' | 'docker' = 'edge',\n\t) {\n\t\tconst names = apps.map((a) => a.app).join(' ');\n\t\tsuper(\n\t\t\tvia === 'docker'\n\t\t\t\t? `${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` +\n\t\t\t\t\t\tapps\n\t\t\t\t\t\t\t.map(({ app, last }) => ` - ${app}: Docker reports it ${last}`)\n\t\t\t\t\t\t\t.join('\\n') +\n\t\t\t\t\t\t`\\nSee why with \\`docker compose -p ${project} ps ${names}\\` and \\`docker compose -p ${project} logs ${names}\\`, fix the app, and deploy again.`\n\t\t\t\t: `${project} started, but ${apps.length === 1 ? 'this app does' : 'these apps do'} not answer through ${proxy === 'caddy' ? 'Caddy' : 'the shared Traefik edge'}:\\n` +\n\t\t\t\t\t\tapps.map(({ url, last }) => ` - ${url}: ${last}`).join('\\n') +\n\t\t\t\t\t\t(proxy === 'caddy'\n\t\t\t\t\t\t\t? `\\nSee why with \\`docker compose -p ${project} logs caddy ${names}\\`.`\n\t\t\t\t\t\t\t: `\\nSee why with \\`docker compose -p gkm-edge logs traefik\\` and \\`docker compose -p ${project} logs ${names}\\`.`),\n\t\t);\n\t\tthis.name = 'ComposeAppsUnhealthy';\n\t}\n}\n","/**\n * The SNS subscriptions a compose deploy makes for a topic whose connection\n * string the stage set by hand.\n *\n * On a compose stage a topic is pg-boss unless the stage says otherwise; one\n * that names an SNS topic is the stage's own, made somewhere this deploy does\n * not provision. Its subscribers are still pushed to — the worker answers on\n * its host — and the worker cannot subscribe itself, so the deploy does: with\n * the connection string's own keys, one subscription per subscriber, filtered\n * on the event types it names, each ARN recorded for the worker to accept\n * deliveries under. A bucket's subscriptions are the `s3` provider's.\n */\n\nimport type { ConstructManifest } from '@geekmidas/manifest';\nimport { provideKey } from '@geekmidas/manifest';\nimport type { ComposeStack } from '../../compose/stack.js';\nimport type { ResourceInput, ResourceRecord } from '../../deploy/StateStore.js';\nimport {\n\tSUBSCRIPTION_TYPE,\n\tsubscriptionKey,\n\tsubscriptionResource,\n\ttopicConnection,\n} from '../../deploy/snsSubscriptions.js';\n\n/** One topic subscriber SNS pushes to, as the deploy subscribes it. */\nexport interface TopicPush {\n\t/** The worker's construct id — what its subscriptions are recorded under. */\n\tworker: string;\n\t/** The subscriber's export. */\n\tname: string;\n\t/** `https://<worker host>/__gkm/subscribers/<name>` */\n\tendpoint: string;\n\t/** The topic's connection string's key, and its value on this stage. */\n\tconnectionKey: string;\n\tconnectionString: string;\n\t/** The event types it names: its subscription's filter. */\n\tevents?: readonly string[];\n}\n\n/**\n * Every topic subscriber the stack pushes to: a subscriber whose connection\n * key is a topic's publisher string — a bucket's events key is not — and\n * whose value on this stage is an SNS one.\n */\nexport function topicPushes(\n\tstack: Pick<ComposeStack, 'workers'>,\n\tmanifest: ConstructManifest,\n): TopicPush[] {\n\tconst topicKeys = new Set(\n\t\tObject.values(manifest)\n\t\t\t.filter((declaration) => declaration.kind === 'topic')\n\t\t\t.map((topic) => provideKey(topic.id, 'publisherConnectionString')),\n\t);\n\n\tconst pushes: TopicPush[] = [];\n\tfor (const worker of stack.workers) {\n\t\tfor (const subscriber of worker.push?.subscribers ?? []) {\n\t\t\tif (!topicKeys.has(subscriber.connectionKey)) continue;\n\t\t\tconst connectionString = worker.env?.[subscriber.connectionKey];\n\t\t\tif (!connectionString?.startsWith('sns:')) continue;\n\t\t\tpushes.push({\n\t\t\t\tworker: worker.id,\n\t\t\t\tname: subscriber.name,\n\t\t\t\tendpoint: subscriber.endpoint,\n\t\t\t\tconnectionKey: subscriber.connectionKey,\n\t\t\t\tconnectionString,\n\t\t\t\t...(subscriber.events ? { events: subscriber.events } : {}),\n\t\t\t});\n\t\t}\n\t}\n\treturn pushes;\n}\n\n/** The subscriptions recorded for hand-set topics: those with a key. */\nexport function recordedTopicSubscriptions(\n\tresources: Readonly<Record<string, ResourceRecord>> | undefined,\n): ResourceRecord[] {\n\treturn Object.values(resources ?? {}).filter(\n\t\t(record) =>\n\t\t\trecord.type === SUBSCRIPTION_TYPE &&\n\t\t\ttypeof record.data?.connectionKey === 'string',\n\t);\n}\n\n/**\n * Converge each hand-set topic's subscriptions on the subscribers pushed to:\n * subscribe, bring filters up to date, unsubscribe a route on the worker's\n * host no subscriber wants any more — and record each ARN, forgetting what\n * was removed.\n *\n * @returns each worker's subscriptions, by export — what it is handed\n */\nexport async function ensureTopicSubscriptions(input: {\n\tpushes: readonly TopicPush[];\n\trecorded: Readonly<Record<string, ResourceRecord>> | undefined;\n\t/** The stage's secrets: a topic only removed subscribers still name. */\n\tsecrets: Readonly<Record<string, string>>;\n\tstage: string;\n\tenv: NodeJS.ProcessEnv;\n\trecord: (resource: ResourceInput) => Promise<void>;\n\tforget: (key: string) => Promise<void>;\n\tlog: (line: string) => void;\n}): Promise<Record<string, Record<string, string>>> {\n\tconst { snsUrl, reconcileHttpSubscriptions } = await import(\n\t\t'@geekmidas/events/sns'\n\t);\n\n\t// One reconcile per topic and worker host: what it is not handed on that\n\t// host is unsubscribed, so it is handed every subscriber there.\n\ttype Group = {\n\t\ttopicArn: string;\n\t\thost: string;\n\t\tconnectionKey: string;\n\t\tconnectionString?: string;\n\t\tpushes: TopicPush[];\n\t\trecorded: ResourceRecord[];\n\t};\n\tconst groups = new Map<string, Group>();\n\tconst group = (\n\t\ttopicArn: string,\n\t\thost: string,\n\t\tconnectionKey: string,\n\t): Group => {\n\t\tconst id = `${topicArn}|${host}`;\n\t\tconst found = groups.get(id);\n\t\tif (found) return found;\n\t\tconst created: Group = {\n\t\t\ttopicArn,\n\t\t\thost,\n\t\t\tconnectionKey,\n\t\t\tpushes: [],\n\t\t\trecorded: [],\n\t\t};\n\t\tgroups.set(id, created);\n\t\treturn created;\n\t};\n\n\tfor (const push of input.pushes) {\n\t\tconst { topicArn } = snsUrl.parse(push.connectionString);\n\t\tconst into = group(\n\t\t\ttopicArn,\n\t\t\tnew URL(push.endpoint).host,\n\t\t\tpush.connectionKey,\n\t\t);\n\t\tinto.connectionString = push.connectionString;\n\t\tinto.pushes.push(push);\n\t}\n\tfor (const record of recordedTopicSubscriptions(input.recorded)) {\n\t\tgroup(\n\t\t\tString(record.data?.topicArn),\n\t\t\tnew URL(String(record.data?.endpoint)).host,\n\t\t\tString(record.data?.connectionKey),\n\t\t).recorded.push(record);\n\t}\n\n\tconst wanted = new Set(\n\t\tinput.pushes.map(({ worker, name }) => subscriptionKey(worker, name)),\n\t);\n\tconst arns: Record<string, Record<string, string>> = {};\n\tfor (const { topicArn, host, connectionKey, ...members } of groups.values()) {\n\t\t// Forgotten only when no subscriber wants the key on any topic: one\n\t\t// the stage moved to another topic is recorded again there.\n\t\tconst stale = members.recorded.filter((r) => !wanted.has(r.key));\n\n\t\t// A topic only removed subscribers name is reached as the stage now\n\t\t// names it, at the topic they were subscribed to.\n\t\tconst named = members.connectionString ?? input.secrets[connectionKey];\n\t\tif (!named?.startsWith('sns:')) {\n\t\t\tfor (const record of stale) {\n\t\t\t\tinput.log(\n\t\t\t\t\t` – forgot ${record.data?.endpoint}: '${connectionKey}' no longer names an SNS topic to unsubscribe it from`,\n\t\t\t\t);\n\t\t\t\tawait input.forget(record.key);\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tconst address = new URL(named);\n\t\taddress.searchParams.set('topicArn', topicArn);\n\n\t\tconst connection = await topicConnection({\n\t\t\tconnectionKey,\n\t\t\tconnectionString: address.toString(),\n\t\t\tstage: input.stage,\n\t\t\tenv: input.env,\n\t\t});\n\t\tconst result = await reconcileHttpSubscriptions(connection, {\n\t\t\tendpoints: members.pushes.map((push) => ({\n\t\t\t\tname: push.name,\n\t\t\t\tendpoint: push.endpoint,\n\t\t\t\t...(push.events ? { events: push.events } : {}),\n\t\t\t})),\n\t\t\townedHost: host,\n\t\t});\n\t\tawait connection.close();\n\n\t\tfor (const push of members.pushes) {\n\t\t\tconst arn = result.subscriptions[push.name]!;\n\t\t\tconst key = subscriptionKey(push.worker, push.name);\n\t\t\tif (input.recorded?.[key]?.id !== arn) {\n\t\t\t\tinput.log(\n\t\t\t\t\t` ✓ '${push.name}' subscribed to ${topicArn.split(':').pop()} at ${push.endpoint}`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tawait input.record(\n\t\t\t\tsubscriptionResource(\n\t\t\t\t\t{\n\t\t\t\t\t\tworker: push.worker,\n\t\t\t\t\t\tname: push.name,\n\t\t\t\t\t\ttopicArn,\n\t\t\t\t\t\tendpoint: push.endpoint,\n\t\t\t\t\t\tconnectionKey: push.connectionKey,\n\t\t\t\t\t\tpending: result.pending.includes(push.name),\n\t\t\t\t\t\t...(push.events ? { events: push.events } : {}),\n\t\t\t\t\t},\n\t\t\t\t\tarn,\n\t\t\t\t),\n\t\t\t);\n\t\t\tarns[push.worker] = { ...arns[push.worker], [push.name]: arn };\n\t\t}\n\t\tfor (const arn of result.removed) {\n\t\t\tinput.log(` – unsubscribed ${arn}: no subscriber wants it any more`);\n\t\t}\n\t\tfor (const record of stale) await input.forget(record.key);\n\t}\n\treturn arns;\n}\n","/**\n * Warming a server-rendered site once its stack is up.\n *\n * A site's image is built before the APIs it fetches from run, so its pages\n * render on their first request rather than at build (`GKM_BUILD_OFFLINE`).\n * The warm-up is that first request: the site's `/` and every page its\n * `/sitemap.xml` lists, asked through the edge the way a visitor's browser\n * asks, so a framework that caches a rendered page (Next's ISR) has it cached\n * from the deployed APIs before traffic arrives.\n *\n * Plain HTTP, whatever the framework. A page that fails to warm is said and\n * never fails the deploy: every app is already healthy, and the page renders\n * on the next request that asks for it.\n */\n\nimport {\n\ttype EdgeFetch,\n\ttype HealthRequest,\n\tHealthRequestTimedOut,\n\tisHealthy,\n} from './health';\n\n/** The most pages warmed per site, its `/` included. */\nexport const WARMUP_MAX_URLS = 500;\n\n/** How many of one site's pages are asked at once. */\nexport const WARMUP_CONCURRENCY = 4;\n\n/**\n * How long one page has to answer: a first render fetches from the site's\n * APIs, so it is given longer than a health check is.\n */\nexport const WARMUP_TIMEOUT_MS = 30_000;\n\n/** One request that did not warm its page, and what it got instead. */\nexport interface WarmupWarning {\n\turl: string;\n\t/** `HTTP 500`, or the error the request failed with. */\n\treason: string;\n}\n\n/** What one site's warm-up did. */\nexport interface WarmupResult {\n\t/** Each page that answered, in the order asked. */\n\twarmed: string[];\n\t/** Each page — or sitemap — that did not. */\n\twarnings: WarmupWarning[];\n\t/** Pages its sitemaps listed beyond {@link WARMUP_MAX_URLS}, not asked. */\n\tleftOut: number;\n}\n\nexport interface WarmupOptions {\n\t/** The site's public URL: `https://<host>`, with the edge's port if any. */\n\turl: string;\n\tfetch: EdgeFetch;\n\t/** How each request reaches the edge: where to connect, the CA, a login. */\n\tedge?: Pick<\n\t\tHealthRequest,\n\t\t'ca' | 'connectTo' | 'connectPort' | 'authorization' | 'signal'\n\t>;\n\tmaxUrls?: number;\n\tconcurrency?: number;\n\ttimeoutMs?: number;\n}\n\n/**\n * Asks the site for `/`, then for every page its `/sitemap.xml` lists — a\n * sitemap index's sitemaps followed one level — up to `maxUrls` pages in\n * all, `concurrency` at a time. Only pages on the site's own origin are\n * asked: a sitemap may list another's, which this deploy did not start.\n */\nexport async function warmSite(options: WarmupOptions): Promise<WarmupResult> {\n\tconst {\n\t\tfetch,\n\t\tedge = {},\n\t\tmaxUrls = WARMUP_MAX_URLS,\n\t\tconcurrency = WARMUP_CONCURRENCY,\n\t\ttimeoutMs = WARMUP_TIMEOUT_MS,\n\t} = options;\n\tconst origin = new URL(options.url).origin;\n\tconst result: WarmupResult = { warmed: [], warnings: [], leftOut: 0 };\n\n\t/** One GET; a failure is a warning, and `undefined`. */\n\tconst get = async (\n\t\turl: string,\n\t\tread: boolean,\n\t): Promise<{ status: number; body: string } | undefined> => {\n\t\ttry {\n\t\t\treturn await fetch({ url, ...edge, timeoutMs, read });\n\t\t} catch (error) {\n\t\t\tif (edge.signal?.aborted) throw error;\n\t\t\tresult.warnings.push({\n\t\t\t\turl,\n\t\t\t\treason:\n\t\t\t\t\terror instanceof HealthRequestTimedOut\n\t\t\t\t\t\t? `no answer within ${error.timeoutMs}ms`\n\t\t\t\t\t\t: error instanceof Error\n\t\t\t\t\t\t\t? error.message\n\t\t\t\t\t\t\t: String(error),\n\t\t\t});\n\t\t\treturn undefined;\n\t\t}\n\t};\n\n\tconst warm = async (url: string): Promise<void> => {\n\t\tconst response = await get(url, false);\n\t\tif (!response) return;\n\t\tif (isHealthy(response.status)) result.warmed.push(url);\n\t\telse result.warnings.push({ url, reason: `HTTP ${response.status}` });\n\t};\n\n\t/** A sitemap's `<loc>`s, or none where it has none — or did not answer. */\n\tconst sitemap = async (url: string): Promise<Sitemap | undefined> => {\n\t\tconst response = await get(url, true);\n\t\tif (!response) return undefined;\n\t\t// A site with no sitemap answers 404 (or asks for a login it was not\n\t\t// given): nothing to follow, and nothing wrong.\n\t\tif (response.status >= 400 && response.status < 500) return undefined;\n\t\tif (!isHealthy(response.status)) {\n\t\t\tresult.warnings.push({ url, reason: `HTTP ${response.status}` });\n\t\t\treturn undefined;\n\t\t}\n\t\treturn readSitemap(response.body);\n\t};\n\n\tconst root = `${origin}/`;\n\tawait warm(root);\n\n\tconst pages = new Set<string>([root]);\n\tconst sameOrigin = (loc: string): string | undefined => {\n\t\tif (!URL.canParse(loc, root)) return undefined;\n\t\tconst url = new URL(loc, root);\n\t\turl.hash = '';\n\t\treturn url.origin === origin ? url.href : undefined;\n\t};\n\tconst list = (locs: readonly string[]) => {\n\t\tfor (const loc of locs) {\n\t\t\tconst url = sameOrigin(loc);\n\t\t\tif (url) pages.add(url);\n\t\t}\n\t};\n\n\tconst top = await sitemap(`${origin}/sitemap.xml`);\n\tif (top?.kind === 'index') {\n\t\t// One level: a sitemap an index lists is read; an index it lists is not.\n\t\tconst children = [\n\t\t\t...new Set(top.locs.map(sameOrigin).filter((u) => u !== undefined)),\n\t\t];\n\t\tconst read = await pool(children, concurrency, sitemap);\n\t\tfor (const child of read) {\n\t\t\tif (child?.kind === 'urlset') list(child.locs);\n\t\t}\n\t} else if (top) {\n\t\tlist(top.locs);\n\t}\n\n\tconst listed = [...pages].slice(1);\n\tconst room = Math.max(0, maxUrls - 1);\n\tresult.leftOut = Math.max(0, listed.length - room);\n\tawait pool(listed.slice(0, room), concurrency, warm);\n\n\treturn result;\n}\n\n/** A sitemap's kind and the `<loc>` of each entry. */\nexport interface Sitemap {\n\t/** `index` lists sitemaps; `urlset` lists pages. */\n\tkind: 'index' | 'urlset';\n\tlocs: string[];\n}\n\n/**\n * Reads a sitemap (sitemaps.org): each entry's `<loc>`, entity-decoded or\n * from CDATA. Only an unprefixed `<loc>` is an entry's — an `<image:loc>` is\n * an image on a page, not a page.\n */\nexport function readSitemap(xml: string): Sitemap {\n\tconst kind = /<(?:[\\w-]+:)?sitemapindex[\\s>]/.test(xml) ? 'index' : 'urlset';\n\tconst locs: string[] = [];\n\tfor (const match of xml.matchAll(\n\t\t/<loc>\\s*(?:<!\\[CDATA\\[([\\s\\S]*?)\\]\\]>|([\\s\\S]*?))\\s*<\\/loc>/g,\n\t)) {\n\t\tconst loc = match[1] ?? decodeEntities(match[2] ?? '');\n\t\tif (loc.trim()) locs.push(loc.trim());\n\t}\n\treturn { kind, locs };\n}\n\nconst ENTITIES: Record<string, string> = {\n\tamp: '&',\n\tlt: '<',\n\tgt: '>',\n\tquot: '\"',\n\tapos: \"'\",\n};\n\nfunction decodeEntities(text: string): string {\n\treturn text.replace(\n\t\t/&(#x[\\da-f]+|#\\d+|amp|lt|gt|quot|apos);/gi,\n\t\t(whole, entity: string) => {\n\t\t\tif (entity[0] === '#') {\n\t\t\t\tconst code =\n\t\t\t\t\tentity[1] === 'x' || entity[1] === 'X'\n\t\t\t\t\t\t? Number.parseInt(entity.slice(2), 16)\n\t\t\t\t\t\t: Number.parseInt(entity.slice(1), 10);\n\t\t\t\treturn Number.isFinite(code) ? String.fromCodePoint(code) : whole;\n\t\t\t}\n\t\t\treturn ENTITIES[entity.toLowerCase()] ?? whole;\n\t\t},\n\t);\n}\n\n/** Each item through `run`, at most `size` at once, results in order. */\nasync function pool<T, R>(\n\titems: readonly T[],\n\tsize: number,\n\trun: (item: T) => Promise<R>,\n): Promise<R[]> {\n\tconst results: R[] = new Array(items.length);\n\tlet next = 0;\n\tconst worker = async () => {\n\t\twhile (next < items.length) {\n\t\t\tconst index = next++;\n\t\t\tresults[index] = await run(items[index]!);\n\t\t}\n\t};\n\tawait Promise.all(\n\t\tArray.from({ length: Math.min(size, items.length) }, worker),\n\t);\n\treturn results;\n}\n","/**\n * The compose target's phases: a stage as one Docker Compose stack behind\n * Caddy — the local stage on this machine's Docker, a deployed stage on its\n * server's, driven over SSH (`compose/server.ts`) from wherever the deploy\n * runs.\n *\n * The order is the point of this file, and the rules it keeps are these:\n *\n * - A tag is checked before anything happens (`validate`). Every app's image\n * is asked of the registry first; one missing image stops the run naming\n * them all, and nothing is written, pulled or started.\n * - The databases exist before the apps do (`provision`). Postgres comes up\n * alone, its databases, roles and grants are created, its migrations\n * applied and its seeds run from this machine — through an SSH tunnel to a\n * server's loopback — and only then do the apps\n * start — so an app\n * never boots against a schema that is not there yet.\n * - What a stage runs is recorded (`release`). Each app's image, the tag it\n * was released under and the digest it resolved to are written to the\n * stage's state, so \"what is this stage running\" has an exact answer.\n * - What was started answers (`verify`): each app is asked through Caddy,\n * over HTTPS, with the certificate verified. Then each server-rendered site\n * is warmed (`warmup.ts`): a page that fails to warm is said, never failed.\n *\n * Every image is built inside Docker from a pruned slice of the build root —\n * the same Dockerfiles `gkm docker` writes — so nothing is built on this\n * machine before `docker compose build`.\n *\n * Docker, the registry, Postgres and the health probe are\n * injected, so the rules are asserted without a daemon; the defaults are the\n * real ones.\n */\n\nimport { existsSync } from 'node:fs';\nimport {\n\tchmod,\n\tmkdir,\n\treaddir,\n\treadFile,\n\trm,\n\twriteFile,\n} from 'node:fs/promises';\nimport { hostname, userInfo } from 'node:os';\nimport { dirname, join } from 'node:path';\nimport type { ConstructManifest } from '@geekmidas/manifest';\nimport { stringify } from 'yaml';\nimport { BACKUPS_SERVICE, backupsRoleStatements } from '../../backups/service';\nimport { type AcmeDnsClients, ensureEdgeAcmeKey } from '../../compose/acmeDns';\nimport {\n\ttype HostLookup,\n\tHostNotPointingAtServer,\n\tisLocalHost,\n\tisReservedStageKey,\n\ttype PrunedDnsRecord,\n\trequiredServerAddress,\n\tSERVER_IPV4_KEY,\n\tserverAddressHint,\n\tstackHosts,\n\tstageDns,\n\tsystemLookup,\n} from '../../compose/dns';\nimport {\n\ttype ComposeDocker,\n\tdockerCompose,\n\ttype StackRef,\n} from '../../compose/docker';\nimport {\n\tassertEdgePorts,\n\tedgeRef,\n\tensureEdge,\n\tremoveEdgeRoutes,\n\twriteEdgeRoutes,\n} from '../../compose/edge';\nimport {\n\tassertImagesExist,\n\ttype ImageDigests,\n\tpinImages,\n\tRegistryRequired,\n} from '../../compose/images';\nimport { LOGS_SERVICE, logsAccess, type StackLogs } from '../../compose/logs';\nimport { ComposeTlsFileMissing } from '../../compose/proxy';\nimport { REDIS_SERVICE } from '../../compose/redis';\nimport { deployedStackSecrets } from '../../compose/secrets';\nimport {\n\ttype ComposeServer,\n\tcomposeServer,\n\tdockerHost,\n\ttype ServerAccess,\n\tsshAccess,\n\tsshTarget,\n} from '../../compose/server';\nimport type { SiteAuth } from '../../compose/sitePassword';\nimport {\n\ttype ComposeStack,\n\tcomposeProject,\n\tcomposeStack,\n\tEDGE_PORT_ENV,\n\tenvFile,\n\tLOG_ROTATION,\n\tLOGS_PORT_ENV,\n\tLOOPBACK_SERVICES,\n\treplicaNames,\n\ttype StackApp,\n\ttype StackInput,\n\tstackDir,\n\twithCaddyConfigs,\n} from '../../compose/stack';\nimport { EDGE_PROJECT, EDGE_SERVICE } from '../../compose/traefik';\nimport { currentActor } from '../../deploy/actor.js';\nimport {\n\tdnsResources,\n\tforgetDnsResource,\n\trecordDnsChanges,\n} from '../../deploy/dnsResources.js';\nimport type { ResourceChange } from '../../deploy/events';\nimport { imageRef } from '../../deploy/identity.js';\nimport { DeployJournal } from '../../deploy/journal';\nimport type { ResourceRecord } from '../../deploy/StateStore.js';\nimport {\n\tconfirmPendingSubscriptions,\n\tPushSubscriptionsUnconfirmed,\n\trecordedPushSubscriptions,\n\tSUBSCRIPTION_TYPE,\n\tsubscriptionKey,\n} from '../../deploy/snsSubscriptions.js';\nimport {\n\tcreateComposeState,\n\ttype DeployedImage,\n\trecordRelease,\n} from '../../deploy/state.js';\nimport type { DeployResult } from '../../deploy/types';\nimport { ensureDockerignore } from '../../docker/index.js';\nimport { imageLayout } from '../../docker/layout.js';\nimport { findBuildRoot } from '../../docker/templates.js';\nimport { GkmError } from '../../errors';\nimport { installedFrom } from '../../generators/drivers.js';\nimport {\n\tmigrateDatabases,\n\tplannedSeeds,\n\tSeedFailed,\n\tseedDatabases,\n} from '../../migrate/databases.js';\nimport { appEnvKeys, workerEnvKeys } from '../../reconcile/apps.js';\nimport { bucketClient, pgClient } from '../../reconcile/clients.js';\nimport { primaryPortKey } from '../../reconcile/containers.js';\nimport {\n\ttype BoundSubscriber,\n\ttype ConstructSource,\n\tdiscover,\n} from '../../reconcile/discover.js';\nimport { envFor, stageEnv } from '../../reconcile/env.js';\nimport { loadLocalCredentials } from '../../reconcile/localCredentials.js';\nimport {\n\tensurePostgresLogin,\n\tLEGACY_LOCAL_LOGIN,\n} from '../../reconcile/logins.js';\nimport {\n\tapplyBuckets,\n\tapplyLifecycles,\n\tapplyNotifications,\n\tapplyPolicies,\n\tapplyPostgres,\n\tpostgresStatements,\n} from '../../reconcile/provision.js';\nimport { backendsOf, constructGlobs } from '../../reconcile/workspace.js';\nimport { runOutput } from '../../run';\nimport { toEmbeddableSecrets } from '../../secrets/storage.js';\nimport type { StageSecrets } from '../../secrets/types.js';\nimport {\n\tensureLocalAuthority,\n\tensureLocalCertificate,\n\ttype LocalAuthorityPaths,\n\tlocalCertificateNames,\n\treadLocalAuthority,\n} from '../../trust/authority.js';\nimport type {\n\tDnsProvider as DnsProviderConfig,\n\tNormalizedWorkspace,\n} from '../../workspace/types.js';\nimport type { DnsProvider, Route53DnsConfig } from '../dokploy/dns/DnsProvider';\nimport { findRootDomain, normalizeDnsConfig } from '../dokploy/dns/index';\nimport {\n\tDeploySeedsFailed,\n\treportDatabaseRuns,\n\treportPlannedSeeds,\n} from '../seeds';\nimport type { DeployPhaseContext } from '../types';\nimport {\n\tComposeAppsUnhealthy,\n\ttype EdgeFetch,\n\tedgeFetch,\n\ttype HealthProbe,\n\thttpsProbe,\n\tisHealthy,\n} from './health';\nimport {\n\tensureTopicSubscriptions,\n\trecordedTopicSubscriptions,\n\ttype TopicPush,\n\ttopicPushes,\n} from './topicSubscriptions';\nimport { WARMUP_MAX_URLS, warmSite } from './warmup';\n\n/** Every phase's context: the compose target takes no options. */\nexport type ComposeContext = DeployPhaseContext<undefined>;\n\n/** What the target needs from outside the process, so tests can stand in. */\nexport interface ComposeDeps {\n\tdocker: ComposeDocker;\n\t/** The commit a build is tagged with. */\n\trevision: (root: string) => Promise<string>;\n\t/** The Postgres client provisioning and migrations connect through. */\n\tsql: typeof pgClient;\n\t/** The S3 client the stack's buckets are created through. */\n\tbuckets: typeof bucketClient;\n\t/** Bring the stack's Postgres onto its superuser — see `logins.ts`. */\n\tlogins: typeof ensurePostgresLogin;\n\t/** Apply the stage's migrations — `migrateDatabases` by default. */\n\tmigrate: typeof migrateDatabases;\n\t/** Run the stage's seeds, after its migrations — `seedDatabases` by default. */\n\tseed: typeof seedDatabases;\n\t/** Ask one app, through the edge, whether it answers. */\n\tprobe: HealthProbe;\n\t/**\n\t * Ask the edge for a page — and, for a sitemap, its body — once the stack\n\t * is healthy, to warm each server-rendered site. `edgeFetch` by default.\n\t */\n\tfetch?: EdgeFetch;\n\t/** How many times each app is asked before it counts as down. */\n\thealthAttempts: number;\n\t/** How long to wait between two asks of one app. */\n\thealthIntervalMs: number;\n\t/** Where the edge's ports are read from (`GKM_COMPOSE_HTTPS_PORT`, …). */\n\tenv: NodeJS.ProcessEnv;\n\t/**\n\t * Resolves a public host to every address it has, for the DNS check —\n\t * the system resolver by default.\n\t */\n\tlookup?: HostLookup;\n\t/** The DNS provider for a `dns` domain — `createDnsProvider` by default. */\n\tdnsProviderFor?: (config: DnsProviderConfig) => Promise<DnsProvider | null>;\n\t/**\n\t * A deployed stage's server, beyond its Docker engine: the SSH check\n\t * before a deploy, and the tunnels its databases are reached through.\n\t */\n\tserver: ServerAccess;\n\t/**\n\t * Once the stack is up, have SNS resend each pending subscription's\n\t * confirmation and wait for it — `confirmPendingSubscriptions` by default.\n\t */\n\tconfirmSubscriptions?: typeof confirmPendingSubscriptions;\n\t/**\n\t * The IAM and Route 53 clients the shared edge's DNS-challenge key is\n\t * issued through, for a domain's Route 53 entry — the AWS SDK's own\n\t * chain, with its `profile` and `region`, by default.\n\t */\n\tacmeClients?: (config: Route53DnsConfig) => Promise<AcmeDnsClients>;\n}\n\n/** One app's image, as the stage runs it. */\nexport interface ComposeImage {\n\tref: string;\n\ttag: string;\n\tdigest?: string;\n}\n\n/** A compose deploy in progress: what `validate` found, and what follows. */\nexport interface ComposeRun {\n\t/** Build the images from this checkout, or pull the ones a tag names. */\n\tmode: 'build' | 'pull';\n\t/**\n\t * Build and push the images, and nothing else (`--build --push`): no\n\t * provisioning, no container started, nothing recorded.\n\t */\n\tpush: boolean;\n\tstack: ComposeStack;\n\t/**\n\t * The deployed stage's server, whose Docker engine — over SSH — runs the\n\t * stack. Absent for the local stage, and for a push, which builds here.\n\t */\n\tserver?: ComposeServer;\n\t/** The stack's directory, absolute: `.gkm/compose/<stage>`. */\n\tdir: string;\n\tref: StackRef;\n\t/** The stage's secrets, with whatever a deployed stage generates once. */\n\tsecrets: StageSecrets | null;\n\t/** The names of what was generated, written back in `provision`. */\n\tgenerated: string[];\n\t/** Each app's image as the stage's state last recorded it. */\n\tprevious: Record<string, DeployedImage>;\n\t/** Every file written, absolute. */\n\tfiles: string[];\n\t/** Each app's image, once built or pulled. */\n\timages: Record<string, ComposeImage>;\n\t/** Every resource the run touched, or for a dry run would. */\n\tchanges: ResourceChange[];\n\t/**\n\t * The subscriptions `provision` makes for topics the stage set to SNS by\n\t * hand — and the stack composed again once their ARNs are recorded. Until\n\t * then {@link stack} hands those workers no subscriptions.\n\t */\n\ttopicSubscriptions?: {\n\t\tpushes: TopicPush[];\n\t\trecorded: Readonly<Record<string, ResourceRecord>> | undefined;\n\t\trestack: (arns: Record<string, Record<string, string>>) => ComposeStack;\n\t};\n\t/**\n\t * Deletes the DNS records gkm wrote for hosts the stage no longer serves:\n\t * found by `ready`, run by `verify` once the stack answers on its new ones.\n\t */\n\tpruneDns?: () => Promise<PrunedDnsRecord[]>;\n}\n\n/** How a run gets its images, beyond what the tag implies. */\nexport interface ComposeRunOptions {\n\t/**\n\t * Build or pull whatever the tag says. By default a given tag is pulled\n\t * and no tag builds from the checkout.\n\t */\n\tmode?: 'build' | 'pull';\n\t/** Push what was built, and start nothing (`--build --push`). */\n\tpush?: boolean;\n\t/** Run each pulled image at the digest a push reported for it. */\n\tpin?: { file: string; digests: ImageDigests };\n}\n\n/** `--push` without `--build`: there is nothing built here to push. */\nexport class ComposePushNeedsBuild extends GkmError {\n\tconstructor() {\n\t\tsuper(\n\t\t\t'--push pushes the images this checkout builds, so it needs --build ' +\n\t\t\t\t'(and never --pull): gkm compose --stage <stage> --build --push --tag <tag>.',\n\t\t);\n\t\tthis.name = 'ComposePushNeedsBuild';\n\t}\n}\n\n/** Digests to run by, on a run that pulls nothing. */\nexport class ComposePinNeedsPull extends GkmError {\n\tconstructor() {\n\t\tsuper(\n\t\t\t'--digests-file pins the images a release pulls, so it needs --tag ' +\n\t\t\t\t'(or --pull) — or, with --build --push, it is where the pushed digests ' +\n\t\t\t\t'are written.',\n\t\t);\n\t\tthis.name = 'ComposePinNeedsPull';\n\t}\n}\n\n/** A port variable that does not hold a port. */\nexport class EdgePortInvalid extends GkmError {\n\tconstructor(\n\t\treadonly variable: string,\n\t\treadonly value: string,\n\t) {\n\t\tsuper(\n\t\t\t`${variable}=${value} is not a port. Set it to a number between 1 and 65535, or unset it for the default.`,\n\t\t);\n\t\tthis.name = 'EdgePortInvalid';\n\t}\n}\n\n/** A build with no commit to tag its images with. */\nexport class NoGitRevision extends GkmError {\n\tconstructor(readonly root: string) {\n\t\tsuper(\n\t\t\t`Images built here are tagged with the commit they were built from, ` +\n\t\t\t\t`and ${root} is not in a git repository with a commit. Commit, or ` +\n\t\t\t\t`pass --tag to name the images yourself.`,\n\t\t);\n\t\tthis.name = 'NoGitRevision';\n\t}\n}\n\n/**\n * The project's own file merged over a stage's stack: `docker-compose.<stage>.yml`\n * at the workspace root. What the generated file cannot know — a port bound\n * to a tailnet address, another log driver — goes there, and is never\n * overwritten.\n */\nexport function stackOverrideFile(root: string, stage: string): string {\n\treturn join(root, `docker-compose.${stage}.yml`);\n}\n\n/** The commit HEAD is at, short — and `-dirty` when the tree has changes. */\nexport async function gitRevision(root: string): Promise<string> {\n\tlet sha: string;\n\ttry {\n\t\tsha = (\n\t\t\tawait runOutput('git', ['rev-parse', '--short', 'HEAD'], { cwd: root })\n\t\t).trim();\n\t} catch {\n\t\tthrow new NoGitRevision(root);\n\t}\n\tif (!sha) throw new NoGitRevision(root);\n\n\t// An image built from uncommitted changes is not the commit's image, and a\n\t// tag that said it was would be the one thing worse than no tag.\n\tconst status = await runOutput('git', ['status', '--porcelain'], {\n\t\tcwd: root,\n\t}).catch(() => '');\n\treturn status.trim() ? `${sha}-dirty` : sha;\n}\n\n/** The edge's ports, from the environment — 443 and 80 when unset. */\nexport function edgePorts(env: NodeJS.ProcessEnv = process.env): {\n\thttps: number;\n\thttp: number;\n\tlogs?: number;\n} {\n\tconst read = (variable: string, fallback: number) => {\n\t\tconst value = env[variable];\n\t\tif (value === undefined || value === '') return fallback;\n\t\tconst port = Number(value);\n\t\tif (!Number.isInteger(port) || port < 1 || port > 65_535) {\n\t\t\tthrow new EdgePortInvalid(variable, value);\n\t\t}\n\t\treturn port;\n\t};\n\tconst logs = env[LOGS_PORT_ENV] ? read(LOGS_PORT_ENV, 0) : undefined;\n\treturn {\n\t\thttps: read(EDGE_PORT_ENV.https, 443),\n\t\thttp: read(EDGE_PORT_ENV.http, 80),\n\t\t...(logs ? { logs } : {}),\n\t};\n}\n\n/**\n * The real ones. Each app is asked for three minutes before it counts as\n * down: a deployed stage's first ACME certificate can take that long.\n */\nexport const defaultDeps: ComposeDeps = {\n\tdocker: dockerCompose,\n\trevision: gitRevision,\n\tsql: pgClient,\n\tbuckets: bucketClient,\n\tlogins: ensurePostgresLogin,\n\tmigrate: migrateDatabases,\n\tseed: seedDatabases,\n\tprobe: httpsProbe,\n\tfetch: edgeFetch,\n\thealthAttempts: 90,\n\thealthIntervalMs: 2_000,\n\tenv: process.env,\n\tlookup: systemLookup,\n\tserver: sshAccess,\n};\n\n// ============================================================================\n// validate\n// ============================================================================\n\n/**\n * The stack the stage would run, and — for a tag — the registry's word that\n * every image it names exists. Nothing is written: a missing image stops the\n * run here, before a file, a secret or a container is touched.\n */\nexport async function validateCompose(\n\tctx: ComposeContext,\n\tdeps: ComposeDeps,\n\toptions: ComposeRunOptions = {},\n): Promise<ComposeRun> {\n\tconst { workspace, stage, identity, tag } = ctx;\n\tconst root = workspace.root;\n\tconst mode = options.mode ?? (ctx.tagGiven ? 'pull' : 'build');\n\tconst push = options.push === true;\n\tif (push && mode !== 'build') throw new ComposePushNeedsBuild();\n\tif (options.pin && mode !== 'pull') throw new ComposePinNeedsPull();\n\n\t// An image pushed or pulled with no registry is a Docker Hub name, which\n\t// is somebody else's. Refused before anything is discovered, built or\n\t// asked of a registry.\n\tconst registry = workspace.deploy?.registry;\n\tif (!registry && (push || mode === 'pull')) {\n\t\tthrow new RegistryRequired(\n\t\t\tpush ? 'push' : 'pull',\n\t\t\timageRef(identity, ctx.apps[0] ?? workspace.name, undefined, tag),\n\t\t);\n\t}\n\n\tconst background: Record<string, string[]> = {};\n\tconst subscribers: Record<string, BoundSubscriber[]> = {};\n\tconst manifest = await discover({\n\t\tpatterns: constructGlobs(workspace),\n\t\tcwd: root,\n\t\tbackground,\n\t\tsubscribers,\n\t});\n\n\tconst { secrets, generated } = await stageSecrets(ctx, manifest);\n\n\t// What each app ran before this release, and the SNS subscriptions the\n\t// stage's providers made: a push changes no stage, so it reads neither.\n\tconst recorded = push ? undefined : await ctx.state.read(stage);\n\n\t// Where and with what the images are built — only asked when they are.\n\tconst layout = mode === 'build' ? imageLayout(workspace) : undefined;\n\n\tconst input: StackInput = {\n\t\tworkspace,\n\t\tmanifest,\n\t\tbackground,\n\t\tsubscribers,\n\t\tstage,\n\t\tidentity,\n\t\timages: {\n\t\t\tmode,\n\t\t\ttag,\n\t\t\t...(registry ? { registry } : {}),\n\t\t},\n\t\tsecrets,\n\t\t...(stage === workspace.stages.local\n\t\t\t? {\n\t\t\t\t\tlocalCredentials: (await loadLocalCredentials(workspace)).credentials,\n\t\t\t\t}\n\t\t\t: {}),\n\t\tallowDevServices: ctx.allowDevServices,\n\t\tports: edgePorts(deps.env),\n\t\t...(layout ? { layout } : {}),\n\t\t...(push ? { buildOnly: true } : {}),\n\t};\n\tconst recordedArns = recordedPushSubscriptions(recorded?.resources);\n\n\t// A topic the stage set to SNS by hand is subscribed by this deploy, in\n\t// `provision` — so until then the stack is composed to learn where SNS\n\t// pushes, and composed again with the ARNs once they are recorded.\n\tconst planned = push\n\t\t? undefined\n\t\t: composeStack({ ...input, recordingSubscriptions: true });\n\tconst pushes = planned ? topicPushes(planned, manifest) : [];\n\tconst topics =\n\t\tplanned &&\n\t\t(pushes.length > 0 ||\n\t\t\trecordedTopicSubscriptions(recorded?.resources).length > 0)\n\t\t\t? { pushes, recorded: recorded?.resources }\n\t\t\t: undefined;\n\tconst composed =\n\t\ttopics && planned\n\t\t\t? planned\n\t\t\t: composeStack({ ...input, pushSubscriptions: recordedArns });\n\n\t// A cache is reached over the Redis wire protocol, and the client is the\n\t// project's own dependency: a build without it fails deep inside Docker.\n\tif (mode === 'build') {\n\t\tassertRedisClient(workspace, composed, manifest);\n\t}\n\n\t// No image embeds the stage's secrets: a backend reads them at runtime\n\t// from its env file, so one image built at a commit runs on every stage.\n\t// A pinned release runs each image at the digest its push reported.\n\tconst pinned = (unpinned: ComposeStack) =>\n\t\toptions.pin\n\t\t\t? withPinnedImages(unpinned, options.pin.file, options.pin.digests)\n\t\t\t: unpinned;\n\tconst stack = pinned(composed);\n\n\t// A release is all of its images or none of them. A dry run asks nothing,\n\t// so it can be run without a registry login.\n\tif (mode === 'pull' && !ctx.dryRun) {\n\t\tawait assertImagesExist(deps.docker, tag, [\n\t\t\t...stack.apps,\n\t\t\t...stack.workers,\n\t\t\t...stack.processors,\n\t\t]);\n\t}\n\n\tif (stack.redis && !stack.local) ctx.secrets.mask(stack.redis.password);\n\n\t// The log UI's root login and the header every backend signs in with:\n\t// secrets, unless they are the local stage's fixed ones.\n\tif (stack.logs && (!stack.local || stack.logs.passwordFromSecrets)) {\n\t\tctx.secrets.mask(stack.logs.password);\n\t\tctx.secrets.mask(stack.logs.appEnv.OTEL_EXPORTER_OTLP_HEADERS);\n\t}\n\n\t// Where the stack runs: a deployed stage on its server's engine, over\n\t// SSH — never this machine's. A push builds here and runs nothing.\n\t// A domain's stage names its address before anything else is said of\n\t// its server: it is the host SSH reaches too, unless config names one.\n\tif (!push && !stack.local) {\n\t\trequiredServerAddress(stage, workspace.domains?.[stage], secrets?.custom);\n\t}\n\tconst server = push\n\t\t? undefined\n\t\t: composeServer({\n\t\t\t\tstage,\n\t\t\t\tlocal: stack.local,\n\t\t\t\tconfig: workspace.deploy?.compose?.server,\n\t\t\t\tcustom: secrets?.custom,\n\t\t\t});\n\n\tconst dir = join(root, stackDir(stage));\n\tconst override = stackOverrideFile(root, stage);\n\tconst overrides = existsSync(override) ? [override] : [];\n\tif (overrides.length > 0) {\n\t\tctx.logger.info(\n\t\t\t`🧩 Merging docker-compose.${stage}.yml over the generated stack`,\n\t\t);\n\t}\n\t// What each app ran before this release: its current release, by the same\n\t// record the Dokploy target keeps, so a rollback reads one shape for both.\n\tconst previous = Object.fromEntries(\n\t\tObject.entries(recorded?.state.releases ?? {}).map(\n\t\t\t([name, releases]): [string, DeployedImage] => {\n\t\t\t\tconst { ref, tag, digest } = releases.current;\n\t\t\t\treturn [\n\t\t\t\t\tname,\n\t\t\t\t\t{ ref, ...(tag ? { tag } : {}), ...(digest ? { digest } : {}) },\n\t\t\t\t];\n\t\t\t},\n\t\t),\n\t);\n\n\treturn {\n\t\tmode,\n\t\tpush,\n\t\tstack,\n\t\t...(topics\n\t\t\t? {\n\t\t\t\t\ttopicSubscriptions: {\n\t\t\t\t\t\t...topics,\n\t\t\t\t\t\trestack: (arns) => {\n\t\t\t\t\t\t\tconst merged = { ...recordedArns };\n\t\t\t\t\t\t\tfor (const [worker, own] of Object.entries(arns)) {\n\t\t\t\t\t\t\t\tmerged[worker] = { ...merged[worker], ...own };\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn pinned(\n\t\t\t\t\t\t\t\tcomposeStack({ ...input, pushSubscriptions: merged }),\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t}\n\t\t\t: {}),\n\t\t...(server ? { server } : {}),\n\t\tdir,\n\t\tref: {\n\t\t\tproject: composeProject(identity),\n\t\t\tfile: join(dir, 'docker-compose.yml'),\n\t\t\t...(overrides.length > 0 ? { overrides } : {}),\n\t\t\tcwd: root,\n\t\t\t...(server ? { host: dockerHost(server) } : {}),\n\t\t\toutput: ctx.childOutput,\n\t\t\tsignal: ctx.signal,\n\t\t},\n\t\tsecrets,\n\t\tgenerated,\n\t\tprevious,\n\t\tfiles: [],\n\t\timages: {},\n\t\tchanges: [],\n\t};\n}\n\n// ============================================================================\n// ready\n// ============================================================================\n\n/**\n * What only a compose deploy checks before it changes anything, once the\n * stage's own keys are: the stage's own certificate is there, and every\n * public host points at the stage's server — its records written where a\n * provider holds them, then confirmed — before Caddy or Traefik ask Let's\n * Encrypt for a certificate it could not issue. A build-only run never asks.\n */\nexport async function readyCompose(\n\tctx: ComposeContext,\n\trun: ComposeRun,\n\tdeps: ComposeDeps,\n): Promise<void> {\n\tconst { stack } = run;\n\n\t// Read when the stack starts; one that is not there stops the run here,\n\t// before anything is written or started.\n\tif (stack.tls) {\n\t\tconst { certFile, keyFile, caFile } = stack.tls;\n\t\tfor (const file of [certFile, keyFile, ...(caFile ? [caFile] : [])]) {\n\t\t\tif (!existsSync(file)) throw new ComposeTlsFileMissing(ctx.stage, file);\n\t\t}\n\t}\n\n\tif (stack.local) return;\n\t// The server answers before anything is written — a DNS record included.\n\t// A dry run changes nothing anywhere, and connects to nothing.\n\tif (run.server && !ctx.dryRun && !run.push) {\n\t\tawait deps.server.check(run.server);\n\t}\n\tconst prune = await stageHostsDns(\n\t\tctx,\n\t\tdeps,\n\t\tstackHosts(stack).filter((host) => !isLocalHost(host)),\n\t\trun.secrets?.custom,\n\t\tstack.wildcard?.host,\n\t);\n\tif (prune) run.pruneDns = prune;\n}\n\n/** A stack whose caches are in Redis, built for an app that has no client. */\nexport class RedisClientMissing extends GkmError {\n\tconstructor(readonly apps: readonly string[]) {\n\t\tsuper(\n\t\t\t`The stack keeps every cache in Redis, and ${apps.join(', ')} ` +\n\t\t\t\t`${apps.length === 1 ? 'does' : 'do'} not depend on ioredis, the client ` +\n\t\t\t\t'the generated server reaches it with. Add it to the workspace: ' +\n\t\t\t\t'pnpm add ioredis',\n\t\t);\n\t\tthis.name = 'RedisClientMissing';\n\t}\n}\n\n/**\n * Every backend and worker image whose process reaches a cache can resolve\n * `ioredis` — listed by its app or a directory above it, the way Node and\n * the image's install find it. A process that reaches no cache registers no\n * cache driver, so it needs no client.\n */\nfunction assertRedisClient(\n\tworkspace: NormalizedWorkspace,\n\tstack: ComposeStack,\n\tmanifest: ConstructManifest,\n): void {\n\tif (!stack.plan.resources.some((r) => r.kind === 'cache')) return;\n\n\tconst cacheKeys = Object.values(manifest)\n\t\t.filter((d) => d.kind === 'cache')\n\t\t.flatMap((d) => d.provides ?? []);\n\tconst reachesCache = (keys: Set<string> | undefined) =>\n\t\tcacheKeys.some((key) => keys?.has(key));\n\n\tconst hosts = new Set([\n\t\t...stack.apps\n\t\t\t.filter(\n\t\t\t\t(app) =>\n\t\t\t\t\t(app.kind === 'rest-api' || app.kind === 'websocket-api') &&\n\t\t\t\t\treachesCache(appEnvKeys(manifest, app.name)),\n\t\t\t)\n\t\t\t.map((a) => a.name),\n\t\t...stack.workers\n\t\t\t.filter((worker) => reachesCache(workerEnvKeys(manifest, worker.id)))\n\t\t\t.map((worker) => worker.host),\n\t]);\n\tconst missing = [...hosts]\n\t\t.filter((name) => {\n\t\t\tconst app = workspace.apps[name];\n\t\t\treturn app && !installedFrom(join(workspace.root, app.path), 'ioredis');\n\t\t})\n\t\t.sort();\n\tif (missing.length > 0) throw new RedisClientMissing(missing);\n}\n\n/**\n * The deploy's DNS step, for a deployed stage: its server's address — required\n * where it serves a real domain — then its own hosts written through each\n * domain's provider in `dns` where they differ, read back from it, and\n * recorded in the stage's state; hosts no provider writes resolved with the\n * system resolver. A dry run prints the plan and writes nothing, and warns\n * rather than stops. Returns the prune of the records gkm wrote for hosts the\n * stage no longer serves — which a dry run prints there and then.\n *\n * @throws {ServerAddressMissing} when the stage has a domain and no address\n * @throws {ServerAddressInvalid} for a value that is not an address\n * @throws {HostNotPointingAtServer} when a host is not the server\n */\nasync function stageHostsDns(\n\tctx: ComposeContext,\n\tdeps: ComposeDeps,\n\thosts: readonly string[],\n\tcustom: Readonly<Record<string, string>> | undefined,\n\twildcard: string | undefined,\n): Promise<(() => Promise<PrunedDnsRecord[]>) | undefined> {\n\tconst { workspace, stage } = ctx;\n\tconst server = requiredServerAddress(\n\t\tstage,\n\t\tworkspace.domains?.[stage],\n\t\tcustom,\n\t);\n\tif (hosts.length === 0) return;\n\tif (ctx.skipDns) {\n\t\tctx.logger.info(\n\t\t\t'🌐 DNS skipped (--skip-dns): no record is written or checked',\n\t\t);\n\t\treturn;\n\t}\n\tif (!server) {\n\t\tctx.logger.info(\n\t\t\t`🌐 DNS skipped: no ${SERVER_IPV4_KEY} in '${stage}''s secrets — ${serverAddressHint(stage)}`,\n\t\t);\n\t\treturn;\n\t}\n\tconst log = (line: string) => ctx.logger.info(line);\n\tif (workspace.dns) {\n\t\tlog(\n\t\t\t`🌐 DNS for '${stage}' → ${server.ipv4}${server.ipv6 ? ` / ${server.ipv6}` : ''}${ctx.dryRun ? ' (dry run — nothing is written)' : ''}`,\n\t\t);\n\t}\n\ttry {\n\t\tconst stored = await ctx.state.read(stage);\n\t\tconst result = await stageDns({\n\t\t\tstage,\n\t\t\thosts,\n\t\t\tserver,\n\t\t\tdns: workspace.dns,\n\t\t\trecorded: dnsResources(stored?.resources ?? {}),\n\t\t\t...(wildcard ? { wildcard } : {}),\n\t\t\tcredentials: ctx.credentials,\n\t\t\tlog,\n\t\t\tlookup: deps.lookup ?? systemLookup,\n\t\t\t...(ctx.dryRun ? { dryRun: true } : {}),\n\t\t\t...(deps.dnsProviderFor ? { providerFor: deps.dnsProviderFor } : {}),\n\t\t});\n\t\t// What it wrote, kept in the stage's state; what it deleted, forgotten.\n\t\tif (!ctx.dryRun) {\n\t\t\tconst journal = await DeployJournal.open(ctx.state, stage, () =>\n\t\t\t\tcreateComposeState(stage),\n\t\t\t);\n\t\t\tconst providers = new Map(\n\t\t\t\tresult.plan.domains.map((d) => [d.domain, d.provider]),\n\t\t\t);\n\t\t\tawait recordDnsChanges(journal, result.changes, (domain) =>\n\t\t\t\tproviders.get(domain),\n\t\t\t);\n\t\t}\n\t\tconst parts = [\n\t\t\tresult.confirmed.length > 0\n\t\t\t\t? `${result.confirmed.length} host${result.confirmed.length === 1 ? '' : 's'} confirmed by the DNS provider`\n\t\t\t\t: '',\n\t\t\tresult.resolved.length > 0\n\t\t\t\t? `${result.resolved.length} host${result.resolved.length === 1 ? '' : 's'} resolve${result.resolved.length === 1 ? 's' : ''} to ${server.ipv4}`\n\t\t\t\t: '',\n\t\t].filter(Boolean);\n\t\tif (parts.length > 0) log(`🌐 ${parts.join(', ')}`);\n\t\tif (ctx.dryRun) {\n\t\t\tawait result.prune();\n\t\t\treturn undefined;\n\t\t}\n\t\treturn result.recorded.stale.length > 0 ? result.prune : undefined;\n\t} catch (error) {\n\t\tif (ctx.dryRun && error instanceof HostNotPointingAtServer) {\n\t\t\tctx.logger.warn(`⚠ ${error.message}`);\n\t\t\treturn undefined;\n\t\t}\n\t\tthrow error;\n\t}\n}\n\n/**\n * The records gkm wrote for hosts the stage no longer serves, deleted once it\n * answers on its new ones — and forgotten from its state, deleted or not:\n * none is gkm's to manage any more.\n */\nasync function pruneStageDns(\n\tctx: ComposeContext,\n\trun: ComposeRun,\n): Promise<void> {\n\tif (!run.pruneDns) return;\n\tconst pruned = await run.pruneDns();\n\tconst journal = await DeployJournal.open(ctx.state, ctx.stage, () =>\n\t\tcreateComposeState(ctx.stage),\n\t);\n\tfor (const { record } of pruned) await forgetDnsResource(journal, record);\n\tconst deleted = pruned.filter((p) => p.action === 'delete').length;\n\tif (deleted > 0) {\n\t\tctx.logger.info(`🌐 ${deleted} record${deleted === 1 ? '' : 's'} deleted`);\n\t}\n}\n\n/**\n * The stage's secrets — and, for a deployed stage, everything it generates\n * once: its seed, and each declared secret and keyring. Kept only once the\n * run goes ahead (`provision`), so a dry run, or a tag that is not there,\n * leaves the stage's secrets as it found them.\n */\nasync function stageSecrets(\n\tctx: ComposeContext,\n\tmanifest: ConstructManifest,\n): Promise<{ secrets: StageSecrets | null; generated: string[] }> {\n\tconst stored = await ctx.secrets.read();\n\tif (ctx.stage === ctx.workspace.stages.local) {\n\t\t// The local stage's logins are this machine's, generated once with\n\t\t// `gkm dev`'s — not the stage's secrets.\n\t\treturn { secrets: stored, generated: [] };\n\t}\n\n\tconst { secrets, generated } = deployedStackSecrets(\n\t\tctx.workspace,\n\t\tctx.stage,\n\t\tstored,\n\t\tmanifest,\n\t);\n\t// Read through the store they are masked; made up here, they are not yet.\n\tif (secrets.seed) ctx.secrets.mask(secrets.seed);\n\tfor (const [key, value] of Object.entries(secrets.custom ?? {})) {\n\t\tif (!isReservedStageKey(key)) ctx.secrets.mask(value);\n\t}\n\treturn { secrets, generated };\n}\n\n/**\n * The stack with each app's and worker's image pinned to the digest the file\n * names: the refs it is checked, pulled and recorded by, and the image each\n * compose service runs.\n */\nfunction withPinnedImages(\n\tstack: ComposeStack,\n\tfile: string,\n\tdigests: ImageDigests,\n): ComposeStack {\n\tconst apps = pinImages(file, digests, stack.apps);\n\tconst workers = pinImages(file, digests, stack.workers);\n\tconst processors = pinImages(file, digests, stack.processors);\n\tconst services = { ...stack.compose.services };\n\tfor (const image of [...apps, ...workers, ...processors]) {\n\t\tservices[image.name] = { ...services[image.name]!, image: image.ref };\n\t}\n\treturn {\n\t\t...stack,\n\t\tapps,\n\t\tworkers,\n\t\tprocessors,\n\t\tcompose: { ...stack.compose, services },\n\t};\n}\n\n// ============================================================================\n// plan (dry run)\n// ============================================================================\n\n/**\n * A dry run: the stack's files, written so they can be read, and what a real\n * run would do — no image is built or pulled, no container touched, nothing\n * recorded and no secret kept.\n */\nexport async function planCompose(\n\tctx: ComposeContext,\n\trun: ComposeRun,\n): Promise<void> {\n\tif (run.generated.length > 0) {\n\t\tctx.logger.info(\n\t\t\t`🔑 \"${ctx.stage}\" has no ${run.generated.join(', ')} yet; this dry run used values it did not keep.`,\n\t\t);\n\t}\n\trun.files = await writeStack(ctx.cwd, run.dir, run.stack);\n\tprintPlan(ctx, run);\n\n\t// A push migrates and seeds nothing; a release runs every seed, every\n\t// time, so the list is the same whatever the database holds.\n\tif (!run.push && run.stack.infra.includes('postgres')) {\n\t\treportPlannedSeeds(\n\t\t\t(\n\t\t\t\tawait plannedSeeds({ root: ctx.workspace.root, manifest: ctx.manifest })\n\t\t\t).map(({ target, seeds }) => ({ folder: target.seeds, seeds })),\n\t\t\t(line) => ctx.logger.info(line),\n\t\t);\n\t}\n\n\tconst planned = (change: ResourceChange) => {\n\t\trun.changes.push(change);\n\t\tctx.emit({ type: 'resource.planned', ...change });\n\t};\n\tfor (const service of run.push ? [] : run.stack.infra) {\n\t\tplanned({\n\t\t\tkey: `service:${service}`,\n\t\t\tresourceType: 'service',\n\t\t\taction: 'ensure',\n\t\t});\n\t}\n\tfor (const app of run.stack.apps) {\n\t\tplanned({\n\t\t\tkey: `image:${app.name}`,\n\t\t\tresourceType: 'image',\n\t\t\taction: run.mode === 'build' ? 'build' : 'reuse',\n\t\t\tid: app.ref,\n\t\t});\n\t\tif (run.push) continue;\n\t\tplanned({\n\t\t\tkey: `service:${app.name}`,\n\t\t\tresourceType: 'service',\n\t\t\taction: run.previous[app.name] ? 'reuse' : 'create',\n\t\t});\n\t}\n\tfor (const worker of [...run.stack.workers, ...run.stack.processors]) {\n\t\tplanned({\n\t\t\tkey: `image:${worker.name}`,\n\t\t\tresourceType: 'image',\n\t\t\taction: run.mode === 'build' ? 'build' : 'reuse',\n\t\t\tid: worker.ref,\n\t\t});\n\t\tif (run.push) continue;\n\t\tplanned({\n\t\t\tkey: `service:${worker.name}`,\n\t\t\tresourceType: 'service',\n\t\t\taction: run.previous[worker.name] ? 'reuse' : 'create',\n\t\t});\n\t}\n\tfor (const push of run.topicSubscriptions?.pushes ?? []) {\n\t\tconst key = subscriptionKey(push.worker, push.name);\n\t\tconst id = run.topicSubscriptions?.recorded?.[key]?.id;\n\t\tplanned({\n\t\t\tkey,\n\t\t\tresourceType: SUBSCRIPTION_TYPE,\n\t\t\taction: id ? 'reuse' : 'create',\n\t\t\t...(id ? { id } : {}),\n\t\t});\n\t}\n\tif (!run.push) {\n\t\tplanned({\n\t\t\tkey:\n\t\t\t\trun.stack.proxy === 'caddy'\n\t\t\t\t\t? 'service:caddy'\n\t\t\t\t\t: `service:${EDGE_PROJECT}/${EDGE_SERVICE}`,\n\t\t\tresourceType: 'service',\n\t\t\taction: 'ensure',\n\t\t});\n\t}\n}\n\n/**\n * The shared edge's key for the stage's wildcard certificate: the DNS\n * challenge's record, and nothing else, through the stage domain's Route 53\n * entry — before the stack's routes ask for the certificate.\n */\nasync function edgeAcmeKey(\n\tctx: ComposeContext,\n\trun: ComposeRun,\n\tdeps: ComposeDeps,\n): Promise<void> {\n\tconst { workspace, stage } = ctx;\n\tconst domain = workspace.domains?.[stage];\n\tconst dns = workspace.dns ? normalizeDnsConfig(workspace.dns) : {};\n\tconst zone = domain ? findRootDomain(domain, dns) : null;\n\tconst config = zone ? dns[zone] : undefined;\n\tif (!domain || !zone || config?.provider !== 'route53') return;\n\tconst route53 = config as Route53DnsConfig;\n\n\t// The edge is the server's: its key is named for the server, whichever\n\t// stage on it asked first.\n\tconst server =\n\t\trequiredServerAddress(stage, domain, run.secrets?.custom)?.ipv4 ??\n\t\trun.server?.host ??\n\t\t'local';\n\tconst clients = await (deps.acmeClients ?? defaultAcmeClients)(route53);\n\tawait ensureEdgeAcmeKey(deps.docker, {\n\t\tclients,\n\t\tedge: edgeRef(edgeFile(run), {\n\t\t\t...(run.ref.host ? { host: run.ref.host } : {}),\n\t\t\t...(run.ref.output ? { output: run.ref.output } : {}),\n\t\t}),\n\t\tserver,\n\t\tproject: run.stack.project,\n\t\tdomain,\n\t\tzone,\n\t\t...(route53.hostedZoneId ? { hostedZoneId: route53.hostedZoneId } : {}),\n\t\t...(ctx.dryRun ? { dryRun: true } : {}),\n\t\tlog: (line) => ctx.logger.info(line),\n\t});\n}\n\n/** IAM and Route 53 through the AWS SDK's own chain, or the entry's profile. */\nasync function defaultAcmeClients(\n\tconfig: Route53DnsConfig,\n): Promise<AcmeDnsClients> {\n\tconst [{ IAMClient }, { Route53Client }, { fromIni }] = await Promise.all([\n\t\timport('@aws-sdk/client-iam'),\n\t\timport('@aws-sdk/client-route-53'),\n\t\timport('@aws-sdk/credential-providers'),\n\t]);\n\tconst options = {\n\t\tregion: config.region ?? 'us-east-1',\n\t\t...(config.profile\n\t\t\t? { credentials: fromIni({ profile: config.profile }) }\n\t\t\t: {}),\n\t};\n\treturn { iam: new IAMClient(options), route53: new Route53Client(options) };\n}\n\n// ============================================================================\n// provision\n// ============================================================================\n\n/**\n * What the apps run on: the stage's generated secrets kept, the stack's files\n * written, its infrastructure started, and its databases, roles, grants and\n * migrations applied.\n */\nexport async function provisionCompose(\n\tctx: ComposeContext,\n\trun: ComposeRun,\n\tdeps: ComposeDeps,\n): Promise<void> {\n\tconst { ref } = run;\n\t// A push provisions nothing; its files are written where it builds.\n\tif (run.push) return;\n\n\tif (run.generated.length > 0 && run.secrets) {\n\t\tawait ctx.secrets.write(run.secrets);\n\t\tctx.logger.info(\n\t\t\t`🔑 Generated for \"${ctx.stage}\" (${ctx.secrets.store}): ${run.generated.join(', ')}`,\n\t\t);\n\t}\n\n\t// Nothing but the stack's own proxy may hold the edge's ports — checked\n\t// before a file is written or a container started.\n\tconst ports = edgePorts(deps.env);\n\tawait assertEdgePorts(deps.docker, {\n\t\tproject: run.stack.project,\n\t\tproxy: run.stack.proxy,\n\t\tports,\n\t\tengine: ref,\n\t});\n\n\tif (run.topicSubscriptions) {\n\t\tawait subscribeTopics(ctx, run, deps);\n\t}\n\n\tconst { stack } = run;\n\trun.files = await writeStack(ctx.cwd, run.dir, stack);\n\tprintPlan(ctx, run);\n\n\t// The shared edge, and the network the stack's public services join —\n\t// before any of them, MinIO among them, is started.\n\tif (stack.proxy === 'traefik') {\n\t\tctx.logger.info(`\\n🌐 Starting the shared edge (${EDGE_PROJECT})…`);\n\t\trun.files.push(\n\t\t\t...(await ensureEdge(deps.docker, {\n\t\t\t\tfile: edgeFile(run),\n\t\t\t\tports,\n\t\t\t\t...(ref.host ? { host: ref.host } : {}),\n\t\t\t\tlogging: {\n\t\t\t\t\tdriver: LOG_ROTATION.driver,\n\t\t\t\t\toptions: { ...LOG_ROTATION.options },\n\t\t\t\t},\n\t\t\t\t...(ref.output ? { output: ref.output } : {}),\n\t\t\t\t...(ref.signal ? { signal: ref.signal } : {}),\n\t\t\t})),\n\t\t);\n\t\tapplied(ctx, run, {\n\t\t\tkey: `service:${EDGE_PROJECT}/${EDGE_SERVICE}`,\n\t\t\tresourceType: 'service',\n\t\t\taction: 'ensure',\n\t\t\tid: `${EDGE_PROJECT}/${EDGE_SERVICE}`,\n\t\t\tvia: 'found',\n\t\t});\n\t\tif (stack.wildcard?.tls === 'dns') await edgeAcmeKey(ctx, run, deps);\n\t}\n\n\tif (stack.infra.length > 0) {\n\t\tctx.logger.info(`\\n🗄️ Starting ${stack.infra.join(', ')}…`);\n\t\tawait deps.docker.up(ref, stack.infra);\n\t\tfor (const service of stack.infra) {\n\t\t\tapplied(ctx, run, {\n\t\t\t\tkey: `service:${service}`,\n\t\t\t\tresourceType: 'service',\n\t\t\t\taction: 'ensure',\n\t\t\t\tid: `${stack.project}/${service}`,\n\t\t\t\tvia: Object.keys(run.previous).length > 0 ? 'recorded' : 'created',\n\t\t\t});\n\t\t}\n\t}\n\n\t// The buckets before the seeds: a seed that uploads one object writes it\n\t// to a bucket that has to exist.\n\tif (stack.storage && stack.infra.includes('minio')) {\n\t\tawait prepareBuckets(ctx, run, deps);\n\t}\n\tif (stack.infra.includes('postgres')) {\n\t\tawait prepareDatabases(ctx, run, deps);\n\t}\n}\n\n/**\n * Subscribe each topic subscriber SNS pushes to — for a topic the stage set\n * to SNS by hand — record the ARNs, and compose the stack again with them,\n * before a file is written.\n */\nasync function subscribeTopics(\n\tctx: ComposeContext,\n\trun: ComposeRun,\n\tdeps: ComposeDeps,\n): Promise<void> {\n\tconst { pushes, recorded, restack } = run.topicSubscriptions!;\n\tif (pushes.length > 0) {\n\t\tctx.logger.info(\"\\n📮 SNS subscriptions for the stage's own topics\");\n\t}\n\tconst arns = await ensureTopicSubscriptions({\n\t\tpushes,\n\t\trecorded,\n\t\tsecrets: run.secrets?.custom ?? {},\n\t\tstage: ctx.stage,\n\t\tenv: deps.env,\n\t\trecord: async (resource) => {\n\t\t\tawait ctx.state.putResource(ctx.stage, resource);\n\t\t\tapplied(ctx, run, {\n\t\t\t\tkey: resource.key,\n\t\t\t\tresourceType: SUBSCRIPTION_TYPE,\n\t\t\t\taction: 'ensure',\n\t\t\t\tid: resource.id!,\n\t\t\t\tvia:\n\t\t\t\t\trecorded?.[resource.key]?.id === resource.id ? 'recorded' : 'created',\n\t\t\t});\n\t\t},\n\t\tforget: async (key) => {\n\t\t\tawait ctx.state.deleteResource(ctx.stage, key);\n\t\t},\n\t\tlog: (line) => ctx.logger.info(line),\n\t});\n\trun.stack = restack(arns);\n}\n\n/**\n * Create each bucket the stack's MinIO serves, and the open paths of each\n * one a file server fronts — from this machine, on MinIO's loopback port,\n * the way `gkm dev` creates them.\n */\nasync function prepareBuckets(\n\tctx: ComposeContext,\n\trun: ComposeRun,\n\tdeps: ComposeDeps,\n): Promise<void> {\n\tconst storage = run.stack.storage!;\n\tif (storage.buckets.length === 0) return;\n\n\tconst tunnel = await reach(run, deps, 'minio', LOOPBACK_SERVICES.minio);\n\tlet done: Awaited<ReturnType<typeof applyBuckets>>;\n\ttry {\n\t\tconst client = deps.buckets(tunnel.port, storage);\n\t\tdone = [\n\t\t\t...(await applyBuckets(client, storage.buckets)),\n\t\t\t...(await applyPolicies(client, storage.policies)),\n\t\t\t...(await applyLifecycles(client, storage.lifecycles)),\n\t\t\t// Each watched bucket's events to the worker MinIO was started\n\t\t\t// pointing at — and none from a bucket no longer watched.\n\t\t\t...(await applyNotifications(\n\t\t\t\tclient,\n\t\t\t\tstorage.objects,\n\t\t\t\tnew Set(storage.webhooks.map((hook) => hook.bucket)),\n\t\t\t)),\n\t\t];\n\t} finally {\n\t\tawait tunnel.close();\n\t}\n\tconst created = done.filter((entry) => entry.created).length;\n\tctx.logger.info(\n\t\t`🪣 Buckets: ${storage.buckets.join(', ')}${created ? ` (${created} change(s))` : ''}`,\n\t);\n}\n\n/**\n * Create what the plan names in the stack's Postgres, migrate it, then run\n * its seeds — every one, every time, as each construct's owner.\n *\n * Every service the stack publishes on its loopback is reached, not only\n * Postgres: a seed runs project code, and project code that uploads a file\n * reaches the stack's MinIO as well.\n */\nasync function prepareDatabases(\n\tctx: ComposeContext,\n\trun: ComposeRun,\n\tdeps: ComposeDeps,\n): Promise<void> {\n\tconst tunnels: { port: number; close: () => Promise<void> }[] = [];\n\ttry {\n\t\tconst ports: Record<string, number> = {};\n\t\tfor (const [service, inside] of Object.entries(LOOPBACK_SERVICES)) {\n\t\t\tif (!run.stack.infra.includes(service)) continue;\n\t\t\tconst tunnel = await reach(run, deps, service, inside);\n\t\t\ttunnels.push(tunnel);\n\t\t\tports[primaryPortKey(service)] = tunnel.port;\n\t\t}\n\t\tawait migrateAndSeed(ctx, run, deps, ports);\n\t} finally {\n\t\tawait Promise.all(tunnels.map((tunnel) => tunnel.close()));\n\t}\n}\n\n/**\n * A port a stack's service publishes on its engine's loopback, reachable\n * from this machine: the published port itself on the local stage, and on a\n * server an SSH tunnel to it over the deploy's own login — so Postgres and\n * MinIO are never published beyond the server's loopback.\n *\n * Migrations and seeds run here, in this process, with the project's own\n * Kysely — the way `gkm migrate` runs them — through that port. No image\n * needs to carry them, and nothing is run on the server but the stack.\n */\nasync function reach(\n\trun: ComposeRun,\n\tdeps: ComposeDeps,\n\tservice: string,\n\tinside: number,\n): Promise<{ port: number; close: () => Promise<void> }> {\n\tconst published = await deps.docker.port(run.ref, service, inside);\n\tif (!run.server) return { port: published, close: async () => {} };\n\treturn deps.server.tunnel(run.server, published);\n}\n\nasync function migrateAndSeed(\n\tctx: ComposeContext,\n\trun: ComposeRun,\n\tdeps: ComposeDeps,\n\t/** Each loopback service's port on this machine, by port key. */\n\tports: Record<string, number>,\n): Promise<void> {\n\tconst { stack } = run;\n\tconst workspace: NormalizedWorkspace = ctx.workspace;\n\tconst port = ports[primaryPortKey('postgres')]!;\n\n\t// A stack an older gkm started made its superuser under the old fixed\n\t// name, with the password this stage derives; it is moved to the\n\t// superuser named now — the local stage's from the old fixed login too.\n\tconst superuser = stack.credential.containers.postgres;\n\tconst login = await deps.logins({\n\t\tport,\n\t\tlogin: superuser,\n\t\tlegacy: [\n\t\t\t{ user: LEGACY_LOCAL_LOGIN.user, password: superuser.password },\n\t\t\t...(stack.local ? [LEGACY_LOCAL_LOGIN] : []),\n\t\t],\n\t});\n\tif (login.notice) ctx.logger.info(login.notice);\n\n\tconst statements = [\n\t\t...postgresStatements(stack.plan, workspace.name, stack.credential.seed),\n\t\t// The backups service's own login: it reads, and writes nothing.\n\t\t...(stack.backups ? backupsRoleStatements(stack.backups) : []),\n\t];\n\tif (statements.length > 0) {\n\t\tctx.logger.info('🗄️ Creating databases, roles and grants…');\n\t\tawait applyPostgres(deps.sql(port, login.login), statements);\n\t}\n\n\t// Migrations run here, with the project's own Kysely, the way `gkm\n\t// migrate` runs them — so the constructs themselves are needed, which\n\t// only an in-process discovery hands back.\n\tconst sources: Record<string, ConstructSource> = {};\n\tconst manifest = await discover({\n\t\tpatterns: constructGlobs(workspace),\n\t\tcwd: workspace.root,\n\t\tsources,\n\t});\n\n\t// What `gkm seed` hands a seed — the stage's secrets under what it\n\t// resolves — resolved as the stack resolves it, on the ports this machine\n\t// reaches the stack by. A key the stage set by hand is what its apps are\n\t// given, so it is not resolved over.\n\tconst custom = run.secrets?.custom ?? {};\n\tconst resolved = envFor(stack.plan, {\n\t\t...stack.resolution,\n\t\tports,\n\t\tcredentials: {\n\t\t\t...stack.resolution.credentials,\n\t\t\tpostgres: login.login,\n\t\t},\n\t});\n\tconst env = stageEnv(\n\t\trun.secrets ? toEmbeddableSecrets(run.secrets) : {},\n\t\tObject.fromEntries(\n\t\t\tObject.entries(resolved).filter(([key]) => custom[key] === undefined),\n\t\t),\n\t);\n\tconst options = { root: workspace.root, manifest, sources, env };\n\tconst runs = await deps.migrate(options);\n\n\t// Seeds after migrations, before any app starts: an app that boots with\n\t// its reference data missing fails on the first request that needs it.\n\tconst seeds = await deps\n\t\t.seed({ ...options, stage: ctx.stage, backends: backendsOf(workspace) })\n\t\t.catch((error: unknown) => {\n\t\t\tif (error instanceof SeedFailed) {\n\t\t\t\tthrow new DeploySeedsFailed(\n\t\t\t\t\tctx.stage,\n\t\t\t\t\terror.construct,\n\t\t\t\t\terror.seed,\n\t\t\t\t\terror,\n\t\t\t\t);\n\t\t\t}\n\t\t\tthrow error;\n\t\t});\n\n\treportDatabaseRuns(\n\t\truns.map(({ target, applied }) => ({\n\t\t\tconstruct: target.id,\n\t\t\tfolder: target.migrations,\n\t\t\tapplied,\n\t\t})),\n\t\tseeds.map(({ target, seeded }) => ({\n\t\t\tconstruct: target.id,\n\t\t\tfolder: target.seeds,\n\t\t\tseeded,\n\t\t})),\n\t\t(line) => ctx.logger.info(line),\n\t\t(event) => ctx.emit(event),\n\t);\n}\n\n// ============================================================================\n// build\n// ============================================================================\n\n/**\n * Each app's image: built from this checkout — inside Docker, every one of\n * them, from a pruned slice of the build root — or pulled at the tag. Nothing\n * live changes.\n */\nexport async function buildCompose(\n\tctx: ComposeContext,\n\trun: ComposeRun,\n\tdeps: ComposeDeps,\n): Promise<void> {\n\tconst { stack, ref } = run;\n\tconst images = [...stack.apps, ...stack.workers, ...stack.processors];\n\tconst apps = images.map((image) => image.app);\n\n\t// Nothing was provisioned, so nothing has written the files it builds from.\n\tif (run.push) {\n\t\trun.files = await writeStack(ctx.cwd, run.dir, stack);\n\t\tprintPlan(ctx, run);\n\t}\n\n\tif (run.mode === 'build') {\n\t\tctx.logger.info('\\n🐳 Building images…');\n\t\tawait deps.docker.build(ref, apps);\n\t} else {\n\t\tctx.logger.info(`\\n🐳 Pulling ${ctx.tag}…`);\n\t\tawait deps.docker.pull(ref, apps);\n\t}\n\n\tif (run.push) ctx.logger.info('\\n📤 Pushing images…');\n\n\t// What each tag resolved to: the registry's digest for a pushed or pulled\n\t// image, or — for one built here and never pushed — its content id.\n\tfor (const image of images) {\n\t\tconst digest = run.push\n\t\t\t? await deps.docker.push(ref, image.ref)\n\t\t\t: await deps.docker.digest(ref, image.ref);\n\t\tif (run.push) {\n\t\t\tctx.logger.info(` ${image.app.padEnd(12)} ${image.ref}@${digest}`);\n\t\t}\n\t\trun.images[image.app] = {\n\t\t\tref: image.ref,\n\t\t\ttag: image.tag,\n\t\t\t...(digest ? { digest } : {}),\n\t\t};\n\t\tctx.emit({\n\t\t\ttype: 'artifact.built',\n\t\t\tapp: image.app,\n\t\t\timageRef: image.ref,\n\t\t\t...(digest ? { digest } : {}),\n\t\t});\n\t\trun.changes.push({\n\t\t\tkey: `image:${image.app}`,\n\t\t\tresourceType: 'image',\n\t\t\taction: run.mode === 'build' ? 'build' : 'reuse',\n\t\t\tid: digest ?? image.ref,\n\t\t});\n\t}\n}\n\n// ============================================================================\n// release\n// ============================================================================\n\n/**\n * The whole stack up — anything it no longer defines removed — and each\n * app's image recorded in the stage's state.\n */\nexport async function releaseCompose(\n\tctx: ComposeContext,\n\trun: ComposeRun,\n\tdeps: ComposeDeps,\n): Promise<void> {\n\tconst { stack, ref } = run;\n\t// A push starts nothing and records nothing: a stage runs what it pulls.\n\tif (run.push) return;\n\n\t// Registered with the shared edge before anything waits on health, so one\n\t// app that never turns healthy leaves the others routed: a route to an\n\t// app not up yet answers 502, which says more than no route at all. It is\n\t// also what lets an app whose own health check goes through the edge — a\n\t// site whose `/` calls its API at the API's public host — turn healthy.\n\t// A stack on its own Caddy leaves nothing behind there from a run on the\n\t// edge — the server's, or this machine's for a local stage that ran\n\t// behind it before (its directory still has the edge's file).\n\tconst edge = edgeRef(edgeFile(run), {\n\t\t...(ref.host ? { host: ref.host } : {}),\n\t\t...(ref.output ? { output: ref.output } : {}),\n\t});\n\tif (stack.proxy === 'traefik' && stack.traefik) {\n\t\tconst written = await writeEdgeRoutes(\n\t\t\tdeps.docker,\n\t\t\tedge,\n\t\t\tstack.project,\n\t\t\tstack.traefik,\n\t\t\tawait edgeCertificate(run.dir, stack),\n\t\t);\n\t\tctx.logger.info(\n\t\t\t`🌐 Registered ${stack.routes.length} route(s) with ${EDGE_PROJECT}: ${written.at(-1)}`,\n\t\t);\n\t} else if (!stack.local || existsSync(edgeFile(run))) {\n\t\tawait removeEdgeRoutes(deps.docker, edge, stack.project);\n\t}\n\n\tctx.logger.info('\\n🚀 Starting the stack…');\n\t// Caddy starts once its apps have, not once they are healthy, so its\n\t// routes are served whatever their health. `up --wait` still fails when\n\t// one never turns healthy: which ones is asked of Docker, and said once\n\t// the rest of the stack is released — never instead of releasing it.\n\tconst down = await deps.docker.up(ref).then(\n\t\t() => [],\n\t\t(error: unknown) => unhealthyAfterUp(ctx, run, deps, error),\n\t);\n\tconst isDown = new Set(down.map(({ app }) => app));\n\n\tawait recordImages(ctx, run);\n\n\tfor (const app of stack.apps) {\n\t\tif (isDown.has(app.name)) continue;\n\t\tconst image = run.images[app.name];\n\t\tapplied(ctx, run, {\n\t\t\tkey: `service:${app.name}`,\n\t\t\tresourceType: 'service',\n\t\t\taction: 'ensure',\n\t\t\tid: `${stack.project}/${app.name}`,\n\t\t\tvia: run.previous[app.name] ? 'recorded' : 'created',\n\t\t});\n\t\tctx.emit({\n\t\t\ttype: 'app.deployed',\n\t\t\tapp: app.name,\n\t\t\tapplicationId: `${stack.project}/${app.name}`,\n\t\t\timageRef: image?.ref ?? app.ref,\n\t\t\turl: app.url,\n\t\t});\n\t}\n\n\t// A worker has no URL, so no `app.deployed`: its service, applied, is it —\n\t// nor has a processor unit, which answers on its file server's.\n\tfor (const worker of [...stack.workers, ...stack.processors]) {\n\t\tif (isDown.has(worker.name)) continue;\n\t\tapplied(ctx, run, {\n\t\t\tkey: `service:${worker.name}`,\n\t\t\tresourceType: 'service',\n\t\t\taction: 'ensure',\n\t\t\tid: `${stack.project}/${worker.name}`,\n\t\t\tvia: run.previous[worker.name] ? 'recorded' : 'created',\n\t\t});\n\t}\n\n\tctx.logger.info(`\\n✅ ${stack.project} is running:`);\n\tfor (const app of stack.apps) {\n\t\tif (isDown.has(app.name)) continue;\n\t\tctx.logger.info(\n\t\t\t` ${app.name.padEnd(12)} ${app.url}${\n\t\t\t\tapp.auth\n\t\t\t\t\t? ` 🔒 user: ${app.auth.user}, password: gkm secrets:show --stage ${ctx.stage} --reveal → ${app.auth.key}`\n\t\t\t\t\t: ''\n\t\t\t}`,\n\t\t);\n\t}\n\tif (stack.mailInbox) {\n\t\tctx.logger.info(` ${'mail'.padEnd(12)} ${stack.mailInbox.url} (inbox)`);\n\t}\n\tfor (const worker of stack.workers) {\n\t\tif (isDown.has(worker.name)) continue;\n\t\tctx.logger.info(` ${worker.name.padEnd(12)} worker ${worker.id}`);\n\t}\n\tfor (const unit of stack.processors) {\n\t\tif (isDown.has(unit.name)) continue;\n\t\tctx.logger.info(` ${unit.name.padEnd(12)} processors of ${unit.id}`);\n\t}\n\tif (stack.authority) {\n\t\tctx.logger.info(\n\t\t\t`\\n🔐 Certificates are from gkm's local CA (\"gkm trust\" trusts it here): NODE_EXTRA_CA_CERTS=${stack.authority.certFile}`,\n\t\t);\n\t} else if (stack.local && stack.tls) {\n\t\tctx.logger.info(\n\t\t\tstack.tls.caFile\n\t\t\t\t? `\\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\t\t\t\t: `\\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.`,\n\t\t);\n\t}\n\n\tif (down.length > 0) {\n\t\tthrow new ComposeAppsUnhealthy(stack.project, down, stack.proxy, 'docker');\n\t}\n}\n\n/**\n * After `up --wait` failed: each app's and worker's service that is not\n * healthy once its health settles — waited on while it is still starting,\n * as `--wait` stops at the first that is not. None means the failure was not\n * health's, and it is thrown as it was.\n */\nasync function unhealthyAfterUp(\n\tctx: ComposeContext,\n\trun: ComposeRun,\n\tdeps: ComposeDeps,\n\terror: unknown,\n): Promise<{ app: string; url: string; last: string }[]> {\n\tconst { stack } = run;\n\tconst services = [\n\t\t...stack.apps.flatMap(replicaNames),\n\t\t...stack.workers.map((worker) => worker.name),\n\t\t...stack.processors.map((unit) => unit.name),\n\t];\n\tconst settled = await Promise.all(\n\t\tservices.map(async (service) => {\n\t\t\tlet last: string | undefined;\n\t\t\tfor (let attempt = 1; attempt <= deps.healthAttempts; attempt++) {\n\t\t\t\tctx.signal.throwIfAborted();\n\t\t\t\tlast = await deps.docker\n\t\t\t\t\t.health(run.ref, service)\n\t\t\t\t\t.catch(() => undefined);\n\t\t\t\tif (last !== 'starting') break;\n\t\t\t\tif (attempt < deps.healthAttempts) {\n\t\t\t\t\tawait new Promise((resolve) =>\n\t\t\t\t\t\tsetTimeout(resolve, deps.healthIntervalMs),\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn { app: service, url: `docker:${service}`, last };\n\t\t}),\n\t);\n\tconst down = settled\n\t\t.filter(({ last }) => last !== 'healthy')\n\t\t.map(({ app, url, last }) => ({ app, url, last: last ?? 'not running' }));\n\tif (down.length === 0) throw error;\n\n\tctx.logger.warn(\n\t\t`\\n⚠️ ${down.map(({ app }) => app).join(', ')} did not turn healthy; the rest of the stack is released and routed.`,\n\t);\n\treturn down;\n}\n\n/**\n * Each app's image in the stage's state — the same `images` a Dokploy deploy\n * records: the ref it runs, the tag it was released under, and the digest\n * the tag resolved to.\n */\nasync function recordImages(\n\tctx: ComposeContext,\n\trun: ComposeRun,\n): Promise<void> {\n\tconst journal = await DeployJournal.open(ctx.state, ctx.stage, () =>\n\t\tcreateComposeState(ctx.stage),\n\t);\n\tconst by = currentActor();\n\tfor (const app of [\n\t\t...run.stack.apps,\n\t\t...run.stack.workers,\n\t\t...run.stack.processors,\n\t]) {\n\t\tconst image = run.images[app.app] ?? { ref: app.ref, tag: app.tag };\n\t\trecordRelease(journal.state, app.app, image, by);\n\t}\n\tjournal.state.identity = ctx.identity.key;\n\tawait journal.save();\n}\n\n// ============================================================================\n// verify\n// ============================================================================\n\n/**\n * Each app asked through Caddy, over HTTPS, the certificate verified: an API\n * at `/health`, a site at `/`. On the local stage the edge is this machine and\n * its certificate is from gkm's local CA, so that root is the one trusted and\n * the request goes to 127.0.0.1.\n */\nexport async function verifyCompose(\n\tctx: ComposeContext,\n\trun: ComposeRun,\n\tdeps: ComposeDeps,\n): Promise<void> {\n\tconst { stack } = run;\n\tif (run.push) return;\n\tconst ca = await verifyAuthority(stack);\n\n\tctx.logger.info(\n\t\t`\\n🩺 Checking each app through ${stack.proxy === 'caddy' ? 'Caddy' : 'the shared edge'}…`,\n\t);\n\t// The local stage's edge is this machine; a deployed stage's is its\n\t// server. Either is asked directly, on its published port, with each host\n\t// as SNI and Host: what is checked is its routing and its certificate,\n\t// whatever DNS — or a record not yet propagated — says.\n\tconst edge = stack.local\n\t\t? { connectTo: '127.0.0.1' }\n\t\t: run.server\n\t\t\t? { connectTo: run.server.host, connectPort: edgePorts(deps.env).https }\n\t\t\t: undefined;\n\t// A wildcard site has no one host to ask: each tenant's is the app's to\n\t// answer, and an unknown one may get no certificate. Its container's own\n\t// health check is the answer, as a worker's is.\n\tconst results = await Promise.all(\n\t\tstack.apps.map((app) =>\n\t\t\tapp.id === stack.wildcard?.site\n\t\t\t\t? checkContainer(ctx, run, deps, app.name)\n\t\t\t\t: checkApp(ctx, app, deps, { ca, edge }),\n\t\t),\n\t);\n\n\t// A worker has no route through the edge: its own health check, as Docker\n\t// reports it, is the answer.\n\tresults.push(\n\t\t...(await Promise.all(\n\t\t\t[...stack.workers, ...stack.processors].map((worker) =>\n\t\t\t\tcheckContainer(ctx, run, deps, worker.name),\n\t\t\t),\n\t\t)),\n\t);\n\tif (stack.logs) {\n\t\tresults.push(await checkContainer(ctx, run, deps, LOGS_SERVICE));\n\t}\n\n\tconst down = results\n\t\t.filter((result) => !result.healthy)\n\t\t.map(({ app, url, last }) => ({ app, url, last }));\n\tif (down.length > 0) {\n\t\tthrow new ComposeAppsUnhealthy(stack.project, down, stack.proxy);\n\t}\n\tawait pruneStageDns(ctx, run);\n\n\tawait confirmSubscriptions(ctx, run, deps);\n\n\tawait warmSites(ctx, run, deps, { ca, edge });\n\n\tif (stack.logs) reportLogs(ctx, stack.logs, stack.local, run.server);\n}\n\n/**\n * Each server-rendered site (`next`, `tanstack`) asked for its `/` and every\n * page its sitemap lists, through the edge as `checkApp` asks it — see\n * `warmup.ts`. Its image was built with no API reachable, so each page\n * renders on its first request: this is that request, made before any\n * visitor's.\n *\n * Only ever said, never failed on: every app is already healthy, and a page\n * that did not warm renders on the next request for it.\n */\nasync function warmSites(\n\tctx: ComposeContext,\n\trun: ComposeRun,\n\tdeps: ComposeDeps,\n\toptions: {\n\t\tca: string | undefined;\n\t\tedge?: { connectTo: string; connectPort?: number };\n\t},\n): Promise<void> {\n\tconst { stack } = run;\n\tconst sites = stack.apps.filter(\n\t\t(app) =>\n\t\t\tapp.kind === 'site' &&\n\t\t\t(app.variant === 'next' || app.variant === 'tanstack'),\n\t);\n\tif (sites.length === 0) return;\n\n\tctx.logger.info('\\n🔥 Warming each server-rendered site…');\n\tfor (const app of sites) {\n\t\tif (app.id === stack.wildcard?.site) {\n\t\t\tctx.logger.info(\n\t\t\t\t` – ${app.name.padEnd(12)} serves every subdomain: there is no one host to warm, so it is skipped`,\n\t\t\t);\n\t\t\tcontinue;\n\t\t}\n\t\ttry {\n\t\t\tconst { warmed, warnings, leftOut } = await warmSite({\n\t\t\t\turl: app.url,\n\t\t\t\tfetch: deps.fetch ?? edgeFetch,\n\t\t\t\tedge: {\n\t\t\t\t\t...(options.ca ? { ca: options.ca } : {}),\n\t\t\t\t\t...(app.auth ? { authorization: basicAuthorization(app.auth) } : {}),\n\t\t\t\t\t...options.edge,\n\t\t\t\t\tsignal: ctx.signal,\n\t\t\t\t},\n\t\t\t});\n\t\t\tconst said = `warmed ${warmed.length} page(s)${\n\t\t\t\twarnings.length > 0 ? `, ${warnings.length} warning(s)` : ''\n\t\t\t}`;\n\t\t\tif (warnings.length === 0) {\n\t\t\t\tctx.logger.info(` ✓ ${app.name.padEnd(12)} ${said}`);\n\t\t\t} else {\n\t\t\t\tctx.logger.warn(` ⚠ ${app.name.padEnd(12)} ${said}:`);\n\t\t\t\tfor (const { url, reason } of warnings) {\n\t\t\t\t\tctx.logger.warn(` ${url}: ${reason}`);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (leftOut > 0) {\n\t\t\t\tctx.logger.info(\n\t\t\t\t\t` ${leftOut} more page(s) in its sitemap were not asked: at most ${WARMUP_MAX_URLS} are warmed per site`,\n\t\t\t\t);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tif (ctx.signal.aborted) throw error;\n\t\t\tctx.logger.warn(\n\t\t\t\t` ⚠ ${app.name.padEnd(12)} not warmed: ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t);\n\t\t}\n\t}\n}\n\n/**\n * The SNS subscriptions the stage's providers made before the workers were\n * up: each still pending is subscribed again, so SNS resends its\n * confirmation to a worker now there to answer it, and waited on. One still\n * pending after that is said, not failed on — every app is healthy, and\n * rolling them back would not confirm it.\n */\nasync function confirmSubscriptions(\n\tctx: ComposeContext,\n\trun: ComposeRun,\n\tdeps: ComposeDeps,\n): Promise<void> {\n\tconst stored = await ctx.state.read(ctx.stage);\n\tconst confirm = deps.confirmSubscriptions ?? confirmPendingSubscriptions;\n\tconst left = await confirm({\n\t\tworkspace: ctx.workspace,\n\t\tstage: ctx.stage,\n\t\tsecrets: run.secrets?.custom ?? {},\n\t\tresources: stored?.resources,\n\t\tenv: deps.env,\n\t\tlog: (line) => ctx.logger.info(line),\n\t\trecord: async (record) => {\n\t\t\tconst { updatedAt: _, updatedBy: __, ...input } = record;\n\t\t\tawait ctx.state.putResource(ctx.stage, input);\n\t\t},\n\t});\n\tif (left.length > 0) {\n\t\tctx.logger.warn(`⚠ ${new PushSubscriptionsUnconfirmed(left).message}`);\n\t}\n}\n\n/**\n * A container's own health check, as Docker reports it: a worker's, which\n * has no route through the edge, and OpenObserve's — by default it has no\n * host there, and served publicly it answers only the addresses it allows,\n * which need not include this one.\n */\nasync function checkContainer(\n\tctx: ComposeContext,\n\trun: ComposeRun,\n\tdeps: ComposeDeps,\n\tservice: string,\n): Promise<{ app: string; url: string; last: string; healthy: boolean }> {\n\tconst url = `docker:${service}`;\n\tlet last = 'not asked';\n\n\tfor (let attempt = 1; attempt <= deps.healthAttempts; attempt++) {\n\t\tctx.signal.throwIfAborted();\n\t\tconst health = await deps.docker\n\t\t\t.health(run.ref, service)\n\t\t\t.catch((error: unknown) =>\n\t\t\t\terror instanceof Error ? error.message : String(error),\n\t\t\t);\n\t\tlast = health ?? 'not running';\n\t\tconst healthy = health === 'healthy';\n\t\tctx.emit({\n\t\t\ttype: 'health.checked',\n\t\t\tapp: service,\n\t\t\turl,\n\t\t\thealthy,\n\t\t\tattempt,\n\t\t});\n\t\tif (healthy) {\n\t\t\tctx.logger.info(` ✓ ${service.padEnd(12)} ${url} (${last})`);\n\t\t\treturn { app: service, url, last, healthy };\n\t\t}\n\t\tif (attempt < deps.healthAttempts) {\n\t\t\tawait new Promise((resolve) =>\n\t\t\t\tsetTimeout(resolve, deps.healthIntervalMs),\n\t\t\t);\n\t\t}\n\t}\n\n\tctx.logger.warn(` ✗ ${service.padEnd(12)} ${url} (${last})`);\n\treturn { app: service, url, last, healthy: false };\n}\n\n/** A login, as the `Authorization` header that carries it. */\nfunction basicAuthorization(auth: SiteAuth): string {\n\treturn `Basic ${Buffer.from(`${auth.user}:${auth.password}`).toString('base64')}`;\n}\n\n/** How to open the logs, printed — and as an event, for a headless caller. */\nfunction reportLogs(\n\tctx: ComposeContext,\n\tlogs: StackLogs,\n\tlocal: boolean,\n\tserver: ComposeServer | undefined,\n): void {\n\tconst lines = logsAccess(logs, {\n\t\tstage: ctx.stage,\n\t\tlocal,\n\t\tuser: server?.user ?? currentUser(),\n\t\thostname: server?.host ?? hostname(),\n\t\t...(server ? { known: true } : {}),\n\t});\n\tctx.logger.info(`\\n${lines.join('\\n')}`);\n\tctx.emit({\n\t\ttype: 'logs.ready',\n\t\tservice: LOGS_SERVICE,\n\t\taccess: logs.public ? 'public' : 'tunnel',\n\t\turl: logs.url,\n\t\t...(logs.public ? { allow: [...logs.public.allow] } : { port: logs.port }),\n\t\temail: logs.email,\n\t});\n}\n\n/** This machine's user — a guess at who would SSH in. */\nfunction currentUser(): string {\n\ttry {\n\t\treturn userInfo().username;\n\t} catch {\n\t\treturn process.env.USER ?? 'user';\n\t}\n}\n\nasync function checkApp(\n\tctx: ComposeContext,\n\tapp: StackApp,\n\tdeps: ComposeDeps,\n\toptions: {\n\t\tca: string | undefined;\n\t\tedge?: { connectTo: string; connectPort?: number };\n\t},\n): Promise<{ app: string; url: string; last: string; healthy: boolean }> {\n\t// A WebSocket surface answers its health over plain HTTPS on its host.\n\tconst url = `${app.url.replace(/^ws/, 'http')}${app.kind === 'site' ? '/' : '/health'}`;\n\tlet last = 'not asked';\n\n\tfor (let attempt = 1; attempt <= deps.healthAttempts; attempt++) {\n\t\tctx.signal.throwIfAborted();\n\t\tlet status: number | undefined;\n\t\ttry {\n\t\t\tstatus = await deps.probe({\n\t\t\t\turl,\n\t\t\t\t...(options.ca ? { ca: options.ca } : {}),\n\t\t\t\t...(app.auth ? { authorization: basicAuthorization(app.auth) } : {}),\n\t\t\t\t...options.edge,\n\t\t\t\ttimeoutMs: 10_000,\n\t\t\t\tsignal: ctx.signal,\n\t\t\t});\n\t\t\tlast = `HTTP ${status}`;\n\t\t} catch (error) {\n\t\t\tlast = error instanceof Error ? error.message : String(error);\n\t\t}\n\n\t\tconst healthy = status !== undefined && isHealthy(status);\n\t\tctx.emit({\n\t\t\ttype: 'health.checked',\n\t\t\tapp: app.name,\n\t\t\turl,\n\t\t\thealthy,\n\t\t\t...(status !== undefined ? { status } : {}),\n\t\t\tattempt,\n\t\t});\n\t\tif (healthy) {\n\t\t\tctx.logger.info(` ✓ ${app.name.padEnd(12)} ${url} (${last})`);\n\t\t\treturn { app: app.name, url, last, healthy };\n\t\t}\n\t\tif (attempt < deps.healthAttempts) {\n\t\t\tawait new Promise((resolve) =>\n\t\t\t\tsetTimeout(resolve, deps.healthIntervalMs),\n\t\t\t);\n\t\t}\n\t}\n\n\tctx.logger.warn(` ✗ ${app.name.padEnd(12)} ${url} (${last})`);\n\treturn { app: app.name, url, last, healthy: false };\n}\n\n// ============================================================================\n// result\n// ============================================================================\n\nexport function composeResult(\n\tctx: ComposeContext,\n\trun: ComposeRun,\n): DeployResult {\n\tconst apps = [\n\t\t...run.stack.apps.map((app) => {\n\t\t\tconst image = run.images[app.name];\n\t\t\treturn {\n\t\t\t\tappName: app.name,\n\t\t\t\ttype: app.kind === 'site' ? ('web' as const) : ('backend' as const),\n\t\t\t\tsuccess: !ctx.dryRun,\n\t\t\t\tapplicationId: `${run.stack.project}/${app.name}`,\n\t\t\t\timageRef: image?.ref ?? app.ref,\n\t\t\t\t...(image?.digest ? { digest: image.digest } : {}),\n\t\t\t\turl: app.url,\n\t\t\t};\n\t\t}),\n\t\t...[...run.stack.workers, ...run.stack.processors].map((worker) => {\n\t\t\tconst image = run.images[worker.name];\n\t\t\treturn {\n\t\t\t\tappName: worker.name,\n\t\t\t\ttype: 'backend' as const,\n\t\t\t\tsuccess: !ctx.dryRun,\n\t\t\t\tapplicationId: `${run.stack.project}/${worker.name}`,\n\t\t\t\timageRef: image?.ref ?? worker.ref,\n\t\t\t\t...(image?.digest ? { digest: image.digest } : {}),\n\t\t\t};\n\t\t}),\n\t];\n\treturn {\n\t\tapps,\n\t\tprojectId: run.stack.project,\n\t\tsuccessCount: ctx.dryRun ? 0 : apps.length,\n\t\tfailedCount: 0,\n\t\tstage: ctx.stage,\n\t\tidentity: ctx.identity.key,\n\t\ttag: ctx.tag,\n\t\tdryRun: ctx.dryRun,\n\t\tenvironmentId: '',\n\t\tskipped: [...ctx.skipped],\n\t\turls: Object.fromEntries(run.stack.apps.map((app) => [app.name, app.url])),\n\t\tchanges: run.changes,\n\t};\n}\n\n// ============================================================================\n// Files\n// ============================================================================\n\n/** The shared edge's compose file, as this machine hands it to compose. */\nfunction edgeFile(run: ComposeRun): string {\n\treturn join(run.dir, `${EDGE_PROJECT}.yml`);\n}\n\nfunction applied(\n\tctx: ComposeContext,\n\trun: ComposeRun,\n\tchange: ResourceChange & {\n\t\tid: string;\n\t\tvia: 'recorded' | 'resumed' | 'found' | 'created';\n\t},\n): void {\n\tconst { via, ...rest } = change;\n\trun.changes.push(rest);\n\tctx.emit({ type: 'resource.applied', ...rest, via });\n}\n\n/**\n * The root the check after a start trusts, PEM: gkm's on the local stage that\n * set no certificate of its own, and otherwise the one the stage's own names\n * (`deploy.compose.tls.<stage>.caFile`). Undefined — Node's own roots, and\n * `NODE_EXTRA_CA_CERTS` — for a certificate that names none: a public CA's.\n */\nexport async function verifyAuthority(\n\tstack: Pick<ComposeStack, 'authority' | 'tls'>,\n): Promise<string | undefined> {\n\tif (stack.authority) return (await readLocalAuthority(stack.authority)).cert;\n\tif (stack.tls?.caFile) return readFile(stack.tls.caFile, 'utf-8');\n\treturn undefined;\n}\n\n/**\n * The certificate the stack's proxy serves, PEM: the stage's own where it set\n * one, the one gkm's local CA issued the local stage otherwise, and none — a\n * deployed stage's comes from Let's Encrypt — when neither.\n */\nasync function edgeCertificate(\n\tdir: string,\n\tstack: ComposeStack,\n): Promise<{ cert: string; key: string } | undefined> {\n\tif (stack.tls) {\n\t\treturn {\n\t\t\tcert: await readFile(stack.tls.certFile, 'utf-8'),\n\t\t\tkey: await readFile(stack.tls.keyFile, 'utf-8'),\n\t\t};\n\t}\n\tif (stack.authority) {\n\t\treturn localEdgeCertificate(dir, stack, stack.authority);\n\t}\n\treturn undefined;\n}\n\n/** Where the local stage's edge certificate is kept, between runs. */\nexport const LOCAL_EDGE_CERTIFICATE = 'local-edge.pem';\n\n/**\n * The local stage's edge certificate, from gkm's local CA: the one kept in\n * the stack's directory while it still covers every host, so an unchanged\n * stack does not recreate its Caddy for a new certificate each run.\n */\nasync function localEdgeCertificate(\n\tdir: string,\n\tstack: ComposeStack,\n\tauthority: LocalAuthorityPaths,\n): Promise<{ cert: string; key: string }> {\n\tconst { cert, key } = await ensureLocalCertificate(\n\t\tawait ensureLocalAuthority(authority),\n\t\tlocalCertificateNames(stack.resolution.project ?? '', stackHosts(stack)),\n\t\tjoin(dir, LOCAL_EDGE_CERTIFICATE),\n\t);\n\treturn { cert, key };\n}\n\n/** Write the stack's files: owner-only, since the env files hold secrets. */\nasync function writeStack(\n\troot: string,\n\tdir: string,\n\tstack: ComposeStack,\n): Promise<string[]> {\n\tawait mkdir(dir, { recursive: true, mode: 0o700 });\n\tawait chmod(dir, 0o700);\n\n\tconst files: string[] = [];\n\tconst write = async (path: string, content: string, mode = 0o644) => {\n\t\tawait mkdir(dirname(path), { recursive: true });\n\t\tawait writeFile(path, content, { mode });\n\t\tawait chmod(path, mode);\n\t\tfiles.push(path);\n\t};\n\n\t// Caddy's files go inline, in the compose file: nothing the stack runs\n\t// mounts a path on this machine, so the same file runs on a server's\n\t// engine over SSH. With the stage's own key in it, it is owner-only.\n\t// Behind the shared edge, the certificate is written into the edge as the\n\t// stack registers with it (`writeEdgeRoutes`); the local stage's is still\n\t// issued here, kept beside the stack between runs.\n\tconst issued = await edgeCertificate(dir, stack);\n\tconst tls = stack.proxy === 'caddy' ? issued : undefined;\n\tconst compose =\n\t\tstack.caddyfile !== undefined\n\t\t\t? withCaddyConfigs(stack.compose, {\n\t\t\t\t\tcaddyfile: stack.caddyfile,\n\t\t\t\t\t...(tls ? { tls } : {}),\n\t\t\t\t})\n\t\t\t: stack.compose;\n\tawait write(\n\t\tjoin(dir, 'docker-compose.yml'),\n\t\tcomposeYaml(stack, compose),\n\t\ttls ? 0o600 : 0o644,\n\t);\n\t// For reading: the proxy's configuration — the stack's own Caddy's, or a\n\t// copy of what the stack registers with the shared edge. The other is\n\t// removed, so the directory never shows a proxy the stack does not use.\n\tif (stack.caddyfile !== undefined) {\n\t\tawait write(join(dir, 'Caddyfile'), stack.caddyfile);\n\t\tawait rm(join(dir, 'traefik.yml'), { force: true });\n\t} else {\n\t\tawait rm(join(dir, 'Caddyfile'), { force: true });\n\t}\n\tif (stack.traefik !== undefined) {\n\t\tawait write(join(dir, 'traefik.yml'), stack.traefik);\n\t}\n\t// The copy of the stage's certificate an older gkm mounted from here.\n\tawait rm(join(dir, 'tls'), { recursive: true, force: true });\n\t// Env files stay on this machine: compose reads each one here and sends\n\t// its values in the call that creates the container — on a server's\n\t// engine too, where no secret is ever written as a file.\n\tfor (const app of [...stack.apps, ...stack.workers, ...stack.processors]) {\n\t\tif (app.env)\n\t\t\tawait write(join(dir, `${app.name}.env`), envFile(app.env), 0o600);\n\t}\n\t// A stack that only builds reads no env file, so none is written.\n\tif (stack.logs && stack.compose.services[LOGS_SERVICE]?.env_file) {\n\t\tawait write(\n\t\t\tjoin(dir, `${LOGS_SERVICE}.env`),\n\t\t\tenvFile(stack.logs.env),\n\t\t\t0o600,\n\t\t);\n\t}\n\tif (stack.redis && stack.compose.services[REDIS_SERVICE]?.env_file) {\n\t\tawait write(\n\t\t\tjoin(dir, `${REDIS_SERVICE}.env`),\n\t\t\tenvFile(stack.redis.env),\n\t\t\t0o600,\n\t\t);\n\t}\n\t// The backups image's build context, and its key — read from its own env\n\t// file like any app's, never from the host.\n\tif (stack.backups) {\n\t\tfor (const [name, content] of Object.entries(stack.backups.files)) {\n\t\t\tawait write(join(dir, BACKUPS_SERVICE, name), content);\n\t\t}\n\t\tif (stack.compose.services[BACKUPS_SERVICE]?.env_file) {\n\t\t\tawait write(\n\t\t\t\tjoin(dir, `${BACKUPS_SERVICE}.env`),\n\t\t\t\tenvFile(stack.backups.env),\n\t\t\t\t0o600,\n\t\t\t);\n\t\t}\n\t} else {\n\t\tawait rm(join(dir, BACKUPS_SERVICE), { recursive: true, force: true });\n\t\tawait rm(join(dir, `${BACKUPS_SERVICE}.env`), { force: true });\n\t}\n\t// Images no longer embed a stage's credentials. The ciphertexts an older\n\t// gkm left beside the compose file for them to embed are removed.\n\tfor (const entry of await readdir(dir)) {\n\t\tif (entry.endsWith('.credentials')) await rm(join(dir, entry));\n\t}\n\tfor (const [path, content] of Object.entries(stack.dockerfiles)) {\n\t\tawait write(join(root, path), content);\n\t}\n\n\t// The build context is the build root, and the env files are under it:\n\t// its ignore file is what keeps a stage's secrets out of every image's\n\t// context.\n\tawait ensureDockerignore(findBuildRoot(root));\n\n\treturn files;\n}\n\nfunction composeYaml(\n\tstack: ComposeStack,\n\tcompose: ComposeStack['compose'],\n): string {\n\tconst stage = ` --stage ${stack.stage}`;\n\treturn `# Generated by gkm compose from the construct manifest — do not edit.\n# The ${stack.stage} stage's APIs and sites behind ${stack.proxy === 'caddy' ? 'one Caddy' : `the shared Traefik edge (${EDGE_PROJECT})`}, and its workers.\n# Each backend and worker reads exactly the keys in its own env file beside\n# this one.\n#\n# gkm compose${stage} start or update it\n# gkm compose${stage} --down stop it\n${stringify(compose, { lineWidth: 0, aliasDuplicateObjects: false })}`;\n}\n\nfunction printPlan(ctx: ComposeContext, run: ComposeRun): void {\n\tconst { stack, mode, files } = run;\n\tctx.logger.info(`\\n🧱 ${stack.project} — stage ${stack.stage}`);\n\tif (run.server) {\n\t\tctx.logger.info(` → ${sshTarget(run.server)} (docker over ssh)`);\n\t}\n\tfor (const app of stack.apps) {\n\t\tctx.logger.info(\n\t\t\t` ${app.name.padEnd(12)} ${app.url.padEnd(40)} ${mode} ${app.ref}`,\n\t\t);\n\t}\n\tfor (const worker of stack.workers) {\n\t\tctx.logger.info(\n\t\t\t` ${worker.name.padEnd(12)} ${`worker ${worker.id} (no route)`.padEnd(40)} ${mode} ${worker.ref}`,\n\t\t);\n\t}\n\tfor (const unit of stack.processors) {\n\t\tctx.logger.info(\n\t\t\t` ${unit.name.padEnd(12)} ${`processors of ${unit.id}`.padEnd(40)} ${mode} ${unit.ref}`,\n\t\t);\n\t}\n\tif (stack.infra.length > 0) {\n\t\tctx.logger.info(` infrastructure: ${stack.infra.join(', ')}`);\n\t}\n\tif (stack.backups) {\n\t\tctx.logger.info(\n\t\t\t` ${BACKUPS_SERVICE.padEnd(12)} ${stack.backups.databases.map((d) => d.file).join(', ')} — ${stack.backups.backups.describe}, to ${stack.backups.prefix}/`,\n\t\t);\n\t}\n\tctx.logger.info(\n\t\t`\\n📝 Wrote ${files.length} file(s) under ${stackDir(stack.stage)}/`,\n\t);\n}\n","/**\n * The built-in `compose` target: a stage as one Docker Compose stack behind\n * Caddy — the local stage on the machine that runs the deploy, a deployed\n * stage on its server's Docker engine, over SSH (`deploy.compose.server`).\n *\n * ```bash\n * gkm deploy --target compose --stage production --tag v1.4.0 # what CI pushed\n * gkm deploy --target compose --stage production # built from here\n * gkm deploy --target compose --stage development # the local stage\n * ```\n *\n * - `validate`: the stack (`composeStack`, pure) and, for a tag, every image\n * looked up in the registry — `ImageTagNotFound` before anything changes\n * - `ready`: a deploy's own checks, after the stage's keys are — the stage's\n * certificate, its server's address, and every public host's DNS\n * - `plan`: the stack's files and what a run would create or reuse\n * - `provision`: generated secrets kept, files written, infrastructure up,\n * databases, roles, grants and migrations\n * - `build`: each backend bundled on the host and every image built — or, for\n * a tag, pulled\n * - `release`: the stack's routes on the shared edge, then `up --wait\n * --remove-orphans`, and each app's image, tag and digest in the stage's\n * state — an app that never turns healthy fails it only once the rest is\n * released and routed\n * - `verify`: each app asked through Caddy over HTTPS, then each\n * server-rendered site warmed — its `/` and its sitemap's pages asked, a\n * failure only warned of\n *\n * With `push` (`gkm compose --build --push`), run with `buildOnly`, it builds\n * every image and pushes it to `deploy.registry`, and does nothing else: no\n * readiness check runs, so a stage whose keys the deploy has yet to write\n * still builds.\n *\n * `gkm compose` is this target with a few more switches (`--build`, `--pull`,\n * `--down`), run through the same `deploy()`.\n */\n\nimport { defineTarget } from '../define';\nimport type { DeployTarget } from '../types';\nimport {\n\tbuildCompose,\n\ttype ComposeDeps,\n\ttype ComposeRun,\n\ttype ComposeRunOptions,\n\tcomposeResult,\n\tdefaultDeps,\n\tplanCompose,\n\tprovisionCompose,\n\treadyCompose,\n\treleaseCompose,\n\tvalidateCompose,\n\tverifyCompose,\n} from './phases';\n\nexport {\n\tComposeAppsUnhealthy,\n\ttype HealthProbe,\n\ttype HealthRequest,\n\tHealthRequestTimedOut,\n} from './health';\nexport {\n\ttype ComposeDeps,\n\ttype ComposeImage,\n\tComposePinNeedsPull,\n\tComposePushNeedsBuild,\n\ttype ComposeRun,\n\ttype ComposeRunOptions,\n\tEdgePortInvalid,\n\tedgePorts,\n\tgitRevision,\n\tNoGitRevision,\n\tRedisClientMissing,\n\tstackOverrideFile,\n} from './phases';\n\nexport interface ComposeTargetOptions\n\textends Partial<ComposeDeps>,\n\t\tComposeRunOptions {\n\t/** Handed the finished run — `gkm compose` prints and returns from it. */\n\treport?: (run: ComposeRun) => void;\n}\n\n/** The compose target, with its Docker, bundler and probe as given. */\nexport function composeTarget(\n\toptions: ComposeTargetOptions = {},\n): DeployTarget<undefined, ComposeRun> {\n\tconst { mode, push, pin, report, ...given } = options;\n\tconst deps: ComposeDeps = { ...defaultDeps, ...given };\n\n\treturn defineTarget<undefined, ComposeRun>({\n\t\tname: 'compose',\n\t\truntime: 'server',\n\t\tcapabilities: {\n\t\t\trollback: false,\n\t\t\tmigrations: 'target',\n\t\t\timages: true,\n\t\t\t// The local stage runs where the deploy does — the `gkm dev`\n\t\t\t// hostnames, behind gkm's local CA.\n\t\t\tlocalStage: true,\n\t\t\t// OpenObserve, in the stack, on loopback.\n\t\t\tselfHostedTelemetry: true,\n\t\t},\n\t\t// Images are pulled with this machine's own `docker login`, which\n\t\t// docker sends with each pull — on a server's engine too.\n\t\tcredentials: [],\n\t\t// Built from the checkout, an image is named after its commit.\n\t\ttag: ({ cwd }) => deps.revision(cwd),\n\t\tvalidate: (ctx) =>\n\t\t\tvalidateCompose(ctx, deps, {\n\t\t\t\t...(mode ? { mode } : {}),\n\t\t\t\t...(push ? { push } : {}),\n\t\t\t\t...(pin ? { pin } : {}),\n\t\t\t}),\n\t\tready: (ctx, run) => readyCompose(ctx, run, deps),\n\t\tplan: (ctx, run) => planCompose(ctx, run),\n\t\tprovision: (ctx, run) => provisionCompose(ctx, run, deps),\n\t\tbuild: (ctx, run) => buildCompose(ctx, run, deps),\n\t\trelease: (ctx, run) => releaseCompose(ctx, run, deps),\n\t\tverify: (ctx, run) => verifyCompose(ctx, run, deps),\n\t\tresult: (ctx, run) => {\n\t\t\treport?.(run);\n\t\t\treturn composeResult(ctx, run);\n\t\t},\n\t});\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiDA,MAAM,QAAsE;CAC3E,SAAS;CACT,QAAQ;EAAC;EAAU;EAAG;CAAC;CACvB,QAAQ;AACT;;;;;AAMA,SAAgB,UACf,QACA,QAA2B,CAAC,GACI;CAChC,IAAI,CAAC,OAAO,QAAQ,OAAO,KAAK,KAAK,CAAC,CAAC,WAAW,GAAG,OAAO,KAAA;CAC5D,OAAO;EACN,GAAG,QAAQ;EACX,GAAG;EACH,GAAI,OAAO,OAAO,EAAE,aAAa,OAAO,KAAK,IAAI,CAAC;CACnD;AACD;;AAGA,SAAS,WAAW,OAAiB,OAAuC;CAC3E,MAAM,MAAM,UAAU,OAAO,KAAK;CAClC,OAAO;EACN,KAAK,MAAM;EACX,OAAO,MAAM,MAAM,UAAU;EAC7B,GAAI,MAAM,EAAE,IAAI,IAAI,CAAC;EACrB,GAAI,MAAM,SAAS,EAAE,QAAQ,MAAM,OAAO,IAAI,CAAC;CAChD;AACD;;AAkHA,SAAgB,eAAe,SAAyB;CACvD,OAAO,GAAG,QAAQ;AACnB;;;;;AAMA,SAAgB,eAAe,QAA0B;CACxD,MAAM,wBAAQ,IAAI,IAAY;CAC9B,KAAK,MAAM,SAAS,OAAO,SAC1B,2CACD,GAAG;EACF,MAAM,QAAQ,OAAO,MAAM,EAAE;EAC7B,MAAM,OAAO,MAAM,KAAK,OAAO,MAAM,EAAE,IAAI;E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AAC;EACF,QAAQ,KAAK,QAAQ,aAAa,KAAK,KAAK,IAAI;EAChD,OAAO,KAAK,QAAQ,YAAY,KAAK,GAAG;EACxC,YAAY,KAAK,QAAQ,iBAAiB,KAAK,KAAK,IAAI;EACxD,QAAQ,KAAK,QAAQ,aAAa,KAAK,KAAK,IAAI;EAChD,UAAU,KAAK,QAAQ,eAAe,KAAK,KAAK,IAAI;EACpD,SAAS,KAAK,QAAQ,cAAc,KAAK,KAAK,IAAI;EAClD,SAAS,KAAK,QAAQ;GACrB,SAAS,GAAG;GACZ,OAAO,cAAc,KAAK,GAAG;EAC9B;CACD,CAAC;AACF"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const require_errors = require("./errors-DMC4Umsb.cjs");
|
|
2
|
-
const require_credentials = require("./credentials-
|
|
3
|
-
const require_workspace = require("./workspace-
|
|
4
|
-
const require_config = require("./config-
|
|
2
|
+
const require_credentials = require("./credentials-D11xozSF.cjs");
|
|
3
|
+
const require_workspace = require("./workspace-1szcahj9.cjs");
|
|
4
|
+
const require_config = require("./config-juUyBlb1.cjs");
|
|
5
5
|
let node_path = require("node:path");
|
|
6
6
|
let node_fs = require("node:fs");
|
|
7
7
|
let node_fs_promises = require("node:fs/promises");
|
|
@@ -1178,7 +1178,7 @@ async function prepareEntryCredentials(options) {
|
|
|
1178
1178
|
const declaredKeys = [];
|
|
1179
1179
|
let reconciled;
|
|
1180
1180
|
if (workspace) {
|
|
1181
|
-
const { reconcileWorkspace } = await Promise.resolve().then(() => require("./apps-
|
|
1181
|
+
const { reconcileWorkspace } = await Promise.resolve().then(() => require("./apps-BIsxWYUo.cjs")).then((n) => n.workspace_exports);
|
|
1182
1182
|
reconciled = await reconcileWorkspace(workspace, {
|
|
1183
1183
|
stage: options.reconcileStage ?? workspace.stages.local,
|
|
1184
1184
|
start: options.startDocker ?? false
|
|
@@ -1892,4 +1892,4 @@ Object.defineProperty(exports, "withRedisPassword", {
|
|
|
1892
1892
|
}
|
|
1893
1893
|
});
|
|
1894
1894
|
|
|
1895
|
-
//# sourceMappingURL=compose-
|
|
1895
|
+
//# sourceMappingURL=compose-Cius-YHS.cjs.map
|