@geekmidas/cli 10.0.0-alpha.66 → 10.0.0-alpha.67

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 (114) hide show
  1. package/README.md +110 -178
  2. package/dist/{HostingerProvider-CY_VpVud.mjs → HostingerProvider-D85ayzTi.mjs} +2 -2
  3. package/dist/{HostingerProvider-CY_VpVud.mjs.map → HostingerProvider-D85ayzTi.mjs.map} +1 -1
  4. package/dist/{HostingerProvider-BznqRC2S.cjs → HostingerProvider-dxkwynSs.cjs} +2 -2
  5. package/dist/{HostingerProvider-BznqRC2S.cjs.map → HostingerProvider-dxkwynSs.cjs.map} +1 -1
  6. package/dist/{LegacyStateStore-BFcTT2QL.cjs → LegacyStateStore-BZiO9-Lw.cjs} +2 -2
  7. package/dist/{LegacyStateStore-BFcTT2QL.cjs.map → LegacyStateStore-BZiO9-Lw.cjs.map} +1 -1
  8. package/dist/{LegacyStateStore-CFheFo62.mjs → LegacyStateStore-C39UKwmf.mjs} +2 -2
  9. package/dist/{LegacyStateStore-CFheFo62.mjs.map → LegacyStateStore-C39UKwmf.mjs.map} +1 -1
  10. package/dist/{LocalStateStore-BVUexSvu.cjs → LocalStateStore-DHVsZLyF.cjs} +2 -2
  11. package/dist/{LocalStateStore-BVUexSvu.cjs.map → LocalStateStore-DHVsZLyF.cjs.map} +1 -1
  12. package/dist/{LocalStateStore-Bm3x9oOg.mjs → LocalStateStore-Dk3Wbvzk.mjs} +2 -2
  13. package/dist/{LocalStateStore-Bm3x9oOg.mjs.map → LocalStateStore-Dk3Wbvzk.mjs.map} +1 -1
  14. package/dist/{S3StateStore-CoXBhILd.cjs → S3StateStore--4tYVMAL.cjs} +2 -2
  15. package/dist/{S3StateStore-CoXBhILd.cjs.map → S3StateStore--4tYVMAL.cjs.map} +1 -1
  16. package/dist/{S3StateStore-BFHuctWM.mjs → S3StateStore-B_ZF9eHt.mjs} +2 -2
  17. package/dist/{S3StateStore-BFHuctWM.mjs.map → S3StateStore-B_ZF9eHt.mjs.map} +1 -1
  18. package/dist/{SSMStateStore-BqCA9TP2.cjs → SSMStateStore-ACZ8hRvZ.cjs} +2 -2
  19. package/dist/{SSMStateStore-BqCA9TP2.cjs.map → SSMStateStore-ACZ8hRvZ.cjs.map} +1 -1
  20. package/dist/{SSMStateStore-C1kvHScY.mjs → SSMStateStore-DjPuKqrm.mjs} +2 -2
  21. package/dist/{SSMStateStore-C1kvHScY.mjs.map → SSMStateStore-DjPuKqrm.mjs.map} +1 -1
  22. package/dist/{bundler-Dvaiud0h.mjs → bundler-Bq3HaLOZ.mjs} +20 -5
  23. package/dist/bundler-Bq3HaLOZ.mjs.map +1 -0
  24. package/dist/{bundler-orRqUJNZ.cjs → bundler-pyLj-gS0.cjs} +20 -5
  25. package/dist/bundler-pyLj-gS0.cjs.map +1 -0
  26. package/dist/{cli-CfHm0AO7.mjs → cli-C2Tjbn27.mjs} +4 -4
  27. package/dist/{cli-CfHm0AO7.mjs.map → cli-C2Tjbn27.mjs.map} +1 -1
  28. package/dist/{cli-D1JkkOwg.cjs → cli-DR7B2_fX.cjs} +4 -4
  29. package/dist/{cli-D1JkkOwg.cjs.map → cli-DR7B2_fX.cjs.map} +1 -1
  30. package/dist/{compose-jrLy7KGO.cjs → compose-5oNHAKNT.cjs} +135 -110
  31. package/dist/compose-5oNHAKNT.cjs.map +1 -0
  32. package/dist/{compose-CNQL8BnO.mjs → compose-BjToENzG.mjs} +128 -103
  33. package/dist/compose-BjToENzG.mjs.map +1 -0
  34. package/dist/{credentials-Bzbg23n8.cjs → credentials-BVs7mrtw.cjs} +239 -3
  35. package/dist/credentials-BVs7mrtw.cjs.map +1 -0
  36. package/dist/{credentials-Dq1MnWQf.mjs → credentials-pAtB70k3.mjs} +223 -5
  37. package/dist/credentials-pAtB70k3.mjs.map +1 -0
  38. package/dist/deploy/public.cjs +17 -17
  39. package/dist/deploy/public.cjs.map +1 -1
  40. package/dist/deploy/public.mjs +9 -9
  41. package/dist/{deploy-B7aJi_Ah.cjs → deploy-BucRfbvX.cjs} +9 -9
  42. package/dist/{deploy-B7aJi_Ah.cjs.map → deploy-BucRfbvX.cjs.map} +1 -1
  43. package/dist/{deploy-DWn7YfIc.mjs → deploy-DRAwTG72.mjs} +6 -6
  44. package/dist/{deploy-DWn7YfIc.mjs.map → deploy-DRAwTG72.mjs.map} +1 -1
  45. package/dist/{dokploy-DalwLML5.mjs → dokploy-DIt1IZl1.mjs} +2 -2
  46. package/dist/{dokploy-DalwLML5.mjs.map → dokploy-DIt1IZl1.mjs.map} +1 -1
  47. package/dist/{dokploy-B4LcYG1E.cjs → dokploy-m345Zx02.cjs} +2 -2
  48. package/dist/{dokploy-B4LcYG1E.cjs.map → dokploy-m345Zx02.cjs.map} +1 -1
  49. package/dist/{encryption-CPfENwWO.mjs → encryption-Ccbahik7.mjs} +2 -2
  50. package/dist/{encryption-CPfENwWO.mjs.map → encryption-Ccbahik7.mjs.map} +1 -1
  51. package/dist/{encryption-3KlGS1sl.cjs → encryption-rZ3BghXy.cjs} +2 -2
  52. package/dist/{encryption-3KlGS1sl.cjs.map → encryption-rZ3BghXy.cjs.map} +1 -1
  53. package/dist/{engine-DR6KurWX.cjs → engine-Cx_dvx9q.cjs} +9 -187
  54. package/dist/engine-Cx_dvx9q.cjs.map +1 -0
  55. package/dist/{engine-CunvOG3s.mjs → engine-Gs0abjuj.mjs} +5 -183
  56. package/dist/engine-Gs0abjuj.mjs.map +1 -0
  57. package/dist/{github-MXA9v7Ge.mjs → github-CJANTYqi.mjs} +2 -2
  58. package/dist/{github-MXA9v7Ge.mjs.map → github-CJANTYqi.mjs.map} +1 -1
  59. package/dist/{github-BJ5gh9bw.cjs → github-CrcGFkfD.cjs} +2 -2
  60. package/dist/{github-BJ5gh9bw.cjs.map → github-CrcGFkfD.cjs.map} +1 -1
  61. package/dist/index.cjs +51 -65
  62. package/dist/index.cjs.map +1 -1
  63. package/dist/index.mjs +47 -61
  64. package/dist/index.mjs.map +1 -1
  65. package/dist/{migrate-CF4J4GQS.cjs → migrate-CQdSpttI.cjs} +2 -2
  66. package/dist/{migrate-CF4J4GQS.cjs.map → migrate-CQdSpttI.cjs.map} +1 -1
  67. package/dist/{migrate-BJBcm4sG.mjs → migrate-DCVo5gLS.mjs} +2 -2
  68. package/dist/{migrate-BJBcm4sG.mjs.map → migrate-DCVo5gLS.mjs.map} +1 -1
  69. package/dist/{resolve-CVmch0wI.cjs → resolve-BexmDcsN.cjs} +4 -4
  70. package/dist/{resolve-CVmch0wI.cjs.map → resolve-BexmDcsN.cjs.map} +1 -1
  71. package/dist/{resolve-Db0tNlrW.mjs → resolve-DhZgtvZe.mjs} +4 -4
  72. package/dist/{resolve-Db0tNlrW.mjs.map → resolve-DhZgtvZe.mjs.map} +1 -1
  73. package/dist/{rollback-DxJK84hy.cjs → rollback-BnY7KuG_.cjs} +6 -7
  74. package/dist/{rollback-DxJK84hy.cjs.map → rollback-BnY7KuG_.cjs.map} +1 -1
  75. package/dist/{rollback-DvAo4OKS.mjs → rollback-m4Yeym5x.mjs} +5 -6
  76. package/dist/{rollback-DvAo4OKS.mjs.map → rollback-m4Yeym5x.mjs.map} +1 -1
  77. package/dist/run-BJLIerMM.mjs +133 -0
  78. package/dist/run-BJLIerMM.mjs.map +1 -0
  79. package/dist/run-fVZ-rLnc.cjs +174 -0
  80. package/dist/run-fVZ-rLnc.cjs.map +1 -0
  81. package/dist/{sniffer-BAQhLEsI.mjs → sniffer-BdFeLSmA.mjs} +8 -60
  82. package/dist/sniffer-BdFeLSmA.mjs.map +1 -0
  83. package/dist/{sniffer-5xmrkh2a.cjs → sniffer-D66HIvi9.cjs} +7 -77
  84. package/dist/{sniffer-5xmrkh2a.cjs.map → sniffer-D66HIvi9.cjs.map} +1 -1
  85. package/dist/{sst-B2HbrDR3.mjs → sst-DRi3H5TB.mjs} +3 -3
  86. package/dist/{sst-B2HbrDR3.mjs.map → sst-DRi3H5TB.mjs.map} +1 -1
  87. package/dist/{sst-DcfsVH6x.cjs → sst-hBrKouBy.cjs} +5 -5
  88. package/dist/{sst-DcfsVH6x.cjs.map → sst-hBrKouBy.cjs.map} +1 -1
  89. package/dist/{state-Y6ATakMX.cjs → state-DgmM4EKq.cjs} +3588 -3415
  90. package/dist/state-DgmM4EKq.cjs.map +1 -0
  91. package/dist/{state-uuYqnRVO.mjs → state-DkUStoqJ.mjs} +3528 -3385
  92. package/dist/state-DkUStoqJ.mjs.map +1 -0
  93. package/dist/target/public.cjs +1 -1
  94. package/dist/target/public.mjs +1 -1
  95. package/dist/{terminal-DUhcZ1ND.mjs → terminal-C3cv-OQu.mjs} +2 -2
  96. package/dist/{terminal-DUhcZ1ND.mjs.map → terminal-C3cv-OQu.mjs.map} +1 -1
  97. package/dist/{terminal-CHy_MdjG.cjs → terminal-DjzgLu6m.cjs} +2 -2
  98. package/dist/{terminal-CHy_MdjG.cjs.map → terminal-DjzgLu6m.cjs.map} +1 -1
  99. package/package.json +13 -13
  100. package/dist/bundler-Dvaiud0h.mjs.map +0 -1
  101. package/dist/bundler-orRqUJNZ.cjs.map +0 -1
  102. package/dist/compose-CNQL8BnO.mjs.map +0 -1
  103. package/dist/compose-jrLy7KGO.cjs.map +0 -1
  104. package/dist/credentials-Bzbg23n8.cjs.map +0 -1
  105. package/dist/credentials-Dq1MnWQf.mjs.map +0 -1
  106. package/dist/engine-CunvOG3s.mjs.map +0 -1
  107. package/dist/engine-DR6KurWX.cjs.map +0 -1
  108. package/dist/local-BdH4XN0E.cjs +0 -409
  109. package/dist/local-BdH4XN0E.cjs.map +0 -1
  110. package/dist/local-CWR4Y_kW.mjs +0 -350
  111. package/dist/local-CWR4Y_kW.mjs.map +0 -1
  112. package/dist/sniffer-BAQhLEsI.mjs.map +0 -1
  113. package/dist/state-Y6ATakMX.cjs.map +0 -1
  114. package/dist/state-uuYqnRVO.mjs.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"rollback-DvAo4OKS.mjs","names":[],"sources":["../src/target/dokploy/rollback.ts"],"sourcesContent":["/**\n * `gkm deploy:rollback`: a stage's apps put back on the release before the\n * one they run, by hand — for a release that passed its checks and turned out\n * wrong anyway.\n *\n * One app by default, because an app is what usually broke: rolling the API\n * back over a site fix that shipped beside it undoes the fix too. `atomic`\n * rolls back every app that has a release to go back to, for apps that only\n * work together — an API and the site built against its newer contract.\n *\n * It restores images and nothing else. The environment an app runs with is\n * the stage's, resolved on every deploy, and migrations are forward-only: a\n * migration that the older code cannot run against is undone by a new\n * migration, never by a rollback.\n */\n\nimport { resolve } from 'node:path';\nimport { findWorkspaceRoot, loadWorkspaceConfig } from '../../config';\nimport {\n\ttype CredentialProvider,\n\tstoredCredentials,\n} from '../../deploy/credentials';\nimport { DeployJournal } from '../../deploy/journal';\nimport { createStateStore } from '../../deploy/StateStore';\nimport {\n\tcreateEmptyState,\n\ttype ReleasedImage,\n\trecordRollback,\n} from '../../deploy/state';\nimport { LocalSandbox } from '../../sandbox/local';\nimport { type Sandbox, withSandbox } from '../../sandbox/sandbox';\nimport { assertDeployedStage } from '../../workspace/stages';\nimport { dokployApi, restoreImage, verifySettings } from './engine';\n\nexport interface RollbackInput {\n\t/** The project: the directory holding `gkm.config.ts`, or one inside it. */\n\tcwd: string;\n\tstage: string;\n\t/** The app to roll back. */\n\tapp?: string;\n\t/** Every app with an earlier release, instead of one. */\n\tatomic?: boolean;\n\t/** Defaults to the environment, then the logins `gkm login` stored. */\n\tcredentials?: CredentialProvider;\n\tsignal?: AbortSignal;\n\t/** Each progress line. Defaults to none. */\n\tlog?: (line: string) => void;\n\t/** Where the config is loaded. Defaults to a `LocalSandbox` on the project. */\n\tsandbox?: Sandbox;\n}\n\n/** One app rolled back. */\nexport interface RolledBack {\n\tapp: string;\n\tfrom: ReleasedImage;\n\tto: ReleasedImage;\n}\n\n/** Neither an app nor every app was asked for. */\nexport class RollbackNeedsApp extends Error {\n\tconstructor(\n\t\treadonly stage: string,\n\t\t/** The apps that have a release to go back to. */\n\t\treadonly apps: readonly string[],\n\t) {\n\t\tsuper(\n\t\t\t`Say what to roll back: --app <name> for one app (${apps.join(', ') || 'none has an earlier release'}), ` +\n\t\t\t\t`or --atomic for every app of \"${stage}\" together.`,\n\t\t);\n\t\tthis.name = 'RollbackNeedsApp';\n\t}\n}\n\n/** An app has no release before the one it runs. */\nexport class NothingToRollBack extends Error {\n\tconstructor(\n\t\treadonly stage: string,\n\t\treadonly app: string,\n\t) {\n\t\tsuper(\n\t\t\t`\"${app}\" has no earlier release on \"${stage}\" to roll back to: it has been released once, ` +\n\t\t\t\t'or every earlier release was itself rolled back. Deploy the version you want instead.',\n\t\t);\n\t\tthis.name = 'NothingToRollBack';\n\t}\n}\n\n/** The stage was never deployed through Dokploy from this state. */\nexport class StageNeverDeployed extends Error {\n\tconstructor(readonly stage: string) {\n\t\tsuper(\n\t\t\t`\"${stage}\" has no deploy state, so there is nothing to roll back. ` +\n\t\t\t\t'Check the stage name, and that `state` in gkm.config.ts points at the store the deploys write to.',\n\t\t);\n\t\tthis.name = 'StageNeverDeployed';\n\t}\n}\n\n/**\n * Roll a stage's app — or, `atomic`, all of them — back to its previous\n * release, holding the stage's lock as a deploy does.\n */\nexport async function rollbackStage(\n\tinput: RollbackInput,\n): Promise<RolledBack[]> {\n\tconst signal = input.signal ?? new AbortController().signal;\n\tconst log = input.log ?? (() => {});\n\tconst credentials = input.credentials ?? storedCredentials();\n\tconst sandbox =\n\t\tinput.sandbox ??\n\t\tnew LocalSandbox({ root: findWorkspaceRoot(resolve(input.cwd)) });\n\n\treturn withSandbox(sandbox, async () => {\n\t\tconst { workspace } = await loadWorkspaceConfig(resolve(input.cwd), {\n\t\t\tsandbox,\n\t\t});\n\t\tassertDeployedStage(workspace.stages, input.stage);\n\n\t\tconst store = await createStateStore({\n\t\t\tconfig: workspace.state,\n\t\t\tworkspaceRoot: workspace.root,\n\t\t\tworkspaceName: workspace.name,\n\t\t});\n\t\tif (!(await store.read(input.stage))) {\n\t\t\tthrow new StageNeverDeployed(input.stage);\n\t\t}\n\n\t\tconst lock = await store.lock(input.stage, { operation: 'rollback' });\n\t\ttry {\n\t\t\tconst journal = await DeployJournal.open(store, input.stage, () =>\n\t\t\t\tcreateEmptyState(input.stage, '', ''),\n\t\t\t);\n\t\t\tconst { state } = journal;\n\t\t\tconst releases = state.releases ?? {};\n\t\t\tconst restorable = Object.keys(releases).filter(\n\t\t\t\t(app) => releases[app]!.previous,\n\t\t\t);\n\n\t\t\tlet apps: string[];\n\t\t\tif (input.atomic) {\n\t\t\t\tapps = restorable;\n\t\t\t\tif (apps.length === 0) {\n\t\t\t\t\tthrow new RollbackNeedsApp(input.stage, restorable);\n\t\t\t\t}\n\t\t\t} else if (input.app) {\n\t\t\t\tif (!releases[input.app]?.previous) {\n\t\t\t\t\tthrow new NothingToRollBack(input.stage, input.app);\n\t\t\t\t}\n\t\t\t\tapps = [input.app];\n\t\t\t} else {\n\t\t\t\tthrow new RollbackNeedsApp(input.stage, restorable);\n\t\t\t}\n\n\t\t\tconst { api } = await dokployApi(workspace, { credentials, signal });\n\t\t\tconst verify = verifySettings(workspace.deploy.dokploy?.verify);\n\t\t\tconst rolled: RolledBack[] = [];\n\n\t\t\tfor (const app of apps) {\n\t\t\t\tsignal.throwIfAborted();\n\t\t\t\tconst { current, previous } = releases[app]!;\n\t\t\t\tconst applicationId = state.applications[app];\n\t\t\t\tif (!previous || !applicationId) {\n\t\t\t\t\tthrow new NothingToRollBack(input.stage, app);\n\t\t\t\t}\n\n\t\t\t\tlog(`⏪ ${app}: ${current.ref} → ${previous.ref}`);\n\t\t\t\tawait restoreImage(api, {\n\t\t\t\t\tapplicationId,\n\t\t\t\t\timage: previous,\n\t\t\t\t\tregistryId: state.registryId,\n\t\t\t\t\tverify,\n\t\t\t\t\tsignal,\n\t\t\t\t});\n\t\t\t\trecordRollback(state, app, previous);\n\t\t\t\tawait journal.save();\n\t\t\t\tlog(` ✓ ${app} is running ${previous.ref}`);\n\t\t\t\trolled.push({ app, from: current, to: previous });\n\t\t\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AAK;KAAE;KAAK,MAAM;KAAS,IAAI;IAAS,CAAC;GACjD;GAEA,OAAO;EACR,UAAU;GACT,MAAM,KAAK,QAAQ;EACpB;CACD,CAAC;AACF"}
1
+ {"version":3,"file":"rollback-m4Yeym5x.mjs","names":[],"sources":["../src/target/dokploy/rollback.ts"],"sourcesContent":["/**\n * `gkm deploy:rollback`: a stage's apps put back on the release before the\n * one they run, by hand — for a release that passed its checks and turned out\n * wrong anyway.\n *\n * One app by default, because an app is what usually broke: rolling the API\n * back over a site fix that shipped beside it undoes the fix too. `atomic`\n * rolls back every app that has a release to go back to, for apps that only\n * work together — an API and the site built against its newer contract.\n *\n * It restores images and nothing else. The environment an app runs with is\n * the stage's, resolved on every deploy, and migrations are forward-only: a\n * migration that the older code cannot run against is undone by a new\n * migration, never by a rollback.\n */\n\nimport { resolve } from 'node:path';\nimport { findWorkspaceRoot, loadWorkspaceConfig } from '../../config';\nimport {\n\ttype CredentialProvider,\n\tstoredCredentials,\n} from '../../deploy/credentials';\nimport { DeployJournal } from '../../deploy/journal';\nimport { createStateStore } from '../../deploy/StateStore';\nimport {\n\tcreateEmptyState,\n\ttype ReleasedImage,\n\trecordRollback,\n} from '../../deploy/state';\nimport { LocalSandbox } from '../../sandbox/local';\nimport { type Sandbox, withSandbox } from '../../sandbox/sandbox';\nimport { assertDeployedStage } from '../../workspace/stages';\nimport { dokployApi, restoreImage, verifySettings } from './engine';\n\nexport interface RollbackInput {\n\t/** The project: the directory holding `gkm.config.ts`, or one inside it. */\n\tcwd: string;\n\tstage: string;\n\t/** The app to roll back. */\n\tapp?: string;\n\t/** Every app with an earlier release, instead of one. */\n\tatomic?: boolean;\n\t/** Defaults to the environment, then the logins `gkm login` stored. */\n\tcredentials?: CredentialProvider;\n\tsignal?: AbortSignal;\n\t/** Each progress line. Defaults to none. */\n\tlog?: (line: string) => void;\n\t/** Where the config is loaded. Defaults to a `LocalSandbox` on the project. */\n\tsandbox?: Sandbox;\n}\n\n/** One app rolled back. */\nexport interface RolledBack {\n\tapp: string;\n\tfrom: ReleasedImage;\n\tto: ReleasedImage;\n}\n\n/** Neither an app nor every app was asked for. */\nexport class RollbackNeedsApp extends Error {\n\tconstructor(\n\t\treadonly stage: string,\n\t\t/** The apps that have a release to go back to. */\n\t\treadonly apps: readonly string[],\n\t) {\n\t\tsuper(\n\t\t\t`Say what to roll back: --app <name> for one app (${apps.join(', ') || 'none has an earlier release'}), ` +\n\t\t\t\t`or --atomic for every app of \"${stage}\" together.`,\n\t\t);\n\t\tthis.name = 'RollbackNeedsApp';\n\t}\n}\n\n/** An app has no release before the one it runs. */\nexport class NothingToRollBack extends Error {\n\tconstructor(\n\t\treadonly stage: string,\n\t\treadonly app: string,\n\t) {\n\t\tsuper(\n\t\t\t`\"${app}\" has no earlier release on \"${stage}\" to roll back to: it has been released once, ` +\n\t\t\t\t'or every earlier release was itself rolled back. Deploy the version you want instead.',\n\t\t);\n\t\tthis.name = 'NothingToRollBack';\n\t}\n}\n\n/** The stage was never deployed through Dokploy from this state. */\nexport class StageNeverDeployed extends Error {\n\tconstructor(readonly stage: string) {\n\t\tsuper(\n\t\t\t`\"${stage}\" has no deploy state, so there is nothing to roll back. ` +\n\t\t\t\t'Check the stage name, and that `state` in gkm.config.ts points at the store the deploys write to.',\n\t\t);\n\t\tthis.name = 'StageNeverDeployed';\n\t}\n}\n\n/**\n * Roll a stage's app — or, `atomic`, all of them — back to its previous\n * release, holding the stage's lock as a deploy does.\n */\nexport async function rollbackStage(\n\tinput: RollbackInput,\n): Promise<RolledBack[]> {\n\tconst signal = input.signal ?? new AbortController().signal;\n\tconst log = input.log ?? (() => {});\n\tconst credentials = input.credentials ?? storedCredentials();\n\tconst sandbox =\n\t\tinput.sandbox ??\n\t\tnew LocalSandbox({ root: findWorkspaceRoot(resolve(input.cwd)) });\n\n\treturn withSandbox(sandbox, async () => {\n\t\tconst { workspace } = await loadWorkspaceConfig(resolve(input.cwd), {\n\t\t\tsandbox,\n\t\t});\n\t\tassertDeployedStage(workspace.stages, input.stage);\n\n\t\tconst store = await createStateStore({\n\t\t\tconfig: workspace.state,\n\t\t\tworkspaceRoot: workspace.root,\n\t\t\tworkspaceName: workspace.name,\n\t\t});\n\t\tif (!(await store.read(input.stage))) {\n\t\t\tthrow new StageNeverDeployed(input.stage);\n\t\t}\n\n\t\tconst lock = await store.lock(input.stage, { operation: 'rollback' });\n\t\ttry {\n\t\t\tconst journal = await DeployJournal.open(store, input.stage, () =>\n\t\t\t\tcreateEmptyState(input.stage, '', ''),\n\t\t\t);\n\t\t\tconst { state } = journal;\n\t\t\tconst releases = state.releases ?? {};\n\t\t\tconst restorable = Object.keys(releases).filter(\n\t\t\t\t(app) => releases[app]!.previous,\n\t\t\t);\n\n\t\t\tlet apps: string[];\n\t\t\tif (input.atomic) {\n\t\t\t\tapps = restorable;\n\t\t\t\tif (apps.length === 0) {\n\t\t\t\t\tthrow new RollbackNeedsApp(input.stage, restorable);\n\t\t\t\t}\n\t\t\t} else if (input.app) {\n\t\t\t\tif (!releases[input.app]?.previous) {\n\t\t\t\t\tthrow new NothingToRollBack(input.stage, input.app);\n\t\t\t\t}\n\t\t\t\tapps = [input.app];\n\t\t\t} else {\n\t\t\t\tthrow new RollbackNeedsApp(input.stage, restorable);\n\t\t\t}\n\n\t\t\tconst { api } = await dokployApi(workspace, { credentials, signal });\n\t\t\tconst verify = verifySettings(workspace.deploy.dokploy?.verify);\n\t\t\tconst rolled: RolledBack[] = [];\n\n\t\t\tfor (const app of apps) {\n\t\t\t\tsignal.throwIfAborted();\n\t\t\t\tconst { current, previous } = releases[app]!;\n\t\t\t\tconst applicationId = state.applications[app];\n\t\t\t\tif (!previous || !applicationId) {\n\t\t\t\t\tthrow new NothingToRollBack(input.stage, app);\n\t\t\t\t}\n\n\t\t\t\tlog(`⏪ ${app}: ${current.ref} → ${previous.ref}`);\n\t\t\t\tawait restoreImage(api, {\n\t\t\t\t\tapplicationId,\n\t\t\t\t\timage: previous,\n\t\t\t\t\tregistryId: state.registryId,\n\t\t\t\t\tverify,\n\t\t\t\t\tsignal,\n\t\t\t\t});\n\t\t\t\trecordRollback(state, app, previous);\n\t\t\t\tawait journal.save();\n\t\t\t\tlog(` ✓ ${app} is running ${previous.ref}`);\n\t\t\t\trolled.push({ app, from: current, to: previous });\n\t\t\t}\n\n\t\t\treturn rolled;\n\t\t} finally {\n\t\t\tawait lock.release();\n\t\t}\n\t});\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2DA,IAAa,mBAAb,cAAsC,MAAM;CAEjC;CAEA;CAHV,YACC,OAEA,MACC;EACD,MACC,oDAAoD,KAAK,KAAK,IAAI,KAAK,8BAA8B,mCACnE,MAAM,YACzC;EAPS,KAAA,QAAA;EAEA,KAAA,OAAA;EAMT,KAAK,OAAO;CACb;AACD;;AAGA,IAAa,oBAAb,cAAuC,MAAM;CAElC;CACA;CAFV,YACC,OACA,KACC;EACD,MACC,IAAI,IAAI,+BAA+B,MAAM,oIAE9C;EANS,KAAA,QAAA;EACA,KAAA,MAAA;EAMT,KAAK,OAAO;CACb;AACD;;AAGA,IAAa,qBAAb,cAAwC,MAAM;CACxB;CAArB,YAAY,OAAwB;EACnC,MACC,IAAI,MAAM,6JAEX;EAJoB,KAAA,QAAA;EAKpB,KAAK,OAAO;CACb;AACD;;;;;AAMA,eAAsB,cACrB,OACwB;CACxB,MAAM,SAAS,MAAM,UAAU,IAAI,gBAAgB,CAAC,CAAC;CACrD,MAAM,MAAM,MAAM,cAAc,CAAC;CACjC,MAAM,cAAc,MAAM,eAAe,kBAAkB;CAC3D,MAAM,UACL,MAAM,WACN,IAAI,aAAa,EAAE,MAAM,kBAAkB,QAAQ,MAAM,GAAG,CAAC,EAAE,CAAC;CAEjE,OAAO,YAAY,SAAS,YAAY;EACvC,MAAM,EAAE,cAAc,MAAM,oBAAoB,QAAQ,MAAM,GAAG,GAAG,EACnE,QACD,CAAC;EACD,oBAAoB,UAAU,QAAQ,MAAM,KAAK;EAEjD,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AM,aAAa,KAAK;KACvB;KACA,OAAO;KACP,YAAY,MAAM;KAClB;KACA;IACD,CAAC;IACD,eAAe,OAAO,KAAK,QAAQ;IACnC,MAAM,QAAQ,KAAK;IACnB,IAAI,QAAQ,IAAI,cAAc,SAAS,KAAK;IAC5C,OAAO,KAAK;KAAE;KAAK,MAAM;KAAS,IAAI;IAAS,CAAC;GACjD;GAEA,OAAO;EACR,UAAU;GACT,MAAM,KAAK,QAAQ;EACpB;CACD,CAAC;AACF"}
@@ -0,0 +1,133 @@
1
+ import { join, resolve } from "node:path";
2
+ import { homedir } from "node:os";
3
+ import { spawn } from "node:child_process";
4
+ //#region src/home.ts
5
+ /**
6
+ * Where the CLI keeps what belongs to a person rather than a project: stage
7
+ * keys and stored provider credentials.
8
+ *
9
+ * `GKM_HOME` names it, so a CI job, a shared build runner or a test can give
10
+ * every run its own instead of reaching into whoever's home directory the
11
+ * process happens to have. Unset, it is `~/.gkm`, where it has always been.
12
+ */
13
+ /** The environment variable that moves the CLI's home. */
14
+ const GKM_HOME_ENV = "GKM_HOME";
15
+ /** The CLI's home: `GKM_HOME` if set, else `~/.gkm`. */
16
+ function gkmHome(env = process.env) {
17
+ const configured = env[GKM_HOME_ENV];
18
+ return configured ? resolve(configured) : join(homedir(), ".gkm");
19
+ }
20
+ //#endregion
21
+ //#region src/run.ts
22
+ /**
23
+ * Start a program with an argument array, never a shell string.
24
+ *
25
+ * `gkm build`, `gkm docker` and `gkm deploy` pass values that come from the
26
+ * workspace — image refs, tags, build args, package names — to `docker` and
27
+ * `turbo`. Joined into a string and handed to a shell, a package named
28
+ * `x;curl …|sh` or a tag holding `$(…)` became part of the command line, which
29
+ * matters most where the CLI builds a repository it didn't write: a CI job for a
30
+ * fork, a shared build runner. Here every value reaches the program as one
31
+ * `argv` element, whatever it contains.
32
+ */
33
+ /** Long enough for a cold image build; short enough that a hung one ends. */
34
+ const DEFAULT_TIMEOUT_MS = 18e5;
35
+ /** How long a timed-out child has to exit on SIGTERM before it is killed. */
36
+ const KILL_GRACE_MS = 5e3;
37
+ /** The command line as a person would read it — for messages, never to run. */
38
+ function display(command, args) {
39
+ return [command, ...args].join(" ");
40
+ }
41
+ /** The program ran and exited unsuccessfully; its own output said why. */
42
+ var CommandFailed = class extends Error {
43
+ command;
44
+ args;
45
+ exitCode;
46
+ signal;
47
+ constructor(command, args, exitCode, signal) {
48
+ super(`\`${display(command, args)}\` ${exitCode === null ? `was stopped by ${signal ?? "a signal"}` : `exited with code ${exitCode}`}. Its output above says why; run it by hand to see it again.`);
49
+ this.command = command;
50
+ this.args = args;
51
+ this.exitCode = exitCode;
52
+ this.signal = signal;
53
+ this.name = "CommandFailed";
54
+ }
55
+ };
56
+ /** The program ran past its timeout and was killed. */
57
+ var CommandTimedOut = class extends Error {
58
+ command;
59
+ args;
60
+ timeoutMs;
61
+ constructor(command, args, timeoutMs) {
62
+ super(`\`${display(command, args)}\` was still running after ${Math.round(timeoutMs / 1e3)}s and was stopped. Check what it was waiting on — a registry, the Docker daemon, a prompt — and run it again.`);
63
+ this.command = command;
64
+ this.args = args;
65
+ this.timeoutMs = timeoutMs;
66
+ this.name = "CommandTimedOut";
67
+ }
68
+ };
69
+ /**
70
+ * Run `command` with `args`, resolving when it exits 0.
71
+ *
72
+ * Rejects with {@link CommandFailed} on any other exit, {@link CommandTimedOut}
73
+ * once `timeoutMs` passes (after the child is gone), and with the spawn error
74
+ * itself when the program cannot be started at all — `ENOENT` already names it.
75
+ */
76
+ async function run(command, args, options = {}) {
77
+ await spawnChild(command, args, options, false);
78
+ }
79
+ /**
80
+ * {@link run}, resolving with what the program wrote to stdout — for a value
81
+ * the CLI reads back, such as the digest `docker inspect` reports. stderr still
82
+ * reaches the terminal, so a failure explains itself the same way.
83
+ */
84
+ function runOutput(command, args, options = {}) {
85
+ return spawnChild(command, args, options, true);
86
+ }
87
+ function spawnChild(command, args, options, capture) {
88
+ const { timeoutMs = DEFAULT_TIMEOUT_MS, ...spawnOptions } = options;
89
+ return new Promise((resolve, reject) => {
90
+ const child = spawn(command, [...args], {
91
+ stdio: "inherit",
92
+ ...spawnOptions,
93
+ ...capture ? { stdio: [
94
+ "ignore",
95
+ "pipe",
96
+ "inherit"
97
+ ] } : {},
98
+ shell: false
99
+ });
100
+ let stdout = "";
101
+ child.stdout?.on("data", (chunk) => {
102
+ stdout += chunk.toString();
103
+ });
104
+ let timedOut = false;
105
+ let killer;
106
+ const timer = setTimeout(() => {
107
+ timedOut = true;
108
+ child.kill("SIGTERM");
109
+ killer = setTimeout(() => child.kill("SIGKILL"), KILL_GRACE_MS);
110
+ killer.unref?.();
111
+ }, timeoutMs);
112
+ timer.unref?.();
113
+ const settle = () => {
114
+ clearTimeout(timer);
115
+ if (killer) clearTimeout(killer);
116
+ };
117
+ child.on("error", (error) => {
118
+ settle();
119
+ reject(spawnOptions.signal?.aborted ? spawnOptions.signal.reason : error);
120
+ });
121
+ child.on("close", (code, signal) => {
122
+ settle();
123
+ if (spawnOptions.signal?.aborted) reject(spawnOptions.signal.reason);
124
+ else if (timedOut) reject(new CommandTimedOut(command, args, timeoutMs));
125
+ else if (code === 0) resolve(stdout);
126
+ else reject(new CommandFailed(command, args, code, signal));
127
+ });
128
+ });
129
+ }
130
+ //#endregion
131
+ export { runOutput as a, run as i, CommandTimedOut as n, GKM_HOME_ENV as o, DEFAULT_TIMEOUT_MS as r, gkmHome as s, CommandFailed as t };
132
+
133
+ //# sourceMappingURL=run-BJLIerMM.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-BJLIerMM.mjs","names":[],"sources":["../src/home.ts","../src/run.ts"],"sourcesContent":["/**\n * Where the CLI keeps what belongs to a person rather than a project: stage\n * keys and stored provider credentials.\n *\n * `GKM_HOME` names it, so a CI job, a shared build runner or a test can give\n * every run its own instead of reaching into whoever's home directory the\n * process happens to have. Unset, it is `~/.gkm`, where it has always been.\n */\n\nimport { homedir } from 'node:os';\nimport { join, resolve } from 'node:path';\n\n/** The environment variable that moves the CLI's home. */\nexport const GKM_HOME_ENV = 'GKM_HOME';\n\n/** The CLI's home: `GKM_HOME` if set, else `~/.gkm`. */\nexport function gkmHome(env: NodeJS.ProcessEnv = process.env): string {\n\tconst configured = env[GKM_HOME_ENV];\n\treturn configured ? resolve(configured) : join(homedir(), '.gkm');\n}\n","/**\n * Start a program with an argument array, never a shell string.\n *\n * `gkm build`, `gkm docker` and `gkm deploy` pass values that come from the\n * workspace — image refs, tags, build args, package names — to `docker` and\n * `turbo`. Joined into a string and handed to a shell, a package named\n * `x;curl …|sh` or a tag holding `$(…)` became part of the command line, which\n * matters most where the CLI builds a repository it didn't write: a CI job for a\n * fork, a shared build runner. Here every value reaches the program as one\n * `argv` element, whatever it contains.\n */\n\nimport { type SpawnOptions, spawn } from 'node:child_process';\n\n/** Long enough for a cold image build; short enough that a hung one ends. */\nexport const DEFAULT_TIMEOUT_MS = 30 * 60_000;\n\n/** How long a timed-out child has to exit on SIGTERM before it is killed. */\nconst KILL_GRACE_MS = 5_000;\n\nexport interface RunOptions {\n\tcwd?: string;\n\tenv?: NodeJS.ProcessEnv;\n\tstdio?: SpawnOptions['stdio'];\n\t/** Kill the child after this long. Defaults to {@link DEFAULT_TIMEOUT_MS}. */\n\ttimeoutMs?: number;\n\t/**\n\t * Kills the child when aborted, and rejects with the signal's reason — the\n\t * same as a stopped deploy's other calls.\n\t */\n\tsignal?: AbortSignal;\n}\n\n/** The command line as a person would read it — for messages, never to run. */\nfunction display(command: string, args: readonly string[]): string {\n\treturn [command, ...args].join(' ');\n}\n\n/** The program ran and exited unsuccessfully; its own output said why. */\nexport class CommandFailed extends Error {\n\tconstructor(\n\t\treadonly command: string,\n\t\treadonly args: readonly string[],\n\t\treadonly exitCode: number | null,\n\t\treadonly signal: NodeJS.Signals | null,\n\t) {\n\t\tsuper(\n\t\t\t`\\`${display(command, args)}\\` ${exitCode === null ? `was stopped by ${signal ?? 'a signal'}` : `exited with code ${exitCode}`}. Its output above says why; run it by hand to see it again.`,\n\t\t);\n\t\tthis.name = 'CommandFailed';\n\t}\n}\n\n/** The program ran past its timeout and was killed. */\nexport class CommandTimedOut extends Error {\n\tconstructor(\n\t\treadonly command: string,\n\t\treadonly args: readonly string[],\n\t\treadonly timeoutMs: number,\n\t) {\n\t\tsuper(\n\t\t\t`\\`${display(command, args)}\\` was still running after ${Math.round(timeoutMs / 1000)}s and was stopped. Check what it was waiting on — a registry, the Docker daemon, a prompt — and run it again.`,\n\t\t);\n\t\tthis.name = 'CommandTimedOut';\n\t}\n}\n\n/**\n * Run `command` with `args`, resolving when it exits 0.\n *\n * Rejects with {@link CommandFailed} on any other exit, {@link CommandTimedOut}\n * once `timeoutMs` passes (after the child is gone), and with the spawn error\n * itself when the program cannot be started at all — `ENOENT` already names it.\n */\nexport async function run(\n\tcommand: string,\n\targs: readonly string[],\n\toptions: RunOptions = {},\n): Promise<void> {\n\tawait spawnChild(command, args, options, false);\n}\n\n/**\n * {@link run}, resolving with what the program wrote to stdout — for a value\n * the CLI reads back, such as the digest `docker inspect` reports. stderr still\n * reaches the terminal, so a failure explains itself the same way.\n */\nexport function runOutput(\n\tcommand: string,\n\targs: readonly string[],\n\toptions: Omit<RunOptions, 'stdio'> = {},\n): Promise<string> {\n\treturn spawnChild(command, args, options, true);\n}\n\nfunction spawnChild(\n\tcommand: string,\n\targs: readonly string[],\n\toptions: RunOptions,\n\tcapture: boolean,\n): Promise<string> {\n\tconst { timeoutMs = DEFAULT_TIMEOUT_MS, ...spawnOptions } = options;\n\n\treturn new Promise<string>((resolve, reject) => {\n\t\tconst child = spawn(command, [...args], {\n\t\t\tstdio: 'inherit',\n\t\t\t...spawnOptions,\n\t\t\t...(capture ? { stdio: ['ignore', 'pipe', 'inherit'] } : {}),\n\t\t\tshell: false,\n\t\t});\n\n\t\tlet stdout = '';\n\t\tchild.stdout?.on('data', (chunk: Buffer) => {\n\t\t\tstdout += chunk.toString();\n\t\t});\n\n\t\tlet timedOut = false;\n\t\tlet killer: NodeJS.Timeout | undefined;\n\t\tconst timer = setTimeout(() => {\n\t\t\ttimedOut = true;\n\t\t\tchild.kill('SIGTERM');\n\t\t\t// A child that ignores SIGTERM would hold the deploy open forever.\n\t\t\tkiller = setTimeout(() => child.kill('SIGKILL'), KILL_GRACE_MS);\n\t\t\tkiller.unref?.();\n\t\t}, timeoutMs);\n\t\ttimer.unref?.();\n\n\t\tconst settle = () => {\n\t\t\tclearTimeout(timer);\n\t\t\tif (killer) clearTimeout(killer);\n\t\t};\n\n\t\tchild.on('error', (error) => {\n\t\t\tsettle();\n\t\t\t// Node reports an abort as its own `AbortError`; the caller asked\n\t\t\t// with a reason, and that is what it should get back.\n\t\t\treject(spawnOptions.signal?.aborted ? spawnOptions.signal.reason : error);\n\t\t});\n\n\t\tchild.on('close', (code: number | null, signal: NodeJS.Signals | null) => {\n\t\t\tsettle();\n\t\t\tif (spawnOptions.signal?.aborted) reject(spawnOptions.signal.reason);\n\t\t\telse if (timedOut) reject(new CommandTimedOut(command, args, timeoutMs));\n\t\t\telse if (code === 0) resolve(stdout);\n\t\t\telse reject(new CommandFailed(command, args, code, signal));\n\t\t});\n\t});\n}\n"],"mappings":";;;;;;;;;;;;;AAaA,MAAa,eAAe;;AAG5B,SAAgB,QAAQ,MAAyB,QAAQ,KAAa;CACrE,MAAM,aAAa,IAAI;CACvB,OAAO,aAAa,QAAQ,UAAU,IAAI,KAAK,QAAQ,GAAG,MAAM;AACjE;;;;;;;;;;;;;;;ACJA,MAAa,qBAAqB;;AAGlC,MAAM,gBAAgB;;AAgBtB,SAAS,QAAQ,SAAiB,MAAiC;CAClE,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC,CAAC,KAAK,GAAG;AACnC;;AAGA,IAAa,gBAAb,cAAmC,MAAM;CAE9B;CACA;CACA;CACA;CAJV,YACC,SACA,MACA,UACA,QACC;EACD,MACC,KAAK,QAAQ,SAAS,IAAI,EAAE,KAAK,aAAa,OAAO,kBAAkB,UAAU,eAAe,oBAAoB,WAAW,6DAChI;EAPS,KAAA,UAA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AO;GAGP,OAAO,aAAa,QAAQ,UAAU,aAAa,OAAO,SAAS,KAAK;EACzE,CAAC;EAED,MAAM,GAAG,UAAU,MAAqB,WAAkC;GACzE,OAAO;GACP,IAAI,aAAa,QAAQ,SAAS,OAAO,aAAa,OAAO,MAAM;QAC9D,IAAI,UAAU,OAAO,IAAI,gBAAgB,SAAS,MAAM,SAAS,CAAC;QAClE,IAAI,SAAS,GAAG,QAAQ,MAAM;QAC9B,OAAO,IAAI,cAAc,SAAS,MAAM,MAAM,MAAM,CAAC;EAC3D,CAAC;CACF,CAAC;AACF"}
@@ -0,0 +1,174 @@
1
+ let node_path = require("node:path");
2
+ let node_os = require("node:os");
3
+ let node_child_process = require("node:child_process");
4
+ //#region src/home.ts
5
+ /**
6
+ * Where the CLI keeps what belongs to a person rather than a project: stage
7
+ * keys and stored provider credentials.
8
+ *
9
+ * `GKM_HOME` names it, so a CI job, a shared build runner or a test can give
10
+ * every run its own instead of reaching into whoever's home directory the
11
+ * process happens to have. Unset, it is `~/.gkm`, where it has always been.
12
+ */
13
+ /** The environment variable that moves the CLI's home. */
14
+ const GKM_HOME_ENV = "GKM_HOME";
15
+ /** The CLI's home: `GKM_HOME` if set, else `~/.gkm`. */
16
+ function gkmHome(env = process.env) {
17
+ const configured = env[GKM_HOME_ENV];
18
+ return configured ? (0, node_path.resolve)(configured) : (0, node_path.join)((0, node_os.homedir)(), ".gkm");
19
+ }
20
+ //#endregion
21
+ //#region src/run.ts
22
+ /**
23
+ * Start a program with an argument array, never a shell string.
24
+ *
25
+ * `gkm build`, `gkm docker` and `gkm deploy` pass values that come from the
26
+ * workspace — image refs, tags, build args, package names — to `docker` and
27
+ * `turbo`. Joined into a string and handed to a shell, a package named
28
+ * `x;curl …|sh` or a tag holding `$(…)` became part of the command line, which
29
+ * matters most where the CLI builds a repository it didn't write: a CI job for a
30
+ * fork, a shared build runner. Here every value reaches the program as one
31
+ * `argv` element, whatever it contains.
32
+ */
33
+ /** Long enough for a cold image build; short enough that a hung one ends. */
34
+ const DEFAULT_TIMEOUT_MS = 18e5;
35
+ /** How long a timed-out child has to exit on SIGTERM before it is killed. */
36
+ const KILL_GRACE_MS = 5e3;
37
+ /** The command line as a person would read it — for messages, never to run. */
38
+ function display(command, args) {
39
+ return [command, ...args].join(" ");
40
+ }
41
+ /** The program ran and exited unsuccessfully; its own output said why. */
42
+ var CommandFailed = class extends Error {
43
+ command;
44
+ args;
45
+ exitCode;
46
+ signal;
47
+ constructor(command, args, exitCode, signal) {
48
+ super(`\`${display(command, args)}\` ${exitCode === null ? `was stopped by ${signal ?? "a signal"}` : `exited with code ${exitCode}`}. Its output above says why; run it by hand to see it again.`);
49
+ this.command = command;
50
+ this.args = args;
51
+ this.exitCode = exitCode;
52
+ this.signal = signal;
53
+ this.name = "CommandFailed";
54
+ }
55
+ };
56
+ /** The program ran past its timeout and was killed. */
57
+ var CommandTimedOut = class extends Error {
58
+ command;
59
+ args;
60
+ timeoutMs;
61
+ constructor(command, args, timeoutMs) {
62
+ super(`\`${display(command, args)}\` was still running after ${Math.round(timeoutMs / 1e3)}s and was stopped. Check what it was waiting on — a registry, the Docker daemon, a prompt — and run it again.`);
63
+ this.command = command;
64
+ this.args = args;
65
+ this.timeoutMs = timeoutMs;
66
+ this.name = "CommandTimedOut";
67
+ }
68
+ };
69
+ /**
70
+ * Run `command` with `args`, resolving when it exits 0.
71
+ *
72
+ * Rejects with {@link CommandFailed} on any other exit, {@link CommandTimedOut}
73
+ * once `timeoutMs` passes (after the child is gone), and with the spawn error
74
+ * itself when the program cannot be started at all — `ENOENT` already names it.
75
+ */
76
+ async function run(command, args, options = {}) {
77
+ await spawnChild(command, args, options, false);
78
+ }
79
+ /**
80
+ * {@link run}, resolving with what the program wrote to stdout — for a value
81
+ * the CLI reads back, such as the digest `docker inspect` reports. stderr still
82
+ * reaches the terminal, so a failure explains itself the same way.
83
+ */
84
+ function runOutput(command, args, options = {}) {
85
+ return spawnChild(command, args, options, true);
86
+ }
87
+ function spawnChild(command, args, options, capture) {
88
+ const { timeoutMs = DEFAULT_TIMEOUT_MS, ...spawnOptions } = options;
89
+ return new Promise((resolve, reject) => {
90
+ const child = (0, node_child_process.spawn)(command, [...args], {
91
+ stdio: "inherit",
92
+ ...spawnOptions,
93
+ ...capture ? { stdio: [
94
+ "ignore",
95
+ "pipe",
96
+ "inherit"
97
+ ] } : {},
98
+ shell: false
99
+ });
100
+ let stdout = "";
101
+ child.stdout?.on("data", (chunk) => {
102
+ stdout += chunk.toString();
103
+ });
104
+ let timedOut = false;
105
+ let killer;
106
+ const timer = setTimeout(() => {
107
+ timedOut = true;
108
+ child.kill("SIGTERM");
109
+ killer = setTimeout(() => child.kill("SIGKILL"), KILL_GRACE_MS);
110
+ killer.unref?.();
111
+ }, timeoutMs);
112
+ timer.unref?.();
113
+ const settle = () => {
114
+ clearTimeout(timer);
115
+ if (killer) clearTimeout(killer);
116
+ };
117
+ child.on("error", (error) => {
118
+ settle();
119
+ reject(spawnOptions.signal?.aborted ? spawnOptions.signal.reason : error);
120
+ });
121
+ child.on("close", (code, signal) => {
122
+ settle();
123
+ if (spawnOptions.signal?.aborted) reject(spawnOptions.signal.reason);
124
+ else if (timedOut) reject(new CommandTimedOut(command, args, timeoutMs));
125
+ else if (code === 0) resolve(stdout);
126
+ else reject(new CommandFailed(command, args, code, signal));
127
+ });
128
+ });
129
+ }
130
+ //#endregion
131
+ Object.defineProperty(exports, "CommandFailed", {
132
+ enumerable: true,
133
+ get: function() {
134
+ return CommandFailed;
135
+ }
136
+ });
137
+ Object.defineProperty(exports, "CommandTimedOut", {
138
+ enumerable: true,
139
+ get: function() {
140
+ return CommandTimedOut;
141
+ }
142
+ });
143
+ Object.defineProperty(exports, "DEFAULT_TIMEOUT_MS", {
144
+ enumerable: true,
145
+ get: function() {
146
+ return DEFAULT_TIMEOUT_MS;
147
+ }
148
+ });
149
+ Object.defineProperty(exports, "GKM_HOME_ENV", {
150
+ enumerable: true,
151
+ get: function() {
152
+ return GKM_HOME_ENV;
153
+ }
154
+ });
155
+ Object.defineProperty(exports, "gkmHome", {
156
+ enumerable: true,
157
+ get: function() {
158
+ return gkmHome;
159
+ }
160
+ });
161
+ Object.defineProperty(exports, "run", {
162
+ enumerable: true,
163
+ get: function() {
164
+ return run;
165
+ }
166
+ });
167
+ Object.defineProperty(exports, "runOutput", {
168
+ enumerable: true,
169
+ get: function() {
170
+ return runOutput;
171
+ }
172
+ });
173
+
174
+ //# sourceMappingURL=run-fVZ-rLnc.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-fVZ-rLnc.cjs","names":["resolve","join","homedir","spawn"],"sources":["../src/home.ts","../src/run.ts"],"sourcesContent":["/**\n * Where the CLI keeps what belongs to a person rather than a project: stage\n * keys and stored provider credentials.\n *\n * `GKM_HOME` names it, so a CI job, a shared build runner or a test can give\n * every run its own instead of reaching into whoever's home directory the\n * process happens to have. Unset, it is `~/.gkm`, where it has always been.\n */\n\nimport { homedir } from 'node:os';\nimport { join, resolve } from 'node:path';\n\n/** The environment variable that moves the CLI's home. */\nexport const GKM_HOME_ENV = 'GKM_HOME';\n\n/** The CLI's home: `GKM_HOME` if set, else `~/.gkm`. */\nexport function gkmHome(env: NodeJS.ProcessEnv = process.env): string {\n\tconst configured = env[GKM_HOME_ENV];\n\treturn configured ? resolve(configured) : join(homedir(), '.gkm');\n}\n","/**\n * Start a program with an argument array, never a shell string.\n *\n * `gkm build`, `gkm docker` and `gkm deploy` pass values that come from the\n * workspace — image refs, tags, build args, package names — to `docker` and\n * `turbo`. Joined into a string and handed to a shell, a package named\n * `x;curl …|sh` or a tag holding `$(…)` became part of the command line, which\n * matters most where the CLI builds a repository it didn't write: a CI job for a\n * fork, a shared build runner. Here every value reaches the program as one\n * `argv` element, whatever it contains.\n */\n\nimport { type SpawnOptions, spawn } from 'node:child_process';\n\n/** Long enough for a cold image build; short enough that a hung one ends. */\nexport const DEFAULT_TIMEOUT_MS = 30 * 60_000;\n\n/** How long a timed-out child has to exit on SIGTERM before it is killed. */\nconst KILL_GRACE_MS = 5_000;\n\nexport interface RunOptions {\n\tcwd?: string;\n\tenv?: NodeJS.ProcessEnv;\n\tstdio?: SpawnOptions['stdio'];\n\t/** Kill the child after this long. Defaults to {@link DEFAULT_TIMEOUT_MS}. */\n\ttimeoutMs?: number;\n\t/**\n\t * Kills the child when aborted, and rejects with the signal's reason — the\n\t * same as a stopped deploy's other calls.\n\t */\n\tsignal?: AbortSignal;\n}\n\n/** The command line as a person would read it — for messages, never to run. */\nfunction display(command: string, args: readonly string[]): string {\n\treturn [command, ...args].join(' ');\n}\n\n/** The program ran and exited unsuccessfully; its own output said why. */\nexport class CommandFailed extends Error {\n\tconstructor(\n\t\treadonly command: string,\n\t\treadonly args: readonly string[],\n\t\treadonly exitCode: number | null,\n\t\treadonly signal: NodeJS.Signals | null,\n\t) {\n\t\tsuper(\n\t\t\t`\\`${display(command, args)}\\` ${exitCode === null ? `was stopped by ${signal ?? 'a signal'}` : `exited with code ${exitCode}`}. Its output above says why; run it by hand to see it again.`,\n\t\t);\n\t\tthis.name = 'CommandFailed';\n\t}\n}\n\n/** The program ran past its timeout and was killed. */\nexport class CommandTimedOut extends Error {\n\tconstructor(\n\t\treadonly command: string,\n\t\treadonly args: readonly string[],\n\t\treadonly timeoutMs: number,\n\t) {\n\t\tsuper(\n\t\t\t`\\`${display(command, args)}\\` was still running after ${Math.round(timeoutMs / 1000)}s and was stopped. Check what it was waiting on — a registry, the Docker daemon, a prompt — and run it again.`,\n\t\t);\n\t\tthis.name = 'CommandTimedOut';\n\t}\n}\n\n/**\n * Run `command` with `args`, resolving when it exits 0.\n *\n * Rejects with {@link CommandFailed} on any other exit, {@link CommandTimedOut}\n * once `timeoutMs` passes (after the child is gone), and with the spawn error\n * itself when the program cannot be started at all — `ENOENT` already names it.\n */\nexport async function run(\n\tcommand: string,\n\targs: readonly string[],\n\toptions: RunOptions = {},\n): Promise<void> {\n\tawait spawnChild(command, args, options, false);\n}\n\n/**\n * {@link run}, resolving with what the program wrote to stdout — for a value\n * the CLI reads back, such as the digest `docker inspect` reports. stderr still\n * reaches the terminal, so a failure explains itself the same way.\n */\nexport function runOutput(\n\tcommand: string,\n\targs: readonly string[],\n\toptions: Omit<RunOptions, 'stdio'> = {},\n): Promise<string> {\n\treturn spawnChild(command, args, options, true);\n}\n\nfunction spawnChild(\n\tcommand: string,\n\targs: readonly string[],\n\toptions: RunOptions,\n\tcapture: boolean,\n): Promise<string> {\n\tconst { timeoutMs = DEFAULT_TIMEOUT_MS, ...spawnOptions } = options;\n\n\treturn new Promise<string>((resolve, reject) => {\n\t\tconst child = spawn(command, [...args], {\n\t\t\tstdio: 'inherit',\n\t\t\t...spawnOptions,\n\t\t\t...(capture ? { stdio: ['ignore', 'pipe', 'inherit'] } : {}),\n\t\t\tshell: false,\n\t\t});\n\n\t\tlet stdout = '';\n\t\tchild.stdout?.on('data', (chunk: Buffer) => {\n\t\t\tstdout += chunk.toString();\n\t\t});\n\n\t\tlet timedOut = false;\n\t\tlet killer: NodeJS.Timeout | undefined;\n\t\tconst timer = setTimeout(() => {\n\t\t\ttimedOut = true;\n\t\t\tchild.kill('SIGTERM');\n\t\t\t// A child that ignores SIGTERM would hold the deploy open forever.\n\t\t\tkiller = setTimeout(() => child.kill('SIGKILL'), KILL_GRACE_MS);\n\t\t\tkiller.unref?.();\n\t\t}, timeoutMs);\n\t\ttimer.unref?.();\n\n\t\tconst settle = () => {\n\t\t\tclearTimeout(timer);\n\t\t\tif (killer) clearTimeout(killer);\n\t\t};\n\n\t\tchild.on('error', (error) => {\n\t\t\tsettle();\n\t\t\t// Node reports an abort as its own `AbortError`; the caller asked\n\t\t\t// with a reason, and that is what it should get back.\n\t\t\treject(spawnOptions.signal?.aborted ? spawnOptions.signal.reason : error);\n\t\t});\n\n\t\tchild.on('close', (code: number | null, signal: NodeJS.Signals | null) => {\n\t\t\tsettle();\n\t\t\tif (spawnOptions.signal?.aborted) reject(spawnOptions.signal.reason);\n\t\t\telse if (timedOut) reject(new CommandTimedOut(command, args, timeoutMs));\n\t\t\telse if (code === 0) resolve(stdout);\n\t\t\telse reject(new CommandFailed(command, args, code, signal));\n\t\t});\n\t});\n}\n"],"mappings":";;;;;;;;;;;;;AAaA,MAAa,eAAe;;AAG5B,SAAgB,QAAQ,MAAyB,QAAQ,KAAa;CACrE,MAAM,aAAa,IAAI;CACvB,OAAO,cAAA,GAAaA,UAAAA,QAAAA,CAAQ,UAAU,KAAA,GAAIC,UAAAA,KAAAA,EAAAA,GAAKC,QAAAA,QAAAA,CAAQ,GAAG,MAAM;AACjE;;;;;;;;;;;;;;;ACJA,MAAa,qBAAqB;;AAGlC,MAAM,gBAAgB;;AAgBtB,SAAS,QAAQ,SAAiB,MAAiC;CAClE,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC,CAAC,KAAK,GAAG;AACnC;;AAGA,IAAa,gBAAb,cAAmC,MAAM;CAE9B;CACA;CACA;CACA;CAJV,YACC,SACA,MACA,UACA,QACC;EACD,MACC,KAAK,QAAQ,SAAS,IAAI,EAAE,KAAK,aAAa,OAAO,kBAAkB,UAAU,eAAe,oBAAoB,WAAW,6DAChI;EAPS,KAAA,UAAA;EACA,KAAA,OAAA;EACA,KAAA,WAAA;EACA,KAAA,SAAA;EAKT,KAAK,OAAO;CACb;AACD;;AAGA,IAAa,kBAAb,cAAqC,MAAM;CAEhC;CACA;CACA;CAHV,YACC,SACA,MACA,WACC;EACD,MACC,KAAK,QAAQ,SAAS,IAAI,EAAE,6BAA6B,KAAK,MAAM,YAAY,GAAI,EAAE,8GACvF;EANS,KAAA,UAAA;EACA,KAAA,OAAA;EACA,KAAA,YAAA;EAKT,KAAK,OAAO;CACb;AACD;;;;;;;;AASA,eAAsB,IACrB,SACA,MACA,UAAsB,CAAC,GACP;CAChB,MAAM,WAAW,SAAS,MAAM,SAAS,KAAK;AAC/C;;;;;;AAOA,SAAgB,UACf,SACA,MACA,UAAqC,CAAC,GACpB;CAClB,OAAO,WAAW,SAAS,MAAM,SAA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ox } from "./credentials-pAtB70k3.mjs";
3
3
  import { d as output, s as nodeWithTsx } from "./discover-BFoJWKGD.mjs";
4
4
  import { i as activeSandbox } from "./sandbox-Dm247NGx.mjs";
5
5
  import { h as getPublicEnvPrefix } from "./workspace-Be6uBhlF.mjs";
@@ -7,7 +7,7 @@ import { dirname, resolve } from "node:path";
7
7
  import { existsSync } from "node:fs";
8
8
  import { hostname, userInfo } from "node:os";
9
9
  import { fileURLToPath } from "node:url";
10
- import { createCipheriv, createHash, randomBytes, randomUUID } from "node:crypto";
10
+ import { createHash, randomUUID } from "node:crypto";
11
11
  //#region src/workspace/client-generator.ts
12
12
  /**
13
13
  * Normalize routes to an array of patterns.
@@ -19,58 +19,6 @@ function normalizeRoutes(routes) {
19
19
  return Array.isArray(routes) ? routes : [routes];
20
20
  }
21
21
  //#endregion
22
- //#region src/secrets/encryption.ts
23
- var encryption_exports = /* @__PURE__ */ __exportAll({
24
- encryptSecrets: () => encryptSecrets,
25
- generateDefineOptions: () => generateDefineOptions,
26
- keyFingerprint: () => keyFingerprint
27
- });
28
- /** AES-256-GCM configuration */
29
- const ALGORITHM = "aes-256-gcm";
30
- const KEY_LENGTH = 32;
31
- const IV_LENGTH = 12;
32
- /**
33
- * Encrypt secrets for embedding in a bundle.
34
- * Uses AES-256-GCM with a randomly generated ephemeral key.
35
- *
36
- * @param secrets - Key-value pairs to encrypt
37
- * @returns Encrypted payload with ephemeral master key
38
- */
39
- function encryptSecrets(secrets) {
40
- const masterKey = randomBytes(KEY_LENGTH);
41
- const iv = randomBytes(IV_LENGTH);
42
- const plaintext = JSON.stringify(secrets);
43
- const cipher = createCipheriv(ALGORITHM, masterKey, iv);
44
- const ciphertext = Buffer.concat([cipher.update(plaintext, "utf-8"), cipher.final()]);
45
- const authTag = cipher.getAuthTag();
46
- return {
47
- encrypted: Buffer.concat([ciphertext, authTag]).toString("base64"),
48
- iv: iv.toString("hex"),
49
- masterKey: masterKey.toString("hex")
50
- };
51
- }
52
- /**
53
- * Generate the define options for tsdown/esbuild.
54
- * These will be injected at build time.
55
- */
56
- function generateDefineOptions(payload) {
57
- return {
58
- __GKM_ENCRYPTED_CREDENTIALS__: JSON.stringify(payload.encrypted),
59
- __GKM_CREDENTIALS_IV__: JSON.stringify(payload.iv)
60
- };
61
- }
62
- /**
63
- * A short, one-way name for a master key: the first 8 hex characters of its
64
- * SHA-256.
65
- *
66
- * Printed where the key itself used to be, so a person can tell which key a
67
- * build used — and match it against the one they hold — without the output
68
- * carrying a value that decrypts every secret of the stage.
69
- */
70
- function keyFingerprint(masterKey) {
71
- return createHash("sha256").update(masterKey).digest("hex").slice(0, 8);
72
- }
73
- //#endregion
74
22
  //#region src/deploy/events.ts
75
23
  /** An error as an event carries it: its name and message, nothing else. */
76
24
  function eventError(error) {
@@ -405,17 +353,17 @@ function isStateStore(value) {
405
353
  async function createStateStore(options) {
406
354
  const { config, workspaceRoot, workspaceName } = options;
407
355
  if (!config || config.provider === "local") {
408
- const { LocalStateStore } = await import("./LocalStateStore-Bm3x9oOg.mjs").then((n) => n.n);
356
+ const { LocalStateStore } = await import("./LocalStateStore-Dk3Wbvzk.mjs").then((n) => n.n);
409
357
  return new LocalStateStore(workspaceRoot);
410
358
  }
411
359
  if (isStateStore(config.provider)) return config.provider;
412
360
  if (isStateProvider(config.provider)) {
413
- const { LegacyStateStore } = await import("./LegacyStateStore-CFheFo62.mjs");
361
+ const { LegacyStateStore } = await import("./LegacyStateStore-C39UKwmf.mjs");
414
362
  return new LegacyStateStore(config.provider, { warn: options.warn });
415
363
  }
416
364
  if (config.provider === "ssm") {
417
365
  if (!workspaceName) throw new StateStoreNeedsWorkspaceName("ssm");
418
- const { SSMStateStore } = await import("./SSMStateStore-C1kvHScY.mjs");
366
+ const { SSMStateStore } = await import("./SSMStateStore-DjPuKqrm.mjs");
419
367
  const ssm = config;
420
368
  return SSMStateStore.create({
421
369
  workspaceName,
@@ -425,7 +373,7 @@ async function createStateStore(options) {
425
373
  }
426
374
  if (config.provider === "s3") {
427
375
  if (!workspaceName) throw new StateStoreNeedsWorkspaceName("s3");
428
- const { S3StateStore } = await import("./S3StateStore-BFHuctWM.mjs");
376
+ const { S3StateStore } = await import("./S3StateStore-B_ZF9eHt.mjs");
429
377
  const s3 = config;
430
378
  return S3StateStore.create({
431
379
  workspaceName,
@@ -1612,6 +1560,6 @@ async function sniffAllApps(apps, workspacePath, options = {}) {
1612
1560
  return results;
1613
1561
  }
1614
1562
  //#endregion
1615
- export { newLockHolder as _, DeploymentTimedOut as a, encryption_exports as b, dokploy_api_exports as c, StateLocked as d, StateStoreBusy as f, createStateStore as g, contentVersion as h, DeploymentFailed as i, DocumentStateStore as l, StateVersionConflict as m, sniffAppEnvironment as n, DokployApi as o, StateStoreWithoutLocking as p, DEFAULT_DEPLOYMENT_TIMEOUT_MS as r, DokployApiError as s, sniffAllApps as t, StageStateMissing as u, eventError as v, keyFingerprint as x, encryptSecrets as y };
1563
+ export { newLockHolder as _, DeploymentTimedOut as a, dokploy_api_exports as c, StateLocked as d, StateStoreBusy as f, createStateStore as g, contentVersion as h, DeploymentFailed as i, DocumentStateStore as l, StateVersionConflict as m, sniffAppEnvironment as n, DokployApi as o, StateStoreWithoutLocking as p, DEFAULT_DEPLOYMENT_TIMEOUT_MS as r, DokployApiError as s, sniffAllApps as t, StageStateMissing as u, eventError as v };
1616
1564
 
1617
- //# sourceMappingURL=sniffer-BAQhLEsI.mjs.map
1565
+ //# sourceMappingURL=sniffer-BdFeLSmA.mjs.map