@geekmidas/cli 10.0.0-alpha.94 → 10.0.0-alpha.95

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.
Files changed (192) hide show
  1. package/dist/{GoDaddyProvider-BRZUWD8z.mjs → GoDaddyProvider-BwW51hPm.mjs} +3 -3
  2. package/dist/{GoDaddyProvider-BRZUWD8z.mjs.map → GoDaddyProvider-BwW51hPm.mjs.map} +1 -1
  3. package/dist/{GoDaddyProvider-DzguxU_a.cjs → GoDaddyProvider-C_DgIkMv.cjs} +3 -3
  4. package/dist/{GoDaddyProvider-DzguxU_a.cjs.map → GoDaddyProvider-C_DgIkMv.cjs.map} +1 -1
  5. package/dist/{HostingerProvider-Cjh_2Ml6.mjs → HostingerProvider-BNpS9aRJ.mjs} +2 -2
  6. package/dist/{HostingerProvider-Cjh_2Ml6.mjs.map → HostingerProvider-BNpS9aRJ.mjs.map} +1 -1
  7. package/dist/{HostingerProvider-OdQmKXE3.cjs → HostingerProvider-DR1iws1P.cjs} +2 -2
  8. package/dist/{HostingerProvider-OdQmKXE3.cjs.map → HostingerProvider-DR1iws1P.cjs.map} +1 -1
  9. package/dist/{LegacyStateStore-D50dgUPc.cjs → LegacyStateStore-BawjE_5n.cjs} +3 -3
  10. package/dist/{LegacyStateStore-D50dgUPc.cjs.map → LegacyStateStore-BawjE_5n.cjs.map} +1 -1
  11. package/dist/{LegacyStateStore-BQZb6-j2.mjs → LegacyStateStore-D5DarNA2.mjs} +3 -3
  12. package/dist/{LegacyStateStore-BQZb6-j2.mjs.map → LegacyStateStore-D5DarNA2.mjs.map} +1 -1
  13. package/dist/{LocalStateStore-EFBUjuMX.cjs → LocalStateStore-D8fu5WiF.cjs} +2 -2
  14. package/dist/{LocalStateStore-EFBUjuMX.cjs.map → LocalStateStore-D8fu5WiF.cjs.map} +1 -1
  15. package/dist/{LocalStateStore-BSaS2535.mjs → LocalStateStore-YjIqlgAz.mjs} +2 -2
  16. package/dist/{LocalStateStore-BSaS2535.mjs.map → LocalStateStore-YjIqlgAz.mjs.map} +1 -1
  17. package/dist/{S3StateStore-CrFq4UZU.mjs → S3StateStore-CjTAVsWh.mjs} +2 -2
  18. package/dist/{S3StateStore-CrFq4UZU.mjs.map → S3StateStore-CjTAVsWh.mjs.map} +1 -1
  19. package/dist/{S3StateStore-C5mv8To3.cjs → S3StateStore-Cm-v2IPI.cjs} +2 -2
  20. package/dist/{S3StateStore-C5mv8To3.cjs.map → S3StateStore-Cm-v2IPI.cjs.map} +1 -1
  21. package/dist/{SSMStateStore-DuZCH7_v.cjs → SSMStateStore-BS4BiZCN.cjs} +2 -2
  22. package/dist/{SSMStateStore-DuZCH7_v.cjs.map → SSMStateStore-BS4BiZCN.cjs.map} +1 -1
  23. package/dist/{SSMStateStore-D3Z6mZnA.mjs → SSMStateStore-BhtM6jOh.mjs} +2 -2
  24. package/dist/{SSMStateStore-D3Z6mZnA.mjs.map → SSMStateStore-BhtM6jOh.mjs.map} +1 -1
  25. package/dist/{add-DsVDdvon.cjs → add-D-3IKT7W.cjs} +22 -51
  26. package/dist/add-D-3IKT7W.cjs.map +1 -0
  27. package/dist/{add-C85isXFl.mjs → add-ylx8dejw.mjs} +21 -50
  28. package/dist/add-ylx8dejw.mjs.map +1 -0
  29. package/dist/{bundler-BEgUKc4j.cjs → bundler-CI3elfZS.cjs} +5 -5
  30. package/dist/{bundler-BEgUKc4j.cjs.map → bundler-CI3elfZS.cjs.map} +1 -1
  31. package/dist/{bundler-BSHog8CH.mjs → bundler-ywR3C1B_.mjs} +5 -5
  32. package/dist/{bundler-BSHog8CH.mjs.map → bundler-ywR3C1B_.mjs.map} +1 -1
  33. package/dist/{cli-BsFenyaf.mjs → cli-BCSuCfQk.mjs} +4 -4
  34. package/dist/{cli-BsFenyaf.mjs.map → cli-BCSuCfQk.mjs.map} +1 -1
  35. package/dist/{cli-BvBdv660.cjs → cli-Dewt2T21.cjs} +4 -4
  36. package/dist/{cli-BvBdv660.cjs.map → cli-Dewt2T21.cjs.map} +1 -1
  37. package/dist/{compose-D2RFYd_f.mjs → compose-C4js1JDv.mjs} +42 -46
  38. package/dist/compose-C4js1JDv.mjs.map +1 -0
  39. package/dist/{compose-Cd09gW-n.cjs → compose-Dd0XphvF.cjs} +59 -63
  40. package/dist/compose-Dd0XphvF.cjs.map +1 -0
  41. package/dist/{config-Ngesg4O8.d.mts → config-4yirvxS8.d.cts} +4 -4
  42. package/dist/{config-DvHNMoOp.d.cts.map → config-4yirvxS8.d.cts.map} +1 -1
  43. package/dist/{config-DvHNMoOp.d.cts → config-C8NPCn1l.d.mts} +4 -4
  44. package/dist/{config-Ngesg4O8.d.mts.map → config-C8NPCn1l.d.mts.map} +1 -1
  45. package/dist/config.d.cts +3 -3
  46. package/dist/config.d.mts +3 -3
  47. package/dist/{credentials-DpfnUvIR.mjs → credentials-B5N5yKk6.mjs} +4 -132
  48. package/dist/credentials-B5N5yKk6.mjs.map +1 -0
  49. package/dist/{credentials-D7XJypNd.cjs → credentials-Zqr3QQYB.cjs} +3 -173
  50. package/dist/credentials-Zqr3QQYB.cjs.map +1 -0
  51. package/dist/deploy/public.cjs +15 -14
  52. package/dist/deploy/public.cjs.map +1 -1
  53. package/dist/deploy/public.d.cts +5 -5
  54. package/dist/deploy/public.d.cts.map +1 -1
  55. package/dist/deploy/public.d.mts +5 -5
  56. package/dist/deploy/public.d.mts.map +1 -1
  57. package/dist/deploy/public.mjs +10 -9
  58. package/dist/deploy/public.mjs.map +1 -1
  59. package/dist/{providers-sTj-BG0S.mjs → deploy-B0drCD6s.mjs} +898 -123
  60. package/dist/deploy-B0drCD6s.mjs.map +1 -0
  61. package/dist/{providers-BFeP_mYw.cjs → deploy-Bw1FjX_x.cjs} +939 -134
  62. package/dist/deploy-Bw1FjX_x.cjs.map +1 -0
  63. package/dist/{discover-CTzOSGUF.d.cts → discover-BtFofyQB.d.cts} +2 -2
  64. package/dist/{discover-CTzOSGUF.d.cts.map → discover-BtFofyQB.d.cts.map} +1 -1
  65. package/dist/{discover-CihAtaoj.d.mts → discover-D-MdXZgm.d.mts} +2 -2
  66. package/dist/{discover-CihAtaoj.d.mts.map → discover-D-MdXZgm.d.mts.map} +1 -1
  67. package/dist/dns-Bmk7P9c2.cjs +663 -0
  68. package/dist/dns-Bmk7P9c2.cjs.map +1 -0
  69. package/dist/dns-CyMIq6to.cjs +55 -0
  70. package/dist/dns-CyMIq6to.cjs.map +1 -0
  71. package/dist/dns-X3oqEV4C.mjs +44 -0
  72. package/dist/dns-X3oqEV4C.mjs.map +1 -0
  73. package/dist/dns-idXfyCay.mjs +610 -0
  74. package/dist/dns-idXfyCay.mjs.map +1 -0
  75. package/dist/{dokploy-D_aat2Xj.mjs → dokploy-CZYxXeMa.mjs} +2 -2
  76. package/dist/{dokploy-D_aat2Xj.mjs.map → dokploy-CZYxXeMa.mjs.map} +1 -1
  77. package/dist/{dokploy-CV7GcobZ.cjs → dokploy-DaT0mgLU.cjs} +2 -2
  78. package/dist/{dokploy-CV7GcobZ.cjs.map → dokploy-DaT0mgLU.cjs.map} +1 -1
  79. package/dist/{encryption-_4qKqtTx.mjs → encryption-D0ucY4O7.mjs} +2 -2
  80. package/dist/{encryption-_4qKqtTx.mjs.map → encryption-D0ucY4O7.mjs.map} +1 -1
  81. package/dist/{encryption-DFcivJaO.cjs → encryption-Dp0IvLVX.cjs} +2 -2
  82. package/dist/{encryption-DFcivJaO.cjs.map → encryption-Dp0IvLVX.cjs.map} +1 -1
  83. package/dist/{engine-DPMHThkg.mjs → engine-BcuhnyQO.mjs} +13 -31
  84. package/dist/{engine-DPMHThkg.mjs.map → engine-BcuhnyQO.mjs.map} +1 -1
  85. package/dist/{engine-Bv-LZpmj.cjs → engine-WY6j_kvA.cjs} +17 -35
  86. package/dist/engine-WY6j_kvA.cjs.map +1 -0
  87. package/dist/{github-xsDT19im.mjs → github-DUGA57du.mjs} +4 -2
  88. package/dist/{github-xsDT19im.mjs.map → github-DUGA57du.mjs.map} +1 -1
  89. package/dist/{github-Br42NMrW.cjs → github-DgmW83OP.cjs} +8 -6
  90. package/dist/{github-Br42NMrW.cjs.map → github-DgmW83OP.cjs.map} +1 -1
  91. package/dist/{index-CwLvFqtH.d.cts → index-5eL8rM6H.d.mts} +2 -2
  92. package/dist/{index-BlpcClwM.d.mts.map → index-5eL8rM6H.d.mts.map} +1 -1
  93. package/dist/{index-BlpcClwM.d.mts → index-Dz-gyjm_.d.cts} +2 -2
  94. package/dist/{index-CwLvFqtH.d.cts.map → index-Dz-gyjm_.d.cts.map} +1 -1
  95. package/dist/index.cjs +53 -52
  96. package/dist/index.cjs.map +1 -1
  97. package/dist/index.mjs +51 -50
  98. package/dist/index.mjs.map +1 -1
  99. package/dist/{local-B7Zv1NoA.mjs → local-BwC2v2Y8.mjs} +2 -2
  100. package/dist/{local-B7Zv1NoA.mjs.map → local-BwC2v2Y8.mjs.map} +1 -1
  101. package/dist/{local-OPC9BCZt.cjs → local-DNhnkugT.cjs} +3 -3
  102. package/dist/{local-OPC9BCZt.cjs.map → local-DNhnkugT.cjs.map} +1 -1
  103. package/dist/{migrate-SkWJotn5.cjs → migrate-BBcG1dhS.cjs} +2 -2
  104. package/dist/{migrate-SkWJotn5.cjs.map → migrate-BBcG1dhS.cjs.map} +1 -1
  105. package/dist/{migrate-DhvFPGLi.mjs → migrate-CZ-v5WV0.mjs} +2 -2
  106. package/dist/{migrate-DhvFPGLi.mjs.map → migrate-CZ-v5WV0.mjs.map} +1 -1
  107. package/dist/{migrate-B7evHv7O.mjs → migrate-D6PlNv2o.mjs} +2 -2
  108. package/dist/{migrate-B7evHv7O.mjs.map → migrate-D6PlNv2o.mjs.map} +1 -1
  109. package/dist/{migrate-D5jUz20_.cjs → migrate-afgRL3Hg.cjs} +2 -2
  110. package/dist/{migrate-D5jUz20_.cjs.map → migrate-afgRL3Hg.cjs.map} +1 -1
  111. package/dist/openapi.d.cts +1 -1
  112. package/dist/openapi.d.mts +1 -1
  113. package/dist/reconcile/public.d.cts +2 -2
  114. package/dist/reconcile/public.d.mts +2 -2
  115. package/dist/{resolve-CFEOtRsl.cjs → resolve-CFb4Navi.cjs} +4 -4
  116. package/dist/{resolve-CFEOtRsl.cjs.map → resolve-CFb4Navi.cjs.map} +1 -1
  117. package/dist/{resolve-Dyd1S2wn.mjs → resolve-DakDhr6Z.mjs} +4 -4
  118. package/dist/{resolve-Dyd1S2wn.mjs.map → resolve-DakDhr6Z.mjs.map} +1 -1
  119. package/dist/{rollback-D720SFhV.cjs → rollback-B-1dPP0m.cjs} +7 -8
  120. package/dist/{rollback-D720SFhV.cjs.map → rollback-B-1dPP0m.cjs.map} +1 -1
  121. package/dist/{rollback-NroNbGC0.mjs → rollback-B1TIpjdE.mjs} +6 -7
  122. package/dist/{rollback-NroNbGC0.mjs.map → rollback-B1TIpjdE.mjs.map} +1 -1
  123. package/dist/run-BJLIerMM.mjs +133 -0
  124. package/dist/run-BJLIerMM.mjs.map +1 -0
  125. package/dist/run-fVZ-rLnc.cjs +174 -0
  126. package/dist/run-fVZ-rLnc.cjs.map +1 -0
  127. package/dist/{runtime-VktAo_8B.d.cts → runtime-DUQdM-mW.d.cts} +2 -2
  128. package/dist/{runtime-BRCq6dQ7.d.mts.map → runtime-DUQdM-mW.d.cts.map} +1 -1
  129. package/dist/{runtime-BRCq6dQ7.d.mts → runtime-Vr6mleo2.d.mts} +2 -2
  130. package/dist/{runtime-VktAo_8B.d.cts.map → runtime-Vr6mleo2.d.mts.map} +1 -1
  131. package/dist/{sandbox-D1gd0iDz.d.cts → sandbox-BbJmh2rI.d.cts} +2 -2
  132. package/dist/{sandbox-D1gd0iDz.d.cts.map → sandbox-BbJmh2rI.d.cts.map} +1 -1
  133. package/dist/{sandbox-zHnRLCj0.d.mts → sandbox-DGOsMPMf.d.mts} +2 -2
  134. package/dist/{sandbox-zHnRLCj0.d.mts.map → sandbox-DGOsMPMf.d.mts.map} +1 -1
  135. package/dist/{secrets-DAvi_O9g.cjs → secrets-CPM0Qffe.cjs} +2 -2
  136. package/dist/{secrets-DAvi_O9g.cjs.map → secrets-CPM0Qffe.cjs.map} +1 -1
  137. package/dist/{secrets-CwLauUB_.mjs → secrets-oI9ClAPR.mjs} +2 -2
  138. package/dist/{secrets-CwLauUB_.mjs.map → secrets-oI9ClAPR.mjs.map} +1 -1
  139. package/dist/{seeds-BCg8X36S.cjs → seeds-CnXkgKUv.cjs} +192 -945
  140. package/dist/seeds-CnXkgKUv.cjs.map +1 -0
  141. package/dist/{seeds-CTxTZa-R.mjs → seeds-CoKkrSny.mjs} +156 -825
  142. package/dist/seeds-CoKkrSny.mjs.map +1 -0
  143. package/dist/{sniffer-DCcuzHz_.mjs → sniffer-CFRzIrby.mjs} +7 -7
  144. package/dist/{sniffer-DCcuzHz_.mjs.map → sniffer-CFRzIrby.mjs.map} +1 -1
  145. package/dist/{sniffer-C0z3NB2A.cjs → sniffer-vbiQ2Isn.cjs} +7 -7
  146. package/dist/{sniffer-C0z3NB2A.cjs.map → sniffer-vbiQ2Isn.cjs.map} +1 -1
  147. package/dist/{sst-DRDSDwOk.mjs → sst-CGdjHn2A.mjs} +4 -3
  148. package/dist/{sst-DRDSDwOk.mjs.map → sst-CGdjHn2A.mjs.map} +1 -1
  149. package/dist/{sst-DKNH243z.cjs → sst-DGuHDxVU.cjs} +5 -4
  150. package/dist/{sst-DKNH243z.cjs.map → sst-DGuHDxVU.cjs.map} +1 -1
  151. package/dist/{stack-B3fPDTBg.cjs → stack-1g57OfOw.cjs} +13 -51
  152. package/dist/stack-1g57OfOw.cjs.map +1 -0
  153. package/dist/{stack-NrdH5ngX.mjs → stack-B7O975TR.mjs} +13 -51
  154. package/dist/stack-B7O975TR.mjs.map +1 -0
  155. package/dist/{stages-veC4TcQe.mjs → stages-Bt4OggMm.mjs} +3 -2
  156. package/dist/{stages-veC4TcQe.mjs.map → stages-Bt4OggMm.mjs.map} +1 -1
  157. package/dist/{stages-CkqP1N4S.cjs → stages-BujUB4we.cjs} +4 -3
  158. package/dist/{stages-CkqP1N4S.cjs.map → stages-BujUB4we.cjs.map} +1 -1
  159. package/dist/target/public.cjs +1 -1
  160. package/dist/target/public.d.cts +2 -2
  161. package/dist/target/public.d.mts +2 -2
  162. package/dist/target/public.mjs +1 -1
  163. package/dist/{terminal-CkUYuAPd.cjs → terminal-CPHuH4S1.cjs} +2 -2
  164. package/dist/{terminal-CkUYuAPd.cjs.map → terminal-CPHuH4S1.cjs.map} +1 -1
  165. package/dist/{terminal-DAHs2Zko.mjs → terminal-iNmAXXjs.mjs} +2 -2
  166. package/dist/{terminal-DAHs2Zko.mjs.map → terminal-iNmAXXjs.mjs.map} +1 -1
  167. package/dist/{types-DMoaFrjg.d.mts → types-bkqVscdN.d.mts} +12 -3
  168. package/dist/types-bkqVscdN.d.mts.map +1 -0
  169. package/dist/{types-DXyaSmqu.d.cts → types-dipJRmKV.d.cts} +12 -3
  170. package/dist/types-dipJRmKV.d.cts.map +1 -0
  171. package/dist/workspace/index.d.cts +2 -2
  172. package/dist/workspace/index.d.mts +2 -2
  173. package/package.json +15 -15
  174. package/dist/add-C85isXFl.mjs.map +0 -1
  175. package/dist/add-DsVDdvon.cjs.map +0 -1
  176. package/dist/compose-Cd09gW-n.cjs.map +0 -1
  177. package/dist/compose-D2RFYd_f.mjs.map +0 -1
  178. package/dist/credentials-D7XJypNd.cjs.map +0 -1
  179. package/dist/credentials-DpfnUvIR.mjs.map +0 -1
  180. package/dist/deploy-C911Akkn.cjs +0 -670
  181. package/dist/deploy-C911Akkn.cjs.map +0 -1
  182. package/dist/deploy-CeJ5D0xn.mjs +0 -641
  183. package/dist/deploy-CeJ5D0xn.mjs.map +0 -1
  184. package/dist/engine-Bv-LZpmj.cjs.map +0 -1
  185. package/dist/providers-BFeP_mYw.cjs.map +0 -1
  186. package/dist/providers-sTj-BG0S.mjs.map +0 -1
  187. package/dist/seeds-BCg8X36S.cjs.map +0 -1
  188. package/dist/seeds-CTxTZa-R.mjs.map +0 -1
  189. package/dist/stack-B3fPDTBg.cjs.map +0 -1
  190. package/dist/stack-NrdH5ngX.mjs.map +0 -1
  191. package/dist/types-DMoaFrjg.d.mts.map +0 -1
  192. package/dist/types-DXyaSmqu.d.cts.map +0 -1
@@ -1,125 +1,82 @@
1
1
  import { t as GkmError } from "./errors-D8Gwp5kU.mjs";
2
- import { r as storedCredentials } from "./credentials-DpfnUvIR.mjs";
3
- import { t as appKey } from "./derive-B4vDpzgP.mjs";
4
- import { $ as RotationInProgress, G as checkS3Config, J as BucketNameUnavailable, K as AccessKeyLimit, Q as RecordedBucketUnreachable, U as stageProvider, W as S3_PROVISIONING, X as IamUserNotOwned, Y as BucketOwnedByAnotherProject, Z as ProvisionedBucketUnreachable, et as S3RegionRequired, q as BucketKeySetElsewhere } from "./workspace-DWK1PTXP.mjs";
5
- import { F as iamUserName, H as PROVIDER_KINDS, I as randomSuffix, L as suffixedBucketName, M as IAM_POLICY_NAME, N as IAM_USER_PATH, P as bucketName, U as deploysWithCompose, Xt as appEnvKeys, Zn as deployIdentity, _r as resolveHost, gr as isMainFrontendApp, hr as NoDomainForStage, ir as initStageSecrets, it as createEmptyState, rt as createComposeState, z as assertStageProvidersEnabled } from "./seeds-CTxTZa-R.mjs";
6
- import { dependentsOf, provideKey } from "@geekmidas/manifest";
2
+ import { s as gkmHome } from "./run-BJLIerMM.mjs";
3
+ import { r as storedCredentials } from "./credentials-B5N5yKk6.mjs";
4
+ import { f as withOutput, r as discover } from "./discover-qjFapetL.mjs";
5
+ import { c as withSandbox } from "./sandbox-CbVB7uOD.mjs";
6
+ import { n as derivedApps, t as appKey } from "./derive-B4vDpzgP.mjs";
7
+ import { $ as RotationInProgress, G as checkS3Config, J as BucketNameUnavailable, K as AccessKeyLimit, L as resolveStageTelemetry, N as assertDeployedStage, Q as RecordedBucketUnreachable, U as stageProvider, W as S3_PROVISIONING, X as IamUserNotOwned, Y as BucketOwnedByAnotherProject, Z as ProvisionedBucketUnreachable, et as S3RegionRequired, q as BucketKeySetElsewhere, u as getAppBuildOrder } from "./workspace-DWK1PTXP.mjs";
8
+ import { o as builtinTarget } from "./define-6poNqm5O.mjs";
9
+ import { findWorkspaceRoot, loadWorkspaceConfig } from "./config.mjs";
10
+ import { E as reportDevServices, F as DeployJournal, H as createComposeState, In as applicationName, It as appEnvKeys, Ln as deployIdentity, N as stageProviderNotes, O as stageServiceDeclarations, On as secretsStoreFor, P as PROVIDER_KINDS, T as externalServices, U as createEmptyState, Wn as initStageSecrets, b as DevServicesNeedServerTarget, ct as constructGlobs, fn as usesTelemetry, j as assertStageProvidersEnabled, nr as isMainFrontendApp, rr as resolveHost, tr as NoDomainForStage, w as devServicesUsed, x as ExternalServicesNotConfigured } from "./seeds-CoKkrSny.mjs";
11
+ import { a as parseTargetOptions, o as resolveTarget } from "./resolve-DakDhr6Z.mjs";
12
+ import { t as LocalSandbox } from "./local-BwC2v2Y8.mjs";
13
+ import { S as eventError, _ as assertStateOutlivesRun, y as createStateStore } from "./sniffer-CFRzIrby.mjs";
14
+ import { c as stageDnsDomains, n as dnsCredentials } from "./dns-idXfyCay.mjs";
15
+ import { t as deploysWithCompose } from "./dns-X3oqEV4C.mjs";
16
+ import { n as assertStageCredentials } from "./credentialSchemas-BJFvfkaz.mjs";
17
+ import { resolve } from "node:path";
18
+ import { dependentsOf, kebabCase, provideKey, providedKeyFor } from "@geekmidas/manifest";
19
+ import { randomInt } from "node:crypto";
7
20
  import * as s3Url from "@geekmidas/storage/s3-url";
8
- //#region src/deploy/journal.ts
9
- var DeployJournal = class DeployJournal {
10
- store;
11
- stage;
12
- state;
13
- resources;
14
- version;
15
- existed;
16
- constructor(store, stage, state, resources, version, existed) {
17
- this.store = store;
18
- this.stage = stage;
19
- this.state = state;
20
- this.resources = resources;
21
- this.version = version;
22
- this.existed = existed;
23
- }
24
- static async open(store, stage, initial, adopt = (stored) => stored) {
25
- const stored = await store.read(stage);
26
- if (stored) return new DeployJournal(store, stage, adopt(stored.state), stored.resources, stored.version, true);
27
- const state = initial();
28
- const version = await store.write(stage, state, { expectedVersion: null });
29
- return new DeployJournal(store, stage, state, {}, version, false);
30
- }
31
- record(key) {
32
- return this.resources[key];
33
- }
34
- /** The keys a previous run marked `pending` and never saw created. */
35
- unfinished() {
36
- return Object.values(this.resources).filter((record) => record.status === "pending").map((record) => record.key);
37
- }
38
- /** Records that `entry` is about to be created. */
39
- async pending(entry) {
40
- await this.put({
41
- ...entry,
42
- status: "pending"
43
- });
44
- }
45
- /**
46
- * Records `entry` as existing with `id`; a no-op if it already is, with
47
- * the same data.
48
- */
49
- async ready(entry, id) {
50
- const current = this.resources[entry.key];
51
- if (current?.status === "ready" && current.id === id && JSON.stringify(current.data) === JSON.stringify(entry.data)) return;
52
- await this.put({
53
- ...entry,
54
- status: "ready",
55
- id
56
- });
57
- }
58
- /**
59
- * The resource `entry` names: by its recorded id, else by looking it up,
60
- * else created — with `pending` written before the create and `ready`
61
- * after, so a run that dies in between leaves a record the next run
62
- * resolves by looking the resource up rather than creating another.
63
- */
64
- async ensure(entry, steps) {
65
- const record = this.resources[entry.key];
66
- let staleId;
67
- if (record?.status === "ready" && record.id && steps.get) {
68
- const known = await steps.get(record.id);
69
- if (known) {
70
- await this.ready(entry, steps.id(known));
71
- return {
72
- resource: known,
73
- via: "recorded"
74
- };
75
- }
76
- staleId = record.id;
77
- }
78
- const existing = await steps.find();
79
- if (existing) {
80
- await this.ready(entry, steps.id(existing));
81
- return {
82
- resource: existing,
83
- via: record?.status === "pending" ? "resumed" : "found",
84
- ...staleId ? { staleId } : {}
85
- };
86
- }
87
- await this.pending(entry);
88
- const created = await steps.create();
89
- await this.ready(entry, steps.id(created));
90
- return {
91
- resource: created,
92
- via: "created",
93
- ...staleId ? { staleId } : {}
94
- };
95
- }
96
- /** Removes `key`'s record — a resource that no longer exists. */
97
- async forget(key) {
98
- if (!(key in this.resources)) return;
99
- this.version = await this.store.deleteResource(this.stage, key, { expectedVersion: this.version });
100
- const { [key]: _removed, ...resources } = this.resources;
101
- this.resources = resources;
102
- }
103
- /** Every record, as the journal last wrote or read it. */
104
- records() {
105
- return this.resources;
21
+ //#region src/target/secrets.ts
22
+ /**
23
+ * A stage's secrets as a target sees them: read and written through the
24
+ * stage's own store, and masked in everything the run prints once read.
25
+ */
26
+ /**
27
+ * Shorter values are left alone: what a progress line legitimately prints —
28
+ * a port, a stage, an app name — would otherwise come out as `***` wherever
29
+ * a secret happened to share it.
30
+ */
31
+ const SHORTEST_MASKED = 6;
32
+ /** The values a run must never print, and the rewrite that keeps it so. */
33
+ var Redactor = class {
34
+ values = /* @__PURE__ */ new Set();
35
+ add(value) {
36
+ if (value && value.length >= SHORTEST_MASKED) this.values.add(value);
106
37
  }
107
- /** Writes the stage's state, keeping its resource records. */
108
- async save() {
109
- this.state.lastDeployedAt = (/* @__PURE__ */ new Date()).toISOString();
110
- this.version = await this.store.write(this.stage, this.state, { expectedVersion: this.version });
111
- }
112
- async put(record) {
113
- this.version = await this.store.putResource(this.stage, record, { expectedVersion: this.version });
114
- this.resources = {
115
- ...this.resources,
116
- [record.key]: {
117
- ...record,
118
- updatedAt: (/* @__PURE__ */ new Date()).toISOString()
119
- }
120
- };
38
+ /** `text` with every masked value replaced by `***`, longest first. */
39
+ redact(text) {
40
+ if (this.values.size === 0) return text;
41
+ let out = text;
42
+ const longestFirst = [...this.values].sort((a, b) => b.length - a.length);
43
+ for (const value of longestFirst) out = out.replaceAll(value, "***");
44
+ return out;
121
45
  }
122
46
  };
47
+ /** Every value in `secrets` that is a secret rather than a label. */
48
+ function secretValues(secrets) {
49
+ return [
50
+ secrets.seed,
51
+ ...Object.values(secrets.custom ?? {}),
52
+ ...Object.values(secrets.urls ?? {}),
53
+ ...Object.values(secrets.services ?? {}).map((service) => service?.password)
54
+ ].filter((value) => typeof value === "string");
55
+ }
56
+ /**
57
+ * The stage's secrets through the store `secrets.store` names for it. Opening
58
+ * one builds a client and makes no request, so a target that never reads them
59
+ * costs nothing.
60
+ */
61
+ async function deploySecrets(workspace, stage, redactor, options = {}) {
62
+ const store = await secretsStoreFor(workspace, stage, options);
63
+ const mask = (secrets) => {
64
+ for (const value of secretValues(secrets)) redactor.add(value);
65
+ };
66
+ return {
67
+ store: store.name,
68
+ async read() {
69
+ const secrets = await store.read(stage);
70
+ if (secrets) mask(secrets);
71
+ return secrets;
72
+ },
73
+ async write(secrets) {
74
+ mask(secrets);
75
+ await store.write(stage, secrets);
76
+ },
77
+ mask: (value) => redactor.add(value)
78
+ };
79
+ }
123
80
  //#endregion
124
81
  //#region src/providers/aws.ts
125
82
  /**
@@ -193,6 +150,88 @@ async function awsClientConfig(credential, region) {
193
150
  };
194
151
  return { region };
195
152
  }
153
+ const SUFFIX_ALPHABET = "abcdefghijklmnopqrstuvwxyz0123456789";
154
+ /** A name that S3 would refuse — what the name builder never returns. */
155
+ var InvalidBucketName = class extends GkmError {
156
+ bucket;
157
+ reason;
158
+ constructor(bucket, reason) {
159
+ super(`'${bucket}' is not a valid S3 bucket name: ${reason}. Rename the construct or set deploy.namespace in gkm.config.ts to something that leaves room for it.`);
160
+ this.bucket = bucket;
161
+ this.reason = reason;
162
+ this.name = "InvalidBucketName";
163
+ }
164
+ };
165
+ /** Lowercase `[a-z0-9-]`, runs of anything else one `-`, no edge dashes. */
166
+ function part(value) {
167
+ return kebabCase(value).toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
168
+ }
169
+ /**
170
+ * `parts` joined by `-`, shortened to `max` characters by trimming the longest
171
+ * part one character at a time — so a long construct id gives way before a
172
+ * short stage name does, and every part keeps its start.
173
+ */
174
+ function fitParts(parts, max) {
175
+ const kept = parts.map(part).filter(Boolean);
176
+ const length = () => kept.reduce((sum, p) => sum + p.length, 0) + kept.length - 1;
177
+ while (length() > max) {
178
+ let longest = 0;
179
+ for (let i = 1; i < kept.length; i++) if (kept[i].length > kept[longest].length) longest = i;
180
+ if (kept[longest].length <= 1) break;
181
+ kept[longest] = kept[longest].slice(0, -1).replace(/-+$/, "");
182
+ }
183
+ return kept.join("-");
184
+ }
185
+ /** Why `name` is not a valid bucket name, or undefined when it is. */
186
+ function bucketNameProblem(name) {
187
+ if (name.length < 3 || name.length > 63) return `it is ${name.length} characters, and S3 takes 3 to 63`;
188
+ if (!/^[a-z0-9-]+$/.test(name)) return "it may hold only lowercase letters, digits and -";
189
+ if (!/^[a-z0-9].*[a-z0-9]$/.test(name)) return "it must start and end with a letter or a digit";
190
+ if (name.startsWith("xn--") || name.startsWith("sthree-")) return "it starts with a prefix S3 reserves ('xn--', 'sthree-')";
191
+ if (name.endsWith("-s3alias") || name.endsWith("--ol-s3")) return "it ends with a suffix S3 reserves ('-s3alias', '--ol-s3')";
192
+ }
193
+ /**
194
+ * The good name: `<namespace>-<project>-<stage>-<bucket id>`, lowercased, no
195
+ * dots, shortened to leave room for a clash's suffix.
196
+ *
197
+ * @throws {InvalidBucketName} when nothing usable is left
198
+ */
199
+ function bucketName(input) {
200
+ const name = fitParts([
201
+ input.scope,
202
+ input.stage,
203
+ input.id
204
+ ], 56);
205
+ const problem = bucketNameProblem(name);
206
+ if (problem) throw new InvalidBucketName(name, problem);
207
+ return name;
208
+ }
209
+ /** Six random `[a-z0-9]` characters. */
210
+ function randomSuffix(random = randomInt) {
211
+ let suffix = "";
212
+ for (let i = 0; i < 6; i++) suffix += SUFFIX_ALPHABET[random(36)];
213
+ return suffix;
214
+ }
215
+ /** The good name with a clash's suffix. */
216
+ function suffixedBucketName(good, suffix) {
217
+ return `${good}-${suffix}`;
218
+ }
219
+ /**
220
+ * The IAM user a bucket is reached with on a stage:
221
+ * `gkm-<project>-<stage>-<bucket id>`, at most 64 characters.
222
+ */
223
+ function iamUserName(input) {
224
+ return fitParts([
225
+ "gkm",
226
+ input.scope,
227
+ input.stage,
228
+ input.id
229
+ ], 64);
230
+ }
231
+ /** The path every user gkm creates is under, so it finds its own. */
232
+ const IAM_USER_PATH = "/gkm/";
233
+ /** The inline policy each user is given. */
234
+ const IAM_POLICY_NAME = "gkm-bucket";
196
235
  //#endregion
197
236
  //#region src/providers/s3/origins.ts
198
237
  /**
@@ -907,12 +946,10 @@ function constructsOf(manifest, kind) {
907
946
  /**
908
947
  * What every deploy runs: each provider's `verify()` — the cheap check that
909
948
  * what it created is still there and the stage's key reaches it. Nothing on
910
- * the local stage, and nothing for a kind on `external`.
911
- *
912
- * @throws {StageProviderDisabled} for a declared kind the stage has none of
949
+ * the local stage, and nothing for a kind on `external` or `false` — a kind
950
+ * the stage has none of is the deploy's readiness check's to refuse.
913
951
  */
914
952
  async function verifyStageProviders(input) {
915
- assertStageProvidersEnabled(input.workspace, input.manifest, input.stage);
916
953
  const verified = [];
917
954
  for (const kind of PROVIDER_KINDS) {
918
955
  if (constructsOf(input.manifest, kind).length === 0) continue;
@@ -1074,6 +1111,744 @@ async function readOnlyState(store, stage) {
1074
1111
  };
1075
1112
  }
1076
1113
  //#endregion
1077
- export { verifyStageProviders as n, DeployJournal as r, provisionStage as t };
1114
+ //#region src/secrets/stale.ts
1115
+ /**
1116
+ * Stored secrets an older gkm generated that now shadow a derived value.
1117
+ *
1118
+ * Before constructs, initialising a stage wrote an address for each app into
1119
+ * its custom secrets: `<APP>_DATABASE_URL` as a `postgresql://…@localhost`
1120
+ * URL with a password of its own, and `http://localhost:<port>` for a site or
1121
+ * an auth server. Those keys are now a construct's — `database.schema('AuthDatabase')`
1122
+ * provides `AUTH_DATABASE_URL`, `new BetterAuth('Auth')` provides `AUTH_URL`
1123
+ * — and a deploy derives them. A value the stage holds is a value set by hand,
1124
+ * and set by hand wins: the container is handed `localhost`, where nothing
1125
+ * answers, with a password no role has.
1126
+ *
1127
+ * So a deploy refuses such a stage rather than run it, naming each key and
1128
+ * the command that removes it. Nothing is deleted for the user: the value is
1129
+ * theirs, and only they can say it is stale. A URL that names a real host — a
1130
+ * managed database — is a deliberate choice and still wins.
1131
+ */
1132
+ /** The kinds whose URL an older gkm wrote into a stage's secrets. */
1133
+ const ADDRESSED = /* @__PURE__ */ new Set([
1134
+ "database",
1135
+ "database-reader",
1136
+ "database-schema",
1137
+ "rest-api",
1138
+ "site"
1139
+ ]);
1140
+ /** Hosts that are this machine — never anything, inside a container. */
1141
+ const LOOPBACK = /* @__PURE__ */ new Set([
1142
+ "localhost",
1143
+ "127.0.0.1",
1144
+ "[::1]",
1145
+ "::1"
1146
+ ]);
1147
+ /**
1148
+ * A stage holds a construct's address as a custom secret, pointing at
1149
+ * `localhost` — what an older `gkm secrets:init`, `gkm setup` or `gkm init`
1150
+ * generated. Set by hand wins over derived, so the app would be handed it.
1151
+ */
1152
+ var StaleStageSecrets = class extends GkmError {
1153
+ stage;
1154
+ stale;
1155
+ constructor(stage, stale) {
1156
+ const one = stale.length === 1;
1157
+ super(`The stage '${stage}' holds ${one ? "a value" : "values"} an older gkm generated for ${one ? "an address a construct" : "addresses constructs"} now ${one ? "provides" : "provide"}:\n` + stale.map((s) => ` ${s.key}: ${s.construct}'s, stored pointing at ${s.host}`).join("\n") + `
1158
+ A stored value wins over the derived one, so the app would be handed an address where nothing answers inside its container. Remove ${one ? "it" : "each"}, and the construct's own value is used:\n` + stale.map((s) => ` gkm secrets:unset ${s.key} --stage ${stage}`).join("\n") + "\nA managed service set with its real host is not affected.");
1159
+ this.stage = stage;
1160
+ this.stale = stale;
1161
+ this.name = "StaleStageSecrets";
1162
+ }
1163
+ };
1164
+ /** The host a stored value names, if it is a URL. */
1165
+ function hostOf(value) {
1166
+ try {
1167
+ return new URL(value).hostname;
1168
+ } catch {
1169
+ return;
1170
+ }
1171
+ }
1172
+ /**
1173
+ * Each stored key that a construct provides an address for, holding an
1174
+ * address on this machine.
1175
+ */
1176
+ function staleStageSecrets(manifest, supplied) {
1177
+ const stale = [];
1178
+ for (const [id, declaration] of Object.entries(manifest)) {
1179
+ if (!ADDRESSED.has(declaration.kind)) continue;
1180
+ const key = providedKeyFor(id, declaration.kind, "url");
1181
+ const value = supplied[key];
1182
+ if (value === void 0) continue;
1183
+ const host = hostOf(value);
1184
+ if (host === void 0 || !LOOPBACK.has(host)) continue;
1185
+ stale.push({
1186
+ key,
1187
+ construct: id,
1188
+ host
1189
+ });
1190
+ }
1191
+ return stale.sort((a, b) => a.key.localeCompare(b.key));
1192
+ }
1193
+ /**
1194
+ * Refuse a stage whose stored secrets would shadow a construct's address with
1195
+ * `localhost`.
1196
+ *
1197
+ * @throws {StaleStageSecrets} naming each key and the command removing it
1198
+ */
1199
+ function assertNoStaleSecrets(options) {
1200
+ const stale = staleStageSecrets(options.manifest, options.supplied);
1201
+ if (stale.length > 0) throw new StaleStageSecrets(options.stage, stale);
1202
+ }
1203
+ //#endregion
1204
+ //#region src/deploy/readiness.ts
1205
+ /**
1206
+ * Whether a stage is ready to be deployed: the one check, run once by every
1207
+ * deploy through a server target — after the stage's providers have created
1208
+ * what they create and written its keys, and before the target touches
1209
+ * anything.
1210
+ *
1211
+ * A build is not a deploy. Images carry no stage's keys, so a build-only run
1212
+ * (`gkm compose --build --push`) never calls this: a key the deploy itself
1213
+ * writes — a provider's bucket URL — is not there yet when CI builds, and
1214
+ * must not stop the build.
1215
+ */
1216
+ /**
1217
+ * The stage has every key it needs, read from its secrets as the providers
1218
+ * left them:
1219
+ *
1220
+ * 1. no kind it declares is one the stage set to `false`;
1221
+ * 2. its mail and storage are its own — or a dev service, where allowed,
1222
+ * reported once, loudly;
1223
+ * 3. what its providers created is still there, and its key reaches it;
1224
+ * 4. no key holds an address an older gkm stored for what a construct now
1225
+ * provides;
1226
+ * 5. each third party's credentials match their construct's schema.
1227
+ *
1228
+ * The local stage derives its mail and storage, so only 4 and 5 apply to it.
1229
+ *
1230
+ * @throws {StageProviderDisabled}
1231
+ * @throws {ExternalServicesNotConfigured} naming every missing key at once
1232
+ * @throws {StaleStageSecrets}
1233
+ * @throws {CredentialsInvalid}
1234
+ */
1235
+ async function assertStageReady(ctx) {
1236
+ const { workspace, manifest, stage } = ctx;
1237
+ const supplied = (await ctx.secrets.read())?.custom ?? {};
1238
+ if (stage !== workspace.stages.local) {
1239
+ assertStageProvidersEnabled(workspace, manifest, stage);
1240
+ const domain = workspace.domains?.[stage];
1241
+ const services = externalServices({
1242
+ stage,
1243
+ declarations: stageServiceDeclarations({
1244
+ manifest,
1245
+ ...ctx.runnables ? { runnables: ctx.runnables } : {}
1246
+ }),
1247
+ supplied,
1248
+ allow: ctx.allowDevServices,
1249
+ ...domain ? { domain } : {},
1250
+ providers: stageProviderNotes(workspace, stage)
1251
+ });
1252
+ if (services.missing.length > 0) throw new ExternalServicesNotConfigured(stage, services.missing);
1253
+ reportDevServices(ctx, devServicesUsed(services));
1254
+ const verified = await verifyStageProviders({
1255
+ workspace,
1256
+ manifest,
1257
+ stage,
1258
+ secrets: supplied
1259
+ });
1260
+ for (const line of verified) ctx.logger.info(`✓ ${line} verified`);
1261
+ }
1262
+ assertNoStaleSecrets({
1263
+ manifest,
1264
+ stage,
1265
+ supplied
1266
+ });
1267
+ await assertStageCredentials({
1268
+ root: workspace.root,
1269
+ patterns: constructGlobs(workspace),
1270
+ manifest,
1271
+ stage,
1272
+ supplied
1273
+ });
1274
+ }
1275
+ //#endregion
1276
+ //#region src/deploy/orchestrate.ts
1277
+ /**
1278
+ * The run around a target: what every deploy does whatever it deploys
1279
+ * through.
1280
+ *
1281
+ * It loads the workspace, resolves the target, works out the apps and the
1282
+ * identity, takes the stage's lock, and calls the target's phases in order,
1283
+ * reporting each as it starts, finishes or fails. Everything that is about
1284
+ * *where* the stage goes is the target's.
1285
+ */
1286
+ /** `--resources-only` with `--skip-resources`: the one asks for what the other skips. */
1287
+ var ResourcesOnlyAndSkipped = class extends GkmError {
1288
+ constructor() {
1289
+ super("--resources-only creates the stage's resources and nothing else, and --skip-resources deploys without creating them. Run the first where the cloud credentials are (a CI runner), then the second where the stack runs.");
1290
+ this.name = "ResourcesOnlyAndSkipped";
1291
+ }
1292
+ };
1293
+ /** Apps were asked for by name that the workspace does not have. */
1294
+ var UnknownDeployApps = class extends GkmError {
1295
+ apps;
1296
+ available;
1297
+ constructor(apps, available) {
1298
+ super(`Unknown apps: ${apps.join(", ")}\nAvailable apps: ${available.join(", ")}`);
1299
+ this.apps = apps;
1300
+ this.available = available;
1301
+ this.name = "UnknownDeployApps";
1302
+ }
1303
+ };
1304
+ /** Every app asked for deploys through some other target. */
1305
+ var NoDeployableApps = class extends GkmError {
1306
+ stage;
1307
+ target;
1308
+ constructor(stage, target) {
1309
+ super(`No apps to deploy through "${target}": every selected app deploys somewhere else. Pick the target with --target, or set each app's deploy in gkm.config.ts.`);
1310
+ this.stage = stage;
1311
+ this.target = target;
1312
+ this.name = "NoDeployableApps";
1313
+ }
1314
+ };
1315
+ /** A build-only run through a target with no build phase. */
1316
+ var TargetBuildsNothing = class extends GkmError {
1317
+ target;
1318
+ constructor(target) {
1319
+ super(`"${target}" has no build phase, so a build-only run would do nothing. Deploy it in full, or build through a target that builds images (compose).`);
1320
+ this.target = target;
1321
+ this.name = "TargetBuildsNothing";
1322
+ }
1323
+ };
1324
+ /** A failed rollback, after the failure that called for it. */
1325
+ var RollbackFailed = class extends Error {
1326
+ target;
1327
+ failure;
1328
+ constructor(target, failure, cause) {
1329
+ super(`Deploying through "${target}" failed, and so did rolling it back: ${cause instanceof Error ? cause.message : String(cause)}. The stage may be part-released; deploy again, or roll it back by hand. The first failure: ${failure instanceof Error ? failure.message : String(failure)}`, { cause });
1330
+ this.target = target;
1331
+ this.failure = failure;
1332
+ this.name = "RollbackFailed";
1333
+ }
1334
+ };
1335
+ /**
1336
+ * Generate image tag from stage and timestamp
1337
+ */
1338
+ function generateTag(stage) {
1339
+ return `${stage}-${(/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-").slice(0, 19)}`;
1340
+ }
1341
+ /** Why an app that deploys through another target is left out. */
1342
+ function elsewhere(target, stage) {
1343
+ const instead = builtinTarget(target)?.instead?.(stage);
1344
+ if (instead) return `it deploys through "${target}" — ${instead}`;
1345
+ return `it deploys through "${target}" — run \`gkm deploy --target ${target} --stage ${stage}\``;
1346
+ }
1347
+ /**
1348
+ * Deploy a workspace's stage through its target.
1349
+ *
1350
+ * The engine under `deploy()` and `gkm deploy`. It never prompts and never
1351
+ * exits: credentials come from `ctx.credentials`, progress goes to
1352
+ * `ctx.emit` and to `output`, and every failure is thrown.
1353
+ *
1354
+ * @internal
1355
+ */
1356
+ async function runDeploy(source, request, ctx) {
1357
+ const { stage } = request;
1358
+ const redactor = ctx.redactor ?? new Redactor();
1359
+ const emit = (event) => ctx.emit(event.type === "log" ? {
1360
+ ...event,
1361
+ message: redactor.redact(event.message)
1362
+ } : event);
1363
+ /** Run one phase between its events. */
1364
+ const phase = async (name, body) => {
1365
+ ctx.signal?.throwIfAborted();
1366
+ emit({
1367
+ type: "phase.started",
1368
+ phase: name
1369
+ });
1370
+ try {
1371
+ const value = await body();
1372
+ emit({
1373
+ type: "phase.finished",
1374
+ phase: name
1375
+ });
1376
+ return value;
1377
+ } catch (error) {
1378
+ emit({
1379
+ type: "phase.failed",
1380
+ phase: name,
1381
+ error: eventError(error)
1382
+ });
1383
+ throw error;
1384
+ }
1385
+ };
1386
+ ctx.signal?.throwIfAborted();
1387
+ emit({
1388
+ type: "phase.started",
1389
+ phase: "validate"
1390
+ });
1391
+ let prepared;
1392
+ try {
1393
+ prepared = await prepare(source, request, ctx, emit, redactor);
1394
+ } catch (error) {
1395
+ emit({
1396
+ type: "phase.failed",
1397
+ phase: "validate",
1398
+ error: eventError(error)
1399
+ });
1400
+ throw error;
1401
+ }
1402
+ const { resolved, phaseCtx, store } = prepared;
1403
+ const { target } = resolved;
1404
+ const resources = !ctx.buildOnly && !request.skipResources && phaseCtx.stage !== phaseCtx.workspace.stages.local;
1405
+ const provision = async () => {
1406
+ if (!request.skipDns && resolved.target.runtime === "server") try {
1407
+ await dnsCredentials(phaseCtx.stage, stageDnsDomains(phaseCtx.stage, phaseCtx.workspace.domains, phaseCtx.workspace.dns), ctx.credentials);
1408
+ } catch (error) {
1409
+ emit({
1410
+ type: "phase.failed",
1411
+ phase: "validate",
1412
+ error: eventError(error)
1413
+ });
1414
+ throw error;
1415
+ }
1416
+ await provisionResources(phaseCtx, request, ctx, store, emit);
1417
+ };
1418
+ if (ctx.dryRun) {
1419
+ if (resources) await provision();
1420
+ if (request.resourcesOnly) return resourcesOnly(target, phaseCtx, emit);
1421
+ const run = await validate(phaseCtx, emit, () => readyToDeploy(target, phaseCtx));
1422
+ await phase("plan", () => target.plan(phaseCtx, run));
1423
+ return target.result(phaseCtx, run);
1424
+ }
1425
+ if (ctx.buildOnly) {
1426
+ if (!target.build) throw new TargetBuildsNothing(resolved.name);
1427
+ const run = await validate(phaseCtx, emit, () => target.validate(phaseCtx));
1428
+ await phase("build", () => target.build(phaseCtx, run));
1429
+ return target.result(phaseCtx, run);
1430
+ }
1431
+ let lock;
1432
+ try {
1433
+ assertStateOutlivesRun(phaseCtx.workspace, stage, "deploy");
1434
+ lock = await store.lock(stage, { operation: "deploy" });
1435
+ } catch (error) {
1436
+ emit({
1437
+ type: "phase.failed",
1438
+ phase: "validate",
1439
+ error: eventError(error)
1440
+ });
1441
+ throw error;
1442
+ }
1443
+ try {
1444
+ if (resources) await provision();
1445
+ if (request.resourcesOnly) return resourcesOnly(target, phaseCtx, emit);
1446
+ const run = await validate(phaseCtx, emit, () => readyToDeploy(target, phaseCtx));
1447
+ if (target.provision) await phase("provision", () => target.provision(phaseCtx, run));
1448
+ if (target.build) await phase("build", () => target.build(phaseCtx, run));
1449
+ let releasing = "release";
1450
+ try {
1451
+ await phase("release", () => target.release(phaseCtx, run));
1452
+ releasing = "verify";
1453
+ if (target.verify) await phase("verify", () => target.verify(phaseCtx, run));
1454
+ } catch (error) {
1455
+ if (ctx.signal?.aborted || !target.capabilities.rollback) throw error;
1456
+ if (!target.rollback) throw error;
1457
+ try {
1458
+ await phase("rollback", () => target.rollback(phaseCtx, run, {
1459
+ phase: releasing,
1460
+ error
1461
+ }));
1462
+ } catch (rollbackError) {
1463
+ throw new RollbackFailed(resolved.name, error, rollbackError);
1464
+ }
1465
+ throw error;
1466
+ }
1467
+ return await target.result(phaseCtx, run);
1468
+ } finally {
1469
+ await lock.release();
1470
+ }
1471
+ }
1472
+ /**
1473
+ * The stage's providers, run inside the validate phase. A dry run plans them
1474
+ * and, so the checks after it see the stage as the run would leave it, reads
1475
+ * the keys they would write as placeholders.
1476
+ */
1477
+ async function provisionResources(phaseCtx, request, ctx, store, emit) {
1478
+ try {
1479
+ const reports = await provisionStage({
1480
+ workspace: phaseCtx.workspace,
1481
+ stage: phaseCtx.stage,
1482
+ manifest: phaseCtx.manifest,
1483
+ runnables: phaseCtx.runnables ?? {},
1484
+ secrets: phaseCtx.secrets,
1485
+ state: store,
1486
+ dryRun: ctx.dryRun,
1487
+ ...request.rotateKeys ? { rotateKeys: true } : {},
1488
+ ...request.retireOldKeys ? { retireOldKeys: true } : {},
1489
+ ...ctx.home ? { home: ctx.home } : {},
1490
+ log: (line) => phaseCtx.logger.info(line)
1491
+ });
1492
+ if (!ctx.dryRun) return;
1493
+ const planned = reports.flatMap((r) => r.planned);
1494
+ if (planned.length === 0) return;
1495
+ const secrets = phaseCtx.secrets;
1496
+ phaseCtx.secrets = {
1497
+ ...secrets,
1498
+ async read() {
1499
+ const stored = await secrets.read() ?? initStageSecrets(phaseCtx.stage);
1500
+ const custom = { ...stored.custom };
1501
+ for (const key of planned) custom[key] ??= PLANNED_BY_THE_DEPLOY;
1502
+ return {
1503
+ ...stored,
1504
+ custom
1505
+ };
1506
+ }
1507
+ };
1508
+ } catch (error) {
1509
+ emit({
1510
+ type: "phase.failed",
1511
+ phase: "validate",
1512
+ error: eventError(error)
1513
+ });
1514
+ throw error;
1515
+ }
1516
+ }
1517
+ /** What a dry run reads for a key its providers would write. */
1518
+ const PLANNED_BY_THE_DEPLOY = "s3://planned-by-this-deploy";
1519
+ /** `--resources-only`: the target's own resources, and nothing else. */
1520
+ async function resourcesOnly(target, phaseCtx, emit) {
1521
+ try {
1522
+ if (target.resources) await target.resources(phaseCtx);
1523
+ } catch (error) {
1524
+ emit({
1525
+ type: "phase.failed",
1526
+ phase: "validate",
1527
+ error: eventError(error)
1528
+ });
1529
+ throw error;
1530
+ }
1531
+ emit({
1532
+ type: "phase.finished",
1533
+ phase: "validate"
1534
+ });
1535
+ return resourcesResult(phaseCtx);
1536
+ }
1537
+ /** A `--resources-only` run: no app was deployed. */
1538
+ function resourcesResult(phaseCtx) {
1539
+ return {
1540
+ apps: [],
1541
+ projectId: "",
1542
+ successCount: 0,
1543
+ failedCount: 0,
1544
+ stage: phaseCtx.stage,
1545
+ identity: phaseCtx.identity.key,
1546
+ tag: phaseCtx.tag,
1547
+ dryRun: phaseCtx.dryRun,
1548
+ environmentId: "",
1549
+ skipped: [...phaseCtx.skipped],
1550
+ urls: {},
1551
+ changes: []
1552
+ };
1553
+ }
1554
+ /**
1555
+ * What a deploy validates: the stage ready to be deployed — every key it
1556
+ * needs, read as its providers left them — then what the target would run,
1557
+ * then whatever only the target checks. A build-only run validates the
1558
+ * target's run alone: it calls neither readiness check.
1559
+ */
1560
+ async function readyToDeploy(target, phaseCtx) {
1561
+ if (target.runtime === "server") await assertStageReady(phaseCtx);
1562
+ const run = await target.validate(phaseCtx);
1563
+ await target.ready?.(phaseCtx, run);
1564
+ return run;
1565
+ }
1566
+ /** `body`, then the run's `deploy.started`, inside the validate phase. */
1567
+ async function validate(phaseCtx, emit, body) {
1568
+ try {
1569
+ const run = await body();
1570
+ const skipped = new Set(phaseCtx.skipped.map((s) => s.app));
1571
+ emit({
1572
+ type: "deploy.started",
1573
+ stage: phaseCtx.stage,
1574
+ target: phaseCtx.target,
1575
+ identity: phaseCtx.identity.key,
1576
+ tag: phaseCtx.tag,
1577
+ apps: phaseCtx.apps.filter((app) => !skipped.has(app)),
1578
+ dryRun: phaseCtx.dryRun
1579
+ });
1580
+ emit({
1581
+ type: "phase.finished",
1582
+ phase: "validate"
1583
+ });
1584
+ return run;
1585
+ } catch (error) {
1586
+ emit({
1587
+ type: "phase.failed",
1588
+ phase: "validate",
1589
+ error: eventError(error)
1590
+ });
1591
+ throw error;
1592
+ }
1593
+ }
1594
+ /** Everything the phases are handed, worked out before the first of them. */
1595
+ async function prepare(source, request, ctx, emit, redactor) {
1596
+ const { stage } = request;
1597
+ if (request.resourcesOnly && request.skipResources) throw new ResourcesOnlyAndSkipped();
1598
+ const configured = typeof source === "function" ? await source() : source;
1599
+ const local = stage === configured.stages.local;
1600
+ if (!local) assertDeployedStage(configured.stages, stage);
1601
+ const targetName = request.target ?? configured.deploy?.default ?? "dokploy";
1602
+ const resolved = await resolveTarget(targetName, {
1603
+ workspace: configured,
1604
+ stage,
1605
+ ...ctx.targets ? { host: ctx.targets } : {}
1606
+ });
1607
+ if (local && !resolved.target.capabilities.localStage) assertDeployedStage(configured.stages, stage);
1608
+ const options = await parseTargetOptions(resolved);
1609
+ const allowDevServices = request.allowDevServices === true;
1610
+ if (allowDevServices && resolved.target.runtime === "aws") throw new DevServicesNeedServerTarget(targetName);
1611
+ const runnables = {};
1612
+ const background = {};
1613
+ const manifest = await discover({
1614
+ patterns: constructGlobs(configured),
1615
+ cwd: configured.root,
1616
+ runnables,
1617
+ background
1618
+ });
1619
+ resolveStageTelemetry({
1620
+ ...configured.deploy?.telemetry ? { telemetry: configured.deploy.telemetry } : {},
1621
+ stage,
1622
+ local,
1623
+ target: targetName,
1624
+ runtime: resolved.target.runtime,
1625
+ selfHosted: resolved.target.capabilities.selfHostedTelemetry === true,
1626
+ used: usesTelemetry(manifest)
1627
+ });
1628
+ const units = derivedApps(manifest, configured);
1629
+ const workspace = Object.keys(units).length > 0 ? {
1630
+ ...configured,
1631
+ apps: units
1632
+ } : configured;
1633
+ const identity = deployIdentity(workspace, stage);
1634
+ const tag = request.tag ?? (resolved.target.tag ? await resolved.target.tag({
1635
+ cwd: workspace.root,
1636
+ stage
1637
+ }) : generateTag(stage));
1638
+ const buildOrder = getAppBuildOrder(workspace);
1639
+ let selected = buildOrder;
1640
+ if (request.apps && request.apps.length > 0) {
1641
+ const unknown = request.apps.filter((name) => !workspace.apps[name]);
1642
+ if (unknown.length > 0) throw new UnknownDeployApps(unknown, Object.keys(workspace.apps));
1643
+ selected = buildOrder.filter((name) => request.apps.includes(name));
1644
+ }
1645
+ const skipped = [];
1646
+ const skip = (app, reason) => {
1647
+ skipped.push({
1648
+ app,
1649
+ reason
1650
+ });
1651
+ emit({
1652
+ type: "app.skipped",
1653
+ app,
1654
+ reason
1655
+ });
1656
+ };
1657
+ const byDefault = configured.deploy?.default ?? "dokploy";
1658
+ const apps = selected.filter((name) => {
1659
+ const own = workspace.apps[name].resolvedDeployTarget;
1660
+ const deploysThrough = own === byDefault ? targetName : own;
1661
+ if (deploysThrough === targetName) return true;
1662
+ skip(name, elsewhere(deploysThrough, stage));
1663
+ return false;
1664
+ });
1665
+ if (apps.length === 0) throw new NoDeployableApps(stage, targetName);
1666
+ const store = await createStateStore({
1667
+ config: workspace.state,
1668
+ workspaceRoot: workspace.root,
1669
+ workspaceName: workspace.name
1670
+ });
1671
+ const secrets = await deploySecrets(workspace, stage, redactor, { ...ctx.home ? { home: ctx.home } : {} });
1672
+ const line = (level) => (message) => emit({
1673
+ type: "log",
1674
+ level,
1675
+ message
1676
+ });
1677
+ const logger = {
1678
+ info: line("info"),
1679
+ warn: line("warn"),
1680
+ error: line("error")
1681
+ };
1682
+ return {
1683
+ resolved,
1684
+ phaseCtx: {
1685
+ target: targetName,
1686
+ cwd: workspace.root,
1687
+ stage,
1688
+ tag,
1689
+ tagGiven: request.tag !== void 0,
1690
+ apps,
1691
+ skipped,
1692
+ identity,
1693
+ workspace,
1694
+ manifest,
1695
+ runnables,
1696
+ background,
1697
+ options,
1698
+ dryRun: ctx.dryRun,
1699
+ atomic: request.atomic ?? false,
1700
+ allowDevServices,
1701
+ ...request.skipDns ? { skipDns: true } : {},
1702
+ ...request.skipResources ? { skipResources: true } : {},
1703
+ credentials: ctx.credentials,
1704
+ state: store,
1705
+ secrets,
1706
+ logger,
1707
+ signal: ctx.signal ?? new AbortController().signal,
1708
+ childOutput: ctx.childOutput ?? "inherit",
1709
+ emit,
1710
+ skip,
1711
+ name: (resource) => applicationName(identity, resource)
1712
+ },
1713
+ store
1714
+ };
1715
+ }
1716
+ //#endregion
1717
+ //#region src/deploy/deploy.ts
1718
+ /**
1719
+ * `deploy()`: a deploy as a library call.
1720
+ *
1721
+ * `gkm deploy` could only be driven from an interactive terminal: it prompted
1722
+ * for what it lacked and exited the process on failure, worked out of
1723
+ * `process.cwd()`, and reported progress by printing. Here the caller says
1724
+ * where the project is, hands over the credentials and a signal, and gets back
1725
+ * a run — events to iterate while it goes, and a structured result at the end.
1726
+ * Nothing below this asks a person anything or ends the process; `gkm deploy`
1727
+ * is a thin wrapper that does both.
1728
+ */
1729
+ /**
1730
+ * Every event a run emits, kept so that each iteration — however late it
1731
+ * starts — sees the run from its first event to its last.
1732
+ */
1733
+ var EventLog = class {
1734
+ events = [];
1735
+ closed = false;
1736
+ waiting = [];
1737
+ push(event) {
1738
+ this.events.push(event);
1739
+ this.wake();
1740
+ }
1741
+ close() {
1742
+ this.closed = true;
1743
+ this.wake();
1744
+ }
1745
+ wake() {
1746
+ const waiting = this.waiting;
1747
+ this.waiting = [];
1748
+ for (const resume of waiting) resume();
1749
+ }
1750
+ async *iterate() {
1751
+ let next = 0;
1752
+ while (true) if (next < this.events.length) yield this.events[next++];
1753
+ else if (this.closed) return;
1754
+ else await new Promise((resume) => this.waiting.push(resume));
1755
+ }
1756
+ };
1757
+ function forward(logger, level, message) {
1758
+ if (!logger) return;
1759
+ if (level === "info") logger.info(message);
1760
+ else if (level === "error" && logger.error) logger.error(message);
1761
+ else logger.warn(message);
1762
+ }
1763
+ /**
1764
+ * Deploy a project's stage.
1765
+ *
1766
+ * ```ts
1767
+ * import { deploy } from '@geekmidas/cli/deploy';
1768
+ *
1769
+ * const run = deploy({ cwd: '/srv/checkouts/shop', stage: 'production' });
1770
+ * for await (const event of run) {
1771
+ * if (event.type === 'app.deployed') console.log(event.app, event.url);
1772
+ * }
1773
+ * const result = await run.result;
1774
+ * ```
1775
+ *
1776
+ * The run starts at once; iterating it is optional, and an iteration started
1777
+ * late still sees every event from the first.
1778
+ */
1779
+ function deploy(input) {
1780
+ const log = new EventLog();
1781
+ const redactor = new Redactor();
1782
+ const emit = (event) => {
1783
+ const masked = event.type === "log" ? {
1784
+ ...event,
1785
+ message: redactor.redact(event.message)
1786
+ } : event;
1787
+ log.push(masked);
1788
+ if (masked.type === "log") forward(input.logger, masked.level, masked.message);
1789
+ };
1790
+ const ctx = {
1791
+ emit,
1792
+ credentials: input.credentials ?? storedCredentials({ home: input.home ?? gkmHome() }),
1793
+ dryRun: input.dryRun ?? false,
1794
+ ...input.buildOnly ? { buildOnly: true } : {},
1795
+ home: input.home ?? gkmHome(),
1796
+ redactor,
1797
+ ...input.signal ? { signal: input.signal } : {},
1798
+ ...input.childOutput ? { childOutput: input.childOutput } : {},
1799
+ ...input.targets ? { targets: input.targets } : {}
1800
+ };
1801
+ const result = withOutput((level, message) => emit({
1802
+ type: "log",
1803
+ level,
1804
+ message
1805
+ }), async () => {
1806
+ try {
1807
+ input.signal?.throwIfAborted();
1808
+ const sandbox = input.sandbox ?? new LocalSandbox({ root: findWorkspaceRoot(resolve(input.cwd)) });
1809
+ const deployed = await withSandbox(sandbox, () => runDeploy(() => load(input, sandbox), {
1810
+ stage: input.stage,
1811
+ ...input.target ? { target: input.target } : {},
1812
+ ...input.tag ? { tag: input.tag } : {},
1813
+ ...input.apps ? { apps: input.apps } : {},
1814
+ ...input.atomic ? { atomic: true } : {},
1815
+ ...input.allowDevServices ? { allowDevServices: input.allowDevServices } : {},
1816
+ ...input.skipDns ? { skipDns: true } : {},
1817
+ ...input.resourcesOnly ? { resourcesOnly: true } : {},
1818
+ ...input.skipResources ? { skipResources: true } : {},
1819
+ ...input.rotateKeys ? { rotateKeys: true } : {},
1820
+ ...input.retireOldKeys ? { retireOldKeys: true } : {}
1821
+ }, ctx));
1822
+ emit({
1823
+ type: "deploy.finished",
1824
+ result: deployed
1825
+ });
1826
+ return deployed;
1827
+ } catch (error) {
1828
+ emit({
1829
+ type: "deploy.failed",
1830
+ error: eventError(error)
1831
+ });
1832
+ throw error;
1833
+ } finally {
1834
+ log.close();
1835
+ }
1836
+ });
1837
+ result.catch(() => {});
1838
+ return {
1839
+ result,
1840
+ [Symbol.asyncIterator]: () => log.iterate()
1841
+ };
1842
+ }
1843
+ /**
1844
+ * The workspace at `input.cwd`. The stage is checked by the run, once it
1845
+ * knows the target: one that runs on this machine may take the local stage.
1846
+ */
1847
+ async function load(input, sandbox) {
1848
+ const { workspace } = await loadWorkspaceConfig(resolve(input.cwd), { sandbox });
1849
+ return workspace;
1850
+ }
1851
+ //#endregion
1852
+ export { UnknownDeployApps as a, iamUserName as c, TargetBuildsNothing as i, NoDeployableApps as n, IAM_USER_PATH as o, RollbackFailed as r, bucketName as s, deploy as t };
1078
1853
 
1079
- //# sourceMappingURL=providers-sTj-BG0S.mjs.map
1854
+ //# sourceMappingURL=deploy-B0drCD6s.mjs.map