@geekmidas/cli 10.0.0-alpha.65 → 10.0.0-alpha.66
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -0
- package/dist/{HostingerProvider-Dlmbfass.cjs → HostingerProvider-BznqRC2S.cjs} +3 -3
- package/dist/HostingerProvider-BznqRC2S.cjs.map +1 -0
- package/dist/{HostingerProvider-x9gQTAGZ.mjs → HostingerProvider-CY_VpVud.mjs} +3 -3
- package/dist/HostingerProvider-CY_VpVud.mjs.map +1 -0
- package/dist/{LegacyStateStore-BGoo__sO.cjs → LegacyStateStore-BFcTT2QL.cjs} +2 -2
- package/dist/{LegacyStateStore-BGoo__sO.cjs.map → LegacyStateStore-BFcTT2QL.cjs.map} +1 -1
- package/dist/{LegacyStateStore-BUu1nQ5u.mjs → LegacyStateStore-CFheFo62.mjs} +2 -2
- package/dist/{LegacyStateStore-BUu1nQ5u.mjs.map → LegacyStateStore-CFheFo62.mjs.map} +1 -1
- package/dist/{LocalStateStore-93urXyQe.cjs → LocalStateStore-BVUexSvu.cjs} +2 -2
- package/dist/{LocalStateStore-93urXyQe.cjs.map → LocalStateStore-BVUexSvu.cjs.map} +1 -1
- package/dist/{LocalStateStore-BRhMQRuy.mjs → LocalStateStore-Bm3x9oOg.mjs} +2 -2
- package/dist/{LocalStateStore-BRhMQRuy.mjs.map → LocalStateStore-Bm3x9oOg.mjs.map} +1 -1
- package/dist/{OpenApiTsGenerator-BWuDRHe9.cjs → OpenApiTsGenerator-B2zrdyP4.cjs} +2 -2
- package/dist/{OpenApiTsGenerator-BWuDRHe9.cjs.map → OpenApiTsGenerator-B2zrdyP4.cjs.map} +1 -1
- package/dist/{OpenApiTsGenerator-C6v-IeHt.mjs → OpenApiTsGenerator-BmUAcR7d.mjs} +2 -2
- package/dist/{OpenApiTsGenerator-C6v-IeHt.mjs.map → OpenApiTsGenerator-BmUAcR7d.mjs.map} +1 -1
- package/dist/{Route53Provider-DVILBsvV.cjs → Route53Provider-Bllus2NR.cjs} +2 -2
- package/dist/Route53Provider-Bllus2NR.cjs.map +1 -0
- package/dist/{Route53Provider-Cvj40A8I.mjs → Route53Provider-QXxjkZO1.mjs} +2 -2
- package/dist/Route53Provider-QXxjkZO1.mjs.map +1 -0
- package/dist/{S3StateStore-pw1GhWwt.mjs → S3StateStore-BFHuctWM.mjs} +2 -2
- package/dist/{S3StateStore-pw1GhWwt.mjs.map → S3StateStore-BFHuctWM.mjs.map} +1 -1
- package/dist/{S3StateStore-F4dxw6kS.cjs → S3StateStore-CoXBhILd.cjs} +2 -2
- package/dist/{S3StateStore-F4dxw6kS.cjs.map → S3StateStore-CoXBhILd.cjs.map} +1 -1
- package/dist/{SSMStateStore-Bt9acuAF.cjs → SSMStateStore-BqCA9TP2.cjs} +2 -2
- package/dist/{SSMStateStore-Bt9acuAF.cjs.map → SSMStateStore-BqCA9TP2.cjs.map} +1 -1
- package/dist/{SSMStateStore-Dmj7zzFO.mjs → SSMStateStore-C1kvHScY.mjs} +2 -2
- package/dist/{SSMStateStore-Dmj7zzFO.mjs.map → SSMStateStore-C1kvHScY.mjs.map} +1 -1
- package/dist/{backup-provisioner-DIVCbfee.mjs → backup-provisioner-C8DnCmxK.mjs} +2 -2
- package/dist/backup-provisioner-C8DnCmxK.mjs.map +1 -0
- package/dist/{backup-provisioner-BmhIO_Yr.cjs → backup-provisioner-oDEsPj02.cjs} +2 -2
- package/dist/backup-provisioner-oDEsPj02.cjs.map +1 -0
- package/dist/{bundler-D_14JLZF.mjs → bundler-Dvaiud0h.mjs} +4 -4
- package/dist/{bundler-D_14JLZF.mjs.map → bundler-Dvaiud0h.mjs.map} +1 -1
- package/dist/{bundler-D6MlIfBT.cjs → bundler-orRqUJNZ.cjs} +4 -4
- package/dist/{bundler-D6MlIfBT.cjs.map → bundler-orRqUJNZ.cjs.map} +1 -1
- package/dist/{cli-P56vvrDQ.mjs → cli-CfHm0AO7.mjs} +5 -4
- package/dist/cli-CfHm0AO7.mjs.map +1 -0
- package/dist/{cli-BfH1deAT.cjs → cli-D1JkkOwg.cjs} +5 -4
- package/dist/cli-D1JkkOwg.cjs.map +1 -0
- package/dist/{compose-DprE3ASm.mjs → compose-CNQL8BnO.mjs} +18 -482
- package/dist/compose-CNQL8BnO.mjs.map +1 -0
- package/dist/{compose-391oEKj1.cjs → compose-jrLy7KGO.cjs} +16 -571
- package/dist/compose-jrLy7KGO.cjs.map +1 -0
- package/dist/{config-V_X_BMpm.d.cts → config-4XFxX1al.d.cts} +3 -3
- package/dist/{config-BonvTW8p.d.mts.map → config-4XFxX1al.d.cts.map} +1 -1
- package/dist/{config-BonvTW8p.d.mts → config-UtKzhpFb.d.mts} +3 -3
- package/dist/{config-V_X_BMpm.d.cts.map → config-UtKzhpFb.d.mts.map} +1 -1
- package/dist/config.cjs +3 -3
- package/dist/config.d.cts +3 -3
- package/dist/config.d.mts +3 -3
- package/dist/config.mjs +3 -3
- package/dist/databases-C2p5LGAp.cjs +419 -0
- package/dist/databases-C2p5LGAp.cjs.map +1 -0
- package/dist/databases-hUHTuwhx.mjs +346 -0
- package/dist/databases-hUHTuwhx.mjs.map +1 -0
- package/dist/deploy/public.cjs +26 -17
- package/dist/deploy/public.d.cts +136 -19
- package/dist/deploy/public.d.cts.map +1 -1
- package/dist/deploy/public.d.mts +136 -19
- package/dist/deploy/public.d.mts.map +1 -1
- package/dist/deploy/public.mjs +8 -8
- package/dist/deploy-B7aJi_Ah.cjs +511 -0
- package/dist/deploy-B7aJi_Ah.cjs.map +1 -0
- package/dist/deploy-DWn7YfIc.mjs +488 -0
- package/dist/deploy-DWn7YfIc.mjs.map +1 -0
- package/dist/{discover-LMrqsWSU.mjs → discover-BFoJWKGD.mjs} +4 -2
- package/dist/discover-BFoJWKGD.mjs.map +1 -0
- package/dist/{discover-DHdECueV.cjs → discover-OEfZ9OkA.cjs} +4 -2
- package/dist/discover-OEfZ9OkA.cjs.map +1 -0
- package/dist/dokploy-B4LcYG1E.cjs +38 -0
- package/dist/dokploy-B4LcYG1E.cjs.map +1 -0
- package/dist/dokploy-DalwLML5.mjs +38 -0
- package/dist/dokploy-DalwLML5.mjs.map +1 -0
- package/dist/{encryption-B1wJwgae.cjs → encryption-3KlGS1sl.cjs} +5 -7
- package/dist/{encryption-B1wJwgae.cjs.map → encryption-3KlGS1sl.cjs.map} +1 -1
- package/dist/{encryption-DF_hgIpl.mjs → encryption-CPfENwWO.mjs} +3 -5
- package/dist/{encryption-DF_hgIpl.mjs.map → encryption-CPfENwWO.mjs.map} +1 -1
- package/dist/{deploy-CZ5nlpsu.mjs → engine-CunvOG3s.mjs} +2100 -1733
- package/dist/engine-CunvOG3s.mjs.map +1 -0
- package/dist/{deploy-Cy8igpQF.cjs → engine-DR6KurWX.cjs} +2136 -1727
- package/dist/engine-DR6KurWX.cjs.map +1 -0
- package/dist/{github-CYcmTdFs.cjs → github-BJ5gh9bw.cjs} +7 -7
- package/dist/{github-CYcmTdFs.cjs.map → github-BJ5gh9bw.cjs.map} +1 -1
- package/dist/{github-B0YYE98x.mjs → github-MXA9v7Ge.mjs} +3 -3
- package/dist/{github-B0YYE98x.mjs.map → github-MXA9v7Ge.mjs.map} +1 -1
- package/dist/{index-DwKD_8lt.d.mts → index-CyApaHVe.d.cts} +2 -2
- package/dist/{index-DPUAGJaK.d.cts.map → index-CyApaHVe.d.cts.map} +1 -1
- package/dist/{index-DPUAGJaK.d.cts → index-DD1FfUHh.d.mts} +2 -2
- package/dist/{index-DwKD_8lt.d.mts.map → index-DD1FfUHh.d.mts.map} +1 -1
- package/dist/index.cjs +276 -68
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +254 -50
- package/dist/index.mjs.map +1 -1
- package/dist/{migrate-B2qL5wj4.mjs → migrate-BJBcm4sG.mjs} +6 -6
- package/dist/{migrate-B2qL5wj4.mjs.map → migrate-BJBcm4sG.mjs.map} +1 -1
- package/dist/{migrate-q4pPAXtO.cjs → migrate-CF4J4GQS.cjs} +16 -16
- package/dist/{migrate-q4pPAXtO.cjs.map → migrate-CF4J4GQS.cjs.map} +1 -1
- package/dist/openapi.cjs +1 -1
- package/dist/openapi.d.cts +1 -1
- package/dist/openapi.d.mts +1 -1
- package/dist/openapi.mjs +1 -1
- package/dist/provider-B3Sv_a74.cjs +173 -0
- package/dist/provider-B3Sv_a74.cjs.map +1 -0
- package/dist/provider-D7rQzzzf.mjs +138 -0
- package/dist/provider-D7rQzzzf.mjs.map +1 -0
- package/dist/{ready-bQfu9GES.mjs → ready-2s3-CndS.mjs} +3 -3
- package/dist/{ready-bQfu9GES.mjs.map → ready-2s3-CndS.mjs.map} +1 -1
- package/dist/{ready-brEhh68f.cjs → ready-B6uHr4sm.cjs} +3 -3
- package/dist/{ready-brEhh68f.cjs.map → ready-B6uHr4sm.cjs.map} +1 -1
- package/dist/reconcile/public.cjs +1 -1
- package/dist/reconcile/public.d.cts +1 -1
- package/dist/reconcile/public.d.mts +1 -1
- package/dist/reconcile/public.mjs +1 -1
- package/dist/{resolve-N_i4XNd-.cjs → resolve-CVmch0wI.cjs} +3 -3
- package/dist/{resolve-N_i4XNd-.cjs.map → resolve-CVmch0wI.cjs.map} +1 -1
- package/dist/{resolve-DLkIXTct.mjs → resolve-Db0tNlrW.mjs} +3 -3
- package/dist/{resolve-DLkIXTct.mjs.map → resolve-Db0tNlrW.mjs.map} +1 -1
- package/dist/rollback-DvAo4OKS.mjs +133 -0
- package/dist/rollback-DvAo4OKS.mjs.map +1 -0
- package/dist/rollback-DxJK84hy.cjs +162 -0
- package/dist/rollback-DxJK84hy.cjs.map +1 -0
- package/dist/{runtime-BnD7Nn96.d.cts → runtime-BRqFOvPM.d.cts} +2 -2
- package/dist/{runtime-BnD7Nn96.d.cts.map → runtime-BRqFOvPM.d.cts.map} +1 -1
- package/dist/{runtime-j-tmFL65.d.mts → runtime-CEk5n4VH.d.mts} +2 -2
- package/dist/{runtime-j-tmFL65.d.mts.map → runtime-CEk5n4VH.d.mts.map} +1 -1
- package/dist/sandbox/discover-worker.cjs +1 -1
- package/dist/sandbox/discover-worker.mjs +1 -1
- package/dist/sandbox/migrate-worker.cjs +61 -0
- package/dist/sandbox/migrate-worker.cjs.map +1 -0
- package/dist/sandbox/migrate-worker.d.cts +1 -0
- package/dist/sandbox/migrate-worker.d.mts +1 -0
- package/dist/sandbox/migrate-worker.mjs +62 -0
- package/dist/sandbox/migrate-worker.mjs.map +1 -0
- package/dist/{schemas-D2LCF689.mjs → schemas-Cfhtpdo0.mjs} +10 -2
- package/dist/{schemas-Ckm_aBnF.cjs.map → schemas-Cfhtpdo0.mjs.map} +1 -1
- package/dist/{schemas-Ckm_aBnF.cjs → schemas-RUlKHu27.cjs} +15 -1
- package/dist/{schemas-D2LCF689.mjs.map → schemas-RUlKHu27.cjs.map} +1 -1
- package/dist/{sniffer-BSwaL-dX.cjs → sniffer-5xmrkh2a.cjs} +112 -606
- package/dist/sniffer-5xmrkh2a.cjs.map +1 -0
- package/dist/{sniffer-BZ-OJO4Y.mjs → sniffer-BAQhLEsI.mjs} +95 -546
- package/dist/sniffer-BAQhLEsI.mjs.map +1 -0
- package/dist/{state-DF26e_lo.cjs → state-Y6ATakMX.cjs} +744 -20
- package/dist/state-Y6ATakMX.cjs.map +1 -0
- package/dist/{state-B8YwmUZU.mjs → state-uuYqnRVO.mjs} +605 -19
- package/dist/state-uuYqnRVO.mjs.map +1 -0
- package/dist/target/public.cjs +1 -1
- package/dist/target/public.d.cts +2 -2
- package/dist/target/public.d.mts +2 -2
- package/dist/target/public.mjs +1 -1
- package/dist/{terminal-Bs5E1oxm.cjs → terminal-CHy_MdjG.cjs} +11 -15
- package/dist/{terminal-Bs5E1oxm.cjs.map → terminal-CHy_MdjG.cjs.map} +1 -1
- package/dist/{terminal-CfbiYUbZ.mjs → terminal-DUhcZ1ND.mjs} +4 -4
- package/dist/{terminal-CfbiYUbZ.mjs.map → terminal-DUhcZ1ND.mjs.map} +1 -1
- package/dist/{types-ByMWkXKP.d.cts → types-CSw2w69a.d.mts} +68 -10
- package/dist/types-CSw2w69a.d.mts.map +1 -0
- package/dist/{types-BCzMWBb6.d.mts → types-D5WIxRDP.d.cts} +69 -9
- package/dist/types-D5WIxRDP.d.cts.map +1 -0
- package/dist/vitest.cjs +1 -1
- package/dist/vitest.mjs +1 -1
- package/dist/workspace/index.cjs +1 -1
- package/dist/workspace/index.d.cts +2 -2
- package/dist/workspace/index.d.mts +2 -2
- package/dist/workspace/index.mjs +1 -1
- package/dist/{workspace-C06_pW4g.mjs → workspace-Be6uBhlF.mjs} +10 -3
- package/dist/workspace-Be6uBhlF.mjs.map +1 -0
- package/dist/{workspace-BewAHZIo.cjs → workspace-ON-bqiJz.cjs} +10 -3
- package/dist/workspace-ON-bqiJz.cjs.map +1 -0
- package/package.json +13 -13
- package/dist/HostingerProvider-Dlmbfass.cjs.map +0 -1
- package/dist/HostingerProvider-x9gQTAGZ.mjs.map +0 -1
- package/dist/Route53Provider-Cvj40A8I.mjs.map +0 -1
- package/dist/Route53Provider-DVILBsvV.cjs.map +0 -1
- package/dist/backup-provisioner-BmhIO_Yr.cjs.map +0 -1
- package/dist/backup-provisioner-DIVCbfee.mjs.map +0 -1
- package/dist/cli-BfH1deAT.cjs.map +0 -1
- package/dist/cli-P56vvrDQ.mjs.map +0 -1
- package/dist/compose-391oEKj1.cjs.map +0 -1
- package/dist/compose-DprE3ASm.mjs.map +0 -1
- package/dist/deploy-9MBG_QLd.mjs +0 -137
- package/dist/deploy-9MBG_QLd.mjs.map +0 -1
- package/dist/deploy-B80idPUZ.cjs +0 -142
- package/dist/deploy-B80idPUZ.cjs.map +0 -1
- package/dist/deploy-CZ5nlpsu.mjs.map +0 -1
- package/dist/deploy-Cy8igpQF.cjs.map +0 -1
- package/dist/discover-DHdECueV.cjs.map +0 -1
- package/dist/discover-LMrqsWSU.mjs.map +0 -1
- package/dist/dokploy-BdtBePjp.mjs +0 -32
- package/dist/dokploy-BdtBePjp.mjs.map +0 -1
- package/dist/dokploy-iFY8MY-L.cjs +0 -32
- package/dist/dokploy-iFY8MY-L.cjs.map +0 -1
- package/dist/sniffer-BSwaL-dX.cjs.map +0 -1
- package/dist/sniffer-BZ-OJO4Y.mjs.map +0 -1
- package/dist/state-B8YwmUZU.mjs.map +0 -1
- package/dist/state-DF26e_lo.cjs.map +0 -1
- package/dist/storage-BzaUxmqe.mjs +0 -124
- package/dist/storage-BzaUxmqe.mjs.map +0 -1
- package/dist/storage-CSGoC3bK.cjs +0 -152
- package/dist/storage-CSGoC3bK.cjs.map +0 -1
- package/dist/store-CJF1Tqkq.cjs +0 -510
- package/dist/store-CJF1Tqkq.cjs.map +0 -1
- package/dist/store-CLiHnqOY.mjs +0 -415
- package/dist/store-CLiHnqOY.mjs.map +0 -1
- package/dist/types-BCzMWBb6.d.mts.map +0 -1
- package/dist/types-ByMWkXKP.d.cts.map +0 -1
- package/dist/workspace-BewAHZIo.cjs.map +0 -1
- package/dist/workspace-C06_pW4g.mjs.map +0 -1
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-BhDjJH2R.mjs";
|
|
2
|
+
import { t as LocalSandbox } from "./local-CWR4Y_kW.mjs";
|
|
3
|
+
import { r as storedCredentials } from "./credentials-Dq1MnWQf.mjs";
|
|
4
|
+
import { c as withSandbox } from "./sandbox-Dm247NGx.mjs";
|
|
5
|
+
import { k as assertDeployedStage } from "./workspace-Be6uBhlF.mjs";
|
|
6
|
+
import { findWorkspaceRoot, loadWorkspaceConfig } from "./config.mjs";
|
|
7
|
+
import { o as recordRollback, p as DeployJournal, t as createEmptyState } from "./state-uuYqnRVO.mjs";
|
|
8
|
+
import { g as createStateStore } from "./sniffer-BAQhLEsI.mjs";
|
|
9
|
+
import { i as dokployApi, l as restoreImage, p as verifySettings } from "./engine-CunvOG3s.mjs";
|
|
10
|
+
import { resolve } from "node:path";
|
|
11
|
+
//#region src/target/dokploy/rollback.ts
|
|
12
|
+
/**
|
|
13
|
+
* `gkm deploy:rollback`: a stage's apps put back on the release before the
|
|
14
|
+
* one they run, by hand — for a release that passed its checks and turned out
|
|
15
|
+
* wrong anyway.
|
|
16
|
+
*
|
|
17
|
+
* One app by default, because an app is what usually broke: rolling the API
|
|
18
|
+
* back over a site fix that shipped beside it undoes the fix too. `atomic`
|
|
19
|
+
* rolls back every app that has a release to go back to, for apps that only
|
|
20
|
+
* work together — an API and the site built against its newer contract.
|
|
21
|
+
*
|
|
22
|
+
* It restores images and nothing else. The environment an app runs with is
|
|
23
|
+
* the stage's, resolved on every deploy, and migrations are forward-only: a
|
|
24
|
+
* migration that the older code cannot run against is undone by a new
|
|
25
|
+
* migration, never by a rollback.
|
|
26
|
+
*/
|
|
27
|
+
var rollback_exports = /* @__PURE__ */ __exportAll({
|
|
28
|
+
NothingToRollBack: () => NothingToRollBack,
|
|
29
|
+
RollbackNeedsApp: () => RollbackNeedsApp,
|
|
30
|
+
StageNeverDeployed: () => StageNeverDeployed,
|
|
31
|
+
rollbackStage: () => rollbackStage
|
|
32
|
+
});
|
|
33
|
+
/** Neither an app nor every app was asked for. */
|
|
34
|
+
var RollbackNeedsApp = class extends Error {
|
|
35
|
+
stage;
|
|
36
|
+
apps;
|
|
37
|
+
constructor(stage, apps) {
|
|
38
|
+
super(`Say what to roll back: --app <name> for one app (${apps.join(", ") || "none has an earlier release"}), or --atomic for every app of "${stage}" together.`);
|
|
39
|
+
this.stage = stage;
|
|
40
|
+
this.apps = apps;
|
|
41
|
+
this.name = "RollbackNeedsApp";
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
/** An app has no release before the one it runs. */
|
|
45
|
+
var NothingToRollBack = class extends Error {
|
|
46
|
+
stage;
|
|
47
|
+
app;
|
|
48
|
+
constructor(stage, app) {
|
|
49
|
+
super(`"${app}" has no earlier release on "${stage}" to roll back to: it has been released once, or every earlier release was itself rolled back. Deploy the version you want instead.`);
|
|
50
|
+
this.stage = stage;
|
|
51
|
+
this.app = app;
|
|
52
|
+
this.name = "NothingToRollBack";
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
/** The stage was never deployed through Dokploy from this state. */
|
|
56
|
+
var StageNeverDeployed = class extends Error {
|
|
57
|
+
stage;
|
|
58
|
+
constructor(stage) {
|
|
59
|
+
super(`"${stage}" has no deploy state, so there is nothing to roll back. Check the stage name, and that \`state\` in gkm.config.ts points at the store the deploys write to.`);
|
|
60
|
+
this.stage = stage;
|
|
61
|
+
this.name = "StageNeverDeployed";
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Roll a stage's app — or, `atomic`, all of them — back to its previous
|
|
66
|
+
* release, holding the stage's lock as a deploy does.
|
|
67
|
+
*/
|
|
68
|
+
async function rollbackStage(input) {
|
|
69
|
+
const signal = input.signal ?? new AbortController().signal;
|
|
70
|
+
const log = input.log ?? (() => {});
|
|
71
|
+
const credentials = input.credentials ?? storedCredentials();
|
|
72
|
+
const sandbox = input.sandbox ?? new LocalSandbox({ root: findWorkspaceRoot(resolve(input.cwd)) });
|
|
73
|
+
return withSandbox(sandbox, async () => {
|
|
74
|
+
const { workspace } = await loadWorkspaceConfig(resolve(input.cwd), { sandbox });
|
|
75
|
+
assertDeployedStage(workspace.stages, input.stage);
|
|
76
|
+
const store = await createStateStore({
|
|
77
|
+
config: workspace.state,
|
|
78
|
+
workspaceRoot: workspace.root,
|
|
79
|
+
workspaceName: workspace.name
|
|
80
|
+
});
|
|
81
|
+
if (!await store.read(input.stage)) throw new StageNeverDeployed(input.stage);
|
|
82
|
+
const lock = await store.lock(input.stage, { operation: "rollback" });
|
|
83
|
+
try {
|
|
84
|
+
const journal = await DeployJournal.open(store, input.stage, () => createEmptyState(input.stage, "", ""));
|
|
85
|
+
const { state } = journal;
|
|
86
|
+
const releases = state.releases ?? {};
|
|
87
|
+
const restorable = Object.keys(releases).filter((app) => releases[app].previous);
|
|
88
|
+
let apps;
|
|
89
|
+
if (input.atomic) {
|
|
90
|
+
apps = restorable;
|
|
91
|
+
if (apps.length === 0) throw new RollbackNeedsApp(input.stage, restorable);
|
|
92
|
+
} else if (input.app) {
|
|
93
|
+
if (!releases[input.app]?.previous) throw new NothingToRollBack(input.stage, input.app);
|
|
94
|
+
apps = [input.app];
|
|
95
|
+
} else throw new RollbackNeedsApp(input.stage, restorable);
|
|
96
|
+
const { api } = await dokployApi(workspace, {
|
|
97
|
+
credentials,
|
|
98
|
+
signal
|
|
99
|
+
});
|
|
100
|
+
const verify = verifySettings(workspace.deploy.dokploy?.verify);
|
|
101
|
+
const rolled = [];
|
|
102
|
+
for (const app of apps) {
|
|
103
|
+
signal.throwIfAborted();
|
|
104
|
+
const { current, previous } = releases[app];
|
|
105
|
+
const applicationId = state.applications[app];
|
|
106
|
+
if (!previous || !applicationId) throw new NothingToRollBack(input.stage, app);
|
|
107
|
+
log(`⏪ ${app}: ${current.ref} → ${previous.ref}`);
|
|
108
|
+
await restoreImage(api, {
|
|
109
|
+
applicationId,
|
|
110
|
+
image: previous,
|
|
111
|
+
registryId: state.registryId,
|
|
112
|
+
verify,
|
|
113
|
+
signal
|
|
114
|
+
});
|
|
115
|
+
recordRollback(state, app, previous);
|
|
116
|
+
await journal.save();
|
|
117
|
+
log(` ✓ ${app} is running ${previous.ref}`);
|
|
118
|
+
rolled.push({
|
|
119
|
+
app,
|
|
120
|
+
from: current,
|
|
121
|
+
to: previous
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
return rolled;
|
|
125
|
+
} finally {
|
|
126
|
+
await lock.release();
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
//#endregion
|
|
131
|
+
export { rollback_exports as a, rollbackStage as i, RollbackNeedsApp as n, StageNeverDeployed as r, NothingToRollBack as t };
|
|
132
|
+
|
|
133
|
+
//# sourceMappingURL=rollback-DvAo4OKS.mjs.map
|
|
@@ -0,0 +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\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,MAAM,QAAQ,MAAM,iBAAiB;GACpC,QAAQ,UAAU;GAClB,eAAe,UAAU;GACzB,eAAe,UAAU;EAC1B,CAAC;EACD,IAAI,CAAE,MAAM,MAAM,KAAK,MAAM,KAAK,GACjC,MAAM,IAAI,mBAAmB,MAAM,KAAK;EAGzC,MAAM,OAAO,MAAM,MAAM,KAAK,MAAM,OAAO,EAAE,WAAW,WAAW,CAAC;EACpE,IAAI;GACH,MAAM,UAAU,MAAM,cAAc,KAAK,OAAO,MAAM,aACrD,iBAAiB,MAAM,OAAO,IAAI,EAAE,CACrC;GACA,MAAM,EAAE,UAAU;GAClB,MAAM,WAAW,MAAM,YAAY,CAAC;GACpC,MAAM,aAAa,OAAO,KAAK,QAAQ,CAAC,CAAC,QACvC,QAAQ,SAAS,IAAI,CAAE,QACzB;GAEA,IAAI;GACJ,IAAI,MAAM,QAAQ;IACjB,OAAO;IACP,IAAI,KAAK,WAAW,GACnB,MAAM,IAAI,iBAAiB,MAAM,OAAO,UAAU;GAEpD,OAAO,IAAI,MAAM,KAAK;IACrB,IAAI,CAAC,SAAS,MAAM,IAAI,EAAE,UACzB,MAAM,IAAI,kBAAkB,MAAM,OAAO,MAAM,GAAG;IAEnD,OAAO,CAAC,MAAM,GAAG;GAClB,OACC,MAAM,IAAI,iBAAiB,MAAM,OAAO,UAAU;GAGnD,MAAM,EAAE,QAAQ,MAAM,WAAW,WAAW;IAAE;IAAa;GAAO,CAAC;GACnE,MAAM,SAAS,eAAe,UAAU,OAAO,SAAS,MAAM;GAC9D,MAAM,SAAuB,CAAC;GAE9B,KAAK,MAAM,OAAO,MAAM;IACvB,OAAO,eAAe;IACtB,MAAM,EAAE,SAAS,aAAa,SAAS;IACvC,MAAM,gBAAgB,MAAM,aAAa;IACzC,IAAI,CAAC,YAAY,CAAC,eACjB,MAAM,IAAI,kBAAkB,MAAM,OAAO,GAAG;IAG7C,IAAI,KAAK,IAAI,IAAI,QAAQ,IAAI,KAAK,SAAS,KAAK;IAChD,MAAM,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,162 @@
|
|
|
1
|
+
const require_rolldown_runtime = require("./rolldown-runtime-C0BPl7ul.cjs");
|
|
2
|
+
const require_local = require("./local-BdH4XN0E.cjs");
|
|
3
|
+
const require_credentials = require("./credentials-Bzbg23n8.cjs");
|
|
4
|
+
const require_sandbox = require("./sandbox-CL--ZDui.cjs");
|
|
5
|
+
const require_workspace = require("./workspace-ON-bqiJz.cjs");
|
|
6
|
+
const require_config = require("./config.cjs");
|
|
7
|
+
const require_state = require("./state-Y6ATakMX.cjs");
|
|
8
|
+
const require_sniffer = require("./sniffer-5xmrkh2a.cjs");
|
|
9
|
+
const require_engine = require("./engine-DR6KurWX.cjs");
|
|
10
|
+
let node_path = require("node:path");
|
|
11
|
+
//#region src/target/dokploy/rollback.ts
|
|
12
|
+
/**
|
|
13
|
+
* `gkm deploy:rollback`: a stage's apps put back on the release before the
|
|
14
|
+
* one they run, by hand — for a release that passed its checks and turned out
|
|
15
|
+
* wrong anyway.
|
|
16
|
+
*
|
|
17
|
+
* One app by default, because an app is what usually broke: rolling the API
|
|
18
|
+
* back over a site fix that shipped beside it undoes the fix too. `atomic`
|
|
19
|
+
* rolls back every app that has a release to go back to, for apps that only
|
|
20
|
+
* work together — an API and the site built against its newer contract.
|
|
21
|
+
*
|
|
22
|
+
* It restores images and nothing else. The environment an app runs with is
|
|
23
|
+
* the stage's, resolved on every deploy, and migrations are forward-only: a
|
|
24
|
+
* migration that the older code cannot run against is undone by a new
|
|
25
|
+
* migration, never by a rollback.
|
|
26
|
+
*/
|
|
27
|
+
var rollback_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({
|
|
28
|
+
NothingToRollBack: () => NothingToRollBack,
|
|
29
|
+
RollbackNeedsApp: () => RollbackNeedsApp,
|
|
30
|
+
StageNeverDeployed: () => StageNeverDeployed,
|
|
31
|
+
rollbackStage: () => rollbackStage
|
|
32
|
+
});
|
|
33
|
+
/** Neither an app nor every app was asked for. */
|
|
34
|
+
var RollbackNeedsApp = class extends Error {
|
|
35
|
+
stage;
|
|
36
|
+
apps;
|
|
37
|
+
constructor(stage, apps) {
|
|
38
|
+
super(`Say what to roll back: --app <name> for one app (${apps.join(", ") || "none has an earlier release"}), or --atomic for every app of "${stage}" together.`);
|
|
39
|
+
this.stage = stage;
|
|
40
|
+
this.apps = apps;
|
|
41
|
+
this.name = "RollbackNeedsApp";
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
/** An app has no release before the one it runs. */
|
|
45
|
+
var NothingToRollBack = class extends Error {
|
|
46
|
+
stage;
|
|
47
|
+
app;
|
|
48
|
+
constructor(stage, app) {
|
|
49
|
+
super(`"${app}" has no earlier release on "${stage}" to roll back to: it has been released once, or every earlier release was itself rolled back. Deploy the version you want instead.`);
|
|
50
|
+
this.stage = stage;
|
|
51
|
+
this.app = app;
|
|
52
|
+
this.name = "NothingToRollBack";
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
/** The stage was never deployed through Dokploy from this state. */
|
|
56
|
+
var StageNeverDeployed = class extends Error {
|
|
57
|
+
stage;
|
|
58
|
+
constructor(stage) {
|
|
59
|
+
super(`"${stage}" has no deploy state, so there is nothing to roll back. Check the stage name, and that \`state\` in gkm.config.ts points at the store the deploys write to.`);
|
|
60
|
+
this.stage = stage;
|
|
61
|
+
this.name = "StageNeverDeployed";
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Roll a stage's app — or, `atomic`, all of them — back to its previous
|
|
66
|
+
* release, holding the stage's lock as a deploy does.
|
|
67
|
+
*/
|
|
68
|
+
async function rollbackStage(input) {
|
|
69
|
+
const signal = input.signal ?? new AbortController().signal;
|
|
70
|
+
const log = input.log ?? (() => {});
|
|
71
|
+
const credentials = input.credentials ?? require_credentials.storedCredentials();
|
|
72
|
+
const sandbox = input.sandbox ?? new require_local.LocalSandbox({ root: require_config.findWorkspaceRoot((0, node_path.resolve)(input.cwd)) });
|
|
73
|
+
return require_sandbox.withSandbox(sandbox, async () => {
|
|
74
|
+
const { workspace } = await require_config.loadWorkspaceConfig((0, node_path.resolve)(input.cwd), { sandbox });
|
|
75
|
+
require_workspace.assertDeployedStage(workspace.stages, input.stage);
|
|
76
|
+
const store = await require_sniffer.createStateStore({
|
|
77
|
+
config: workspace.state,
|
|
78
|
+
workspaceRoot: workspace.root,
|
|
79
|
+
workspaceName: workspace.name
|
|
80
|
+
});
|
|
81
|
+
if (!await store.read(input.stage)) throw new StageNeverDeployed(input.stage);
|
|
82
|
+
const lock = await store.lock(input.stage, { operation: "rollback" });
|
|
83
|
+
try {
|
|
84
|
+
const journal = await require_state.DeployJournal.open(store, input.stage, () => require_state.createEmptyState(input.stage, "", ""));
|
|
85
|
+
const { state } = journal;
|
|
86
|
+
const releases = state.releases ?? {};
|
|
87
|
+
const restorable = Object.keys(releases).filter((app) => releases[app].previous);
|
|
88
|
+
let apps;
|
|
89
|
+
if (input.atomic) {
|
|
90
|
+
apps = restorable;
|
|
91
|
+
if (apps.length === 0) throw new RollbackNeedsApp(input.stage, restorable);
|
|
92
|
+
} else if (input.app) {
|
|
93
|
+
if (!releases[input.app]?.previous) throw new NothingToRollBack(input.stage, input.app);
|
|
94
|
+
apps = [input.app];
|
|
95
|
+
} else throw new RollbackNeedsApp(input.stage, restorable);
|
|
96
|
+
const { api } = await require_engine.dokployApi(workspace, {
|
|
97
|
+
credentials,
|
|
98
|
+
signal
|
|
99
|
+
});
|
|
100
|
+
const verify = require_engine.verifySettings(workspace.deploy.dokploy?.verify);
|
|
101
|
+
const rolled = [];
|
|
102
|
+
for (const app of apps) {
|
|
103
|
+
signal.throwIfAborted();
|
|
104
|
+
const { current, previous } = releases[app];
|
|
105
|
+
const applicationId = state.applications[app];
|
|
106
|
+
if (!previous || !applicationId) throw new NothingToRollBack(input.stage, app);
|
|
107
|
+
log(`⏪ ${app}: ${current.ref} → ${previous.ref}`);
|
|
108
|
+
await require_engine.restoreImage(api, {
|
|
109
|
+
applicationId,
|
|
110
|
+
image: previous,
|
|
111
|
+
registryId: state.registryId,
|
|
112
|
+
verify,
|
|
113
|
+
signal
|
|
114
|
+
});
|
|
115
|
+
require_state.recordRollback(state, app, previous);
|
|
116
|
+
await journal.save();
|
|
117
|
+
log(` ✓ ${app} is running ${previous.ref}`);
|
|
118
|
+
rolled.push({
|
|
119
|
+
app,
|
|
120
|
+
from: current,
|
|
121
|
+
to: previous
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
return rolled;
|
|
125
|
+
} finally {
|
|
126
|
+
await lock.release();
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
//#endregion
|
|
131
|
+
Object.defineProperty(exports, "NothingToRollBack", {
|
|
132
|
+
enumerable: true,
|
|
133
|
+
get: function() {
|
|
134
|
+
return NothingToRollBack;
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
Object.defineProperty(exports, "RollbackNeedsApp", {
|
|
138
|
+
enumerable: true,
|
|
139
|
+
get: function() {
|
|
140
|
+
return RollbackNeedsApp;
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
Object.defineProperty(exports, "StageNeverDeployed", {
|
|
144
|
+
enumerable: true,
|
|
145
|
+
get: function() {
|
|
146
|
+
return StageNeverDeployed;
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
Object.defineProperty(exports, "rollbackStage", {
|
|
150
|
+
enumerable: true,
|
|
151
|
+
get: function() {
|
|
152
|
+
return rollbackStage;
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
Object.defineProperty(exports, "rollback_exports", {
|
|
156
|
+
enumerable: true,
|
|
157
|
+
get: function() {
|
|
158
|
+
return rollback_exports;
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
//# sourceMappingURL=rollback-DxJK84hy.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rollback-DxJK84hy.cjs","names":["storedCredentials","LocalSandbox","findWorkspaceRoot","resolve","withSandbox","loadWorkspaceConfig","createStateStore","DeployJournal","createEmptyState","dokployApi","verifySettings","restoreImage"],"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":"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"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { H as DeployRuntime, X as TargetOptionsIssue } from "./types-
|
|
1
|
+
import { H as DeployRuntime, X as TargetOptionsIssue } from "./types-D5WIxRDP.cjs";
|
|
2
2
|
//#region src/target/builtins.d.ts
|
|
3
3
|
/** A target name that is neither built in nor in `deploy.targets`. */
|
|
4
4
|
declare class UnknownDeployTarget extends Error {
|
|
@@ -87,4 +87,4 @@ declare class TargetRuntimeUndeclared extends Error {
|
|
|
87
87
|
}
|
|
88
88
|
//#endregion
|
|
89
89
|
export { TargetRuntimeMismatch as a, DeployTargetNotYetSupported as c, TargetPackageInvalid as i, UnknownDeployTarget as l, InvalidTargetOptions as n, ProviderRemoved as o, TargetEntryInvalid as r, TargetPackageNotFound as s, TargetRuntimeUndeclared as t };
|
|
90
|
-
//# sourceMappingURL=runtime-
|
|
90
|
+
//# sourceMappingURL=runtime-BRqFOvPM.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime-
|
|
1
|
+
{"version":3,"file":"runtime-BRqFOvPM.d.cts","names":[],"sources":["../src/target/builtins.ts","../src/target/package.ts","../src/target/provider.ts","../src/target/resolve.ts","../src/target/runtime.ts"],"mappings":";;;cA+Da,4BAA4B;WAE9B;;WAEA;EAHV,YACU,gBAEA;;EAAA;;;cAUE,oCAAoC;WAEtC;;WAEA;EAHV,YACU,gBAEA;;EAAA;;;;;cCrDE,8BAA8B;WAEhC;WACA;WACA;EAHV,YACU,gBACA,qBACA;;;;;;;;;;;;;cCZE,wBAAwB;WAE1B;;WAEA;EAHV,YACU,kBAEA;;EAAA;;;;;cCoCE,6BAA6B;WAE/B;WACA;EAFV,YACU,gBACA;;;cAUE,2BAA2B;WAClB;EAArB,YAAqB;;;cAST,8BAA8B;WAEhC;WACA;WACA,UAAU;WACV,QAAQ;EAJlB,YACU,gBACA,qBACA,UAAU,eACV,QAAQ;;;cAUN,6BAA6B;WAE/B;WACA,iBAAiB;EAF3B,YACU,gBACA,iBAAiB;;;;;cC1Ef,gCAAgC;WAElC;WACA;;WAEA;EAJV,YACU,gBACA,qBAEA;;EAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { H as DeployRuntime, X as TargetOptionsIssue } from "./types-
|
|
1
|
+
import { H as DeployRuntime, X as TargetOptionsIssue } from "./types-CSw2w69a.mjs";
|
|
2
2
|
//#region src/target/builtins.d.ts
|
|
3
3
|
/** A target name that is neither built in nor in `deploy.targets`. */
|
|
4
4
|
declare class UnknownDeployTarget extends Error {
|
|
@@ -87,4 +87,4 @@ declare class TargetRuntimeUndeclared extends Error {
|
|
|
87
87
|
}
|
|
88
88
|
//#endregion
|
|
89
89
|
export { TargetRuntimeMismatch as a, DeployTargetNotYetSupported as c, TargetPackageInvalid as i, UnknownDeployTarget as l, InvalidTargetOptions as n, ProviderRemoved as o, TargetEntryInvalid as r, TargetPackageNotFound as s, TargetRuntimeUndeclared as t };
|
|
90
|
-
//# sourceMappingURL=runtime-
|
|
90
|
+
//# sourceMappingURL=runtime-CEk5n4VH.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime-
|
|
1
|
+
{"version":3,"file":"runtime-CEk5n4VH.d.mts","names":[],"sources":["../src/target/builtins.ts","../src/target/package.ts","../src/target/provider.ts","../src/target/resolve.ts","../src/target/runtime.ts"],"mappings":";;;cA+Da,4BAA4B;WAE9B;;WAEA;EAHV,YACU,gBAEA;;EAAA;;;cAUE,oCAAoC;WAEtC;;WAEA;EAHV,YACU,gBAEA;;EAAA;;;;;cCrDE,8BAA8B;WAEhC;WACA;WACA;EAHV,YACU,gBACA,qBACA;;;;;;;;;;;;;cCZE,wBAAwB;WAE1B;;WAEA;EAHV,YACU,kBAEA;;EAAA;;;;;cCoCE,6BAA6B;WAE/B;WACA;EAFV,YACU,gBACA;;;cAUE,2BAA2B;WAClB;EAArB,YAAqB;;;cAST,8BAA8B;WAEhC;WACA;WACA,UAAU;WACV,QAAQ;EAJlB,YACU,gBACA,qBACA,UAAU,eACV,QAAQ;;;cAUN,6BAA6B;WAE/B;WACA,iBAAiB;EAF3B,YACU,gBACA,iBAAiB;;;;;cC1Ef,gCAAgC;WAElC;WACA;;WAEA;EAJV,YACU,gBACA,qBAEA;;EAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { r as discover } from "../discover-
|
|
1
|
+
import { r as discover } from "../discover-BFoJWKGD.mjs";
|
|
2
2
|
import { a as registerAdjacentTsconfig, i as liveValuePaths, n as answer, r as errorData } from "../workerRuntime-CsOyBRx2.mjs";
|
|
3
3
|
//#region src/sandbox/discover-worker.ts
|
|
4
4
|
/**
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
const require_discover = require("../discover-OEfZ9OkA.cjs");
|
|
2
|
+
const require_sandbox = require("../sandbox-CL--ZDui.cjs");
|
|
3
|
+
const require_workerRuntime = require("../workerRuntime-BXfhbe13.cjs");
|
|
4
|
+
const require_databases = require("../databases-C2p5LGAp.cjs");
|
|
5
|
+
let node_path = require("node:path");
|
|
6
|
+
let node_fs_promises = require("node:fs/promises");
|
|
7
|
+
//#region src/sandbox/migrate-worker.ts
|
|
8
|
+
/**
|
|
9
|
+
* Applies a deployed stage's migrations in a sandbox — the migrator
|
|
10
|
+
* `gkm migrate` runs, against URLs the deploy hands it as secret files.
|
|
11
|
+
*
|
|
12
|
+
* Usage (by the Dokploy target's release, never by hand):
|
|
13
|
+
* node --import=<tsx> migrate-worker.ts '{"root":"…","manifest":{…},"patterns":[…]}'
|
|
14
|
+
*
|
|
15
|
+
* Migrations are the project's own code, which is why they run here rather
|
|
16
|
+
* than in the deploy. Each owner URL arrives as a file in `GKM_SECRETS_DIR`,
|
|
17
|
+
* named by its key, and is read into this process's memory only: never into
|
|
18
|
+
* `process.env`, where a child the migration starts would inherit it.
|
|
19
|
+
*/
|
|
20
|
+
/** Every secret file the sandbox mounted, by name. */
|
|
21
|
+
async function mountedSecrets() {
|
|
22
|
+
const dir = process.env[require_sandbox.SECRETS_DIR_ENV];
|
|
23
|
+
if (!dir) return {};
|
|
24
|
+
const secrets = {};
|
|
25
|
+
for (const name of await (0, node_fs_promises.readdir)(dir)) secrets[name] = (await (0, node_fs_promises.readFile)((0, node_path.join)(dir, name), "utf8")).trim();
|
|
26
|
+
return secrets;
|
|
27
|
+
}
|
|
28
|
+
async function main() {
|
|
29
|
+
try {
|
|
30
|
+
const request = JSON.parse(process.argv[2] ?? "{}");
|
|
31
|
+
await require_workerRuntime.registerAdjacentTsconfig();
|
|
32
|
+
const sources = {};
|
|
33
|
+
if (request.patterns.length > 0) await require_discover.discover({
|
|
34
|
+
patterns: request.patterns,
|
|
35
|
+
cwd: request.root,
|
|
36
|
+
sources
|
|
37
|
+
});
|
|
38
|
+
const runs = await require_databases.migrateDatabases({
|
|
39
|
+
root: request.root,
|
|
40
|
+
manifest: request.manifest,
|
|
41
|
+
sources,
|
|
42
|
+
env: await mountedSecrets()
|
|
43
|
+
});
|
|
44
|
+
require_workerRuntime.answer({
|
|
45
|
+
reason: "migrated",
|
|
46
|
+
runs: runs.map(({ target, applied }) => ({
|
|
47
|
+
migrations: target.migrations,
|
|
48
|
+
applied
|
|
49
|
+
}))
|
|
50
|
+
});
|
|
51
|
+
} catch (error) {
|
|
52
|
+
require_workerRuntime.answer({
|
|
53
|
+
reason: "failed",
|
|
54
|
+
error: require_workerRuntime.errorData(error)
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
main();
|
|
59
|
+
//#endregion
|
|
60
|
+
|
|
61
|
+
//# sourceMappingURL=migrate-worker.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migrate-worker.cjs","names":["SECRETS_DIR_ENV","readdir","readFile","join","registerAdjacentTsconfig","discover","migrateDatabases","errorData"],"sources":["../../src/sandbox/migrate-worker.ts"],"sourcesContent":["/**\n * Applies a deployed stage's migrations in a sandbox — the migrator\n * `gkm migrate` runs, against URLs the deploy hands it as secret files.\n *\n * Usage (by the Dokploy target's release, never by hand):\n * node --import=<tsx> migrate-worker.ts '{\"root\":\"…\",\"manifest\":{…},\"patterns\":[…]}'\n *\n * Migrations are the project's own code, which is why they run here rather\n * than in the deploy. Each owner URL arrives as a file in `GKM_SECRETS_DIR`,\n * named by its key, and is read into this process's memory only: never into\n * `process.env`, where a child the migration starts would inherit it.\n */\n\nimport { readdir, readFile } from 'node:fs/promises';\nimport { join } from 'node:path';\nimport type { ConstructManifest } from '@geekmidas/manifest';\nimport { migrateDatabases } from '../migrate/databases';\nimport { type ConstructSource, discover } from '../reconcile/discover';\nimport { SECRETS_DIR_ENV } from './sandbox';\nimport { answer, errorData, registerAdjacentTsconfig } from './workerRuntime';\n\n/** Every secret file the sandbox mounted, by name. */\nasync function mountedSecrets(): Promise<Record<string, string>> {\n\tconst dir = process.env[SECRETS_DIR_ENV];\n\tif (!dir) return {};\n\n\tconst secrets: Record<string, string> = {};\n\tfor (const name of await readdir(dir)) {\n\t\tsecrets[name] = (await readFile(join(dir, name), 'utf8')).trim();\n\t}\n\treturn secrets;\n}\n\nasync function main(): Promise<void> {\n\ttry {\n\t\tconst request = JSON.parse(process.argv[2] ?? '{}') as {\n\t\t\troot: string;\n\t\t\tmanifest: ConstructManifest;\n\t\t\tpatterns: string[];\n\t\t};\n\t\tawait registerAdjacentTsconfig();\n\n\t\t// Where each construct is declared, so a migration runs with the Kysely\n\t\t// its own file resolves. The manifest itself is the deploy's: what it\n\t\t// provisioned is what gets migrated, not a second reading of the files.\n\t\tconst sources: Record<string, ConstructSource> = {};\n\t\tif (request.patterns.length > 0) {\n\t\t\tawait discover({\n\t\t\t\tpatterns: request.patterns,\n\t\t\t\tcwd: request.root,\n\t\t\t\tsources,\n\t\t\t});\n\t\t}\n\n\t\tconst runs = await migrateDatabases({\n\t\t\troot: request.root,\n\t\t\tmanifest: request.manifest,\n\t\t\tsources,\n\t\t\tenv: await mountedSecrets(),\n\t\t});\n\n\t\tanswer({\n\t\t\treason: 'migrated',\n\t\t\truns: runs.map(({ target, applied }) => ({\n\t\t\t\tmigrations: target.migrations,\n\t\t\t\tapplied,\n\t\t\t})),\n\t\t});\n\t} catch (error) {\n\t\tanswer({ reason: 'failed', error: errorData(error) });\n\t}\n}\n\nvoid main();\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAsBA,eAAe,iBAAkD;CAChE,MAAM,MAAM,QAAQ,IAAIA,gBAAAA;CACxB,IAAI,CAAC,KAAK,OAAO,CAAC;CAElB,MAAM,UAAkC,CAAC;CACzC,KAAK,MAAM,QAAQ,OAAA,GAAMC,iBAAAA,QAAAA,CAAQ,GAAG,GACnC,QAAQ,SAAS,OAAA,GAAMC,iBAAAA,SAAAA,EAAAA,GAASC,UAAAA,KAAAA,CAAK,KAAK,IAAI,GAAG,MAAM,EAAA,CAAG,KAAK;CAEhE,OAAO;AACR;AAEA,eAAe,OAAsB;CACpC,IAAI;EACH,MAAM,UAAU,KAAK,MAAM,QAAQ,KAAK,MAAM,IAAI;EAKlD,MAAMC,sBAAAA,yBAAyB;EAK/B,MAAM,UAA2C,CAAC;EAClD,IAAI,QAAQ,SAAS,SAAS,GAC7B,MAAMC,iBAAAA,SAAS;GACd,UAAU,QAAQ;GAClB,KAAK,QAAQ;GACb;EACD,CAAC;EAGF,MAAM,OAAO,MAAMC,kBAAAA,iBAAiB;GACnC,MAAM,QAAQ;GACd,UAAU,QAAQ;GAClB;GACA,KAAK,MAAM,eAAe;EAC3B,CAAC;EAED,sBAAA,OAAO;GACN,QAAQ;GACR,MAAM,KAAK,KAAK,EAAE,QAAQ,eAAe;IACxC,YAAY,OAAO;IACnB;GACD,EAAE;EACH,CAAC;CACF,SAAS,OAAO;EACf,sBAAA,OAAO;GAAE,QAAQ;GAAU,OAAOC,sBAAAA,UAAU,KAAK;EAAE,CAAC;CACrD;AACD;AAEK,KAAK"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { r as discover } from "../discover-BFoJWKGD.mjs";
|
|
2
|
+
import { t as SECRETS_DIR_ENV } from "../sandbox-Dm247NGx.mjs";
|
|
3
|
+
import { a as registerAdjacentTsconfig, n as answer, r as errorData } from "../workerRuntime-CsOyBRx2.mjs";
|
|
4
|
+
import { u as migrateDatabases } from "../databases-hUHTuwhx.mjs";
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
import { readFile, readdir } from "node:fs/promises";
|
|
7
|
+
//#region src/sandbox/migrate-worker.ts
|
|
8
|
+
/**
|
|
9
|
+
* Applies a deployed stage's migrations in a sandbox — the migrator
|
|
10
|
+
* `gkm migrate` runs, against URLs the deploy hands it as secret files.
|
|
11
|
+
*
|
|
12
|
+
* Usage (by the Dokploy target's release, never by hand):
|
|
13
|
+
* node --import=<tsx> migrate-worker.ts '{"root":"…","manifest":{…},"patterns":[…]}'
|
|
14
|
+
*
|
|
15
|
+
* Migrations are the project's own code, which is why they run here rather
|
|
16
|
+
* than in the deploy. Each owner URL arrives as a file in `GKM_SECRETS_DIR`,
|
|
17
|
+
* named by its key, and is read into this process's memory only: never into
|
|
18
|
+
* `process.env`, where a child the migration starts would inherit it.
|
|
19
|
+
*/
|
|
20
|
+
/** Every secret file the sandbox mounted, by name. */
|
|
21
|
+
async function mountedSecrets() {
|
|
22
|
+
const dir = process.env[SECRETS_DIR_ENV];
|
|
23
|
+
if (!dir) return {};
|
|
24
|
+
const secrets = {};
|
|
25
|
+
for (const name of await readdir(dir)) secrets[name] = (await readFile(join(dir, name), "utf8")).trim();
|
|
26
|
+
return secrets;
|
|
27
|
+
}
|
|
28
|
+
async function main() {
|
|
29
|
+
try {
|
|
30
|
+
const request = JSON.parse(process.argv[2] ?? "{}");
|
|
31
|
+
await registerAdjacentTsconfig();
|
|
32
|
+
const sources = {};
|
|
33
|
+
if (request.patterns.length > 0) await discover({
|
|
34
|
+
patterns: request.patterns,
|
|
35
|
+
cwd: request.root,
|
|
36
|
+
sources
|
|
37
|
+
});
|
|
38
|
+
const runs = await migrateDatabases({
|
|
39
|
+
root: request.root,
|
|
40
|
+
manifest: request.manifest,
|
|
41
|
+
sources,
|
|
42
|
+
env: await mountedSecrets()
|
|
43
|
+
});
|
|
44
|
+
answer({
|
|
45
|
+
reason: "migrated",
|
|
46
|
+
runs: runs.map(({ target, applied }) => ({
|
|
47
|
+
migrations: target.migrations,
|
|
48
|
+
applied
|
|
49
|
+
}))
|
|
50
|
+
});
|
|
51
|
+
} catch (error) {
|
|
52
|
+
answer({
|
|
53
|
+
reason: "failed",
|
|
54
|
+
error: errorData(error)
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
main();
|
|
59
|
+
//#endregion
|
|
60
|
+
export {};
|
|
61
|
+
|
|
62
|
+
//# sourceMappingURL=migrate-worker.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migrate-worker.mjs","names":[],"sources":["../../src/sandbox/migrate-worker.ts"],"sourcesContent":["/**\n * Applies a deployed stage's migrations in a sandbox — the migrator\n * `gkm migrate` runs, against URLs the deploy hands it as secret files.\n *\n * Usage (by the Dokploy target's release, never by hand):\n * node --import=<tsx> migrate-worker.ts '{\"root\":\"…\",\"manifest\":{…},\"patterns\":[…]}'\n *\n * Migrations are the project's own code, which is why they run here rather\n * than in the deploy. Each owner URL arrives as a file in `GKM_SECRETS_DIR`,\n * named by its key, and is read into this process's memory only: never into\n * `process.env`, where a child the migration starts would inherit it.\n */\n\nimport { readdir, readFile } from 'node:fs/promises';\nimport { join } from 'node:path';\nimport type { ConstructManifest } from '@geekmidas/manifest';\nimport { migrateDatabases } from '../migrate/databases';\nimport { type ConstructSource, discover } from '../reconcile/discover';\nimport { SECRETS_DIR_ENV } from './sandbox';\nimport { answer, errorData, registerAdjacentTsconfig } from './workerRuntime';\n\n/** Every secret file the sandbox mounted, by name. */\nasync function mountedSecrets(): Promise<Record<string, string>> {\n\tconst dir = process.env[SECRETS_DIR_ENV];\n\tif (!dir) return {};\n\n\tconst secrets: Record<string, string> = {};\n\tfor (const name of await readdir(dir)) {\n\t\tsecrets[name] = (await readFile(join(dir, name), 'utf8')).trim();\n\t}\n\treturn secrets;\n}\n\nasync function main(): Promise<void> {\n\ttry {\n\t\tconst request = JSON.parse(process.argv[2] ?? '{}') as {\n\t\t\troot: string;\n\t\t\tmanifest: ConstructManifest;\n\t\t\tpatterns: string[];\n\t\t};\n\t\tawait registerAdjacentTsconfig();\n\n\t\t// Where each construct is declared, so a migration runs with the Kysely\n\t\t// its own file resolves. The manifest itself is the deploy's: what it\n\t\t// provisioned is what gets migrated, not a second reading of the files.\n\t\tconst sources: Record<string, ConstructSource> = {};\n\t\tif (request.patterns.length > 0) {\n\t\t\tawait discover({\n\t\t\t\tpatterns: request.patterns,\n\t\t\t\tcwd: request.root,\n\t\t\t\tsources,\n\t\t\t});\n\t\t}\n\n\t\tconst runs = await migrateDatabases({\n\t\t\troot: request.root,\n\t\t\tmanifest: request.manifest,\n\t\t\tsources,\n\t\t\tenv: await mountedSecrets(),\n\t\t});\n\n\t\tanswer({\n\t\t\treason: 'migrated',\n\t\t\truns: runs.map(({ target, applied }) => ({\n\t\t\t\tmigrations: target.migrations,\n\t\t\t\tapplied,\n\t\t\t})),\n\t\t});\n\t} catch (error) {\n\t\tanswer({ reason: 'failed', error: errorData(error) });\n\t}\n}\n\nvoid main();\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAsBA,eAAe,iBAAkD;CAChE,MAAM,MAAM,QAAQ,IAAI;CACxB,IAAI,CAAC,KAAK,OAAO,CAAC;CAElB,MAAM,UAAkC,CAAC;CACzC,KAAK,MAAM,QAAQ,MAAM,QAAQ,GAAG,GACnC,QAAQ,SAAS,MAAM,SAAS,KAAK,KAAK,IAAI,GAAG,MAAM,EAAA,CAAG,KAAK;CAEhE,OAAO;AACR;AAEA,eAAe,OAAsB;CACpC,IAAI;EACH,MAAM,UAAU,KAAK,MAAM,QAAQ,KAAK,MAAM,IAAI;EAKlD,MAAM,yBAAyB;EAK/B,MAAM,UAA2C,CAAC;EAClD,IAAI,QAAQ,SAAS,SAAS,GAC7B,MAAM,SAAS;GACd,UAAU,QAAQ;GAClB,KAAK,QAAQ;GACb;EACD,CAAC;EAGF,MAAM,OAAO,MAAM,iBAAiB;GACnC,MAAM,QAAQ;GACd,UAAU,QAAQ;GAClB;GACA,KAAK,MAAM,eAAe;EAC3B,CAAC;EAED,OAAO;GACN,QAAQ;GACR,MAAM,KAAK,KAAK,EAAE,QAAQ,eAAe;IACxC,YAAY,OAAO;IACnB;GACD,EAAE;EACH,CAAC;CACF,SAAS,OAAO;EACf,OAAO;GAAE,QAAQ;GAAU,OAAO,UAAU,KAAK;EAAE,CAAC;CACrD;AACD;AAEK,KAAK"}
|
|
@@ -5439,6 +5439,14 @@ function object(shape, params) {
|
|
|
5439
5439
|
};
|
|
5440
5440
|
return new ZodObject(def);
|
|
5441
5441
|
}
|
|
5442
|
+
function looseObject(shape, params) {
|
|
5443
|
+
return new ZodObject({
|
|
5444
|
+
type: "object",
|
|
5445
|
+
shape,
|
|
5446
|
+
catchall: unknown(),
|
|
5447
|
+
...normalizeParams(params)
|
|
5448
|
+
});
|
|
5449
|
+
}
|
|
5442
5450
|
const ZodUnion = /*@__PURE__*/ $constructor("ZodUnion", (inst, def) => {
|
|
5443
5451
|
$ZodUnion.init(inst, def);
|
|
5444
5452
|
ZodType.init(inst, def);
|
|
@@ -5754,6 +5762,6 @@ function superRefine(fn, params) {
|
|
|
5754
5762
|
return /* @__PURE__ */ _superRefine(fn, params);
|
|
5755
5763
|
}
|
|
5756
5764
|
//#endregion
|
|
5757
|
-
export { discriminatedUnion as a,
|
|
5765
|
+
export { discriminatedUnion as a, number as c, string as d, tuple as f, url as h, custom as i, object as l, unknown as m, array as n, literal as o, union as p, boolean as r, looseObject as s, _enum as t, record as u };
|
|
5758
5766
|
|
|
5759
|
-
//# sourceMappingURL=schemas-
|
|
5767
|
+
//# sourceMappingURL=schemas-Cfhtpdo0.mjs.map
|