@geekmidas/cli 10.0.0-alpha.185 → 10.0.0-alpha.186
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{LegacyStateStore-DKyEAWGI.mjs → LegacyStateStore-BwHw28fJ.mjs} +2 -2
- package/dist/{LegacyStateStore-DKyEAWGI.mjs.map → LegacyStateStore-BwHw28fJ.mjs.map} +1 -1
- package/dist/{LegacyStateStore-BtN83gfS.cjs → LegacyStateStore-LpTY3S7z.cjs} +2 -2
- package/dist/{LegacyStateStore-BtN83gfS.cjs.map → LegacyStateStore-LpTY3S7z.cjs.map} +1 -1
- package/dist/{LocalStateStore-BFh6rPhX.cjs → LocalStateStore-Dpn9kBuK.cjs} +2 -2
- package/dist/{LocalStateStore-BFh6rPhX.cjs.map → LocalStateStore-Dpn9kBuK.cjs.map} +1 -1
- package/dist/{LocalStateStore-Dc3aGvQi.mjs → LocalStateStore-DsdNLm0_.mjs} +2 -2
- package/dist/{LocalStateStore-Dc3aGvQi.mjs.map → LocalStateStore-DsdNLm0_.mjs.map} +1 -1
- package/dist/{S3StateStore-p6DyuAFZ.mjs → S3StateStore-BIpCLzpk.mjs} +4 -4
- package/dist/{S3StateStore-p6DyuAFZ.mjs.map → S3StateStore-BIpCLzpk.mjs.map} +1 -1
- package/dist/{S3StateStore-DZMpqbvD.cjs → S3StateStore-Bk_EIWLU.cjs} +4 -4
- package/dist/{S3StateStore-DZMpqbvD.cjs.map → S3StateStore-Bk_EIWLU.cjs.map} +1 -1
- package/dist/{SSMStateStore-sbaLlCmj.cjs → SSMStateStore-A1bgCF1P.cjs} +2 -2
- package/dist/{SSMStateStore-sbaLlCmj.cjs.map → SSMStateStore-A1bgCF1P.cjs.map} +1 -1
- package/dist/{SSMStateStore-BvH8XX4O.mjs → SSMStateStore-PiZxPXeX.mjs} +2 -2
- package/dist/{SSMStateStore-BvH8XX4O.mjs.map → SSMStateStore-PiZxPXeX.mjs.map} +1 -1
- package/dist/{add-dOvgsAU6.mjs → add-BBhzFpQ7.mjs} +3 -3
- package/dist/{add-dOvgsAU6.mjs.map → add-BBhzFpQ7.mjs.map} +1 -1
- package/dist/{add-CdVGxiKW.cjs → add-sU71e0Lp.cjs} +3 -3
- package/dist/{add-CdVGxiKW.cjs.map → add-sU71e0Lp.cjs.map} +1 -1
- package/dist/{bundler-B5ioF-1Q.cjs → bundler-BM6lq-36.cjs} +6 -6
- package/dist/{bundler-B5ioF-1Q.cjs.map → bundler-BM6lq-36.cjs.map} +1 -1
- package/dist/{bundler-Cvx6Bt3e.mjs → bundler-QKbRwztS.mjs} +6 -6
- package/dist/{bundler-Cvx6Bt3e.mjs.map → bundler-QKbRwztS.mjs.map} +1 -1
- package/dist/{cli-PLhqvPOC.cjs → cli-D_iytris.cjs} +4 -4
- package/dist/{cli-PLhqvPOC.cjs.map → cli-D_iytris.cjs.map} +1 -1
- package/dist/{cli-BjapgcXG.mjs → cli-VCAfR-se.mjs} +4 -4
- package/dist/{cli-BjapgcXG.mjs.map → cli-VCAfR-se.mjs.map} +1 -1
- package/dist/{compose-Dx_nSZYU.mjs → compose-CX2BF3LG.mjs} +41 -193
- package/dist/compose-CX2BF3LG.mjs.map +1 -0
- package/dist/{compose-BEVBxf4w.cjs → compose-D3zc8QN1.cjs} +41 -193
- package/dist/compose-D3zc8QN1.cjs.map +1 -0
- package/dist/{credentials-DW5MvS4A.mjs → credentials-BMdpNO8R.mjs} +73 -5
- package/dist/credentials-BMdpNO8R.mjs.map +1 -0
- package/dist/{credentials-n2abUWwJ.cjs → credentials-BQ1khM28.cjs} +3 -3
- package/dist/{credentials-n2abUWwJ.cjs.map → credentials-BQ1khM28.cjs.map} +1 -1
- package/dist/{credentials-Eyx2tM7B.cjs → credentials-C3uaZ80e.cjs} +102 -4
- package/dist/credentials-C3uaZ80e.cjs.map +1 -0
- package/dist/{credentials-ztezRtR4.mjs → credentials-Ci8nKFw4.mjs} +3 -3
- package/dist/{credentials-ztezRtR4.mjs.map → credentials-Ci8nKFw4.mjs.map} +1 -1
- package/dist/{dbTunnel-DVohSZJQ.cjs → dbTunnel-D000s0YK.cjs} +5 -5
- package/dist/{dbTunnel-DVohSZJQ.cjs.map → dbTunnel-D000s0YK.cjs.map} +1 -1
- package/dist/{dbTunnel-bV1CPWUv.mjs → dbTunnel-DqtSAdQK.mjs} +5 -5
- package/dist/{dbTunnel-bV1CPWUv.mjs.map → dbTunnel-DqtSAdQK.mjs.map} +1 -1
- package/dist/deploy/public.cjs +9 -9
- package/dist/deploy/public.d.cts.map +1 -1
- package/dist/deploy/public.d.mts.map +1 -1
- package/dist/deploy/public.mjs +9 -9
- package/dist/{deploy-CDUWcl58.cjs → deploy-DRH6q_2r.cjs} +9 -9
- package/dist/{deploy-CDUWcl58.cjs.map → deploy-DRH6q_2r.cjs.map} +1 -1
- package/dist/{deploy-Cpz5sKbh.mjs → deploy-DwtM6VSz.mjs} +9 -9
- package/dist/{deploy-Cpz5sKbh.mjs.map → deploy-DwtM6VSz.mjs.map} +1 -1
- package/dist/{destroy-DRlcWJwm.mjs → destroy-C6QwLj3b.mjs} +7 -7
- package/dist/{destroy-DRlcWJwm.mjs.map → destroy-C6QwLj3b.mjs.map} +1 -1
- package/dist/{destroy-DzeV0EdY.cjs → destroy-ChTJ_oUq.cjs} +7 -7
- package/dist/{destroy-DzeV0EdY.cjs.map → destroy-ChTJ_oUq.cjs.map} +1 -1
- package/dist/{dokploy-BveqiW2h.mjs → dokploy-Dm8-eHtx.mjs} +2 -2
- package/dist/{dokploy-BveqiW2h.mjs.map → dokploy-Dm8-eHtx.mjs.map} +1 -1
- package/dist/{dokploy-BTNfj3Zt.cjs → dokploy-jeO7mz1R.cjs} +2 -2
- package/dist/{dokploy-BTNfj3Zt.cjs.map → dokploy-jeO7mz1R.cjs.map} +1 -1
- package/dist/{eas-Dt_vRzb4.cjs → eas-BAitvB5R.cjs} +2 -2
- package/dist/{eas-Dt_vRzb4.cjs.map → eas-BAitvB5R.cjs.map} +1 -1
- package/dist/{eas-BmYTfjY6.mjs → eas-CXYo8hos.mjs} +2 -2
- package/dist/{eas-BmYTfjY6.mjs.map → eas-CXYo8hos.mjs.map} +1 -1
- package/dist/{encryption-DqoQltP8.mjs → encryption-B7IlQ6VO.mjs} +2 -2
- package/dist/{encryption-DqoQltP8.mjs.map → encryption-B7IlQ6VO.mjs.map} +1 -1
- package/dist/{encryption-BE2wxfyH.cjs → encryption-OPCsewWc.cjs} +2 -2
- package/dist/{encryption-BE2wxfyH.cjs.map → encryption-OPCsewWc.cjs.map} +1 -1
- package/dist/{engine-BevpkNZe.cjs → engine-BSnhQLaB.cjs} +11 -6
- package/dist/engine-BSnhQLaB.cjs.map +1 -0
- package/dist/{engine-B72vyrO8.mjs → engine-a6K99WIl.mjs} +11 -6
- package/dist/engine-a6K99WIl.mjs.map +1 -0
- package/dist/{github-DoHdtsDX.cjs → github-C3gUSbLn.cjs} +6 -6
- package/dist/{github-DoHdtsDX.cjs.map → github-C3gUSbLn.cjs.map} +1 -1
- package/dist/{github-hxvid6J3.mjs → github-D4hThtnt.mjs} +6 -6
- package/dist/{github-hxvid6J3.mjs.map → github-D4hThtnt.mjs.map} +1 -1
- package/dist/{googlePlay-CYney-Of.cjs → googlePlay-C5Q7Zov3.cjs} +4 -4
- package/dist/{googlePlay-CYney-Of.cjs.map → googlePlay-C5Q7Zov3.cjs.map} +1 -1
- package/dist/{googlePlay-DsvZTWgP.mjs → googlePlay-DIS9PeFB.mjs} +4 -4
- package/dist/{googlePlay-DsvZTWgP.mjs.map → googlePlay-DIS9PeFB.mjs.map} +1 -1
- package/dist/index.cjs +58 -58
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +58 -58
- package/dist/index.mjs.map +1 -1
- package/dist/{local-BuR4fIW6.cjs → local-B5R1WWEO.cjs} +2 -2
- package/dist/{local-BuR4fIW6.cjs.map → local-B5R1WWEO.cjs.map} +1 -1
- package/dist/{local-Cmq75U_o.mjs → local-CMA_7b0_.mjs} +2 -2
- package/dist/{local-Cmq75U_o.mjs.map → local-CMA_7b0_.mjs.map} +1 -1
- package/dist/{migrate-Bf-EG8Fj.mjs → migrate-168wMF5m.mjs} +4 -4
- package/dist/{migrate-Bf-EG8Fj.mjs.map → migrate-168wMF5m.mjs.map} +1 -1
- package/dist/{migrate-CDMdrniJ.cjs → migrate-B0041tRF.cjs} +4 -4
- package/dist/{migrate-CDMdrniJ.cjs.map → migrate-B0041tRF.cjs.map} +1 -1
- package/dist/{migrate-CuTQha4s.cjs → migrate-BZxh_zU5.cjs} +2 -2
- package/dist/{migrate-CuTQha4s.cjs.map → migrate-BZxh_zU5.cjs.map} +1 -1
- package/dist/{migrate-DYJffHOm.mjs → migrate-BhnCtwMX.mjs} +2 -2
- package/dist/{migrate-DYJffHOm.mjs.map → migrate-BhnCtwMX.mjs.map} +1 -1
- package/dist/{projectBucket-NcgqleyH.cjs → projectBucket-DEBaYEbi.cjs} +2 -2
- package/dist/{projectBucket-NcgqleyH.cjs.map → projectBucket-DEBaYEbi.cjs.map} +1 -1
- package/dist/{projectBucket-B5YkuSVr.mjs → projectBucket-hF0-tlq9.mjs} +2 -2
- package/dist/{projectBucket-B5YkuSVr.mjs.map → projectBucket-hF0-tlq9.mjs.map} +1 -1
- package/dist/{publish--EQ4Tw3F.cjs → publish-B-ffSuAX.cjs} +2 -2
- package/dist/{publish--EQ4Tw3F.cjs.map → publish-B-ffSuAX.cjs.map} +1 -1
- package/dist/{publish-YL8WZHSo.mjs → publish-_lVOoWCy.mjs} +2 -2
- package/dist/{publish-YL8WZHSo.mjs.map → publish-_lVOoWCy.mjs.map} +1 -1
- package/dist/{resolve-Ced8-gj4.cjs → resolve-Cs38fbaX.cjs} +4 -4
- package/dist/{resolve-Ced8-gj4.cjs.map → resolve-Cs38fbaX.cjs.map} +1 -1
- package/dist/{resolve-DcG10_JV.mjs → resolve-UK4b26dm.mjs} +4 -4
- package/dist/{resolve-DcG10_JV.mjs.map → resolve-UK4b26dm.mjs.map} +1 -1
- package/dist/{rollback-BxI2p53H.mjs → rollback-B0eg3M0J.mjs} +6 -6
- package/dist/{rollback-BxI2p53H.mjs.map → rollback-B0eg3M0J.mjs.map} +1 -1
- package/dist/{rollback-C6bCANv7.cjs → rollback-DByniS9X.cjs} +6 -6
- package/dist/{rollback-C6bCANv7.cjs.map → rollback-DByniS9X.cjs.map} +1 -1
- package/dist/{s3-DucPHZAn.cjs → s3-4rmPI6wv.cjs} +2 -2
- package/dist/{s3-DucPHZAn.cjs.map → s3-4rmPI6wv.cjs.map} +1 -1
- package/dist/{s3-BAI0ELtE.mjs → s3-B-IJWFJA.mjs} +2 -2
- package/dist/{s3-BAI0ELtE.mjs.map → s3-B-IJWFJA.mjs.map} +1 -1
- package/dist/{serverSetup-DS9tW50_.mjs → serverSetup-Cok75j21.mjs} +6 -6
- package/dist/{serverSetup-DS9tW50_.mjs.map → serverSetup-Cok75j21.mjs.map} +1 -1
- package/dist/{serverSetup-D3-FE7Dj.cjs → serverSetup-EY5vppoS.cjs} +6 -6
- package/dist/{serverSetup-D3-FE7Dj.cjs.map → serverSetup-EY5vppoS.cjs.map} +1 -1
- package/dist/{sniffer-XlvJLrhZ.cjs → sniffer-CcLTONfm.cjs} +6 -6
- package/dist/{sniffer-XlvJLrhZ.cjs.map → sniffer-CcLTONfm.cjs.map} +1 -1
- package/dist/{sniffer-CX8sI8Cu.mjs → sniffer-DIyYcOXJ.mjs} +6 -6
- package/dist/{sniffer-CX8sI8Cu.mjs.map → sniffer-DIyYcOXJ.mjs.map} +1 -1
- package/dist/{snsSubscriptions-CJAOhWq9.cjs → snsSubscriptions-Bore7t-W.cjs} +2 -2
- package/dist/{snsSubscriptions-CJAOhWq9.cjs.map → snsSubscriptions-Bore7t-W.cjs.map} +1 -1
- package/dist/{snsSubscriptions-DDrra9rN.mjs → snsSubscriptions-CYEVD7ml.mjs} +2 -2
- package/dist/{snsSubscriptions-DDrra9rN.mjs.map → snsSubscriptions-CYEVD7ml.mjs.map} +1 -1
- package/dist/{sst-CsEjVFtz.cjs → sst-Bsu5O1Lt.cjs} +17 -4
- package/dist/sst-Bsu5O1Lt.cjs.map +1 -0
- package/dist/{sst-CdHflajE.mjs → sst-DBH707Na.mjs} +17 -4
- package/dist/sst-DBH707Na.mjs.map +1 -0
- package/dist/{stack-BYhtz-bE.cjs → stack-CwSx-6ea.cjs} +2485 -2209
- package/dist/stack-CwSx-6ea.cjs.map +1 -0
- package/dist/{stack-CLHY-_2m.mjs → stack-DU2SunuO.mjs} +2456 -2186
- package/dist/stack-DU2SunuO.mjs.map +1 -0
- package/dist/{stage-C7aYyDMr.mjs → stage-BGyx0OjL.mjs} +4 -4
- package/dist/{stage-C7aYyDMr.mjs.map → stage-BGyx0OjL.mjs.map} +1 -1
- package/dist/{stage-Bc_BtQeG.cjs → stage-BgD-kKY3.cjs} +4 -4
- package/dist/{stage-Bc_BtQeG.cjs.map → stage-BgD-kKY3.cjs.map} +1 -1
- package/dist/target/public.cjs +1 -1
- package/dist/target/public.mjs +1 -1
- package/dist/{terminal-BZzK69T9.mjs → terminal-BlJ90AIM.mjs} +2 -2
- package/dist/{terminal-BZzK69T9.mjs.map → terminal-BlJ90AIM.mjs.map} +1 -1
- package/dist/{terminal-DXUXlqrO.cjs → terminal-GyXHsRAl.cjs} +2 -2
- package/dist/{terminal-DXUXlqrO.cjs.map → terminal-GyXHsRAl.cjs.map} +1 -1
- package/package.json +16 -16
- package/dist/compose-BEVBxf4w.cjs.map +0 -1
- package/dist/compose-Dx_nSZYU.mjs.map +0 -1
- package/dist/credentials-DW5MvS4A.mjs.map +0 -1
- package/dist/credentials-Eyx2tM7B.cjs.map +0 -1
- package/dist/engine-B72vyrO8.mjs.map +0 -1
- package/dist/engine-BevpkNZe.cjs.map +0 -1
- package/dist/sst-CdHflajE.mjs.map +0 -1
- package/dist/sst-CsEjVFtz.cjs.map +0 -1
- package/dist/stack-BYhtz-bE.cjs.map +0 -1
- package/dist/stack-CLHY-_2m.mjs.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compose-D3zc8QN1.cjs","names":["GkmError","SERVER_IPV4_KEY","createServer","createConnection","spawn","GkmError","withGeneratedSecrets","initStageSecrets","resolveStageTelemetry","usesTelemetry","withLogsLogin","runsRedis","withRedisPassword","GkmError","httpsRequest","httpRequest","EDGE_PROJECT","providedKeyFor","provisionedTopics","subscriptionKey","topicConnection","subscriptionResource","GkmError","join","runOutput","dockerCompose","pgClient","bucketClient","ensurePostgresLogin","migrateDatabases","seedDatabases","systemLookup","imageRef","stageTag","discover","constructGlobs","imageLayout","loadLocalCredentials","edgePorts","recordedPushSubscriptions","composeStack","acmeDnsZone","stackDir","existsSync","composeProject","ComposeTlsFileMissing","stackHosts","isLocalHost","assertEdgeHostsFree","edgeRef","LogsPortTaken","LOGS_SERVICE","LOGS_PORT","withLogsPort","appEnvKeys","workerEnvKeys","installedFrom","dnsResourceKey","requiredServerAddress","SERVER_IPV4_KEY","serverAddressHint","stageDns","dnsResources","DeployJournal","createComposeState","recordDnsChanges","HostNotPointingAtServer","forgetDnsResource","isReservedStageKey","plannedSeeds","subscriptionKey","SUBSCRIPTION_TYPE","EDGE_PROJECT","EDGE_SERVICE","ensureEdgeDnsSecrets","ensureEdgeAcmeKey","assertEdgePorts","ensureEdge","LOG_ROTATION","LOOPBACK_SERVICES","applyBuckets","applyPolicies","applyLifecycles","applyNotifications","primaryPortKey","LEGACY_LOCAL_LOGIN","postgresStatements","backupsRoleStatements","applyPostgres","envFor","stageEnv","toEmbeddableSecrets","backendsOf","SeedFailed","DeploySeedsFailed","writeEdgeRoutes","removeEdgeRoutes","replicaNames","currentActor","relative","findBuildRoot","nextPrerenderManifest","fromBuildRoot","confirmPendingSubscriptions","PushSubscriptionsUnconfirmed","logsAccess","hostname","userInfo","readLocalAuthority","readFile","ensureLocalCertificate","ensureLocalAuthority","localCertificateNames","mkdir","chmod","dirname","writeFile","withCaddyConfigs","rm","envFile","REDIS_SERVICE","BACKUPS_SERVICE","POSTGRES_SERVICE","readdir","ensureDockerignore","stringify","composeLiteral","defineTarget"],"sources":["../src/compose/server.ts","../src/compose/images.ts","../src/compose/secrets.ts","../src/target/compose/health.ts","../src/target/compose/topicSubscriptions.ts","../src/target/compose/warmup.ts","../src/target/compose/phases.ts","../src/target/compose/index.ts"],"sourcesContent":["/**\n * Where a deployed compose stage runs: its server, reached over SSH.\n *\n * gkm never runs on the server. It runs where the deploy is started — a CI\n * runner, a developer's machine — and drives the server's Docker engine over\n * SSH (`DOCKER_HOST=ssh://user@host`), so the server holds Docker, an SSH\n * login and nothing else: no gkm, no checkout, no cloud credentials.\n *\n * ```ts\n * deploy: { compose: { server: { production: { user: 'deploy' } } } }\n * ```\n *\n * The host is the stage's `GKM_SERVER_IPV4` secret — the address its DNS\n * records already point at — unless `host` names another. The local stage is\n * never given one: it runs on this machine's Docker.\n *\n * What the deploy needs from inside the server — Postgres and MinIO, published\n * on the server's loopback alone — it reaches through an SSH tunnel on the same\n * login, so neither is ever published publicly.\n */\n\nimport { spawn } from 'node:child_process';\nimport { createConnection, createServer } from 'node:net';\nimport { GkmError } from '../errors';\nimport type { ComposeServerConfig } from '../workspace/types.js';\nimport { SERVER_IPV4_KEY } from './dnsConfig';\n\n/** A stage's server, as SSH reaches it. */\nexport interface ComposeServer {\n\tuser: string;\n\thost: string;\n\tport: number;\n}\n\n/** A deployed compose stage with nowhere to run. */\nexport class ComposeServerMissing extends GkmError {\n\tconstructor(\n\t\treadonly stage: string,\n\t\treadonly missing: 'config' | 'host',\n\t) {\n\t\tsuper(\n\t\t\tmissing === 'config'\n\t\t\t\t? `'${stage}' is a deployed stage, and gkm deploys it to its server's ` +\n\t\t\t\t\t\t\"Docker over SSH — it never starts a deployed stage on this machine's \" +\n\t\t\t\t\t\t`Docker. Name the login in gkm.config.ts: deploy: { compose: { server: ` +\n\t\t\t\t\t\t`{ ${stage}: { user: 'deploy' } } } } — the host is the stage's ` +\n\t\t\t\t\t\t`${SERVER_IPV4_KEY} secret (gkm secrets:set ${SERVER_IPV4_KEY} '<ip>' ` +\n\t\t\t\t\t\t`--stage ${stage}), or set host there too.`\n\t\t\t\t: `deploy.compose.server.${stage} names no host, and '${stage}' has no ` +\n\t\t\t\t\t\t`${SERVER_IPV4_KEY} secret to default to. Set it: gkm secrets:set ` +\n\t\t\t\t\t\t`${SERVER_IPV4_KEY} '<ip>' --stage ${stage} — or set ` +\n\t\t\t\t\t\t`deploy.compose.server.${stage}.host.`,\n\t\t);\n\t\tthis.name = 'ComposeServerMissing';\n\t}\n}\n\n/** SSH to the stage's server failed before anything was changed there. */\nexport class ComposeServerUnreachable extends GkmError {\n\tconstructor(\n\t\treadonly target: string,\n\t\treadonly stderr: string,\n\t) {\n\t\tsuper(\n\t\t\t`Could not reach Docker on ${target} over SSH (ssh said: ${stderr.trim() || 'nothing'}). ` +\n\t\t\t\t`Check that \\`ssh ${target} docker version\\` works from here: the host key in ` +\n\t\t\t\t'~/.ssh/known_hosts, the key in your agent or ~/.ssh/config, and the user in ' +\n\t\t\t\t\"the server's docker group.\",\n\t\t);\n\t\tthis.name = 'ComposeServerUnreachable';\n\t}\n}\n\n/** An SSH tunnel to a port on the server's loopback did not open. */\nexport class ComposeTunnelFailed extends GkmError {\n\tconstructor(\n\t\treadonly target: string,\n\t\treadonly remotePort: number,\n\t\treadonly stderr: string,\n\t) {\n\t\tsuper(\n\t\t\t`Could not open an SSH tunnel to 127.0.0.1:${remotePort} on ${target} ` +\n\t\t\t\t`(ssh said: ${stderr.trim() || 'nothing'}). The server's sshd must allow ` +\n\t\t\t\t'TCP forwarding for the deploy user (AllowTcpForwarding yes, the default, ' +\n\t\t\t\t'or local), and its key in ~/.ssh/authorized_keys must too: a key ' +\n\t\t\t\t'installed with `restrict` refuses forwarding unless it also says ' +\n\t\t\t\t'`port-forwarding` (`restrict,port-forwarding ssh-ed25519 …`).',\n\t\t);\n\t\tthis.name = 'ComposeTunnelFailed';\n\t}\n}\n\n/**\n * The stage's server: its login from `deploy.compose.server.<stage>`, its\n * host from there or the stage's `GKM_SERVER_IPV4`. Undefined for the local\n * stage, which runs on this machine.\n *\n * @throws {ComposeServerMissing} for a deployed stage with no login or host\n */\nexport function composeServer(options: {\n\tstage: string;\n\tlocal: boolean;\n\tconfig: Readonly<Record<string, ComposeServerConfig>> | undefined;\n\tcustom: Readonly<Record<string, string>> | undefined;\n}): ComposeServer | undefined {\n\tconst { stage } = options;\n\tif (options.local) return undefined;\n\tconst config = options.config?.[stage];\n\tif (!config) throw new ComposeServerMissing(stage, 'config');\n\tconst host = config.host ?? options.custom?.[SERVER_IPV4_KEY]?.trim();\n\tif (!host) throw new ComposeServerMissing(stage, 'host');\n\treturn { user: config.user, host, port: config.port ?? 22 };\n}\n\n/** `user@host`, as a person types it after `ssh`. */\nexport function sshTarget(server: ComposeServer): string {\n\treturn `${server.user}@${server.host}`;\n}\n\n/** The server's Docker engine, as `DOCKER_HOST` names it. */\nexport function dockerHost(server: ComposeServer): string {\n\tconst host = server.host.includes(':') ? `[${server.host}]` : server.host;\n\treturn `ssh://${server.user}@${host}${server.port === 22 ? '' : `:${server.port}`}`;\n}\n\n/** The arguments every `ssh` gkm runs starts with: no prompt, ever. */\nfunction sshArgs(server: ComposeServer): string[] {\n\treturn [\n\t\t'-o',\n\t\t'BatchMode=yes',\n\t\t'-o',\n\t\t'ConnectTimeout=20',\n\t\t'-p',\n\t\tString(server.port),\n\t\tsshTarget(server),\n\t];\n}\n\n/** A local port forwarded to one on the server's loopback. */\nexport interface Tunnel {\n\t/** The port on this machine's loopback. */\n\tport: number;\n\tclose(): Promise<void>;\n}\n\n/** What the deploy does on a stage's server beyond Docker. */\nexport interface ServerAccess {\n\t/**\n\t * Whether SSH logs in and Docker answers there — read-only: `docker\n\t * version`, nothing else.\n\t */\n\tcheck(server: ComposeServer): Promise<void>;\n\t/** Forward a free local port to `remotePort` on the server's loopback. */\n\ttunnel(server: ComposeServer, remotePort: number): Promise<Tunnel>;\n}\n\nasync function freeLocalPort(): Promise<number> {\n\tconst server = createServer();\n\tawait new Promise<void>((resolve, reject) => {\n\t\tserver.once('error', reject);\n\t\tserver.listen(0, '127.0.0.1', resolve);\n\t});\n\tconst address = server.address();\n\tawait new Promise((resolve) => server.close(resolve));\n\tif (!address || typeof address === 'string') return 0;\n\treturn address.port;\n}\n\nfunction connects(port: number): Promise<boolean> {\n\treturn new Promise((resolve) => {\n\t\tconst socket = createConnection({ host: '127.0.0.1', port });\n\t\tsocket.once('connect', () => {\n\t\t\tsocket.destroy();\n\t\t\tresolve(true);\n\t\t});\n\t\tsocket.once('error', () => resolve(false));\n\t});\n}\n\n/** The real one: the system's `ssh`, with the user's keys and known hosts. */\nexport const sshAccess: ServerAccess = {\n\tcheck(server) {\n\t\treturn new Promise((resolve, reject) => {\n\t\t\tconst child = spawn(\n\t\t\t\t'ssh',\n\t\t\t\t[\n\t\t\t\t\t...sshArgs(server),\n\t\t\t\t\t'docker',\n\t\t\t\t\t'version',\n\t\t\t\t\t'--format',\n\t\t\t\t\t'{{.Server.Version}}',\n\t\t\t\t],\n\t\t\t\t{ stdio: ['ignore', 'ignore', 'pipe'] },\n\t\t\t);\n\t\t\tlet stderr = '';\n\t\t\tchild.stderr.on('data', (chunk: Buffer) => {\n\t\t\t\tstderr += chunk.toString();\n\t\t\t});\n\t\t\tchild.on('error', (error) =>\n\t\t\t\treject(new ComposeServerUnreachable(sshTarget(server), error.message)),\n\t\t\t);\n\t\t\tchild.on('close', (code) =>\n\t\t\t\tcode === 0\n\t\t\t\t\t? resolve()\n\t\t\t\t\t: reject(new ComposeServerUnreachable(sshTarget(server), stderr)),\n\t\t\t);\n\t\t});\n\t},\n\n\tasync tunnel(server, remotePort) {\n\t\tconst port = await freeLocalPort();\n\t\tconst child = spawn(\n\t\t\t'ssh',\n\t\t\t[\n\t\t\t\t'-N',\n\t\t\t\t'-o',\n\t\t\t\t'ExitOnForwardFailure=yes',\n\t\t\t\t// A connection of its own: through a shared master (ControlMaster\n\t\t\t\t// in ~/.ssh/config) the forward would be the master's, and this\n\t\t\t\t// process — the tunnel's lifetime — would exit at once.\n\t\t\t\t'-o',\n\t\t\t\t'ControlPath=none',\n\t\t\t\t'-L',\n\t\t\t\t`127.0.0.1:${port}:127.0.0.1:${remotePort}`,\n\t\t\t\t...sshArgs(server),\n\t\t\t],\n\t\t\t{ stdio: ['ignore', 'ignore', 'pipe'] },\n\t\t);\n\t\tlet stderr = '';\n\t\tlet exited = false;\n\t\tchild.stderr.on('data', (chunk: Buffer) => {\n\t\t\tstderr += chunk.toString();\n\t\t});\n\t\tchild.on('exit', () => {\n\t\t\texited = true;\n\t\t});\n\t\tchild.on('error', (error) => {\n\t\t\texited = true;\n\t\t\tstderr += error.message;\n\t\t});\n\t\tconst close = async () => {\n\t\t\tif (exited) return;\n\t\t\tconst gone = new Promise((resolve) => child.once('exit', resolve));\n\t\t\tchild.kill('SIGTERM');\n\t\t\tawait gone;\n\t\t};\n\n\t\t// Open once a connection to it is accepted — ssh only listens once\n\t\t// it has logged in and set the forward up.\n\t\tfor (let attempt = 0; attempt < 150; attempt++) {\n\t\t\tif (exited) break;\n\t\t\tif (await connects(port)) return { port, close };\n\t\t\tawait new Promise((resolve) => setTimeout(resolve, 200));\n\t\t}\n\t\tawait close();\n\t\tthrow new ComposeTunnelFailed(sshTarget(server), remotePort, stderr);\n\t},\n};\n","/**\n * Which image each app runs — and, for a tag, whether every one exists.\n *\n * A tag is a release's identity: `--tag=v1.4.0` means the images CI pushed as\n * v1.4.0, and nothing else. So a stack is never half rolled out: every app's\n * image is asked of the registry before anything is pulled or the running\n * stack is touched, and one missing image stops the whole run naming every\n * one that is missing. Nor is a missing image quietly built instead — a build\n * of whatever is checked out here is not the release the tag names.\n */\n\nimport { GkmError } from '../errors';\nimport type { ComposeDocker } from './docker';\n\n/** One app's image, as the stack runs it. */\nexport interface AppImage {\n\tapp: string;\n\tref: string;\n\ttag: string;\n}\n\n/** Images a tag names that the registry does not have. */\nexport class ImageTagNotFound extends GkmError {\n\tconstructor(\n\t\treadonly tag: string,\n\t\treadonly refs: readonly string[],\n\t) {\n\t\tsuper(\n\t\t\t`The registry has no image for ${refs.length === 1 ? 'this app' : `${refs.length} apps`} at '${tag}':\\n` +\n\t\t\t\trefs.map((ref) => ` - ${ref}`).join('\\n') +\n\t\t\t\t`\\nNothing was pulled or started. Push '${tag}' for every app from CI, ` +\n\t\t\t\t`pick a tag that exists, or run without --tag to build from this checkout.`,\n\t\t);\n\t\tthis.name = 'ImageTagNotFound';\n\t}\n}\n\n/** The registry did not answer, or did not let this machine in. */\nexport class RegistryUnreachable extends GkmError {\n\tconstructor(\n\t\treadonly ref: string,\n\t\treadonly detail: string,\n\t) {\n\t\tsuper(\n\t\t\t`Could not ask the registry about ${ref}: ${detail || 'no answer'}\\n` +\n\t\t\t\t`Nothing was pulled or started. Check the registry is reachable and ` +\n\t\t\t\t`that this machine is logged in to it (\\`docker login <registry>\\`).`,\n\t\t);\n\t\tthis.name = 'RegistryUnreachable';\n\t}\n}\n\n/**\n * A pinned image whose digest the registry would not give, while its tag it\n * would: the tag now names another image than the one the release pinned.\n *\n * Not a login problem — the registry answered for the tag. The tag was pushed\n * again (by another build of it), and the pinned image is gone, or cannot be\n * read, by its digest.\n */\nexport class PinnedImageMoved extends GkmError {\n\tconstructor(\n\t\t/** The pinned ref: `<image>:<tag>@sha256:…`. */\n\t\treadonly ref: string,\n\t\t/** What asking for the digest said; empty when it was not found. */\n\t\treadonly detail: string,\n\t) {\n\t\tconst [tagged, digest] = ref.split('@');\n\t\tsuper(\n\t\t\t`${tagged} is in the registry, but it resolves to a different image ` +\n\t\t\t\t`than the pinned ${digest}, and the registry would not give that ` +\n\t\t\t\t`digest${detail ? `: ${detail}` : ''}\\n` +\n\t\t\t\t`Nothing was pulled or started. The tag was pushed again after this ` +\n\t\t\t\t`release's push; deploy with the digests file of a push whose ` +\n\t\t\t\t`images are still in the registry, or push this release again.`,\n\t\t);\n\t\tthis.name = 'PinnedImageMoved';\n\t}\n}\n\n/**\n * The ref an image is asked of the registry by: a pinned one by its digest\n * alone (`<image>@sha256:…`), so a tag moved since the push cannot change the\n * answer; any other by its tag.\n */\nexport function lookupRef(ref: string): string {\n\tconst [tagged, digest] = ref.split('@');\n\tif (!digest) return ref;\n\treturn `${tagged!.replace(/:[\\w][\\w.-]*$/, '')}@${digest}`;\n}\n\n/**\n * Assert every image exists, before anything else happens.\n *\n * Asked all at once and reported all at once: a release missing two images is\n * one problem with two names, and finding the second only after fixing the\n * first is a slower way to learn the same thing.\n *\n * A pinned image is asked for by its digest. When the registry will not give\n * it, its tag is asked too: a tag that answers means the registry is reachable\n * and the tag names another image, and that is what is reported.\n *\n * @throws {PinnedImageMoved} when a pinned digest fails and its tag answers\n * @throws {RegistryUnreachable} when the registry cannot say\n * @throws {ImageTagNotFound} listing every missing image\n */\nexport async function assertImagesExist(\n\tdocker: Pick<ComposeDocker, 'lookup'>,\n\ttag: string,\n\timages: readonly AppImage[],\n): Promise<void> {\n\tconst lookups = await Promise.all(\n\t\timages.map(async (image) => ({\n\t\t\timage,\n\t\t\tlookup: await docker.lookup(lookupRef(image.ref)),\n\t\t})),\n\t);\n\n\tfor (const { image, lookup } of lookups) {\n\t\tif (lookup.status === 'found' || !image.ref.includes('@')) continue;\n\t\tconst byTag = await docker.lookup(image.ref.split('@')[0]!);\n\t\tif (byTag.status === 'found') {\n\t\t\tthrow new PinnedImageMoved(\n\t\t\t\timage.ref,\n\t\t\t\tlookup.status === 'unreachable' ? lookup.detail : '',\n\t\t\t);\n\t\t}\n\t}\n\n\tfor (const { lookup } of lookups) {\n\t\tif (lookup.status === 'unreachable') {\n\t\t\tthrow new RegistryUnreachable(lookup.ref, lookup.detail);\n\t\t}\n\t}\n\n\tconst missing = lookups\n\t\t.filter(({ lookup }) => lookup.status === 'missing')\n\t\t.map(({ image }) => image.ref);\n\tif (missing.length > 0) throw new ImageTagNotFound(tag, missing);\n}\n\n/**\n * A push or a pull with no `deploy.registry` to push to or pull from.\n *\n * Without one an image is named `<namespace>/<project>-<app>:<tag>`, which\n * Docker resolves to Docker Hub — so a release would be pushed to, or pulled\n * from, somebody else's account. It is never a fallback.\n */\nexport class RegistryRequired extends GkmError {\n\tconstructor(\n\t\t/** What needed the registry: `--push`, or a pull (`--tag`/`--pull`). */\n\t\treadonly operation: 'push' | 'pull',\n\t\t/** The ref an image would have had: a Docker Hub name. */\n\t\treadonly ref: string,\n\t) {\n\t\tsuper(\n\t\t\t`${operation === 'push' ? 'Pushing' : 'Pulling'} images needs a registry, and gkm.config.ts sets no deploy.registry: ` +\n\t\t\t\t`'${ref}' would be ${operation === 'push' ? 'pushed to' : 'pulled from'} Docker Hub. ` +\n\t\t\t\t`Set deploy.registry (e.g. registry: 'ghcr.io/acme') in gkm.config.ts.` +\n\t\t\t\t(operation === 'pull'\n\t\t\t\t\t? ' To run images built here instead, pass --build.'\n\t\t\t\t\t: ''),\n\t\t);\n\t\tthis.name = 'RegistryRequired';\n\t}\n}\n\n/**\n * What a push reports, and what a pull can pin to: each app's image as\n * `<ref>@sha256:…` — the tag it was pushed as, and the exact image, whatever\n * that tag is later moved to.\n */\nexport type ImageDigests = Record<string, string>;\n\n/** An image pinned to its digest: `<ref>@sha256:…`. */\nexport function pinnedRef(ref: string, digest: string): string {\n\treturn `${ref.split('@')[0]}@${digest}`;\n}\n\n/** A digests file with no entry for an app the stack runs. */\nexport class ImageDigestMissing extends GkmError {\n\tconstructor(\n\t\treadonly file: string,\n\t\treadonly apps: readonly string[],\n\t) {\n\t\tsuper(\n\t\t\t`${file} pins no digest for ${apps.join(', ')}. Use the file the ` +\n\t\t\t\t`same release's \\`gkm compose --build --push --digests-file\\` wrote, ` +\n\t\t\t\t`or run without --digests-file to pull by tag.`,\n\t\t);\n\t\tthis.name = 'ImageDigestMissing';\n\t}\n}\n\n/** A digests file entry that is not this app's image. */\nexport class ImageDigestMismatch extends GkmError {\n\tconstructor(\n\t\treadonly app: string,\n\t\treadonly expected: string,\n\t\treadonly found: string,\n\t) {\n\t\tsuper(\n\t\t\t`The digests file pins '${app}' to ${found}, but this release runs ` +\n\t\t\t\t`${expected}. It was written for another registry, project, stage ` +\n\t\t\t\t`or tag; use the file this stage's push of this tag wrote.`,\n\t\t);\n\t\tthis.name = 'ImageDigestMismatch';\n\t}\n}\n\n/** A digests file that is not a JSON object of app to pinned ref. */\nexport class ImageDigestsInvalid extends GkmError {\n\tconstructor(\n\t\treadonly file: string,\n\t\treadonly detail: string,\n\t) {\n\t\tsuper(\n\t\t\t`${file} is not a digests file (${detail}). It should be the JSON ` +\n\t\t\t\t`object \\`gkm compose --build --push --digests-file\\` writes: ` +\n\t\t\t\t`{ \"api\": \"<registry>/<image>:<tag>@sha256:…\" }.`,\n\t\t);\n\t\tthis.name = 'ImageDigestsInvalid';\n\t}\n}\n\n/** Parse a digests file's content, checking its shape. */\nexport function parseDigests(file: string, content: string): ImageDigests {\n\tlet parsed: unknown;\n\ttry {\n\t\tparsed = JSON.parse(content);\n\t} catch (error) {\n\t\tthrow new ImageDigestsInvalid(\n\t\t\tfile,\n\t\t\terror instanceof Error ? error.message : String(error),\n\t\t);\n\t}\n\tif (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {\n\t\tthrow new ImageDigestsInvalid(file, 'not a JSON object');\n\t}\n\tfor (const [app, value] of Object.entries(parsed)) {\n\t\tif (typeof value !== 'string' || !/@sha256:[0-9a-f]{64}$/.test(value)) {\n\t\t\tthrow new ImageDigestsInvalid(\n\t\t\t\tfile,\n\t\t\t\t`'${app}' is not an <image>:<tag>@sha256:… ref`,\n\t\t\t);\n\t\t}\n\t}\n\treturn parsed as ImageDigests;\n}\n\n/**\n * Each image pinned to the digest the file names for it.\n *\n * @throws {ImageDigestMissing} naming every app the file has no entry for\n * @throws {ImageDigestMismatch} when an entry is another image or tag\n */\nexport function pinImages<T extends AppImage>(\n\tfile: string,\n\tdigests: ImageDigests,\n\timages: readonly T[],\n): T[] {\n\tconst missing = images\n\t\t.filter((image) => !digests[image.app])\n\t\t.map((image) => image.app);\n\tif (missing.length > 0) throw new ImageDigestMissing(file, missing);\n\n\treturn images.map((image) => {\n\t\tconst pinned = digests[image.app]!;\n\t\tif (pinned.split('@')[0] !== image.ref) {\n\t\t\tthrow new ImageDigestMismatch(image.app, image.ref, pinned);\n\t\t}\n\t\treturn { ...image, ref: pinned };\n\t});\n}\n","/**\n * What a deployed stage's stack generates once and keeps: its seed, each\n * `secret` construct's value, the log UI's root login where its telemetry\n * is self-hosted, and the stack's Redis password where a cache lives in it.\n *\n * Pure: the compose target writes the result back to the stage's store.\n */\n\nimport type { ConstructManifest } from '@geekmidas/manifest';\nimport {\n\ttype GeneratedSecrets,\n\twithGeneratedSecrets,\n} from '../deploy/generated.js';\nimport { initStageSecrets } from '../secrets/storage.js';\nimport type { StageSecrets } from '../secrets/types.js';\nimport { resolveStageTelemetry } from '../telemetry/config';\nimport { usesTelemetry } from '../telemetry/edges';\nimport type { NormalizedWorkspace } from '../workspace/types.js';\nimport { withLogsLogin } from './logs';\nimport { runsRedis, withRedisPassword } from './redis';\n\nexport function deployedStackSecrets(\n\tworkspace: NormalizedWorkspace,\n\tstage: string,\n\tstored: StageSecrets | null,\n\tmanifest: ConstructManifest,\n): GeneratedSecrets {\n\tconst withSeed = withGeneratedSecrets(\n\t\tstored ?? initStageSecrets(stage),\n\t\tmanifest,\n\t);\n\t// The log UI's root login, stored once like the seed, where the stage's\n\t// telemetry is self-hosted and the stage set none — read ever after, so\n\t// it never moves with the domain under the user OpenObserve stored.\n\tconst telemetry = resolveStageTelemetry({\n\t\t...(workspace.deploy?.telemetry\n\t\t\t? { telemetry: workspace.deploy.telemetry }\n\t\t\t: {}),\n\t\tstage,\n\t\tlocal: false,\n\t\ttarget: 'compose',\n\t\truntime: 'server',\n\t\tselfHosted: true,\n\t\tused: usesTelemetry(manifest),\n\t});\n\tconst withLogs =\n\t\ttelemetry?.provider === 'self-hosted'\n\t\t\t? withLogsLogin(withSeed.secrets, workspace.domains?.[stage])\n\t\t\t: { secrets: withSeed.secrets, generated: [] };\n\t// The stack's Redis password, the same way, where a cache lives in it.\n\tconst withRedis = runsRedis(manifest, withLogs.secrets.custom ?? {})\n\t\t? withRedisPassword(withLogs.secrets)\n\t\t: { secrets: withLogs.secrets, generated: [] };\n\treturn {\n\t\tsecrets: withRedis.secrets,\n\t\tgenerated: [\n\t\t\t...withSeed.generated,\n\t\t\t...withLogs.generated,\n\t\t\t...withRedis.generated,\n\t\t],\n\t};\n}\n","/**\n * Asking each app of a stack whether it answers — through Caddy, over HTTPS,\n * the way a browser reaches it.\n *\n * `docker compose up --wait` already knows each container passed its own\n * health check, asked on 127.0.0.1 inside it. What that cannot say is whether\n * the stack is reachable: whether the edge routes the host to the app, and\n * whether the certificate it presents is one a client accepts. So the check\n * goes through the edge, by hostname, and verifies the certificate.\n */\n\nimport { request as httpRequest } from 'node:http';\nimport { request as httpsRequest } from 'node:https';\nimport { EDGE_PROJECT } from '@geekmidas/edge/proxy/traefik';\nimport { GkmError } from '../../errors';\n\n/** One request to the edge. */\nexport interface HealthRequest {\n\t/** The app's public URL plus its health path. */\n\turl: string;\n\t/**\n\t * The certificate authority to verify against, PEM — gkm's local CA on\n\t * the local stage. The system's when absent.\n\t */\n\tca?: string;\n\t/**\n\t * Connect here instead of resolving the URL's host — the local edge, at\n\t * 127.0.0.1. The host is still sent as SNI and `Host`, so nothing depends\n\t * on how this machine resolves `*.localhost`.\n\t */\n\tconnectTo?: string;\n\t/**\n\t * With `connectTo`, the port to connect to, where it is not the URL's —\n\t * the shared edge's published port, asked for a deployed host.\n\t */\n\tconnectPort?: number;\n\t/**\n\t * The `Authorization` header to send — a site the stage puts behind a\n\t * password is asked with its login, which proves the login works too.\n\t */\n\tauthorization?: string;\n\ttimeoutMs: number;\n\tsignal?: AbortSignal;\n}\n\n/** Asks once, resolving with the HTTP status. Rejects when nothing answers. */\nexport type HealthProbe = (request: HealthRequest) => Promise<number>;\n\n/** A request that got no answer in time. */\nexport class HealthRequestTimedOut extends GkmError {\n\tconstructor(\n\t\treadonly url: string,\n\t\treadonly timeoutMs: number,\n\t) {\n\t\tsuper(\n\t\t\t`${url} did not answer within ${timeoutMs}ms. Check the stack is up with \\`docker compose ps\\`.`,\n\t\t);\n\t\tthis.name = 'HealthRequestTimedOut';\n\t}\n}\n\n/** What the edge answered: its status, and the body where it was asked for. */\nexport interface EdgeResponse {\n\tstatus: number;\n\t/** The body, as text — empty unless the request asked to `read` it. */\n\tbody: string;\n\t/** The response's headers, by lower-case name. */\n\theaders?: Readonly<Record<string, string | string[] | undefined>>;\n}\n\n/** A request to the edge, and whether its body is wanted. */\nexport interface EdgeRequest extends HealthRequest {\n\t/** Read the body, up to {@link EDGE_BODY_LIMIT} bytes; drained otherwise. */\n\tread?: boolean;\n\t/** Headers sent besides `Host` and `Authorization`. */\n\theaders?: Readonly<Record<string, string>>;\n}\n\n/** Asks once. Rejects when nothing answers. */\nexport type EdgeFetch = (request: EdgeRequest) => Promise<EdgeResponse>;\n\n/** The most of a body read — a sitemap may be 50 MB, and none needs to be. */\nexport const EDGE_BODY_LIMIT = 10 * 1024 * 1024;\n\n/** A body larger than {@link EDGE_BODY_LIMIT}. */\nexport class EdgeResponseTooLarge extends GkmError {\n\tconstructor(\n\t\treadonly url: string,\n\t\treadonly limit: number,\n\t) {\n\t\tsuper(\n\t\t\t`${url} answered with more than ${limit} bytes, which is more than gkm reads. Split it — a sitemap index can list several sitemaps.`,\n\t\t);\n\t\tthis.name = 'EdgeResponseTooLarge';\n\t}\n}\n\n/**\n * The real request: one GET to the edge — over HTTPS, the certificate\n * verified, for an `https:` URL, and plain HTTP for an `http:` one — with\n * the URL's host as SNI and `Host` wherever it connects.\n */\nexport const edgeFetch: EdgeFetch = ({\n\turl,\n\tca,\n\tconnectTo,\n\tconnectPort,\n\tauthorization,\n\ttimeoutMs,\n\tsignal,\n\tread,\n\theaders,\n}) => {\n\tconst target = new URL(url);\n\tconst secure = target.protocol === 'https:';\n\tconst request = secure ? httpsRequest : httpRequest;\n\treturn new Promise((resolve, reject) => {\n\t\tconst req = request(\n\t\t\t{\n\t\t\t\thost: connectTo ?? target.hostname,\n\t\t\t\tport: connectPort ?? (target.port || (secure ? 443 : 80)),\n\t\t\t\t...(secure ? { servername: target.hostname } : {}),\n\t\t\t\tpath: `${target.pathname}${target.search}`,\n\t\t\t\tmethod: 'GET',\n\t\t\t\theaders: {\n\t\t\t\t\t...headers,\n\t\t\t\t\thost: target.host,\n\t\t\t\t\t...(authorization ? { authorization } : {}),\n\t\t\t\t},\n\t\t\t\t...(secure && ca ? { ca } : {}),\n\t\t\t\t...(signal ? { signal } : {}),\n\t\t\t\ttimeout: timeoutMs,\n\t\t\t},\n\t\t\t(res) => {\n\t\t\t\tconst status = res.statusCode ?? 0;\n\t\t\t\tconst answered = { status, headers: res.headers };\n\t\t\t\tif (!read) {\n\t\t\t\t\t// The status is the answer; the body is drained so the socket closes.\n\t\t\t\t\tres.resume();\n\t\t\t\t\tres.on('end', () => resolve({ ...answered, body: '' }));\n\t\t\t\t\tres.on('error', reject);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst chunks: Buffer[] = [];\n\t\t\t\tlet size = 0;\n\t\t\t\tres.on('data', (chunk: Buffer) => {\n\t\t\t\t\tsize += chunk.length;\n\t\t\t\t\tif (size > EDGE_BODY_LIMIT) {\n\t\t\t\t\t\treq.destroy(new EdgeResponseTooLarge(url, EDGE_BODY_LIMIT));\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tchunks.push(chunk);\n\t\t\t\t});\n\t\t\t\tres.on('end', () =>\n\t\t\t\t\tresolve({\n\t\t\t\t\t\t...answered,\n\t\t\t\t\t\tbody: Buffer.concat(chunks).toString('utf-8'),\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t\tres.on('error', reject);\n\t\t\t},\n\t\t);\n\t\treq.on('timeout', () =>\n\t\t\treq.destroy(new HealthRequestTimedOut(url, timeoutMs)),\n\t\t);\n\t\treq.on('error', reject);\n\t\treq.end();\n\t});\n};\n\n/** The real probe: one GET through the edge, answered by its status. */\nexport const httpsProbe: HealthProbe = (request) =>\n\tedgeFetch(request).then(({ status }) => status);\n\n/** Whether a status means the app answered as it should. */\nexport function isHealthy(status: number): boolean {\n\treturn status >= 200 && status < 400;\n}\n\n/**\n * Apps that are not healthy. `via` says which check said so:\n * - `edge`: verify asked each app through the edge, by its host, and it did\n * not answer as it should (a worker, with no route, by its container's\n * health);\n * - `docker`: `up --wait` failed, and these containers' own health checks\n * had not passed — the rest of the stack was released and routed first.\n * One class either way, so a caller matches one failure: apps not healthy.\n */\nexport class ComposeAppsUnhealthy extends GkmError {\n\tconstructor(\n\t\treadonly project: string,\n\t\t/**\n\t\t * Each app, and the last thing its check got: a status or an error —\n\t\t * for `docker`, the container's health as Docker reports it.\n\t\t */\n\t\treadonly apps: readonly { app: string; url: string; last: string }[],\n\t\t/** The proxy the stack is served through. */\n\t\treadonly proxy: 'caddy' | 'traefik' = 'caddy',\n\t\t/** Which check failed: through the edge, or Docker's own. */\n\t\treadonly via: 'edge' | 'docker' = 'edge',\n\t) {\n\t\tconst names = apps.map((a) => a.app).join(' ');\n\t\tsuper(\n\t\t\tvia === 'docker'\n\t\t\t\t? `${project} started, but ${apps.length === 1 ? \"this container's health check has\" : \"these containers' health checks have\"} not passed. The rest of the stack is up and routed:\\n` +\n\t\t\t\t\t\tapps\n\t\t\t\t\t\t\t.map(({ app, last }) => ` - ${app}: Docker reports it ${last}`)\n\t\t\t\t\t\t\t.join('\\n') +\n\t\t\t\t\t\t`\\nSee why with \\`docker compose -p ${project} ps ${names}\\` and \\`docker compose -p ${project} logs ${names}\\`, fix the app, and deploy again.`\n\t\t\t\t: `${project} started, but ${apps.length === 1 ? 'this app does' : 'these apps do'} not answer through ${proxy === 'caddy' ? 'Caddy' : 'the shared Traefik edge'}:\\n` +\n\t\t\t\t\t\tapps.map(({ url, last }) => ` - ${url}: ${last}`).join('\\n') +\n\t\t\t\t\t\t(proxy === 'caddy'\n\t\t\t\t\t\t\t? `\\nSee why with \\`docker compose -p ${project} logs caddy ${names}\\`.`\n\t\t\t\t\t\t\t: `\\nSee why with \\`docker compose -p ${EDGE_PROJECT} logs traefik\\` and \\`docker compose -p ${project} logs ${names}\\`.`),\n\t\t);\n\t\tthis.name = 'ComposeAppsUnhealthy';\n\t}\n}\n","/**\n * The SNS subscriptions a compose deploy makes for a topic whose connection\n * string names an SNS topic.\n *\n * On a compose stage a topic is pg-boss unless the stage says otherwise; one\n * that names an SNS topic is either set by hand — made somewhere this deploy\n * does not provision — or made by the stage's providers, as an inbox's topic\n * is. Its subscribers are still pushed to — the worker answers on its host —\n * and the worker cannot subscribe itself, so the deploy does: one\n * subscription per subscriber, filtered on the event types it names, each\n * ARN recorded for the worker to accept deliveries under.\n *\n * A hand-set topic is reached with its connection string's own keys. A topic\n * the providers made is reached with the deploy's credentials: its string is\n * signed with the app's key, which may only confirm a subscription — letting\n * it subscribe would let the app choose who receives the topic's messages.\n * A bucket's subscriptions are the `s3` provider's.\n */\n\nimport type { ConstructManifest } from '@geekmidas/manifest';\nimport { providedKeyFor } from '@geekmidas/manifest';\nimport type { ComposeStack } from '../../compose/stack.js';\nimport type { ResourceInput, ResourceRecord } from '../../deploy/StateStore.js';\nimport {\n\tprovisionedTopics,\n\tSUBSCRIPTION_TYPE,\n\tsubscriptionKey,\n\tsubscriptionResource,\n\ttopicConnection,\n} from '../../deploy/snsSubscriptions.js';\n\n/** One topic subscriber SNS pushes to, as the deploy subscribes it. */\nexport interface TopicPush {\n\t/** The worker's construct id — what its subscriptions are recorded under. */\n\tworker: string;\n\t/** The subscriber's export. */\n\tname: string;\n\t/** `https://<worker host>/__gkm/subscribers/<name>` */\n\tendpoint: string;\n\t/** The topic's connection string's key, and its value on this stage. */\n\tconnectionKey: string;\n\tconnectionString: string;\n\t/** The event types it names: its subscription's filter. */\n\tevents?: readonly string[];\n}\n\n/**\n * Every topic subscriber the stack pushes to: a subscriber whose connection\n * key is a topic's publisher string — a bucket's events key is not — and\n * whose value on this stage is an SNS one.\n */\nexport function topicPushes(\n\tstack: Pick<ComposeStack, 'workers'>,\n\tmanifest: ConstructManifest,\n): TopicPush[] {\n\tconst topicKeys = new Set(\n\t\tObject.values(manifest)\n\t\t\t.filter((declaration) => declaration.kind === 'topic')\n\t\t\t.map((topic) =>\n\t\t\t\tprovidedKeyFor(topic.id, topic.kind, 'publisherConnectionString'),\n\t\t\t),\n\t);\n\n\tconst pushes: TopicPush[] = [];\n\tfor (const worker of stack.workers) {\n\t\tfor (const subscriber of worker.push?.subscribers ?? []) {\n\t\t\tif (!topicKeys.has(subscriber.connectionKey)) continue;\n\t\t\tconst connectionString = worker.env?.[subscriber.connectionKey];\n\t\t\tif (!connectionString?.startsWith('sns:')) continue;\n\t\t\tpushes.push({\n\t\t\t\tworker: worker.id,\n\t\t\t\tname: subscriber.name,\n\t\t\t\tendpoint: subscriber.endpoint,\n\t\t\t\tconnectionKey: subscriber.connectionKey,\n\t\t\t\tconnectionString,\n\t\t\t\t...(subscriber.events ? { events: subscriber.events } : {}),\n\t\t\t});\n\t\t}\n\t}\n\treturn pushes;\n}\n\n/** The subscriptions recorded for hand-set topics: those with a key. */\nexport function recordedTopicSubscriptions(\n\tresources: Readonly<Record<string, ResourceRecord>> | undefined,\n): ResourceRecord[] {\n\treturn Object.values(resources ?? {}).filter(\n\t\t(record) =>\n\t\t\trecord.type === SUBSCRIPTION_TYPE &&\n\t\t\ttypeof record.data?.connectionKey === 'string',\n\t);\n}\n\n/**\n * Converge each hand-set topic's subscriptions on the subscribers pushed to:\n * subscribe, bring filters up to date, unsubscribe a route on the worker's\n * host no subscriber wants any more — and record each ARN, forgetting what\n * was removed.\n *\n * @returns each worker's subscriptions, by export — what it is handed\n */\nexport async function ensureTopicSubscriptions(input: {\n\tpushes: readonly TopicPush[];\n\trecorded: Readonly<Record<string, ResourceRecord>> | undefined;\n\t/** The stage's secrets: a topic only removed subscribers still name. */\n\tsecrets: Readonly<Record<string, string>>;\n\tstage: string;\n\tenv: NodeJS.ProcessEnv;\n\trecord: (resource: ResourceInput) => Promise<void>;\n\tforget: (key: string) => Promise<void>;\n\tlog: (line: string) => void;\n}): Promise<Record<string, Record<string, string>>> {\n\tconst { snsUrl, reconcileHttpSubscriptions } = await import(\n\t\t'@geekmidas/events/sns'\n\t);\n\n\t// One reconcile per topic and worker host: what it is not handed on that\n\t// host is unsubscribed, so it is handed every subscriber there.\n\ttype Group = {\n\t\ttopicArn: string;\n\t\thost: string;\n\t\tconnectionKey: string;\n\t\tconnectionString?: string;\n\t\tpushes: TopicPush[];\n\t\trecorded: ResourceRecord[];\n\t};\n\tconst groups = new Map<string, Group>();\n\tconst group = (\n\t\ttopicArn: string,\n\t\thost: string,\n\t\tconnectionKey: string,\n\t): Group => {\n\t\tconst id = `${topicArn}|${host}`;\n\t\tconst found = groups.get(id);\n\t\tif (found) return found;\n\t\tconst created: Group = {\n\t\t\ttopicArn,\n\t\t\thost,\n\t\t\tconnectionKey,\n\t\t\tpushes: [],\n\t\t\trecorded: [],\n\t\t};\n\t\tgroups.set(id, created);\n\t\treturn created;\n\t};\n\n\tfor (const push of input.pushes) {\n\t\tconst { topicArn } = snsUrl.parse(push.connectionString);\n\t\tconst into = group(\n\t\t\ttopicArn,\n\t\t\tnew URL(push.endpoint).host,\n\t\t\tpush.connectionKey,\n\t\t);\n\t\tinto.connectionString = push.connectionString;\n\t\tinto.pushes.push(push);\n\t}\n\tfor (const record of recordedTopicSubscriptions(input.recorded)) {\n\t\tgroup(\n\t\t\tString(record.data?.topicArn),\n\t\t\tnew URL(String(record.data?.endpoint)).host,\n\t\t\tString(record.data?.connectionKey),\n\t\t).recorded.push(record);\n\t}\n\n\t// Topics the stage's providers made: never managed with the app's key.\n\tconst provisioned = provisionedTopics(input.recorded);\n\tconst wanted = new Set(\n\t\tinput.pushes.map(({ worker, name }) => subscriptionKey(worker, name)),\n\t);\n\tconst arns: Record<string, Record<string, string>> = {};\n\tfor (const { topicArn, host, connectionKey, ...members } of groups.values()) {\n\t\t// Forgotten only when no subscriber wants the key on any topic: one\n\t\t// the stage moved to another topic is recorded again there.\n\t\tconst stale = members.recorded.filter((r) => !wanted.has(r.key));\n\n\t\t// A topic only removed subscribers name is reached as the stage now\n\t\t// names it, at the topic they were subscribed to.\n\t\tconst named = members.connectionString ?? input.secrets[connectionKey];\n\t\tif (!named?.startsWith('sns:')) {\n\t\t\tfor (const record of stale) {\n\t\t\t\tinput.log(\n\t\t\t\t\t` – forgot ${record.data?.endpoint}: '${connectionKey}' no longer names an SNS topic to unsubscribe it from`,\n\t\t\t\t);\n\t\t\t\tawait input.forget(record.key);\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\t\tconst address = new URL(named);\n\t\taddress.searchParams.set('topicArn', topicArn);\n\n\t\tconst connection = await topicConnection({\n\t\t\tconnectionKey,\n\t\t\tconnectionString: address.toString(),\n\t\t\tstage: input.stage,\n\t\t\tenv: input.env,\n\t\t\tprovisioned: provisioned.has(topicArn),\n\t\t});\n\t\tconst result = await reconcileHttpSubscriptions(connection, {\n\t\t\tendpoints: members.pushes.map((push) => ({\n\t\t\t\tname: push.name,\n\t\t\t\tendpoint: push.endpoint,\n\t\t\t\t...(push.events ? { events: push.events } : {}),\n\t\t\t})),\n\t\t\townedHost: host,\n\t\t});\n\t\tawait connection.close();\n\n\t\tfor (const push of members.pushes) {\n\t\t\tconst arn = result.subscriptions[push.name]!;\n\t\t\tconst key = subscriptionKey(push.worker, push.name);\n\t\t\tif (input.recorded?.[key]?.id !== arn) {\n\t\t\t\tinput.log(\n\t\t\t\t\t` ✓ '${push.name}' subscribed to ${topicArn.split(':').pop()} at ${push.endpoint}`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tawait input.record(\n\t\t\t\tsubscriptionResource(\n\t\t\t\t\t{\n\t\t\t\t\t\tworker: push.worker,\n\t\t\t\t\t\tname: push.name,\n\t\t\t\t\t\ttopicArn,\n\t\t\t\t\t\tendpoint: push.endpoint,\n\t\t\t\t\t\tconnectionKey: push.connectionKey,\n\t\t\t\t\t\tpending: result.pending.includes(push.name),\n\t\t\t\t\t\t...(push.events ? { events: push.events } : {}),\n\t\t\t\t\t},\n\t\t\t\t\tarn,\n\t\t\t\t),\n\t\t\t);\n\t\t\tarns[push.worker] = { ...arns[push.worker], [push.name]: arn };\n\t\t}\n\t\tfor (const arn of result.removed) {\n\t\t\tinput.log(` – unsubscribed ${arn}: no subscriber wants it any more`);\n\t\t}\n\t\tfor (const record of stale) await input.forget(record.key);\n\t}\n\treturn arns;\n}\n","/**\n * Warming a server-rendered site once its stack is up.\n *\n * A site's image is built before the APIs it fetches from run, so its pages\n * render on their first request rather than at build (`GKM_BUILD_OFFLINE`).\n * The warm-up is that first request: the site's `/sitemap.xml`, then `/` and\n * every page the sitemap lists, asked through the edge the way a visitor's\n * browser asks, so a framework that caches a rendered page (Next's ISR) has\n * it cached from the deployed APIs before traffic arrives.\n *\n * Plain HTTP, whatever the framework — with one exception for Next. An ISR\n * page Next prerendered at build (empty, offline) is cached as fresh for its\n * whole `revalidate` window, so a plain request is answered from that cache\n * and renders nothing. A Next site is therefore asked with Next's on-demand\n * revalidation header, `x-prerender-revalidate: <previewModeId>`, the id\n * read from the running image's prerender manifest: each page it caches is\n * rendered again, from the deployed APIs, by the warm-up's own request.\n * Where the id cannot be read, the site is warmed with plain requests, and\n * every page Next answered from its cache (`x-nextjs-cache: HIT`) is counted\n * apart, so nothing claims a page rendered when it did not.\n *\n * A page that fails to warm is said and never fails the deploy: every app is\n * already healthy, and the page renders on the next request that asks for it.\n */\n\nimport type { ExecResult } from '../../compose/docker';\nimport {\n\ttype EdgeFetch,\n\ttype HealthRequest,\n\tHealthRequestTimedOut,\n\tisHealthy,\n} from './health';\n\n/** The most pages warmed per site, its `/` included. */\nexport const WARMUP_MAX_URLS = 500;\n\n/** How many of one site's pages are asked at once. */\nexport const WARMUP_CONCURRENCY = 4;\n\n/**\n * How long one page has to answer: a first render fetches from the site's\n * APIs, so it is given longer than a health check is.\n */\nexport const WARMUP_TIMEOUT_MS = 30_000;\n\n/** One request that did not warm its page, and what it got instead. */\nexport interface WarmupWarning {\n\turl: string;\n\t/** `HTTP 500`, or the error the request failed with. */\n\treason: string;\n}\n\n/**\n * Next's on-demand revalidation header: a request carrying the build's\n * preview-mode id is rendered afresh whatever the page's cache says.\n */\nexport const NEXT_REVALIDATE_HEADER = 'x-prerender-revalidate';\n\n/**\n * What Next answered a request from: `HIT` and `STALE` are a cached copy —\n * on a fresh deploy, the build's — and the request rendered nothing.\n */\nconst NEXT_CACHE_HEADER = 'x-nextjs-cache';\nconst FROM_CACHE = new Set(['HIT', 'STALE']);\n\n/** What one site's warm-up did. */\nexport interface WarmupResult {\n\t/** Each page that answered, in the order asked. */\n\twarmed: string[];\n\t/**\n\t * Each page — or sitemap — that answered from the framework's cache\n\t * (`x-nextjs-cache: HIT`) rather than rendering, in the order asked.\n\t */\n\tcached: string[];\n\t/** Each page — or sitemap — that did not. */\n\twarnings: WarmupWarning[];\n\t/** Pages its sitemaps listed beyond {@link WARMUP_MAX_URLS}, not asked. */\n\tleftOut: number;\n}\n\nexport interface WarmupOptions {\n\t/** The site's public URL: `https://<host>`, with the edge's port if any. */\n\turl: string;\n\tfetch: EdgeFetch;\n\t/** How each request reaches the edge: where to connect, the CA, a login. */\n\tedge?: Pick<\n\t\tHealthRequest,\n\t\t'ca' | 'connectTo' | 'connectPort' | 'authorization' | 'signal'\n\t>;\n\t/**\n\t * Sent with every request: for a Next site, `x-prerender-revalidate` —\n\t * see {@link nextPreviewModeId}.\n\t */\n\theaders?: Readonly<Record<string, string>>;\n\tmaxUrls?: number;\n\tconcurrency?: number;\n\ttimeoutMs?: number;\n}\n\n/**\n * Asks the site for its `/sitemap.xml` — a sitemap index's sitemaps followed\n * one level — then for `/` and every page it lists, up to `maxUrls` pages in\n * all, `concurrency` at a time. The sitemap comes first so that, rendered\n * again with `headers`, it lists what the deployed APIs hold. Only pages on\n * the site's own origin are asked: a sitemap may list another's, which this\n * deploy did not start.\n */\nexport async function warmSite(options: WarmupOptions): Promise<WarmupResult> {\n\tconst {\n\t\tfetch,\n\t\tedge = {},\n\t\tmaxUrls = WARMUP_MAX_URLS,\n\t\tconcurrency = WARMUP_CONCURRENCY,\n\t\ttimeoutMs = WARMUP_TIMEOUT_MS,\n\t\theaders,\n\t} = options;\n\tconst origin = new URL(options.url).origin;\n\tconst result: WarmupResult = {\n\t\twarmed: [],\n\t\tcached: [],\n\t\twarnings: [],\n\t\tleftOut: 0,\n\t};\n\n\t/** One GET; a failure is a warning, and `undefined`. */\n\tconst get = async (\n\t\turl: string,\n\t\tread: boolean,\n\t): Promise<{ status: number; body: string } | undefined> => {\n\t\ttry {\n\t\t\tconst response = await fetch({\n\t\t\t\turl,\n\t\t\t\t...edge,\n\t\t\t\t...(headers ? { headers } : {}),\n\t\t\t\ttimeoutMs,\n\t\t\t\tread,\n\t\t\t});\n\t\t\tconst cache = response.headers?.[NEXT_CACHE_HEADER];\n\t\t\tif (typeof cache === 'string' && FROM_CACHE.has(cache.toUpperCase())) {\n\t\t\t\tresult.cached.push(url);\n\t\t\t}\n\t\t\treturn response;\n\t\t} catch (error) {\n\t\t\tif (edge.signal?.aborted) throw error;\n\t\t\tresult.warnings.push({\n\t\t\t\turl,\n\t\t\t\treason:\n\t\t\t\t\terror instanceof HealthRequestTimedOut\n\t\t\t\t\t\t? `no answer within ${error.timeoutMs}ms`\n\t\t\t\t\t\t: error instanceof Error\n\t\t\t\t\t\t\t? error.message\n\t\t\t\t\t\t\t: String(error),\n\t\t\t});\n\t\t\treturn undefined;\n\t\t}\n\t};\n\n\tconst warm = async (url: string): Promise<void> => {\n\t\tconst response = await get(url, false);\n\t\tif (!response) return;\n\t\tif (isHealthy(response.status)) result.warmed.push(url);\n\t\telse result.warnings.push({ url, reason: `HTTP ${response.status}` });\n\t};\n\n\t/** A sitemap's `<loc>`s, or none where it has none — or did not answer. */\n\tconst sitemap = async (url: string): Promise<Sitemap | undefined> => {\n\t\tconst response = await get(url, true);\n\t\tif (!response) return undefined;\n\t\t// A site with no sitemap answers 404 (or asks for a login it was not\n\t\t// given): nothing to follow, and nothing wrong.\n\t\tif (response.status >= 400 && response.status < 500) return undefined;\n\t\tif (!isHealthy(response.status)) {\n\t\t\tresult.warnings.push({ url, reason: `HTTP ${response.status}` });\n\t\t\treturn undefined;\n\t\t}\n\t\treturn readSitemap(response.body);\n\t};\n\n\tconst root = `${origin}/`;\n\tconst pages = new Set<string>([root]);\n\tconst sameOrigin = (loc: string): string | undefined => {\n\t\tif (!URL.canParse(loc, root)) return undefined;\n\t\tconst url = new URL(loc, root);\n\t\turl.hash = '';\n\t\treturn url.origin === origin ? url.href : undefined;\n\t};\n\tconst list = (locs: readonly string[]) => {\n\t\tfor (const loc of locs) {\n\t\t\tconst url = sameOrigin(loc);\n\t\t\tif (url) pages.add(url);\n\t\t}\n\t};\n\n\tconst top = await sitemap(`${origin}/sitemap.xml`);\n\tif (top?.kind === 'index') {\n\t\t// One level: a sitemap an index lists is read; an index it lists is not.\n\t\tconst children = [\n\t\t\t...new Set(top.locs.map(sameOrigin).filter((u) => u !== undefined)),\n\t\t];\n\t\tconst read = await pool(children, concurrency, sitemap);\n\t\tfor (const child of read) {\n\t\t\tif (child?.kind === 'urlset') list(child.locs);\n\t\t}\n\t} else if (top) {\n\t\tlist(top.locs);\n\t}\n\n\tawait warm(root);\n\tconst listed = [...pages].slice(1);\n\tconst room = Math.max(0, maxUrls - 1);\n\tresult.leftOut = Math.max(0, listed.length - room);\n\tawait pool(listed.slice(0, room), concurrency, warm);\n\n\treturn result;\n}\n\n/** A Next site's preview-mode id, or why it could not be read. */\nexport type PreviewModeLookup = { id: string } | { reason: string };\n\n/**\n * Prints the preview-mode id of the prerender manifest at `argv[1]`, and\n * nothing else of it: the manifest's signing and encryption keys never leave\n * the container. Exit 3 when the manifest has no id.\n */\nconst PRINT_PREVIEW_MODE_ID = [\n\t'let m;',\n\t\"try { m = JSON.parse(require('fs').readFileSync(process.argv[1], 'utf8')); }\",\n\t'catch (e) { process.stderr.write(String(e && e.message)); process.exit(2); }',\n\t'const id = m && m.preview && m.preview.previewModeId;',\n\t\"if (typeof id !== 'string' || id === '') process.exit(3);\",\n\t'process.stdout.write(id);',\n].join(' ');\n\n/**\n * The preview-mode id of a running Next site, from the prerender manifest\n * of its image — `manifest`, a path inside the container — by running the\n * image's own `node` in it through `exec` (`docker exec`, on whichever\n * engine runs the stack). Never read from this machine's disk: the image\n * that runs is the one whose id counts.\n *\n * The id is a secret of the site's: it is returned to the warm-up and\n * nowhere else — never logged, never written.\n */\nexport async function nextPreviewModeId(\n\texec: (command: readonly string[]) => Promise<ExecResult>,\n\tmanifest: string,\n): Promise<PreviewModeLookup> {\n\tconst { code, stdout, stderr } = await exec([\n\t\t'node',\n\t\t'-e',\n\t\tPRINT_PREVIEW_MODE_ID,\n\t\tmanifest,\n\t]);\n\tif (code === 0 && stdout) return { id: stdout };\n\tif (code === 3 || code === 0) {\n\t\treturn {\n\t\t\treason: `${manifest} has no preview.previewModeId, which this version of Next may not write`,\n\t\t};\n\t}\n\tconst said = stderr.trim().split('\\n')[0];\n\tif (code === null) return { reason: said || 'its container is not running' };\n\treturn {\n\t\treason: `could not read ${manifest} in its container (${said || `exit ${code}`})`,\n\t};\n}\n\n/** A sitemap's kind and the `<loc>` of each entry. */\nexport interface Sitemap {\n\t/** `index` lists sitemaps; `urlset` lists pages. */\n\tkind: 'index' | 'urlset';\n\tlocs: string[];\n}\n\n/**\n * Reads a sitemap (sitemaps.org): each entry's `<loc>`, entity-decoded or\n * from CDATA. Only an unprefixed `<loc>` is an entry's — an `<image:loc>` is\n * an image on a page, not a page.\n */\nexport function readSitemap(xml: string): Sitemap {\n\tconst kind = /<(?:[\\w-]+:)?sitemapindex[\\s>]/.test(xml) ? 'index' : 'urlset';\n\tconst locs: string[] = [];\n\tfor (const match of xml.matchAll(\n\t\t/<loc>\\s*(?:<!\\[CDATA\\[([\\s\\S]*?)\\]\\]>|([\\s\\S]*?))\\s*<\\/loc>/g,\n\t)) {\n\t\tconst loc = match[1] ?? decodeEntities(match[2] ?? '');\n\t\tif (loc.trim()) locs.push(loc.trim());\n\t}\n\treturn { kind, locs };\n}\n\nconst ENTITIES: Record<string, string> = {\n\tamp: '&',\n\tlt: '<',\n\tgt: '>',\n\tquot: '\"',\n\tapos: \"'\",\n};\n\nfunction decodeEntities(text: string): string {\n\treturn text.replace(\n\t\t/&(#x[\\da-f]+|#\\d+|amp|lt|gt|quot|apos);/gi,\n\t\t(whole, entity: string) => {\n\t\t\tif (entity[0] === '#') {\n\t\t\t\tconst code =\n\t\t\t\t\tentity[1] === 'x' || entity[1] === 'X'\n\t\t\t\t\t\t? Number.parseInt(entity.slice(2), 16)\n\t\t\t\t\t\t: Number.parseInt(entity.slice(1), 10);\n\t\t\t\treturn Number.isFinite(code) ? String.fromCodePoint(code) : whole;\n\t\t\t}\n\t\t\treturn ENTITIES[entity.toLowerCase()] ?? whole;\n\t\t},\n\t);\n}\n\n/** Each item through `run`, at most `size` at once, results in order. */\nasync function pool<T, R>(\n\titems: readonly T[],\n\tsize: number,\n\trun: (item: T) => Promise<R>,\n): Promise<R[]> {\n\tconst results: R[] = new Array(items.length);\n\tlet next = 0;\n\tconst worker = async () => {\n\t\twhile (next < items.length) {\n\t\t\tconst index = next++;\n\t\t\tresults[index] = await run(items[index]!);\n\t\t}\n\t};\n\tawait Promise.all(\n\t\tArray.from({ length: Math.min(size, items.length) }, worker),\n\t);\n\treturn results;\n}\n","/**\n * The compose target's phases: a stage as one Docker Compose stack behind\n * Caddy — the local stage on this machine's Docker, a deployed stage on its\n * server's, driven over SSH (`compose/server.ts`) from wherever the deploy\n * runs.\n *\n * The order is the point of this file, and the rules it keeps are these:\n *\n * - A tag is checked before anything happens (`validate`). Every app's image\n * is asked of the registry first; one missing image stops the run naming\n * them all, and nothing is written, pulled or started.\n * - The databases exist before the apps do (`provision`). Postgres comes up\n * alone, its databases, roles and grants are created, its migrations\n * applied and its seeds run from this machine — through an SSH tunnel to a\n * server's loopback — and only then do the apps\n * start — so an app\n * never boots against a schema that is not there yet.\n * - What a stage runs is recorded (`release`). Each app's image, the tag it\n * was released under and the digest it resolved to are written to the\n * stage's state, so \"what is this stage running\" has an exact answer.\n * - What was started answers (`verify`): each app is asked through Caddy,\n * over HTTPS, with the certificate verified. Then each server-rendered site\n * is warmed (`warmup.ts`): a page that fails to warm is said, never failed.\n *\n * Every image is built inside Docker from a pruned slice of the build root —\n * the same Dockerfiles `gkm docker` writes — so nothing is built on this\n * machine before `docker compose build`.\n *\n * Docker, the registry, Postgres and the health probe are\n * injected, so the rules are asserted without a daemon; the defaults are the\n * real ones.\n */\n\nimport { existsSync } from 'node:fs';\nimport {\n\tchmod,\n\tmkdir,\n\treaddir,\n\treadFile,\n\trm,\n\twriteFile,\n} from 'node:fs/promises';\nimport { hostname, userInfo } from 'node:os';\nimport { dirname, join, relative } from 'node:path';\nimport { composeLiteral } from '@geekmidas/edge';\nimport {\n\tensureLocalAuthority,\n\tensureLocalCertificate,\n\ttype LocalAuthorityPaths,\n\tlocalCertificateNames,\n\treadLocalAuthority,\n} from '@geekmidas/edge/certificates/local';\nimport type { DnsProvider } from '@geekmidas/edge/dns';\nimport { EDGE_PROJECT, EDGE_SERVICE } from '@geekmidas/edge/proxy/traefik';\nimport type { ConstructManifest } from '@geekmidas/manifest';\nimport { stringify } from 'yaml';\nimport {\n\tBACKUPS_SERVICE,\n\tbackupsRoleStatements,\n\tPOSTGRES_SERVICE,\n} from '../../backups/service';\nimport {\n\ttype AcmeDnsClients,\n\tacmeDnsSecrets,\n\tacmeDnsZone,\n\tensureEdgeAcmeKey,\n\tensureEdgeDnsSecrets,\n} from '../../compose/acmeDns';\nimport {\n\ttype HostLookup,\n\tHostNotPointingAtServer,\n\tisLocalHost,\n\tisReservedStageKey,\n\ttype PrunedDnsRecord,\n\trequiredServerAddress,\n\tSERVER_IPV4_KEY,\n\tserverAddressHint,\n\tstackHosts,\n\tstageDns,\n\tsystemLookup,\n} from '../../compose/dns';\nimport {\n\ttype ComposeDocker,\n\tdockerCompose,\n\ttype StackRef,\n} from '../../compose/docker';\nimport {\n\tassertEdgeHostsFree,\n\tassertEdgePorts,\n\tedgePorts,\n\tedgeRef,\n\tensureEdge,\n\tremoveEdgeRoutes,\n\twriteEdgeRoutes,\n} from '../../compose/edge';\nimport {\n\tassertImagesExist,\n\ttype ImageDigests,\n\tpinImages,\n\tRegistryRequired,\n} from '../../compose/images';\nimport {\n\tLOGS_EMAIL_KEY,\n\tLOGS_SERVICE,\n\tLogsPortTaken,\n\tlogsAccess,\n\ttype StackLogs,\n} from '../../compose/logs';\nimport { LOGS_PORT } from '../../compose/logsConfig';\nimport { ComposeTlsFileMissing } from '../../compose/proxy';\nimport { REDIS_SERVICE } from '../../compose/redis';\nimport { deployedStackSecrets } from '../../compose/secrets';\nimport {\n\ttype ComposeServer,\n\tcomposeServer,\n\tdockerHost,\n\ttype ServerAccess,\n\tsshAccess,\n\tsshTarget,\n} from '../../compose/server';\nimport type { SiteAuth } from '../../compose/sitePassword';\nimport {\n\ttype ComposeStack,\n\tcomposeProject,\n\tcomposeStack,\n\tenvFile,\n\tLOG_ROTATION,\n\tLOOPBACK_SERVICES,\n\treplicaNames,\n\ttype StackApp,\n\ttype StackInput,\n\tstackDir,\n\twithCaddyConfigs,\n\twithLogsPort,\n} from '../../compose/stack';\nimport { currentActor } from '../../deploy/actor.js';\nimport {\n\tdnsResourceKey,\n\tdnsResources,\n\tforgetDnsResource,\n\trecordDnsChanges,\n} from '../../deploy/dnsResources.js';\nimport type { ResourceChange } from '../../deploy/events';\nimport { imageRef, stageTag } from '../../deploy/identity.js';\nimport { DeployJournal } from '../../deploy/journal';\nimport type { ResourceRecord } from '../../deploy/StateStore.js';\nimport {\n\tconfirmPendingSubscriptions,\n\tPushSubscriptionsUnconfirmed,\n\trecordedPushSubscriptions,\n\tSUBSCRIPTION_TYPE,\n\tsubscriptionKey,\n} from '../../deploy/snsSubscriptions.js';\nimport {\n\tcreateComposeState,\n\ttype DeployedImage,\n\trecordRelease,\n} from '../../deploy/state.js';\nimport type { DeployResult } from '../../deploy/types';\nimport type { Route53DnsConfig } from '../../dns/providers';\nimport { ensureDockerignore } from '../../docker/index.js';\nimport { fromBuildRoot, imageLayout } from '../../docker/layout.js';\nimport {\n\tfindBuildRoot,\n\tnextPrerenderManifest,\n} from '../../docker/templates.js';\nimport { GkmError } from '../../errors';\nimport { installedFrom } from '../../generators/drivers.js';\nimport {\n\tmigrateDatabases,\n\tplannedSeeds,\n\tSeedFailed,\n\tseedDatabases,\n} from '../../migrate/databases.js';\nimport { appEnvKeys, workerEnvKeys } from '../../reconcile/apps.js';\nimport { bucketClient, pgClient } from '../../reconcile/clients.js';\nimport { primaryPortKey } from '../../reconcile/containers.js';\nimport {\n\ttype BoundSubscriber,\n\ttype ConstructSource,\n\tdiscover,\n} from '../../reconcile/discover.js';\nimport { envFor, stageEnv } from '../../reconcile/env.js';\nimport { loadLocalCredentials } from '../../reconcile/localCredentials.js';\nimport {\n\tensurePostgresLogin,\n\tLEGACY_LOCAL_LOGIN,\n} from '../../reconcile/logins.js';\nimport {\n\tapplyBuckets,\n\tapplyLifecycles,\n\tapplyNotifications,\n\tapplyPolicies,\n\tapplyPostgres,\n\tpostgresStatements,\n} from '../../reconcile/provision.js';\nimport { backendsOf, constructGlobs } from '../../reconcile/workspace.js';\nimport { runOutput } from '../../run';\nimport { toEmbeddableSecrets } from '../../secrets/storage.js';\nimport type { StageSecrets } from '../../secrets/types.js';\nimport type {\n\tDnsProvider as DnsProviderConfig,\n\tNormalizedWorkspace,\n} from '../../workspace/types.js';\nimport {\n\tDeploySeedsFailed,\n\treportDatabaseRuns,\n\treportPlannedSeeds,\n} from '../seeds';\nimport type { DeployPhaseContext } from '../types';\nimport {\n\tComposeAppsUnhealthy,\n\ttype EdgeFetch,\n\tedgeFetch,\n\ttype HealthProbe,\n\thttpsProbe,\n\tisHealthy,\n} from './health';\nimport {\n\tensureTopicSubscriptions,\n\trecordedTopicSubscriptions,\n\ttype TopicPush,\n\ttopicPushes,\n} from './topicSubscriptions';\nimport {\n\tNEXT_REVALIDATE_HEADER,\n\tnextPreviewModeId,\n\tWARMUP_MAX_URLS,\n\twarmSite,\n} from './warmup';\n\n/** Every phase's context: the compose target takes no options. */\nexport type ComposeContext = DeployPhaseContext<undefined>;\n\n/** What the target needs from outside the process, so tests can stand in. */\nexport interface ComposeDeps {\n\tdocker: ComposeDocker;\n\t/** The commit a build is tagged with. */\n\trevision: (root: string) => Promise<string>;\n\t/** The Postgres client provisioning and migrations connect through. */\n\tsql: typeof pgClient;\n\t/** The S3 client the stack's buckets are created through. */\n\tbuckets: typeof bucketClient;\n\t/** Bring the stack's Postgres onto its superuser — see `logins.ts`. */\n\tlogins: typeof ensurePostgresLogin;\n\t/** Apply the stage's migrations — `migrateDatabases` by default. */\n\tmigrate: typeof migrateDatabases;\n\t/** Run the stage's seeds, after its migrations — `seedDatabases` by default. */\n\tseed: typeof seedDatabases;\n\t/** Ask one app, through the edge, whether it answers. */\n\tprobe: HealthProbe;\n\t/**\n\t * Ask the edge for a page — and, for a sitemap, its body — once the stack\n\t * is healthy, to warm each server-rendered site. `edgeFetch` by default.\n\t */\n\tfetch?: EdgeFetch;\n\t/** How many times each app is asked before it counts as down. */\n\thealthAttempts: number;\n\t/** How long to wait between two asks of one app. */\n\thealthIntervalMs: number;\n\t/** Where the edge's ports are read from (`GKM_COMPOSE_HTTPS_PORT`, …). */\n\tenv: NodeJS.ProcessEnv;\n\t/**\n\t * Resolves a public host to every address it has, for the DNS check —\n\t * the system resolver by default.\n\t */\n\tlookup?: HostLookup;\n\t/** The DNS provider for a `dns` domain — `createDnsProvider` by default. */\n\tdnsProviderFor?: (config: DnsProviderConfig) => Promise<DnsProvider | null>;\n\t/**\n\t * A deployed stage's server, beyond its Docker engine: the SSH check\n\t * before a deploy, and the tunnels its databases are reached through.\n\t */\n\tserver: ServerAccess;\n\t/**\n\t * Once the stack is up, have SNS resend each pending subscription's\n\t * confirmation and wait for it — `confirmPendingSubscriptions` by default.\n\t */\n\tconfirmSubscriptions?: typeof confirmPendingSubscriptions;\n\t/**\n\t * The IAM and Route 53 clients the shared edge's DNS-challenge key is\n\t * issued through, for a domain's Route 53 entry — the AWS SDK's own\n\t * chain, with its `profile` and `region`, by default.\n\t */\n\tacmeClients?: (config: Route53DnsConfig) => Promise<AcmeDnsClients>;\n}\n\n/** One app's image, as the stage runs it. */\nexport interface ComposeImage {\n\tref: string;\n\ttag: string;\n\tdigest?: string;\n}\n\n/** A compose deploy in progress: what `validate` found, and what follows. */\nexport interface ComposeRun {\n\t/** Build the images from this checkout, or pull the ones a tag names. */\n\tmode: 'build' | 'pull';\n\t/**\n\t * Build and push the images, and nothing else (`--build --push`): no\n\t * provisioning, no container started, nothing recorded.\n\t */\n\tpush: boolean;\n\tstack: ComposeStack;\n\t/**\n\t * The deployed stage's server, whose Docker engine — over SSH — runs the\n\t * stack. Absent for the local stage, and for a push, which builds here.\n\t */\n\tserver?: ComposeServer;\n\t/** The stack's directory, absolute: `.gkm/compose/<stage>`. */\n\tdir: string;\n\tref: StackRef;\n\t/** The stage's secrets, with whatever a deployed stage generates once. */\n\tsecrets: StageSecrets | null;\n\t/** The names of what was generated, written back in `provision`. */\n\tgenerated: string[];\n\t/** Each app's image as the stage's state last recorded it. */\n\tprevious: Record<string, DeployedImage>;\n\t/** Every file written, absolute. */\n\tfiles: string[];\n\t/** Each app's image, once built or pulled. */\n\timages: Record<string, ComposeImage>;\n\t/** Every resource the run touched, or for a dry run would. */\n\tchanges: ResourceChange[];\n\t/**\n\t * The subscriptions `provision` makes for topics the stage set to SNS by\n\t * hand — and the stack composed again once their ARNs are recorded. Until\n\t * then {@link stack} hands those workers no subscriptions.\n\t */\n\ttopicSubscriptions?: {\n\t\tpushes: TopicPush[];\n\t\trecorded: Readonly<Record<string, ResourceRecord>> | undefined;\n\t\trestack: (arns: Record<string, Record<string, string>>) => ComposeStack;\n\t};\n\t/**\n\t * Deletes the DNS records gkm wrote for hosts the stage no longer serves:\n\t * found by `ready`, run by `verify` once the stack answers on its new ones.\n\t */\n\tpruneDns?: () => Promise<PrunedDnsRecord[]>;\n}\n\n/** How a run gets its images, beyond what the tag implies. */\nexport interface ComposeRunOptions {\n\t/**\n\t * Build or pull whatever the tag says. By default a given tag is pulled\n\t * and no tag builds from the checkout.\n\t */\n\tmode?: 'build' | 'pull';\n\t/** Push what was built, and start nothing (`--build --push`). */\n\tpush?: boolean;\n\t/** Run each pulled image at the digest a push reported for it. */\n\tpin?: { file: string; digests: ImageDigests };\n}\n\n/** `--push` without `--build`: there is nothing built here to push. */\nexport class ComposePushNeedsBuild extends GkmError {\n\tconstructor() {\n\t\tsuper(\n\t\t\t'--push pushes the images this checkout builds, so it needs --build ' +\n\t\t\t\t'(and never --pull): gkm compose --stage <stage> --build --push --tag <tag>.',\n\t\t);\n\t\tthis.name = 'ComposePushNeedsBuild';\n\t}\n}\n\n/** Digests to run by, on a run that pulls nothing. */\nexport class ComposePinNeedsPull extends GkmError {\n\tconstructor() {\n\t\tsuper(\n\t\t\t'--digests-file pins the images a release pulls, so it needs --tag ' +\n\t\t\t\t'(or --pull) — or, with --build --push, it is where the pushed digests ' +\n\t\t\t\t'are written.',\n\t\t);\n\t\tthis.name = 'ComposePinNeedsPull';\n\t}\n}\n\n/**\n * A site that pre-renders against its stage (`prerender: 'stage'`) whose\n * APIs do not answer, so it is not built: pages built without their data\n * would ship, and nothing at runtime could fill them.\n */\nexport class SitePrerenderApisDown extends GkmError {\n\tconstructor(\n\t\treadonly site: string,\n\t\t/** Each API it depends on that did not answer, and what it got. */\n\t\treadonly apis: readonly { app: string; url: string; last: string }[],\n\t\t/**\n\t\t * Which check failed: its container's health, through the edge on\n\t\t * this deploy, or through the edge of the stage a push builds for.\n\t\t */\n\t\treadonly via: 'docker' | 'edge' | 'push',\n\t) {\n\t\tconst lines = apis\n\t\t\t.map(({ app, url, last }) =>\n\t\t\t\tvia === 'docker'\n\t\t\t\t\t? ` - ${app}: Docker reports it ${last}`\n\t\t\t\t\t: ` - ${url}: ${last}`,\n\t\t\t)\n\t\t\t.join('\\n');\n\t\tsuper(\n\t\t\t`'${site}' pre-renders from its stage's APIs (prerender: 'stage'), and ${apis.length === 1 ? 'this one does' : 'these do'} not answer, so it was not built:\\n${lines}\\n` +\n\t\t\t\t(via === 'push'\n\t\t\t\t\t? 'An image pushed for it is built against the stage as it runs now: deploy the stage first, then build and push the site.'\n\t\t\t\t\t: 'Fix the API and deploy again.'),\n\t\t);\n\t\tthis.name = 'SitePrerenderApisDown';\n\t}\n}\n\n/** A build with no commit to tag its images with. */\nexport class NoGitRevision extends GkmError {\n\tconstructor(readonly root: string) {\n\t\tsuper(\n\t\t\t`Images built here are tagged with the commit they were built from, ` +\n\t\t\t\t`and ${root} is not in a git repository with a commit. Commit, or ` +\n\t\t\t\t`pass --tag to name the images yourself.`,\n\t\t);\n\t\tthis.name = 'NoGitRevision';\n\t}\n}\n\n/**\n * The project's own file merged over a stage's stack: `docker-compose.<stage>.yml`\n * at the workspace root. What the generated file cannot know — a port bound\n * to a tailnet address, another log driver — goes there, and is never\n * overwritten.\n */\nexport function stackOverrideFile(root: string, stage: string): string {\n\treturn join(root, `docker-compose.${stage}.yml`);\n}\n\n/** The commit HEAD is at, short — and `-dirty` when the tree has changes. */\nexport async function gitRevision(root: string): Promise<string> {\n\tlet sha: string;\n\ttry {\n\t\tsha = (\n\t\t\tawait runOutput('git', ['rev-parse', '--short', 'HEAD'], { cwd: root })\n\t\t).trim();\n\t} catch {\n\t\tthrow new NoGitRevision(root);\n\t}\n\tif (!sha) throw new NoGitRevision(root);\n\n\t// An image built from uncommitted changes is not the commit's image, and a\n\t// tag that said it was would be the one thing worse than no tag.\n\tconst status = await runOutput('git', ['status', '--porcelain'], {\n\t\tcwd: root,\n\t}).catch(() => '');\n\treturn status.trim() ? `${sha}-dirty` : sha;\n}\n\n/**\n * The real ones. Each app is asked for three minutes before it counts as\n * down: a deployed stage's first ACME certificate can take that long.\n */\nexport const defaultDeps: ComposeDeps = {\n\tdocker: dockerCompose,\n\trevision: gitRevision,\n\tsql: pgClient,\n\tbuckets: bucketClient,\n\tlogins: ensurePostgresLogin,\n\tmigrate: migrateDatabases,\n\tseed: seedDatabases,\n\tprobe: httpsProbe,\n\tfetch: edgeFetch,\n\thealthAttempts: 90,\n\thealthIntervalMs: 2_000,\n\tenv: process.env,\n\tlookup: systemLookup,\n\tserver: sshAccess,\n};\n\n// ============================================================================\n// validate\n// ============================================================================\n\n/**\n * The stack the stage would run, and — for a tag — the registry's word that\n * every image it names exists. Nothing is written: a missing image stops the\n * run here, before a file, a secret or a container is touched.\n */\nexport async function validateCompose(\n\tctx: ComposeContext,\n\tdeps: ComposeDeps,\n\toptions: ComposeRunOptions = {},\n): Promise<ComposeRun> {\n\tconst { workspace, stage, identity, tag } = ctx;\n\tconst root = workspace.root;\n\tconst mode = options.mode ?? (ctx.tagGiven ? 'pull' : 'build');\n\tconst push = options.push === true;\n\tif (push && mode !== 'build') throw new ComposePushNeedsBuild();\n\tif (options.pin && mode !== 'pull') throw new ComposePinNeedsPull();\n\n\t// An image pushed or pulled with no registry is a Docker Hub name, which\n\t// is somebody else's. Refused before anything is discovered, built or\n\t// asked of a registry.\n\tconst registry = workspace.deploy?.registry;\n\tif (!registry && (push || mode === 'pull')) {\n\t\tthrow new RegistryRequired(\n\t\t\tpush ? 'push' : 'pull',\n\t\t\timageRef(\n\t\t\t\tidentity,\n\t\t\t\tctx.apps[0] ?? workspace.name,\n\t\t\t\tundefined,\n\t\t\t\tstageTag(tag, stage),\n\t\t\t),\n\t\t);\n\t}\n\n\tconst background: Record<string, string[]> = {};\n\tconst subscribers: Record<string, BoundSubscriber[]> = {};\n\tconst manifest = await discover({\n\t\tpatterns: constructGlobs(workspace),\n\t\tcwd: root,\n\t\tbackground,\n\t\tsubscribers,\n\t});\n\n\tconst { secrets, generated } = await stageSecrets(ctx, manifest);\n\n\t// What each app ran before this release, and the SNS subscriptions the\n\t// stage's providers made: a push changes no stage, so it reads neither.\n\tconst recorded = push ? undefined : await ctx.state.read(stage);\n\n\t// Where and with what the images are built — only asked when they are.\n\tconst layout = mode === 'build' ? imageLayout(workspace) : undefined;\n\n\tconst input: StackInput = {\n\t\tworkspace,\n\t\tmanifest,\n\t\tbackground,\n\t\tsubscribers,\n\t\tstage,\n\t\tidentity,\n\t\timages: {\n\t\t\tmode,\n\t\t\ttag,\n\t\t\t...(registry ? { registry } : {}),\n\t\t},\n\t\tsecrets,\n\t\t...(stage === workspace.stages.local\n\t\t\t? {\n\t\t\t\t\tlocalCredentials: (await loadLocalCredentials(workspace)).credentials,\n\t\t\t\t}\n\t\t\t: {}),\n\t\tallowDevServices: ctx.allowDevServices,\n\t\tports: edgePorts(deps.env),\n\t\t...(layout ? { layout } : {}),\n\t\t...(push ? { buildOnly: true } : {}),\n\t\t// A site pre-rendered against the stage fetches its data afresh on\n\t\t// every run: this one's moment is part of its build's cache key.\n\t\t...(mode === 'build' ? { prerenderRun: new Date().toISOString() } : {}),\n\t};\n\tconst recordedArns = recordedPushSubscriptions(recorded?.resources);\n\n\t// A topic the stage set to SNS by hand is subscribed by this deploy, in\n\t// `provision` — so until then the stack is composed to learn where SNS\n\t// pushes, and composed again with the ARNs once they are recorded.\n\tconst planned = push\n\t\t? undefined\n\t\t: composeStack({ ...input, recordingSubscriptions: true });\n\tconst pushes = planned ? topicPushes(planned, manifest) : [];\n\tconst topics =\n\t\tplanned &&\n\t\t(pushes.length > 0 ||\n\t\t\trecordedTopicSubscriptions(recorded?.resources).length > 0)\n\t\t\t? { pushes, recorded: recorded?.resources }\n\t\t\t: undefined;\n\tconst composed =\n\t\ttopics && planned\n\t\t\t? planned\n\t\t\t: composeStack({ ...input, pushSubscriptions: recordedArns });\n\n\t// A cache is reached over the Redis wire protocol, and the client is the\n\t// project's own dependency: a build without it fails deep inside Docker.\n\tif (mode === 'build') {\n\t\tassertRedisClient(workspace, composed, manifest);\n\t}\n\n\t// No image embeds the stage's secrets: a backend reads them at runtime\n\t// from its env file. Each stage still builds and tags its own images\n\t// (`stageTag`), so two stages built from one commit never share a tag.\n\t// A pinned release runs each image at the digest its push reported.\n\tconst pinned = (unpinned: ComposeStack) =>\n\t\toptions.pin\n\t\t\t? withPinnedImages(unpinned, options.pin.file, options.pin.digests)\n\t\t\t: unpinned;\n\tconst stack = pinned(composed);\n\tfor (const warning of stack.warnings) ctx.logger.warn(`⚠ ${warning}`);\n\n\t// A release is all of its images or none of them. A dry run asks nothing,\n\t// so it can be run without a registry login.\n\tif (mode === 'pull' && !ctx.dryRun) {\n\t\tawait assertImagesExist(deps.docker, stageTag(tag, stage), [\n\t\t\t...stack.apps,\n\t\t\t...stack.workers,\n\t\t\t...stack.processors,\n\t\t]);\n\t}\n\n\tif (stack.redis && !stack.local) ctx.secrets.mask(stack.redis.password);\n\n\t// The log UI's root login and the header every backend signs in with:\n\t// secrets, unless they are the local stage's fixed ones.\n\tif (stack.logs && (!stack.local || stack.logs.passwordFromSecrets)) {\n\t\tctx.secrets.mask(stack.logs.password);\n\t\tctx.secrets.mask(stack.logs.appEnv.OTEL_EXPORTER_OTLP_HEADERS);\n\t}\n\n\t// Where the stack runs: a deployed stage on its server's engine, over\n\t// SSH — never this machine's. A push builds here and runs nothing.\n\t// A domain's stage names its address before anything else is said of\n\t// its server: it is the host SSH reaches too, unless config names one.\n\tif (!push && !stack.local) {\n\t\trequiredServerAddress(stage, workspace.domains?.[stage], secrets?.custom);\n\t\t// The edge's key for the wildcard's DNS challenge, where the stage\n\t\t// supplies it: refused now, not once the stack is half up.\n\t\tif (stack.proxy === 'traefik' && stack.wildcard?.tls === 'dns') {\n\t\t\tconst zone = acmeDnsZone(workspace, stage);\n\t\t\tif (zone) acmeDnsSecrets(zone, stage, secrets?.custom);\n\t\t}\n\t}\n\tconst server = push\n\t\t? undefined\n\t\t: composeServer({\n\t\t\t\tstage,\n\t\t\t\tlocal: stack.local,\n\t\t\t\tconfig: workspace.deploy?.compose?.server,\n\t\t\t\tcustom: secrets?.custom,\n\t\t\t});\n\n\tconst dir = join(root, stackDir(stage));\n\tconst override = stackOverrideFile(root, stage);\n\tconst overrides = existsSync(override) ? [override] : [];\n\tif (overrides.length > 0) {\n\t\tctx.logger.info(\n\t\t\t`🧩 Merging docker-compose.${stage}.yml over the generated stack`,\n\t\t);\n\t}\n\t// What each app ran before this release: its current release, by the same\n\t// record the Dokploy target keeps, so a rollback reads one shape for both.\n\tconst previous = Object.fromEntries(\n\t\tObject.entries(recorded?.state.releases ?? {}).map(\n\t\t\t([name, releases]): [string, DeployedImage] => {\n\t\t\t\tconst { ref, tag, digest } = releases.current;\n\t\t\t\treturn [\n\t\t\t\t\tname,\n\t\t\t\t\t{ ref, ...(tag ? { tag } : {}), ...(digest ? { digest } : {}) },\n\t\t\t\t];\n\t\t\t},\n\t\t),\n\t);\n\n\treturn {\n\t\tmode,\n\t\tpush,\n\t\tstack,\n\t\t...(topics\n\t\t\t? {\n\t\t\t\t\ttopicSubscriptions: {\n\t\t\t\t\t\t...topics,\n\t\t\t\t\t\trestack: (arns) => {\n\t\t\t\t\t\t\tconst merged = { ...recordedArns };\n\t\t\t\t\t\t\tfor (const [worker, own] of Object.entries(arns)) {\n\t\t\t\t\t\t\t\tmerged[worker] = { ...merged[worker], ...own };\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn pinned(\n\t\t\t\t\t\t\t\tcomposeStack({ ...input, pushSubscriptions: merged }),\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t}\n\t\t\t: {}),\n\t\t...(server ? { server } : {}),\n\t\tdir,\n\t\tref: {\n\t\t\tproject: composeProject(identity),\n\t\t\tfile: join(dir, 'docker-compose.yml'),\n\t\t\t...(overrides.length > 0 ? { overrides } : {}),\n\t\t\tcwd: root,\n\t\t\t...(server ? { host: dockerHost(server) } : {}),\n\t\t\toutput: ctx.childOutput,\n\t\t\tsignal: ctx.signal,\n\t\t},\n\t\tsecrets,\n\t\tgenerated,\n\t\tprevious,\n\t\tfiles: [],\n\t\timages: {},\n\t\tchanges: [],\n\t};\n}\n\n// ============================================================================\n// ready\n// ============================================================================\n\n/**\n * What only a compose deploy checks before it changes anything, once the\n * stage's own keys are: the stage's own certificate is there, and every\n * public host points at the stage's server — its records written where a\n * provider holds them, then confirmed — before Caddy or Traefik ask Let's\n * Encrypt for a certificate it could not issue. A build-only run never asks.\n */\nexport async function readyCompose(\n\tctx: ComposeContext,\n\trun: ComposeRun,\n\tdeps: ComposeDeps,\n): Promise<void> {\n\tconst { stack } = run;\n\n\t// Read when the stack starts; one that is not there stops the run here,\n\t// before anything is written or started.\n\tif (stack.tls) {\n\t\tconst { certFile, keyFile, caFile } = stack.tls;\n\t\tfor (const file of [certFile, keyFile, ...(caFile ? [caFile] : [])]) {\n\t\t\tif (!existsSync(file)) throw new ComposeTlsFileMissing(ctx.stage, file);\n\t\t}\n\t}\n\n\tif (stack.local) {\n\t\tawait edgeHostsFree(ctx, run, deps);\n\t\treturn;\n\t}\n\t// The server answers before anything is written — a DNS record included.\n\t// A dry run changes nothing anywhere, and connects to nothing.\n\tif (run.server && !ctx.dryRun && !run.push) {\n\t\tawait deps.server.check(run.server);\n\t}\n\tawait edgeHostsFree(ctx, run, deps);\n\tawait logsPortOnServer(ctx, run, deps);\n\tconst prune = await stageHostsDns(\n\t\tctx,\n\t\tdeps,\n\t\tstackHosts(stack).filter((host) => !isLocalHost(host)),\n\t\trun.secrets?.custom,\n\t\tstack.wildcard?.host,\n\t);\n\tif (prune) run.pruneDns = prune;\n}\n\n/**\n * No host the stack routes through the shared edge is routed there by another\n * project — asked of the edge on the stage's engine before a record, a\n * secret, an image or a container is touched, so a clash fails the deploy\n * with nothing changed. Asked again as the routes are written\n * (`writeEdgeRoutes`), for an edge that was not running yet.\n */\nasync function edgeHostsFree(\n\tctx: ComposeContext,\n\trun: ComposeRun,\n\tdeps: ComposeDeps,\n): Promise<void> {\n\tconst { stack, ref } = run;\n\tif (ctx.dryRun || run.push) return;\n\tif (stack.proxy !== 'traefik' || !stack.traefik) return;\n\tawait assertEdgeHostsFree(\n\t\tdeps.docker,\n\t\tedgeRef(edgeFile(run), {\n\t\t\t...(ref.host ? { host: ref.host } : {}),\n\t\t\t...(ref.output ? { output: ref.output } : {}),\n\t\t}),\n\t\tstack.project,\n\t\tstack.traefik,\n\t);\n}\n\n/** How many ports past the first a stage's OpenObserve is tried on. */\nconst LOGS_PORT_TRIES = 100;\n\n/**\n * The loopback port the stack's OpenObserve is published on, settled against\n * what every other stack on the server publishes — before anything is\n * written, so two stages on one machine cannot both take `5080` and fail at\n * `up`.\n *\n * - A port the stage named is refused when another project holds it.\n * - Otherwise the stack keeps the port it already publishes, or takes the\n * first from the default up that no other project holds — and the stack,\n * its tunnel line included, is moved onto it.\n *\n * Asked of the server's engine, so not on a dry run, a push, or the local\n * stage; nor for a log UI served through the edge, which publishes nothing.\n *\n * @throws {LogsPortTaken}\n */\nasync function logsPortOnServer(\n\tctx: ComposeContext,\n\trun: ComposeRun,\n\tdeps: ComposeDeps,\n): Promise<void> {\n\tconst logs = run.stack.logs;\n\tif (!logs || logs.public || run.stack.local) return;\n\tif (ctx.dryRun || run.push || !run.server) return;\n\n\tconst engine = run.ref.host ? { host: run.ref.host } : {};\n\tconst project = run.ref.project;\n\tconst holder = async (port: number) => {\n\t\tconst others = (await deps.docker.publishers(engine, port)).filter(\n\t\t\t(held) => held.project !== project,\n\t\t);\n\t\treturn others[0] && (others[0].project ?? others[0].container);\n\t};\n\n\tif (logs.portSet) {\n\t\tconst taken = await holder(logs.port);\n\t\tif (taken) throw new LogsPortTaken(ctx.stage, logs.port, taken, true);\n\t\treturn;\n\t}\n\n\tconst kept = await deps.docker.published(\n\t\tengine,\n\t\tproject,\n\t\tLOGS_SERVICE,\n\t\tLOGS_PORT,\n\t);\n\tlet port = kept;\n\tif (port === undefined) {\n\t\tlet taken: string | undefined;\n\t\tfor (let next = logs.port; next < logs.port + LOGS_PORT_TRIES; next++) {\n\t\t\ttaken = await holder(next);\n\t\t\tif (!taken) {\n\t\t\t\tport = next;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif (port === undefined) {\n\t\t\tthrow new LogsPortTaken(ctx.stage, logs.port, taken ?? '', false);\n\t\t}\n\t}\n\tif (port !== logs.port) {\n\t\tctx.logger.info(\n\t\t\tkept === undefined\n\t\t\t\t? `📜 OpenObserve: ${logs.port} is another stack's on this server, so \"${ctx.stage}\" publishes ${port}`\n\t\t\t\t: `📜 OpenObserve: \"${ctx.stage}\" keeps ${port}, the port it already publishes`,\n\t\t);\n\t\trun.stack = withLogsPort(run.stack, port);\n\t}\n}\n\n/** A stack whose caches are in Redis, built for an app that has no client. */\nexport class RedisClientMissing extends GkmError {\n\tconstructor(readonly apps: readonly string[]) {\n\t\tsuper(\n\t\t\t`The stack keeps every cache in Redis, and ${apps.join(', ')} ` +\n\t\t\t\t`${apps.length === 1 ? 'does' : 'do'} not depend on ioredis, the client ` +\n\t\t\t\t'the generated server reaches it with. Add it to the workspace: ' +\n\t\t\t\t'pnpm add ioredis',\n\t\t);\n\t\tthis.name = 'RedisClientMissing';\n\t}\n}\n\n/**\n * Every backend and worker image whose process reaches a cache can resolve\n * `ioredis` — listed by its app or a directory above it, the way Node and\n * the image's install find it. A process that reaches no cache registers no\n * cache driver, so it needs no client.\n */\nfunction assertRedisClient(\n\tworkspace: NormalizedWorkspace,\n\tstack: ComposeStack,\n\tmanifest: ConstructManifest,\n): void {\n\tif (!stack.plan.resources.some((r) => r.kind === 'cache')) return;\n\n\tconst cacheKeys = Object.values(manifest)\n\t\t.filter((d) => d.kind === 'cache')\n\t\t.flatMap((d) => d.provides ?? []);\n\tconst reachesCache = (keys: Set<string> | undefined) =>\n\t\tcacheKeys.some((key) => keys?.has(key));\n\n\tconst hosts = new Set([\n\t\t...stack.apps\n\t\t\t.filter(\n\t\t\t\t(app) =>\n\t\t\t\t\t(app.kind === 'rest-api' || app.kind === 'websocket-api') &&\n\t\t\t\t\treachesCache(appEnvKeys(manifest, app.name)),\n\t\t\t)\n\t\t\t.map((a) => a.name),\n\t\t...stack.workers\n\t\t\t.filter((worker) => reachesCache(workerEnvKeys(manifest, worker.id)))\n\t\t\t.map((worker) => worker.host),\n\t]);\n\tconst missing = [...hosts]\n\t\t.filter((name) => {\n\t\t\tconst app = workspace.apps[name];\n\t\t\treturn app && !installedFrom(join(workspace.root, app.path), 'ioredis');\n\t\t})\n\t\t.sort();\n\tif (missing.length > 0) throw new RedisClientMissing(missing);\n}\n\n/**\n * The deploy's DNS step, for a deployed stage: its server's address — required\n * where it serves a real domain — then its own hosts written through each\n * domain's provider in `dns` where they differ, read back from it, and\n * recorded in the stage's state; hosts no provider writes resolved with the\n * system resolver. A dry run prints the plan and writes nothing, and warns\n * rather than stops. Returns the prune of the records gkm wrote for hosts the\n * stage no longer serves — which a dry run prints there and then.\n *\n * @throws {ServerAddressMissing} when the stage has a domain and no address\n * @throws {ServerAddressInvalid} for a value that is not an address\n * @throws {HostNotPointingAtServer} when a host is not the server\n */\n/**\n * The records the stack's DNS step weighs against its plan: every one gkm\n * wrote for the stage's hosts, and each a provider asked for on an earlier\n * deploy and not on this one — which the plan does not have either, so it is\n * pruned once the stack answers. One a provider asked for this run is not\n * the stack's to prune; nor is any provider's, when the providers did not\n * run.\n */\nexport function recordedForStack<\n\tR extends { fqdn: string; type: string; source?: string },\n>(recorded: readonly R[], providerDns: readonly string[] | undefined): R[] {\n\tconst asked = new Set(providerDns ?? []);\n\treturn recorded.filter(\n\t\t(record) =>\n\t\t\trecord.source !== 'provider' ||\n\t\t\t(providerDns !== undefined &&\n\t\t\t\t!asked.has(dnsResourceKey(record.fqdn, record.type))),\n\t);\n}\n\nasync function stageHostsDns(\n\tctx: ComposeContext,\n\tdeps: ComposeDeps,\n\thosts: readonly string[],\n\tcustom: Readonly<Record<string, string>> | undefined,\n\twildcard: string | undefined,\n): Promise<(() => Promise<PrunedDnsRecord[]>) | undefined> {\n\tconst { workspace, stage } = ctx;\n\tconst server = requiredServerAddress(\n\t\tstage,\n\t\tworkspace.domains?.[stage],\n\t\tcustom,\n\t);\n\tif (hosts.length === 0) return;\n\tif (ctx.skipDns) {\n\t\tctx.logger.info(\n\t\t\t'🌐 DNS skipped (--skip-dns): no record is written or checked',\n\t\t);\n\t\treturn;\n\t}\n\tif (!server) {\n\t\tctx.logger.info(\n\t\t\t`🌐 DNS skipped: no ${SERVER_IPV4_KEY} in '${stage}''s secrets — ${serverAddressHint(stage)}`,\n\t\t);\n\t\treturn;\n\t}\n\tconst log = (line: string) => ctx.logger.info(line);\n\tif (workspace.dns) {\n\t\tlog(\n\t\t\t`🌐 DNS for '${stage}' → ${server.ipv4}${server.ipv6 ? ` / ${server.ipv6}` : ''}${ctx.dryRun ? ' (dry run — nothing is written)' : ''}`,\n\t\t);\n\t}\n\ttry {\n\t\tconst stored = await ctx.state.read(stage);\n\t\tconst result = await stageDns({\n\t\t\tstage,\n\t\t\thosts,\n\t\t\tserver,\n\t\t\tdns: workspace.dns,\n\t\t\trecorded: recordedForStack(\n\t\t\t\tdnsResources(stored?.resources ?? {}),\n\t\t\t\tctx.providerDns,\n\t\t\t),\n\t\t\t...(wildcard ? { wildcard } : {}),\n\t\t\tcredentials: ctx.credentials,\n\t\t\tlog,\n\t\t\tlookup: deps.lookup ?? systemLookup,\n\t\t\t...(ctx.dryRun ? { dryRun: true } : {}),\n\t\t\t...(deps.dnsProviderFor ? { providerFor: deps.dnsProviderFor } : {}),\n\t\t});\n\t\t// What it wrote, kept in the stage's state; what it deleted, forgotten.\n\t\tif (!ctx.dryRun) {\n\t\t\tconst journal = await DeployJournal.open(ctx.state, stage, () =>\n\t\t\t\tcreateComposeState(stage),\n\t\t\t);\n\t\t\tconst providers = new Map(\n\t\t\t\tresult.plan.domains.map((d) => [d.domain, d.provider]),\n\t\t\t);\n\t\t\tawait recordDnsChanges(journal, result.changes, (domain) =>\n\t\t\t\tproviders.get(domain),\n\t\t\t);\n\t\t}\n\t\tconst parts = [\n\t\t\tresult.confirmed.length > 0\n\t\t\t\t? `${result.confirmed.length} host${result.confirmed.length === 1 ? '' : 's'} confirmed by the DNS provider`\n\t\t\t\t: '',\n\t\t\tresult.resolved.length > 0\n\t\t\t\t? `${result.resolved.length} host${result.resolved.length === 1 ? '' : 's'} resolve${result.resolved.length === 1 ? 's' : ''} to ${server.ipv4}`\n\t\t\t\t: '',\n\t\t].filter(Boolean);\n\t\tif (parts.length > 0) log(`🌐 ${parts.join(', ')}`);\n\t\tif (ctx.dryRun) {\n\t\t\tawait result.prune();\n\t\t\treturn undefined;\n\t\t}\n\t\treturn result.recorded.stale.length > 0 ? result.prune : undefined;\n\t} catch (error) {\n\t\tif (ctx.dryRun && error instanceof HostNotPointingAtServer) {\n\t\t\tctx.logger.warn(`⚠ ${error.message}`);\n\t\t\treturn undefined;\n\t\t}\n\t\tthrow error;\n\t}\n}\n\n/**\n * The records gkm wrote for hosts the stage no longer serves, deleted once it\n * answers on its new ones — and forgotten from its state, deleted or not:\n * none is gkm's to manage any more.\n */\nasync function pruneStageDns(\n\tctx: ComposeContext,\n\trun: ComposeRun,\n): Promise<void> {\n\tif (!run.pruneDns) return;\n\tconst pruned = await run.pruneDns();\n\tconst journal = await DeployJournal.open(ctx.state, ctx.stage, () =>\n\t\tcreateComposeState(ctx.stage),\n\t);\n\tfor (const { record } of pruned) await forgetDnsResource(journal, record);\n\tconst deleted = pruned.filter((p) => p.action === 'delete').length;\n\tif (deleted > 0) {\n\t\tctx.logger.info(`🌐 ${deleted} record${deleted === 1 ? '' : 's'} deleted`);\n\t}\n}\n\n/**\n * The stage's secrets — and, for a deployed stage, everything it generates\n * once: its seed, and each declared secret and keyring. Kept only once the\n * run goes ahead (`provision`), so a dry run, or a tag that is not there,\n * leaves the stage's secrets as it found them.\n */\nasync function stageSecrets(\n\tctx: ComposeContext,\n\tmanifest: ConstructManifest,\n): Promise<{ secrets: StageSecrets | null; generated: string[] }> {\n\tconst stored = await ctx.secrets.read();\n\tif (ctx.stage === ctx.workspace.stages.local) {\n\t\t// The local stage's logins are this machine's, generated once with\n\t\t// `gkm dev`'s — not the stage's secrets.\n\t\treturn { secrets: stored, generated: [] };\n\t}\n\n\tconst { secrets, generated } = deployedStackSecrets(\n\t\tctx.workspace,\n\t\tctx.stage,\n\t\tstored,\n\t\tmanifest,\n\t);\n\t// Read through the store they are masked; made up here, they are not yet.\n\tif (secrets.seed) ctx.secrets.mask(secrets.seed);\n\tfor (const [key, value] of Object.entries(secrets.custom ?? {})) {\n\t\tif (!isReservedStageKey(key) && key !== LOGS_EMAIL_KEY) {\n\t\t\tctx.secrets.mask(value);\n\t\t}\n\t}\n\treturn { secrets, generated };\n}\n\n/**\n * The stack with each app's and worker's image pinned to the digest the file\n * names: the refs it is checked, pulled and recorded by, and the image each\n * compose service runs.\n */\nfunction withPinnedImages(\n\tstack: ComposeStack,\n\tfile: string,\n\tdigests: ImageDigests,\n): ComposeStack {\n\tconst apps = pinImages(file, digests, stack.apps);\n\tconst workers = pinImages(file, digests, stack.workers);\n\tconst processors = pinImages(file, digests, stack.processors);\n\tconst services = { ...stack.compose.services };\n\tfor (const image of [...apps, ...workers, ...processors]) {\n\t\tservices[image.name] = { ...services[image.name]!, image: image.ref };\n\t}\n\treturn {\n\t\t...stack,\n\t\tapps,\n\t\tworkers,\n\t\tprocessors,\n\t\tcompose: { ...stack.compose, services },\n\t};\n}\n\n// ============================================================================\n// plan (dry run)\n// ============================================================================\n\n/**\n * A dry run: the stack's files, written so they can be read, and what a real\n * run would do — no image is built or pulled, no container touched, nothing\n * recorded and no secret kept.\n */\nexport async function planCompose(\n\tctx: ComposeContext,\n\trun: ComposeRun,\n): Promise<void> {\n\tif (run.generated.length > 0) {\n\t\tctx.logger.info(\n\t\t\t`🔑 \"${ctx.stage}\" has no ${run.generated.join(', ')} yet; this dry run used values it did not keep.`,\n\t\t);\n\t}\n\trun.files = await writeStack(ctx.cwd, run.dir, run.stack);\n\tprintPlan(ctx, run);\n\n\t// A push migrates and seeds nothing; a release runs every seed, every\n\t// time, so the list is the same whatever the database holds.\n\tif (!run.push && run.stack.infra.includes('postgres')) {\n\t\treportPlannedSeeds(\n\t\t\t(\n\t\t\t\tawait plannedSeeds({ root: ctx.workspace.root, manifest: ctx.manifest })\n\t\t\t).map(({ target, seeds }) => ({ folder: target.seeds, seeds })),\n\t\t\t(line) => ctx.logger.info(line),\n\t\t);\n\t}\n\n\tconst planned = (change: ResourceChange) => {\n\t\trun.changes.push(change);\n\t\tctx.emit({ type: 'resource.planned', ...change });\n\t};\n\tfor (const service of run.push ? [] : run.stack.infra) {\n\t\tplanned({\n\t\t\tkey: `service:${service}`,\n\t\t\tresourceType: 'service',\n\t\t\taction: 'ensure',\n\t\t});\n\t}\n\tfor (const app of run.stack.apps) {\n\t\tplanned({\n\t\t\tkey: `image:${app.name}`,\n\t\t\tresourceType: 'image',\n\t\t\taction: run.mode === 'build' ? 'build' : 'reuse',\n\t\t\tid: app.ref,\n\t\t});\n\t\tif (run.push) continue;\n\t\tplanned({\n\t\t\tkey: `service:${app.name}`,\n\t\t\tresourceType: 'service',\n\t\t\taction: run.previous[app.name] ? 'reuse' : 'create',\n\t\t});\n\t}\n\tfor (const worker of [...run.stack.workers, ...run.stack.processors]) {\n\t\tplanned({\n\t\t\tkey: `image:${worker.name}`,\n\t\t\tresourceType: 'image',\n\t\t\taction: run.mode === 'build' ? 'build' : 'reuse',\n\t\t\tid: worker.ref,\n\t\t});\n\t\tif (run.push) continue;\n\t\tplanned({\n\t\t\tkey: `service:${worker.name}`,\n\t\t\tresourceType: 'service',\n\t\t\taction: run.previous[worker.name] ? 'reuse' : 'create',\n\t\t});\n\t}\n\tfor (const push of run.topicSubscriptions?.pushes ?? []) {\n\t\tconst key = subscriptionKey(push.worker, push.name);\n\t\tconst id = run.topicSubscriptions?.recorded?.[key]?.id;\n\t\tplanned({\n\t\t\tkey,\n\t\t\tresourceType: SUBSCRIPTION_TYPE,\n\t\t\taction: id ? 'reuse' : 'create',\n\t\t\t...(id ? { id } : {}),\n\t\t});\n\t}\n\tif (!run.push) {\n\t\tplanned({\n\t\t\tkey:\n\t\t\t\trun.stack.proxy === 'caddy'\n\t\t\t\t\t? 'service:caddy'\n\t\t\t\t\t: `service:${EDGE_PROJECT}/${EDGE_SERVICE}`,\n\t\t\tresourceType: 'service',\n\t\t\taction: 'ensure',\n\t\t});\n\t}\n}\n\n/**\n * The shared edge's key for the stage's wildcard certificate, through the\n * DNS provider holding the stage's domain — before the stack's routes ask\n * for the certificate. Route 53's is issued through IAM, allowed the DNS\n * challenge's record and nothing else; every other provider's is the\n * stage's own secrets, written into the edge.\n */\nasync function edgeAcmeKey(\n\tctx: ComposeContext,\n\trun: ComposeRun,\n\tdeps: ComposeDeps,\n): Promise<void> {\n\tconst { workspace, stage } = ctx;\n\tconst zone = acmeDnsZone(workspace, stage);\n\tif (!zone) return;\n\tconst edge = edgeRef(edgeFile(run), {\n\t\t...(run.ref.host ? { host: run.ref.host } : {}),\n\t\t...(run.ref.output ? { output: run.ref.output } : {}),\n\t});\n\tconst log = (line: string) => ctx.logger.info(line);\n\n\tif (zone.provider !== 'route53') {\n\t\tawait ensureEdgeDnsSecrets(deps.docker, {\n\t\t\tedge,\n\t\t\tzone,\n\t\t\tstage,\n\t\t\tcustom: run.secrets?.custom,\n\t\t\t...(ctx.dryRun ? { dryRun: true } : {}),\n\t\t\tlog,\n\t\t});\n\t\treturn;\n\t}\n\n\tconst { domain } = zone;\n\tconst route53 = zone.config as Route53DnsConfig;\n\t// The edge is the server's: its key is named for the server, whichever\n\t// stage on it asked first.\n\tconst server =\n\t\trequiredServerAddress(stage, domain, run.secrets?.custom)?.ipv4 ??\n\t\trun.server?.host ??\n\t\t'local';\n\tconst clients = await (deps.acmeClients ?? defaultAcmeClients)(route53);\n\tawait ensureEdgeAcmeKey(deps.docker, {\n\t\tclients,\n\t\tedge,\n\t\tserver,\n\t\tproject: run.stack.project,\n\t\tdomain,\n\t\tzone: zone.zone,\n\t\t...(route53.hostedZoneId ? { hostedZoneId: route53.hostedZoneId } : {}),\n\t\t...(ctx.dryRun ? { dryRun: true } : {}),\n\t\tlog,\n\t});\n}\n\n/** IAM and Route 53 through the AWS SDK's own chain, or the entry's profile. */\nasync function defaultAcmeClients(\n\tconfig: Route53DnsConfig,\n): Promise<AcmeDnsClients> {\n\tconst [{ IAMClient }, { Route53Client }, { fromIni }] = await Promise.all([\n\t\timport('@aws-sdk/client-iam'),\n\t\timport('@aws-sdk/client-route-53'),\n\t\timport('@aws-sdk/credential-providers'),\n\t]);\n\tconst options = {\n\t\tregion: config.region ?? 'us-east-1',\n\t\t...(config.profile\n\t\t\t? { credentials: fromIni({ profile: config.profile }) }\n\t\t\t: {}),\n\t};\n\treturn { iam: new IAMClient(options), route53: new Route53Client(options) };\n}\n\n// ============================================================================\n// provision\n// ============================================================================\n\n/**\n * What the apps run on: the stage's generated secrets kept, the stack's files\n * written, its infrastructure started, and its databases, roles, grants and\n * migrations applied.\n */\nexport async function provisionCompose(\n\tctx: ComposeContext,\n\trun: ComposeRun,\n\tdeps: ComposeDeps,\n): Promise<void> {\n\tconst { ref } = run;\n\t// A push provisions nothing; its files are written where it builds.\n\tif (run.push) return;\n\n\tif (run.generated.length > 0 && run.secrets) {\n\t\tawait ctx.secrets.write(run.secrets);\n\t\tctx.logger.info(\n\t\t\t`🔑 Generated for \"${ctx.stage}\" (${ctx.secrets.store}): ${run.generated.join(', ')}`,\n\t\t);\n\t}\n\n\t// Nothing but the stack's own proxy may hold the edge's ports — checked\n\t// before a file is written or a container started. The stack's own Caddy,\n\t// from before a switch to the shared edge, is moved below instead.\n\tconst ports = edgePorts(deps.env);\n\tconst ownCaddy = await assertEdgePorts(deps.docker, {\n\t\tproject: run.stack.project,\n\t\tproxy: run.stack.proxy,\n\t\tports,\n\t\tengine: ref,\n\t});\n\n\tif (run.topicSubscriptions) {\n\t\tawait subscribeTopics(ctx, run, deps);\n\t}\n\n\tconst { stack } = run;\n\trun.files = await writeStack(ctx.cwd, run.dir, stack);\n\tprintPlan(ctx, run);\n\n\t// The shared edge, and the network the stack's public services join —\n\t// before any of them, MinIO among them, is started.\n\tif (stack.proxy === 'traefik') {\n\t\t// Switched from its own Caddy: that Caddy goes as late as it can, just\n\t\t// before the edge takes its ports, so the stage is offline only while\n\t\t// the edge starts and the stack registers with it.\n\t\tif (ownCaddy) {\n\t\t\tctx.logger.warn(\n\t\t\t\t`\\n↪ Moving ${stack.project} from its own Caddy to the shared edge: ` +\n\t\t\t\t\t`removing ${ownCaddy.container}. Its hosts are offline until the ` +\n\t\t\t\t\t`edge is up and the stack is registered with it.`,\n\t\t\t);\n\t\t\tawait deps.docker.remove(ref, stack.project, 'caddy');\n\t\t}\n\t\tctx.logger.info(`\\n🌐 Starting the shared edge (${EDGE_PROJECT})…`);\n\t\trun.files.push(\n\t\t\t...(await ensureEdge(deps.docker, {\n\t\t\t\tfile: edgeFile(run),\n\t\t\t\tports,\n\t\t\t\t...(ref.host ? { host: ref.host } : {}),\n\t\t\t\tlogging: {\n\t\t\t\t\tdriver: LOG_ROTATION.driver,\n\t\t\t\t\toptions: { ...LOG_ROTATION.options },\n\t\t\t\t},\n\t\t\t\t...(ref.output ? { output: ref.output } : {}),\n\t\t\t\t...(ref.signal ? { signal: ref.signal } : {}),\n\t\t\t})),\n\t\t);\n\t\tapplied(ctx, run, {\n\t\t\tkey: `service:${EDGE_PROJECT}/${EDGE_SERVICE}`,\n\t\t\tresourceType: 'service',\n\t\t\taction: 'ensure',\n\t\t\tid: `${EDGE_PROJECT}/${EDGE_SERVICE}`,\n\t\t\tvia: 'found',\n\t\t});\n\t\tif (stack.wildcard?.tls === 'dns') await edgeAcmeKey(ctx, run, deps);\n\t}\n\n\tif (stack.infra.length > 0) {\n\t\tctx.logger.info(`\\n🗄️ Starting ${stack.infra.join(', ')}…`);\n\t\tawait deps.docker.up(ref, stack.infra);\n\t\tfor (const service of stack.infra) {\n\t\t\tapplied(ctx, run, {\n\t\t\t\tkey: `service:${service}`,\n\t\t\t\tresourceType: 'service',\n\t\t\t\taction: 'ensure',\n\t\t\t\tid: `${stack.project}/${service}`,\n\t\t\t\tvia: Object.keys(run.previous).length > 0 ? 'recorded' : 'created',\n\t\t\t});\n\t\t}\n\t}\n\n\t// The buckets before the seeds: a seed that uploads one object writes it\n\t// to a bucket that has to exist.\n\tif (stack.storage && stack.infra.includes('minio')) {\n\t\tawait prepareBuckets(ctx, run, deps);\n\t}\n\tif (stack.infra.includes('postgres')) {\n\t\tawait prepareDatabases(ctx, run, deps);\n\t}\n}\n\n/**\n * Subscribe each topic subscriber SNS pushes to — for a topic the stage set\n * to SNS by hand — record the ARNs, and compose the stack again with them,\n * before a file is written.\n */\nasync function subscribeTopics(\n\tctx: ComposeContext,\n\trun: ComposeRun,\n\tdeps: ComposeDeps,\n): Promise<void> {\n\tconst { pushes, recorded, restack } = run.topicSubscriptions!;\n\tif (pushes.length > 0) {\n\t\tctx.logger.info(\"\\n📮 SNS subscriptions for the stage's own topics\");\n\t}\n\tconst arns = await ensureTopicSubscriptions({\n\t\tpushes,\n\t\trecorded,\n\t\tsecrets: run.secrets?.custom ?? {},\n\t\tstage: ctx.stage,\n\t\tenv: deps.env,\n\t\trecord: async (resource) => {\n\t\t\tawait ctx.state.putResource(ctx.stage, resource);\n\t\t\tapplied(ctx, run, {\n\t\t\t\tkey: resource.key,\n\t\t\t\tresourceType: SUBSCRIPTION_TYPE,\n\t\t\t\taction: 'ensure',\n\t\t\t\tid: resource.id!,\n\t\t\t\tvia:\n\t\t\t\t\trecorded?.[resource.key]?.id === resource.id ? 'recorded' : 'created',\n\t\t\t});\n\t\t},\n\t\tforget: async (key) => {\n\t\t\tawait ctx.state.deleteResource(ctx.stage, key);\n\t\t},\n\t\tlog: (line) => ctx.logger.info(line),\n\t});\n\trun.stack = restack(arns);\n}\n\n/**\n * Create each bucket the stack's MinIO serves, and the open paths of each\n * one a file server fronts — from this machine, on MinIO's loopback port,\n * the way `gkm dev` creates them.\n */\nasync function prepareBuckets(\n\tctx: ComposeContext,\n\trun: ComposeRun,\n\tdeps: ComposeDeps,\n): Promise<void> {\n\tconst storage = run.stack.storage!;\n\tif (storage.buckets.length === 0) return;\n\n\tconst tunnel = await reach(run, deps, 'minio', LOOPBACK_SERVICES.minio);\n\tlet done: Awaited<ReturnType<typeof applyBuckets>>;\n\ttry {\n\t\tconst client = deps.buckets(tunnel.port, storage);\n\t\tdone = [\n\t\t\t...(await applyBuckets(client, storage.buckets)),\n\t\t\t...(await applyPolicies(client, storage.policies)),\n\t\t\t...(await applyLifecycles(client, storage.lifecycles)),\n\t\t\t// Each watched bucket's events to the worker MinIO was started\n\t\t\t// pointing at — and none from a bucket no longer watched.\n\t\t\t...(await applyNotifications(\n\t\t\t\tclient,\n\t\t\t\tstorage.objects,\n\t\t\t\tnew Set(storage.webhooks.map((hook) => hook.bucket)),\n\t\t\t)),\n\t\t];\n\t} finally {\n\t\tawait tunnel.close();\n\t}\n\tconst created = done.filter((entry) => entry.created).length;\n\tctx.logger.info(\n\t\t`🪣 Buckets: ${storage.buckets.join(', ')}${created ? ` (${created} change(s))` : ''}`,\n\t);\n}\n\n/**\n * Create what the plan names in the stack's Postgres, migrate it, then run\n * its seeds — every one, every time, as each construct's owner.\n *\n * Every service the stack publishes on its loopback is reached, not only\n * Postgres: a seed runs project code, and project code that uploads a file\n * reaches the stack's MinIO as well.\n */\nasync function prepareDatabases(\n\tctx: ComposeContext,\n\trun: ComposeRun,\n\tdeps: ComposeDeps,\n): Promise<void> {\n\tconst tunnels: { port: number; close: () => Promise<void> }[] = [];\n\ttry {\n\t\tconst ports: Record<string, number> = {};\n\t\tfor (const [service, inside] of Object.entries(LOOPBACK_SERVICES)) {\n\t\t\tif (!run.stack.infra.includes(service)) continue;\n\t\t\tconst tunnel = await reach(run, deps, service, inside);\n\t\t\ttunnels.push(tunnel);\n\t\t\tports[primaryPortKey(service)] = tunnel.port;\n\t\t}\n\t\tawait migrateAndSeed(ctx, run, deps, ports);\n\t} finally {\n\t\tawait Promise.all(tunnels.map((tunnel) => tunnel.close()));\n\t}\n}\n\n/**\n * A port a stack's service publishes on its engine's loopback, reachable\n * from this machine: the published port itself on the local stage, and on a\n * server an SSH tunnel to it over the deploy's own login — so Postgres and\n * MinIO are never published beyond the server's loopback.\n *\n * Migrations and seeds run here, in this process, with the project's own\n * Kysely — the way `gkm migrate` runs them — through that port. No image\n * needs to carry them, and nothing is run on the server but the stack.\n */\nasync function reach(\n\trun: ComposeRun,\n\tdeps: ComposeDeps,\n\tservice: string,\n\tinside: number,\n): Promise<{ port: number; close: () => Promise<void> }> {\n\tconst published = await deps.docker.port(run.ref, service, inside);\n\tif (!run.server) return { port: published, close: async () => {} };\n\treturn deps.server.tunnel(run.server, published);\n}\n\nasync function migrateAndSeed(\n\tctx: ComposeContext,\n\trun: ComposeRun,\n\tdeps: ComposeDeps,\n\t/** Each loopback service's port on this machine, by port key. */\n\tports: Record<string, number>,\n): Promise<void> {\n\tconst { stack } = run;\n\tconst workspace: NormalizedWorkspace = ctx.workspace;\n\tconst port = ports[primaryPortKey('postgres')]!;\n\n\t// A stack an older gkm started made its superuser under the old fixed\n\t// name, with the password this stage derives; it is moved to the\n\t// superuser named now — the local stage's from the old fixed login too.\n\tconst superuser = stack.credential.containers.postgres;\n\tconst login = await deps.logins({\n\t\tport,\n\t\tlogin: superuser,\n\t\tlegacy: [\n\t\t\t{ user: LEGACY_LOCAL_LOGIN.user, password: superuser.password },\n\t\t\t...(stack.local ? [LEGACY_LOCAL_LOGIN] : []),\n\t\t],\n\t});\n\tif (login.notice) ctx.logger.info(login.notice);\n\n\tconst statements = [\n\t\t...postgresStatements(stack.plan, workspace.name, stack.credential.seed),\n\t\t// The backups service's own login: it reads, and writes nothing.\n\t\t...(stack.backups ? backupsRoleStatements(stack.backups) : []),\n\t];\n\tif (statements.length > 0) {\n\t\tctx.logger.info('🗄️ Creating databases, roles and grants…');\n\t\tawait applyPostgres(deps.sql(port, login.login), statements);\n\t}\n\n\t// Migrations run here, with the project's own Kysely, the way `gkm\n\t// migrate` runs them — so the constructs themselves are needed, which\n\t// only an in-process discovery hands back.\n\tconst sources: Record<string, ConstructSource> = {};\n\tconst manifest = await discover({\n\t\tpatterns: constructGlobs(workspace),\n\t\tcwd: workspace.root,\n\t\tsources,\n\t});\n\n\t// What `gkm seed` hands a seed — the stage's secrets under what it\n\t// resolves — resolved as the stack resolves it, on the ports this machine\n\t// reaches the stack by. A key the stage set by hand is what its apps are\n\t// given, so it is not resolved over.\n\tconst custom = run.secrets?.custom ?? {};\n\tconst resolved = envFor(stack.plan, {\n\t\t...stack.resolution,\n\t\tports,\n\t\tcredentials: {\n\t\t\t...stack.resolution.credentials,\n\t\t\tpostgres: login.login,\n\t\t},\n\t});\n\tconst env = stageEnv(\n\t\trun.secrets ? toEmbeddableSecrets(run.secrets) : {},\n\t\tObject.fromEntries(\n\t\t\tObject.entries(resolved).filter(([key]) => custom[key] === undefined),\n\t\t),\n\t);\n\tconst options = { root: workspace.root, manifest, sources, env };\n\tconst runs = await deps.migrate(options);\n\n\t// Seeds after migrations, before any app starts: an app that boots with\n\t// its reference data missing fails on the first request that needs it.\n\tconst seeds = await deps\n\t\t.seed({ ...options, stage: ctx.stage, backends: backendsOf(workspace) })\n\t\t.catch((error: unknown) => {\n\t\t\tif (error instanceof SeedFailed) {\n\t\t\t\tthrow new DeploySeedsFailed(\n\t\t\t\t\tctx.stage,\n\t\t\t\t\terror.construct,\n\t\t\t\t\terror.seed,\n\t\t\t\t\terror,\n\t\t\t\t);\n\t\t\t}\n\t\t\tthrow error;\n\t\t});\n\n\treportDatabaseRuns(\n\t\truns.map(({ target, applied }) => ({\n\t\t\tconstruct: target.id,\n\t\t\tfolder: target.migrations,\n\t\t\tapplied,\n\t\t})),\n\t\tseeds.map(({ target, seeded }) => ({\n\t\t\tconstruct: target.id,\n\t\t\tfolder: target.seeds,\n\t\t\tseeded,\n\t\t})),\n\t\t(line) => ctx.logger.info(line),\n\t\t(event) => ctx.emit(event),\n\t);\n}\n\n// ============================================================================\n// build\n// ============================================================================\n\n/**\n * Each app's image: built from this checkout — inside Docker, every one of\n * them, from a pruned slice of the build root — or pulled at the tag. Nothing\n * live changes.\n */\nexport async function buildCompose(\n\tctx: ComposeContext,\n\trun: ComposeRun,\n\tdeps: ComposeDeps,\n): Promise<void> {\n\tconst { stack, ref } = run;\n\tconst images = [...stack.apps, ...stack.workers, ...stack.processors];\n\tconst apps = images.map((image) => image.app);\n\n\t// Nothing was provisioned, so nothing has written the files it builds from.\n\tif (run.push) {\n\t\trun.files = await writeStack(ctx.cwd, run.dir, stack);\n\t\tprintPlan(ctx, run);\n\t}\n\n\t// A site built against its stage: pushed, against the one already running,\n\t// which has to answer before anything is built; deployed, once `release`\n\t// has its APIs up.\n\tconst prerendered = prerenderedHere(run);\n\tif (run.push) await stageAnswers(ctx, run, deps, prerendered);\n\tconst held = new Set(run.push ? [] : prerendered.map(({ app }) => app));\n\tconst now = images.filter((image) => !held.has(image.app));\n\n\tif (run.mode === 'build') {\n\t\tctx.logger.info('\\n🐳 Building images…');\n\t\tawait deps.docker.build(\n\t\t\tref,\n\t\t\tnow.map((image) => image.app),\n\t\t);\n\t} else {\n\t\tctx.logger.info(`\\n🐳 Pulling ${stageTag(ctx.tag, ctx.stage)}…`);\n\t\tawait deps.docker.pull(ref, apps);\n\t}\n\n\tif (run.push) ctx.logger.info('\\n📤 Pushing images…');\n\n\tawait recordBuilt(ctx, run, deps, now);\n}\n\n/**\n * Each image's tag as it resolved — the registry's digest for a pushed or\n * pulled image, or, for one built here and never pushed, its content id —\n * in the run, and said.\n */\nasync function recordBuilt(\n\tctx: ComposeContext,\n\trun: ComposeRun,\n\tdeps: ComposeDeps,\n\timages: readonly { app: string; ref: string; tag: string }[],\n): Promise<void> {\n\tconst { ref } = run;\n\tfor (const image of images) {\n\t\tconst digest = run.push\n\t\t\t? await deps.docker.push(ref, image.ref)\n\t\t\t: await deps.docker.digest(ref, image.ref);\n\t\tif (run.push) {\n\t\t\tctx.logger.info(` ${image.app.padEnd(12)} ${image.ref}@${digest}`);\n\t\t}\n\t\trun.images[image.app] = {\n\t\t\tref: image.ref,\n\t\t\ttag: image.tag,\n\t\t\t...(digest ? { digest } : {}),\n\t\t};\n\t\tctx.emit({\n\t\t\ttype: 'artifact.built',\n\t\t\tapp: image.app,\n\t\t\timageRef: image.ref,\n\t\t\t...(digest ? { digest } : {}),\n\t\t});\n\t\trun.changes.push({\n\t\t\tkey: `image:${image.app}`,\n\t\t\tresourceType: 'image',\n\t\t\taction: run.mode === 'build' ? 'build' : 'reuse',\n\t\t\tid: digest ?? image.ref,\n\t\t});\n\t}\n}\n\n// ============================================================================\n// release\n// ============================================================================\n\n/**\n * The whole stack up — anything it no longer defines removed — and each\n * app's image recorded in the stage's state.\n */\nexport async function releaseCompose(\n\tctx: ComposeContext,\n\trun: ComposeRun,\n\tdeps: ComposeDeps,\n): Promise<void> {\n\tconst { stack, ref } = run;\n\t// A push starts nothing and records nothing: a stage runs what it pulls.\n\tif (run.push) return;\n\n\t// Registered with the shared edge before anything waits on health, so one\n\t// app that never turns healthy leaves the others routed: a route to an\n\t// app not up yet answers 502, which says more than no route at all. It is\n\t// also what lets an app whose own health check goes through the edge — a\n\t// site whose `/` calls its API at the API's public host — turn healthy.\n\t// A stack on its own Caddy leaves nothing behind there from a run on the\n\t// edge — the server's, or this machine's for a local stage that ran\n\t// behind it before (its directory still has the edge's file).\n\tconst edge = edgeRef(edgeFile(run), {\n\t\t...(ref.host ? { host: ref.host } : {}),\n\t\t...(ref.output ? { output: ref.output } : {}),\n\t});\n\tif (stack.proxy === 'traefik' && stack.traefik) {\n\t\tconst written = await writeEdgeRoutes(\n\t\t\tdeps.docker,\n\t\t\tedge,\n\t\t\tstack.project,\n\t\t\tstack.traefik,\n\t\t\tawait edgeCertificate(run.dir, stack),\n\t\t);\n\t\tctx.logger.info(\n\t\t\t`🌐 Registered ${stack.routes.length} route(s) with ${EDGE_PROJECT}: ${written.at(-1)}`,\n\t\t);\n\t} else if (!stack.local || existsSync(edgeFile(run))) {\n\t\tawait removeEdgeRoutes(deps.docker, edge, stack.project);\n\t}\n\n\tconst prerendered = prerenderedHere(run);\n\tif (prerendered.length > 0) {\n\t\tawait buildAgainstStage(ctx, run, deps, prerendered);\n\t}\n\n\tctx.logger.info('\\n🚀 Starting the stack…');\n\t// Caddy starts once its apps have, not once they are healthy, so its\n\t// routes are served whatever their health. `up --wait` still fails when\n\t// one never turns healthy: which ones is asked of Docker, and said once\n\t// the rest of the stack is released — never instead of releasing it.\n\tconst down = await deps.docker.up(ref).then(\n\t\t() => [],\n\t\t(error: unknown) => unhealthyAfterUp(ctx, run, deps, error),\n\t);\n\tconst isDown = new Set(down.map(({ app }) => app));\n\n\tawait recordImages(ctx, run);\n\n\tfor (const app of stack.apps) {\n\t\tif (isDown.has(app.name)) continue;\n\t\tconst image = run.images[app.name];\n\t\tapplied(ctx, run, {\n\t\t\tkey: `service:${app.name}`,\n\t\t\tresourceType: 'service',\n\t\t\taction: 'ensure',\n\t\t\tid: `${stack.project}/${app.name}`,\n\t\t\tvia: run.previous[app.name] ? 'recorded' : 'created',\n\t\t});\n\t\tctx.emit({\n\t\t\ttype: 'app.deployed',\n\t\t\tapp: app.name,\n\t\t\tapplicationId: `${stack.project}/${app.name}`,\n\t\t\timageRef: image?.ref ?? app.ref,\n\t\t\turl: app.url,\n\t\t});\n\t}\n\n\t// A worker has no URL, so no `app.deployed`: its service, applied, is it —\n\t// nor has a processor unit, which answers on its file server's.\n\tfor (const worker of [...stack.workers, ...stack.processors]) {\n\t\tif (isDown.has(worker.name)) continue;\n\t\tapplied(ctx, run, {\n\t\t\tkey: `service:${worker.name}`,\n\t\t\tresourceType: 'service',\n\t\t\taction: 'ensure',\n\t\t\tid: `${stack.project}/${worker.name}`,\n\t\t\tvia: run.previous[worker.name] ? 'recorded' : 'created',\n\t\t});\n\t}\n\n\tctx.logger.info(`\\n✅ ${stack.project} is running:`);\n\tfor (const app of stack.apps) {\n\t\tif (isDown.has(app.name)) continue;\n\t\tctx.logger.info(\n\t\t\t` ${app.name.padEnd(12)} ${app.url}${\n\t\t\t\tapp.auth\n\t\t\t\t\t? ` 🔒 user: ${app.auth.user}, password: gkm secrets:show --stage ${ctx.stage} --reveal → ${app.auth.key}`\n\t\t\t\t\t: ''\n\t\t\t}`,\n\t\t);\n\t}\n\tif (stack.mailInbox) {\n\t\tctx.logger.info(` ${'mail'.padEnd(12)} ${stack.mailInbox.url} (inbox)`);\n\t}\n\tfor (const worker of stack.workers) {\n\t\tif (isDown.has(worker.name)) continue;\n\t\tctx.logger.info(` ${worker.name.padEnd(12)} worker ${worker.id}`);\n\t}\n\tfor (const unit of stack.processors) {\n\t\tif (isDown.has(unit.name)) continue;\n\t\tctx.logger.info(` ${unit.name.padEnd(12)} processors of ${unit.id}`);\n\t}\n\tif (stack.authority) {\n\t\tctx.logger.info(\n\t\t\t`\\n🔐 Certificates are from gkm's local CA (\"gkm trust\" trusts it here): NODE_EXTRA_CA_CERTS=${stack.authority.certFile}`,\n\t\t);\n\t} else if (stack.local && stack.tls) {\n\t\tctx.logger.info(\n\t\t\tstack.tls.caFile\n\t\t\t\t? `\\n🔐 Certificates are the stage's own (deploy.compose.tls), from the CA in ${stack.tls.caFile}: NODE_EXTRA_CA_CERTS=${stack.tls.caFile}`\n\t\t\t\t: `\\n🔐 Certificates are the stage's own (deploy.compose.tls): ${stack.tls.certFile}. Set its caFile to the root it chains to, so gkm and the stack's containers trust it.`,\n\t\t);\n\t}\n\n\tif (down.length > 0) {\n\t\tthrow new ComposeAppsUnhealthy(stack.project, down, stack.proxy, 'docker');\n\t}\n}\n\n/**\n * After `up --wait` failed: each app's and worker's service that is not\n * healthy once its health settles — waited on while it is still starting,\n * as `--wait` stops at the first that is not. None means the failure was not\n * health's, and it is thrown as it was.\n */\nasync function unhealthyAfterUp(\n\tctx: ComposeContext,\n\trun: ComposeRun,\n\tdeps: ComposeDeps,\n\terror: unknown,\n\t/** Services not started, so not asked. */\n\texcept: ReadonlySet<string> = new Set(),\n): Promise<{ app: string; url: string; last: string }[]> {\n\tconst { stack } = run;\n\tconst services = [\n\t\t...stack.apps.flatMap(replicaNames),\n\t\t...stack.workers.map((worker) => worker.name),\n\t\t...stack.processors.map((unit) => unit.name),\n\t].filter((service) => !except.has(service));\n\tconst settled = await Promise.all(\n\t\tservices.map(async (service) => {\n\t\t\tlet last: string | undefined;\n\t\t\tfor (let attempt = 1; attempt <= deps.healthAttempts; attempt++) {\n\t\t\t\tctx.signal.throwIfAborted();\n\t\t\t\tlast = await deps.docker\n\t\t\t\t\t.health(run.ref, service)\n\t\t\t\t\t.catch(() => undefined);\n\t\t\t\tif (last !== 'starting') break;\n\t\t\t\tif (attempt < deps.healthAttempts) {\n\t\t\t\t\tawait new Promise((resolve) =>\n\t\t\t\t\t\tsetTimeout(resolve, deps.healthIntervalMs),\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn { app: service, url: `docker:${service}`, last };\n\t\t}),\n\t);\n\tconst down = settled\n\t\t.filter(({ last }) => last !== 'healthy')\n\t\t.map(({ app, url, last }) => ({ app, url, last: last ?? 'not running' }));\n\tif (down.length === 0) throw error;\n\n\tctx.logger.warn(\n\t\t`\\n⚠️ ${down.map(({ app }) => app).join(', ')} did not turn healthy; the rest of the stack is released and routed.`,\n\t);\n\treturn down;\n}\n\n/**\n * Where a check through the edge connects: this machine for the local stage,\n * a deployed stage's server on its published port — or, for a push, which\n * has no server, wherever the host resolves.\n */\nfunction edgeTarget(\n\trun: ComposeRun,\n\tdeps: ComposeDeps,\n): { connectTo: string; connectPort?: number } | undefined {\n\tif (run.stack.local) return { connectTo: '127.0.0.1' };\n\tif (run.server) {\n\t\treturn {\n\t\t\tconnectTo: run.server.host,\n\t\t\tconnectPort: edgePorts(deps.env).https,\n\t\t};\n\t}\n\treturn undefined;\n}\n\n/**\n * The sites this run builds against their stage's running APIs\n * (`prerender: 'stage'`). None for a run that pulls: a pulled image was built\n * against the stage when it was pushed.\n */\nfunction prerenderedHere(run: ComposeRun): StackApp[] {\n\tif (run.mode !== 'build') return [];\n\treturn run.stack.apps.filter((app) => app.prerender && app.build);\n}\n\n/**\n * A site that pre-renders against its stage, built once its APIs answer:\n * every service of the stack started but those sites — `up --wait`, so each\n * is healthy by its own check — then each API the site depends on asked\n * through the edge, as a browser reaches it, and only then the site built.\n * The full `up` that follows starts it.\n */\nasync function buildAgainstStage(\n\tctx: ComposeContext,\n\trun: ComposeRun,\n\tdeps: ComposeDeps,\n\tsites: readonly StackApp[],\n): Promise<void> {\n\tconst { stack, ref } = run;\n\tconst held = new Set(sites.flatMap(replicaNames));\n\tconst services = Object.keys(stack.compose.services).filter(\n\t\t(service) => !held.has(service),\n\t);\n\n\tctx.logger.info(\n\t\t`\\n🚀 Starting the stack, but ${listNames(sites)}, built once its APIs answer…`,\n\t);\n\tconst down = await deps.docker.up(ref, services).then(\n\t\t() => [],\n\t\t(error: unknown) => unhealthyAfterUp(ctx, run, deps, error, held),\n\t);\n\tfor (const site of sites) {\n\t\tconst against = new Set(site.prerender?.against);\n\t\tconst blocking = down.filter(({ app }) => against.has(app));\n\t\tif (blocking.length > 0) {\n\t\t\tthrow new SitePrerenderApisDown(site.name, blocking, 'docker');\n\t\t}\n\t}\n\n\tawait stageAnswers(ctx, run, deps, sites);\n\n\tctx.logger.info(\n\t\t`\\n🐳 Building ${listNames(sites)} against the stage's APIs…`,\n\t);\n\tawait deps.docker.build(\n\t\tref,\n\t\tsites.map((site) => site.app),\n\t);\n\tawait recordBuilt(ctx, run, deps, sites);\n}\n\n/** `web` — or `docs and web`. */\nfunction listNames(apps: readonly { name: string }[]): string {\n\tconst names = apps.map(({ name }) => name);\n\treturn names.length > 1\n\t\t? `${names.slice(0, -1).join(', ')} and ${names.at(-1)}`\n\t\t: (names[0] ?? '');\n}\n\n/**\n * Each API a site pre-rendered against its stage depends on, asked through\n * the edge as `verify` asks it — the address the site's build fetches from.\n * Any that does not answer fails the run before the site is built: a build\n * that cannot reach them bakes in pages without their data.\n */\nasync function stageAnswers(\n\tctx: ComposeContext,\n\trun: ComposeRun,\n\tdeps: ComposeDeps,\n\tsites: readonly StackApp[],\n): Promise<void> {\n\tconst { stack } = run;\n\tconst names = new Set(sites.flatMap((site) => site.prerender?.against ?? []));\n\tconst apps = stack.apps.filter((app) => names.has(app.name));\n\tif (apps.length === 0) return;\n\n\tctx.logger.info(\n\t\t`\\n🩺 Checking the APIs ${listNames(sites)} ${sites.length > 1 ? 'pre-render' : 'pre-renders'} from…`,\n\t);\n\tconst ca = await verifyAuthority(stack);\n\tconst edge = edgeTarget(run, deps);\n\tconst results = await Promise.all(\n\t\tapps.map((app) =>\n\t\t\t// A wildcard site has no one host: its container says, where it runs.\n\t\t\tapp.id === stack.wildcard?.site && !run.push\n\t\t\t\t? checkContainer(ctx, run, deps, app.name)\n\t\t\t\t: checkApp(ctx, app, deps, { ca, edge }),\n\t\t),\n\t);\n\tconst down = new Map(\n\t\tresults.filter((r) => !r.healthy).map((r) => [r.app, r] as const),\n\t);\n\tfor (const site of sites) {\n\t\tconst blocking = (site.prerender?.against ?? []).flatMap((name) => {\n\t\t\tconst result = down.get(name);\n\t\t\treturn result ? [result] : [];\n\t\t});\n\t\tif (blocking.length > 0) {\n\t\t\tthrow new SitePrerenderApisDown(\n\t\t\t\tsite.name,\n\t\t\t\tblocking,\n\t\t\t\trun.push ? 'push' : 'edge',\n\t\t\t);\n\t\t}\n\t}\n}\n\n/**\n * Each app's image in the stage's state — the same `images` a Dokploy deploy\n * records: the ref it runs, the tag it was released under, and the digest\n * the tag resolved to.\n */\nasync function recordImages(\n\tctx: ComposeContext,\n\trun: ComposeRun,\n): Promise<void> {\n\tconst journal = await DeployJournal.open(ctx.state, ctx.stage, () =>\n\t\tcreateComposeState(ctx.stage),\n\t);\n\tconst by = currentActor();\n\tfor (const app of [\n\t\t...run.stack.apps,\n\t\t...run.stack.workers,\n\t\t...run.stack.processors,\n\t]) {\n\t\tconst image = run.images[app.app] ?? { ref: app.ref, tag: app.tag };\n\t\trecordRelease(journal.state, app.app, image, by);\n\t}\n\tjournal.state.identity = ctx.identity.key;\n\tawait journal.save();\n}\n\n// ============================================================================\n// verify\n// ============================================================================\n\n/**\n * Each app asked through Caddy, over HTTPS, the certificate verified: an API\n * at `/health`, a site at `/`. On the local stage the edge is this machine and\n * its certificate is from gkm's local CA, so that root is the one trusted and\n * the request goes to 127.0.0.1.\n */\nexport async function verifyCompose(\n\tctx: ComposeContext,\n\trun: ComposeRun,\n\tdeps: ComposeDeps,\n): Promise<void> {\n\tconst { stack } = run;\n\tif (run.push) return;\n\tconst ca = await verifyAuthority(stack);\n\n\tctx.logger.info(\n\t\t`\\n🩺 Checking each app through ${stack.proxy === 'caddy' ? 'Caddy' : 'the shared edge'}…`,\n\t);\n\t// The local stage's edge is this machine; a deployed stage's is its\n\t// server. Either is asked directly, on its published port, with each host\n\t// as SNI and Host: what is checked is its routing and its certificate,\n\t// whatever DNS — or a record not yet propagated — says.\n\tconst edge = edgeTarget(run, deps);\n\t// A wildcard site has no one host to ask: each tenant's is the app's to\n\t// answer, and an unknown one may get no certificate. Its container's own\n\t// health check is the answer, as a worker's is.\n\tconst results = await Promise.all(\n\t\tstack.apps.map((app) =>\n\t\t\tapp.id === stack.wildcard?.site\n\t\t\t\t? checkContainer(ctx, run, deps, app.name)\n\t\t\t\t: checkApp(ctx, app, deps, { ca, edge }),\n\t\t),\n\t);\n\n\t// A worker has no route through the edge: its own health check, as Docker\n\t// reports it, is the answer.\n\tresults.push(\n\t\t...(await Promise.all(\n\t\t\t[...stack.workers, ...stack.processors].map((worker) =>\n\t\t\t\tcheckContainer(ctx, run, deps, worker.name),\n\t\t\t),\n\t\t)),\n\t);\n\tif (stack.logs) {\n\t\tresults.push(await checkContainer(ctx, run, deps, LOGS_SERVICE));\n\t}\n\n\tconst down = results\n\t\t.filter((result) => !result.healthy)\n\t\t.map(({ app, url, last }) => ({ app, url, last }));\n\tif (down.length > 0) {\n\t\tthrow new ComposeAppsUnhealthy(stack.project, down, stack.proxy);\n\t}\n\tawait pruneStageDns(ctx, run);\n\n\tawait confirmSubscriptions(ctx, run, deps);\n\n\tawait warmSites(ctx, run, deps, { ca, edge });\n\n\tif (stack.logs) reportLogs(ctx, stack.logs, stack.local, run.server);\n}\n\n/**\n * Each server-rendered site (`next`, `tanstack`) asked for its sitemap, its\n * `/` and every page the sitemap lists, through the edge as `checkApp` asks\n * it — see `warmup.ts`. Its image was built with no API reachable, so each\n * page renders on its first request: this is that request, made before any\n * visitor's. A Next site is asked with its on-demand revalidation header,\n * so a page its build cached (empty) is rendered again from the deployed\n * APIs rather than served from that cache.\n *\n * Only ever said, never failed on: every app is already healthy, and a page\n * that did not warm renders on the next request for it.\n */\nasync function warmSites(\n\tctx: ComposeContext,\n\trun: ComposeRun,\n\tdeps: ComposeDeps,\n\toptions: {\n\t\tca: string | undefined;\n\t\tedge?: { connectTo: string; connectPort?: number };\n\t},\n): Promise<void> {\n\tconst { stack } = run;\n\tconst sites = stack.apps.filter(\n\t\t(app) =>\n\t\t\tapp.kind === 'site' &&\n\t\t\t(app.variant === 'next' || app.variant === 'tanstack'),\n\t);\n\tif (sites.length === 0) return;\n\n\tctx.logger.info('\\n🔥 Warming each server-rendered site…');\n\tfor (const app of sites) {\n\t\tif (app.id === stack.wildcard?.site) {\n\t\t\tctx.logger.info(\n\t\t\t\t` – ${app.name.padEnd(12)} serves every subdomain: there is no one host to warm, so it is skipped`,\n\t\t\t);\n\t\t\tcontinue;\n\t\t}\n\t\ttry {\n\t\t\tconst headers =\n\t\t\t\tapp.variant === 'next' ? await forceRender(ctx, run, deps, app) : {};\n\t\t\tconst { warmed, cached, warnings, leftOut } = await warmSite({\n\t\t\t\turl: app.url,\n\t\t\t\tfetch: deps.fetch ?? edgeFetch,\n\t\t\t\theaders,\n\t\t\t\tedge: {\n\t\t\t\t\t...(options.ca ? { ca: options.ca } : {}),\n\t\t\t\t\t...(app.auth ? { authorization: basicAuthorization(app.auth) } : {}),\n\t\t\t\t\t...options.edge,\n\t\t\t\t\tsignal: ctx.signal,\n\t\t\t\t},\n\t\t\t});\n\t\t\tconst said = `warmed ${warmed.length} page(s)${\n\t\t\t\tcached.length > 0\n\t\t\t\t\t? `, ${cached.length} served from the build cache`\n\t\t\t\t\t: ''\n\t\t\t}${warnings.length > 0 ? `, ${warnings.length} warning(s)` : ''}`;\n\t\t\tif (warnings.length === 0) {\n\t\t\t\tctx.logger.info(\n\t\t\t\t\t` ✓ ${app.name.padEnd(12)} ${said}${cached.length > 0 ? `: ${listed(cached)}` : ''}`,\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tctx.logger.warn(` ⚠ ${app.name.padEnd(12)} ${said}:`);\n\t\t\t\tfor (const { url, reason } of warnings) {\n\t\t\t\t\tctx.logger.warn(` ${url}: ${reason}`);\n\t\t\t\t}\n\t\t\t\tif (cached.length > 0) {\n\t\t\t\t\tctx.logger.warn(\n\t\t\t\t\t\t` served from the build cache: ${listed(cached)}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (leftOut > 0) {\n\t\t\t\tctx.logger.info(\n\t\t\t\t\t` ${leftOut} more page(s) in its sitemap were not asked: at most ${WARMUP_MAX_URLS} are warmed per site`,\n\t\t\t\t);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tif (ctx.signal.aborted) throw error;\n\t\t\tctx.logger.warn(\n\t\t\t\t` ⚠ ${app.name.padEnd(12)} not warmed: ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t);\n\t\t}\n\t}\n}\n\n/** The most pages a summary names; the rest are counted. */\nconst LISTED_PAGES = 10;\n\n/** Pages by path, `/about`, the first {@link LISTED_PAGES} of them. */\nfunction listed(urls: readonly string[]): string {\n\tconst paths = urls.map((url) => {\n\t\tconst { pathname, search } = new URL(url);\n\t\treturn `${pathname}${search}`;\n\t});\n\tconst shown = paths.slice(0, LISTED_PAGES).join(', ');\n\treturn paths.length > LISTED_PAGES\n\t\t? `${shown} and ${paths.length - LISTED_PAGES} more`\n\t\t: shown;\n}\n\n/**\n * The header that has a Next site render each warmed page whatever its\n * cache says: `x-prerender-revalidate` with the preview-mode id of the image\n * running — read in its container, through the stack's Docker engine, at\n * the path the generated Dockerfile puts the standalone output at. Where the\n * id cannot be read, said once, and the site is warmed with plain requests.\n */\nasync function forceRender(\n\tctx: ComposeContext,\n\trun: ComposeRun,\n\tdeps: ComposeDeps,\n\tapp: { name: string; path: string },\n): Promise<Record<string, string>> {\n\tlet reason: string;\n\ttry {\n\t\tconst root = ctx.workspace.root;\n\t\tconst gkmRoot = relative(findBuildRoot(root), root) || '.';\n\t\tconst manifest = nextPrerenderManifest(\n\t\t\tfromBuildRoot({ gkmRoot }, app.path),\n\t\t);\n\t\tconst lookup = await nextPreviewModeId(\n\t\t\t(command) => deps.docker.exec(run.ref, app.name, command),\n\t\t\tmanifest,\n\t\t);\n\t\tif ('id' in lookup) return { [NEXT_REVALIDATE_HEADER]: lookup.id };\n\t\treason = lookup.reason;\n\t} catch (error) {\n\t\tif (ctx.signal.aborted) throw error;\n\t\treason = error instanceof Error ? error.message : String(error);\n\t}\n\tctx.logger.warn(\n\t\t` ⚠ ${app.name.padEnd(12)} can't force ISR pages to render: ${reason}. Warming with plain requests; a page Next cached at build is served from that cache until its revalidate window ends.`,\n\t);\n\treturn {};\n}\n\n/**\n * The SNS subscriptions the stage's providers made before the workers were\n * up: each still pending is subscribed again, so SNS resends its\n * confirmation to a worker now there to answer it, and waited on. One still\n * pending after that is said, not failed on — every app is healthy, and\n * rolling them back would not confirm it.\n */\nasync function confirmSubscriptions(\n\tctx: ComposeContext,\n\trun: ComposeRun,\n\tdeps: ComposeDeps,\n): Promise<void> {\n\tconst stored = await ctx.state.read(ctx.stage);\n\tconst confirm = deps.confirmSubscriptions ?? confirmPendingSubscriptions;\n\tconst left = await confirm({\n\t\tworkspace: ctx.workspace,\n\t\tstage: ctx.stage,\n\t\tsecrets: run.secrets?.custom ?? {},\n\t\tresources: stored?.resources,\n\t\tenv: deps.env,\n\t\tlog: (line) => ctx.logger.info(line),\n\t\trecord: async (record) => {\n\t\t\tconst { updatedAt: _, updatedBy: __, ...input } = record;\n\t\t\tawait ctx.state.putResource(ctx.stage, input);\n\t\t},\n\t});\n\tif (left.length > 0) {\n\t\tctx.logger.warn(`⚠ ${new PushSubscriptionsUnconfirmed(left).message}`);\n\t}\n}\n\n/**\n * A container's own health check, as Docker reports it: a worker's, which\n * has no route through the edge, and OpenObserve's — by default it has no\n * host there, and served publicly it answers only the addresses it allows,\n * which need not include this one.\n */\nasync function checkContainer(\n\tctx: ComposeContext,\n\trun: ComposeRun,\n\tdeps: ComposeDeps,\n\tservice: string,\n): Promise<{ app: string; url: string; last: string; healthy: boolean }> {\n\tconst url = `docker:${service}`;\n\tlet last = 'not asked';\n\n\tfor (let attempt = 1; attempt <= deps.healthAttempts; attempt++) {\n\t\tctx.signal.throwIfAborted();\n\t\tconst health = await deps.docker\n\t\t\t.health(run.ref, service)\n\t\t\t.catch((error: unknown) =>\n\t\t\t\terror instanceof Error ? error.message : String(error),\n\t\t\t);\n\t\tlast = health ?? 'not running';\n\t\tconst healthy = health === 'healthy';\n\t\tctx.emit({\n\t\t\ttype: 'health.checked',\n\t\t\tapp: service,\n\t\t\turl,\n\t\t\thealthy,\n\t\t\tattempt,\n\t\t});\n\t\tif (healthy) {\n\t\t\tctx.logger.info(` ✓ ${service.padEnd(12)} ${url} (${last})`);\n\t\t\treturn { app: service, url, last, healthy };\n\t\t}\n\t\tif (attempt < deps.healthAttempts) {\n\t\t\tawait new Promise((resolve) =>\n\t\t\t\tsetTimeout(resolve, deps.healthIntervalMs),\n\t\t\t);\n\t\t}\n\t}\n\n\tctx.logger.warn(` ✗ ${service.padEnd(12)} ${url} (${last})`);\n\treturn { app: service, url, last, healthy: false };\n}\n\n/** A login, as the `Authorization` header that carries it. */\nfunction basicAuthorization(auth: SiteAuth): string {\n\treturn `Basic ${Buffer.from(`${auth.user}:${auth.password}`).toString('base64')}`;\n}\n\n/** How to open the logs, printed — and as an event, for a headless caller. */\nfunction reportLogs(\n\tctx: ComposeContext,\n\tlogs: StackLogs,\n\tlocal: boolean,\n\tserver: ComposeServer | undefined,\n): void {\n\tconst lines = logsAccess(logs, {\n\t\tstage: ctx.stage,\n\t\tlocal,\n\t\tuser: server?.user ?? currentUser(),\n\t\thostname: server?.host ?? hostname(),\n\t\t...(server ? { known: true } : {}),\n\t});\n\tctx.logger.info(`\\n${lines.join('\\n')}`);\n\tctx.emit({\n\t\ttype: 'logs.ready',\n\t\tservice: LOGS_SERVICE,\n\t\taccess: logs.public ? 'public' : 'tunnel',\n\t\turl: logs.url,\n\t\t...(logs.public ? { allow: [...logs.public.allow] } : { port: logs.port }),\n\t\temail: logs.email,\n\t});\n}\n\n/** This machine's user — a guess at who would SSH in. */\nfunction currentUser(): string {\n\ttry {\n\t\treturn userInfo().username;\n\t} catch {\n\t\treturn process.env.USER ?? 'user';\n\t}\n}\n\nasync function checkApp(\n\tctx: ComposeContext,\n\tapp: StackApp,\n\tdeps: ComposeDeps,\n\toptions: {\n\t\tca: string | undefined;\n\t\tedge?: { connectTo: string; connectPort?: number };\n\t},\n): Promise<{ app: string; url: string; last: string; healthy: boolean }> {\n\t// A WebSocket surface answers its health over plain HTTPS on its host.\n\tconst url = `${app.url.replace(/^ws/, 'http')}${app.kind === 'site' ? '/' : '/health'}`;\n\tlet last = 'not asked';\n\n\tfor (let attempt = 1; attempt <= deps.healthAttempts; attempt++) {\n\t\tctx.signal.throwIfAborted();\n\t\tlet status: number | undefined;\n\t\ttry {\n\t\t\tstatus = await deps.probe({\n\t\t\t\turl,\n\t\t\t\t...(options.ca ? { ca: options.ca } : {}),\n\t\t\t\t...(app.auth ? { authorization: basicAuthorization(app.auth) } : {}),\n\t\t\t\t...options.edge,\n\t\t\t\ttimeoutMs: 10_000,\n\t\t\t\tsignal: ctx.signal,\n\t\t\t});\n\t\t\tlast = `HTTP ${status}`;\n\t\t} catch (error) {\n\t\t\tlast = error instanceof Error ? error.message : String(error);\n\t\t}\n\n\t\tconst healthy = status !== undefined && isHealthy(status);\n\t\tctx.emit({\n\t\t\ttype: 'health.checked',\n\t\t\tapp: app.name,\n\t\t\turl,\n\t\t\thealthy,\n\t\t\t...(status !== undefined ? { status } : {}),\n\t\t\tattempt,\n\t\t});\n\t\tif (healthy) {\n\t\t\tctx.logger.info(` ✓ ${app.name.padEnd(12)} ${url} (${last})`);\n\t\t\treturn { app: app.name, url, last, healthy };\n\t\t}\n\t\tif (attempt < deps.healthAttempts) {\n\t\t\tawait new Promise((resolve) =>\n\t\t\t\tsetTimeout(resolve, deps.healthIntervalMs),\n\t\t\t);\n\t\t}\n\t}\n\n\tctx.logger.warn(` ✗ ${app.name.padEnd(12)} ${url} (${last})`);\n\treturn { app: app.name, url, last, healthy: false };\n}\n\n// ============================================================================\n// result\n// ============================================================================\n\nexport function composeResult(\n\tctx: ComposeContext,\n\trun: ComposeRun,\n): DeployResult {\n\tconst apps = [\n\t\t...run.stack.apps.map((app) => {\n\t\t\tconst image = run.images[app.name];\n\t\t\treturn {\n\t\t\t\tappName: app.name,\n\t\t\t\ttype: app.kind === 'site' ? ('web' as const) : ('backend' as const),\n\t\t\t\tsuccess: !ctx.dryRun,\n\t\t\t\tapplicationId: `${run.stack.project}/${app.name}`,\n\t\t\t\timageRef: image?.ref ?? app.ref,\n\t\t\t\t...(image?.digest ? { digest: image.digest } : {}),\n\t\t\t\turl: app.url,\n\t\t\t};\n\t\t}),\n\t\t...[...run.stack.workers, ...run.stack.processors].map((worker) => {\n\t\t\tconst image = run.images[worker.name];\n\t\t\treturn {\n\t\t\t\tappName: worker.name,\n\t\t\t\ttype: 'backend' as const,\n\t\t\t\tsuccess: !ctx.dryRun,\n\t\t\t\tapplicationId: `${run.stack.project}/${worker.name}`,\n\t\t\t\timageRef: image?.ref ?? worker.ref,\n\t\t\t\t...(image?.digest ? { digest: image.digest } : {}),\n\t\t\t};\n\t\t}),\n\t];\n\treturn {\n\t\tapps,\n\t\tprojectId: run.stack.project,\n\t\tsuccessCount: ctx.dryRun ? 0 : apps.length,\n\t\tfailedCount: 0,\n\t\tstage: ctx.stage,\n\t\tidentity: ctx.identity.key,\n\t\ttag: stageTag(ctx.tag, ctx.stage),\n\t\tdryRun: ctx.dryRun,\n\t\tenvironmentId: '',\n\t\tskipped: [...ctx.skipped],\n\t\turls: Object.fromEntries(run.stack.apps.map((app) => [app.name, app.url])),\n\t\tchanges: run.changes,\n\t};\n}\n\n// ============================================================================\n// Files\n// ============================================================================\n\n/** The shared edge's compose file, as this machine hands it to compose. */\nfunction edgeFile(run: ComposeRun): string {\n\treturn join(run.dir, `${EDGE_PROJECT}.yml`);\n}\n\nfunction applied(\n\tctx: ComposeContext,\n\trun: ComposeRun,\n\tchange: ResourceChange & {\n\t\tid: string;\n\t\tvia: 'recorded' | 'resumed' | 'found' | 'created';\n\t},\n): void {\n\tconst { via, ...rest } = change;\n\trun.changes.push(rest);\n\tctx.emit({ type: 'resource.applied', ...rest, via });\n}\n\n/**\n * The root the check after a start trusts, PEM: gkm's on the local stage that\n * set no certificate of its own, and otherwise the one the stage's own names\n * (`deploy.compose.tls.<stage>.caFile`). Undefined — Node's own roots, and\n * `NODE_EXTRA_CA_CERTS` — for a certificate that names none: a public CA's.\n */\nexport async function verifyAuthority(\n\tstack: Pick<ComposeStack, 'authority' | 'tls'>,\n): Promise<string | undefined> {\n\tif (stack.authority) return (await readLocalAuthority(stack.authority)).cert;\n\tif (stack.tls?.caFile) return readFile(stack.tls.caFile, 'utf-8');\n\treturn undefined;\n}\n\n/**\n * The certificate the stack's proxy serves, PEM: the stage's own where it set\n * one, the one gkm's local CA issued the local stage otherwise, and none — a\n * deployed stage's comes from Let's Encrypt — when neither.\n */\nasync function edgeCertificate(\n\tdir: string,\n\tstack: ComposeStack,\n): Promise<{ cert: string; key: string } | undefined> {\n\tif (stack.tls) {\n\t\treturn {\n\t\t\tcert: await readFile(stack.tls.certFile, 'utf-8'),\n\t\t\tkey: await readFile(stack.tls.keyFile, 'utf-8'),\n\t\t};\n\t}\n\tif (stack.authority) {\n\t\treturn localEdgeCertificate(dir, stack, stack.authority);\n\t}\n\treturn undefined;\n}\n\n/** Where the local stage's edge certificate is kept, between runs. */\nexport const LOCAL_EDGE_CERTIFICATE = 'local-edge.pem';\n\n/**\n * The local stage's edge certificate, from gkm's local CA: the one kept in\n * the stack's directory while it still covers every host, so an unchanged\n * stack does not recreate its Caddy for a new certificate each run.\n */\nasync function localEdgeCertificate(\n\tdir: string,\n\tstack: ComposeStack,\n\tauthority: LocalAuthorityPaths,\n): Promise<{ cert: string; key: string }> {\n\tconst { cert, key } = await ensureLocalCertificate(\n\t\tawait ensureLocalAuthority(authority),\n\t\tlocalCertificateNames(stack.resolution.project ?? '', stackHosts(stack)),\n\t\tjoin(dir, LOCAL_EDGE_CERTIFICATE),\n\t);\n\treturn { cert, key };\n}\n\n/** Write the stack's files: owner-only, since the env files hold secrets. */\nasync function writeStack(\n\troot: string,\n\tdir: string,\n\tstack: ComposeStack,\n): Promise<string[]> {\n\tawait mkdir(dir, { recursive: true, mode: 0o700 });\n\tawait chmod(dir, 0o700);\n\n\tconst files: string[] = [];\n\tconst write = async (path: string, content: string, mode = 0o644) => {\n\t\tawait mkdir(dirname(path), { recursive: true });\n\t\tawait writeFile(path, content, { mode });\n\t\tawait chmod(path, mode);\n\t\tfiles.push(path);\n\t};\n\n\t// Caddy's files go inline, in the compose file: nothing the stack runs\n\t// mounts a path on this machine, so the same file runs on a server's\n\t// engine over SSH. With the stage's own key in it, it is owner-only.\n\t// Behind the shared edge, the certificate is written into the edge as the\n\t// stack registers with it (`writeEdgeRoutes`); the local stage's is still\n\t// issued here, kept beside the stack between runs.\n\tconst issued = await edgeCertificate(dir, stack);\n\tconst tls = stack.proxy === 'caddy' ? issued : undefined;\n\tconst compose =\n\t\tstack.caddyfile !== undefined\n\t\t\t? withCaddyConfigs(stack.compose, {\n\t\t\t\t\tcaddyfile: stack.caddyfile,\n\t\t\t\t\t...(tls ? { tls } : {}),\n\t\t\t\t})\n\t\t\t: stack.compose;\n\tawait write(\n\t\tjoin(dir, 'docker-compose.yml'),\n\t\tcomposeYaml(stack, compose),\n\t\ttls ? 0o600 : 0o644,\n\t);\n\t// For reading: the proxy's configuration — the stack's own Caddy's, or a\n\t// copy of what the stack registers with the shared edge. The other is\n\t// removed, so the directory never shows a proxy the stack does not use.\n\tif (stack.caddyfile !== undefined) {\n\t\tawait write(join(dir, 'Caddyfile'), stack.caddyfile);\n\t\tawait rm(join(dir, 'traefik.yml'), { force: true });\n\t} else {\n\t\tawait rm(join(dir, 'Caddyfile'), { force: true });\n\t}\n\tif (stack.traefik !== undefined) {\n\t\tawait write(join(dir, 'traefik.yml'), stack.traefik);\n\t}\n\t// The copy of the stage's certificate an older gkm mounted from here.\n\tawait rm(join(dir, 'tls'), { recursive: true, force: true });\n\t// Env files stay on this machine: compose reads each one here and sends\n\t// its values in the call that creates the container — on a server's\n\t// engine too, where no secret is ever written as a file.\n\tfor (const app of [...stack.apps, ...stack.workers, ...stack.processors]) {\n\t\tif (app.env)\n\t\t\tawait write(join(dir, `${app.name}.env`), envFile(app.env), 0o600);\n\t}\n\t// A stack that only builds reads no env file, so none is written.\n\tif (stack.logs && stack.compose.services[LOGS_SERVICE]?.env_file) {\n\t\tawait write(\n\t\t\tjoin(dir, `${LOGS_SERVICE}.env`),\n\t\t\tenvFile(stack.logs.env),\n\t\t\t0o600,\n\t\t);\n\t}\n\tif (stack.redis && stack.compose.services[REDIS_SERVICE]?.env_file) {\n\t\tawait write(\n\t\t\tjoin(dir, `${REDIS_SERVICE}.env`),\n\t\t\tenvFile(stack.redis.env),\n\t\t\t0o600,\n\t\t);\n\t}\n\t// The backups image's build context, and its key — read from its own env\n\t// file like any app's, never from the host.\n\tif (stack.backups) {\n\t\tfor (const [name, content] of Object.entries(stack.backups.files)) {\n\t\t\tawait write(join(dir, BACKUPS_SERVICE, name), content);\n\t\t}\n\t\tif (stack.compose.services[BACKUPS_SERVICE]?.env_file) {\n\t\t\tawait write(\n\t\t\t\tjoin(dir, `${BACKUPS_SERVICE}.env`),\n\t\t\t\tenvFile(stack.backups.env),\n\t\t\t\t0o600,\n\t\t\t);\n\t\t}\n\t} else {\n\t\tawait rm(join(dir, BACKUPS_SERVICE), { recursive: true, force: true });\n\t\tawait rm(join(dir, `${BACKUPS_SERVICE}.env`), { force: true });\n\t}\n\t// Point-in-time recovery: Postgres's own build context, and WAL-G's key.\n\tconst pitr = stack.backups?.pitr;\n\tif (pitr) {\n\t\tfor (const [name, content] of Object.entries(pitr.postgres.files)) {\n\t\t\tawait write(join(dir, POSTGRES_SERVICE, name), content);\n\t\t}\n\t\tif (stack.compose.services[POSTGRES_SERVICE]?.env_file) {\n\t\t\tawait write(\n\t\t\t\tjoin(dir, `${POSTGRES_SERVICE}.env`),\n\t\t\t\tenvFile(pitr.postgres.env),\n\t\t\t\t0o600,\n\t\t\t);\n\t\t}\n\t} else {\n\t\tawait rm(join(dir, POSTGRES_SERVICE), { recursive: true, force: true });\n\t\tawait rm(join(dir, `${POSTGRES_SERVICE}.env`), { force: true });\n\t}\n\t// Images no longer embed a stage's credentials. The ciphertexts an older\n\t// gkm left beside the compose file for them to embed are removed.\n\tfor (const entry of await readdir(dir)) {\n\t\tif (entry.endsWith('.credentials')) await rm(join(dir, entry));\n\t}\n\tfor (const [path, content] of Object.entries(stack.dockerfiles)) {\n\t\tawait write(join(root, path), content);\n\t}\n\n\t// The build context is the build root, and the env files are under it:\n\t// its ignore file is what keeps a stage's secrets out of every image's\n\t// context.\n\tawait ensureDockerignore(findBuildRoot(root));\n\n\treturn files;\n}\n\nfunction composeYaml(\n\tstack: ComposeStack,\n\tcompose: ComposeStack['compose'],\n): string {\n\tconst stage = ` --stage ${stack.stage}`;\n\treturn `# Generated by gkm compose from the construct manifest — do not edit.\n# The ${stack.stage} stage's APIs and sites behind ${stack.proxy === 'caddy' ? 'one Caddy' : `the shared Traefik edge (${EDGE_PROJECT})`}, and its workers.\n# Each backend and worker reads exactly the keys in its own env file beside\n# this one.\n#\n# gkm compose${stage} start or update it\n# gkm compose${stage} --down stop it\n${stringify(composeLiterals(compose), { lineWidth: 0, aliasDuplicateObjects: false })}`;\n}\n\n/**\n * The stack with each inline config's content escaped for compose, which\n * would otherwise read every `$` in it — a bcrypt hash's in the Caddyfile — as\n * a variable. Done here, where the file is written, so no inline file escapes\n * it: the stack itself holds each file as the container is to read it.\n */\nfunction composeLiterals(\n\tcompose: ComposeStack['compose'],\n): ComposeStack['compose'] {\n\tif (!compose.configs) return compose;\n\treturn {\n\t\t...compose,\n\t\tconfigs: Object.fromEntries(\n\t\t\tObject.entries(compose.configs).map(([name, { content }]) => [\n\t\t\t\tname,\n\t\t\t\t{ content: composeLiteral(content) },\n\t\t\t]),\n\t\t),\n\t};\n}\n\nfunction printPlan(ctx: ComposeContext, run: ComposeRun): void {\n\tconst { stack, mode, files } = run;\n\tctx.logger.info(`\\n🧱 ${stack.project} — stage ${stack.stage}`);\n\tif (run.server) {\n\t\tctx.logger.info(` → ${sshTarget(run.server)} (docker over ssh)`);\n\t}\n\tfor (const app of stack.apps) {\n\t\tctx.logger.info(\n\t\t\t` ${app.name.padEnd(12)} ${app.url.padEnd(40)} ${mode} ${app.ref}`,\n\t\t);\n\t}\n\tfor (const worker of stack.workers) {\n\t\tctx.logger.info(\n\t\t\t` ${worker.name.padEnd(12)} ${`worker ${worker.id} (no route)`.padEnd(40)} ${mode} ${worker.ref}`,\n\t\t);\n\t}\n\tfor (const unit of stack.processors) {\n\t\tctx.logger.info(\n\t\t\t` ${unit.name.padEnd(12)} ${`processors of ${unit.id}`.padEnd(40)} ${mode} ${unit.ref}`,\n\t\t);\n\t}\n\tif (stack.infra.length > 0) {\n\t\tctx.logger.info(` infrastructure: ${stack.infra.join(', ')}`);\n\t}\n\tif (stack.backups) {\n\t\tctx.logger.info(\n\t\t\t` ${BACKUPS_SERVICE.padEnd(12)} ${stack.backups.databases.map((d) => d.file).join(', ')} — ${stack.backups.backups.describe}, to ${stack.backups.prefix}/`,\n\t\t);\n\t\tif (stack.backups.pitr) {\n\t\t\tctx.logger.info(\n\t\t\t\t` ${''.padEnd(12)} ${stack.backups.pitr.pitr.describe}, to ${stack.backups.pitr.prefix}/`,\n\t\t\t);\n\t\t}\n\t}\n\tctx.logger.info(\n\t\t`\\n📝 Wrote ${files.length} file(s) under ${stackDir(stack.stage)}/`,\n\t);\n}\n","/**\n * The built-in `compose` target: a stage as one Docker Compose stack behind\n * Caddy — the local stage on the machine that runs the deploy, a deployed\n * stage on its server's Docker engine, over SSH (`deploy.compose.server`).\n *\n * ```bash\n * gkm deploy --target compose --stage production --tag v1.4.0 # what CI pushed\n * gkm deploy --target compose --stage production # built from here\n * gkm deploy --target compose --stage development # the local stage\n * ```\n *\n * - `validate`: the stack (`composeStack`, pure) and, for a tag, every image\n * looked up in the registry — `ImageTagNotFound` before anything changes\n * - `ready`: a deploy's own checks, after the stage's keys are — the stage's\n * certificate, its server's address, and every public host's DNS\n * - `plan`: the stack's files and what a run would create or reuse\n * - `provision`: generated secrets kept, files written, infrastructure up,\n * databases, roles, grants and migrations\n * - `build`: each backend bundled on the host and every image built — or, for\n * a tag, pulled. A site that pre-renders against its stage\n * (`prerender: 'stage'`) is held back, but for a push, which first asks the\n * running stage's APIs and builds it against them\n * - `release`: the stack's routes on the shared edge; a held-back site built\n * once the rest of the stack is up and its APIs answer through the edge;\n * then `up --wait\n * --remove-orphans`, and each app's image, tag and digest in the stage's\n * state — an app that never turns healthy fails it only once the rest is\n * released and routed\n * - `verify`: each app asked through Caddy over HTTPS, then each\n * server-rendered site warmed — its `/` and its sitemap's pages asked, a\n * failure only warned of\n *\n * With `push` (`gkm compose --build --push`), run with `buildOnly`, it builds\n * every image and pushes it to `deploy.registry`, and does nothing else: no\n * readiness check runs, so a stage whose keys the deploy has yet to write\n * still builds.\n *\n * `gkm compose` is this target with a few more switches (`--build`, `--pull`,\n * `--down`), run through the same `deploy()`.\n */\n\nimport { defineTarget } from '../define';\nimport type { DeployTarget } from '../types';\nimport {\n\tbuildCompose,\n\ttype ComposeDeps,\n\ttype ComposeRun,\n\ttype ComposeRunOptions,\n\tcomposeResult,\n\tdefaultDeps,\n\tplanCompose,\n\tprovisionCompose,\n\treadyCompose,\n\treleaseCompose,\n\tvalidateCompose,\n\tverifyCompose,\n} from './phases';\n\nexport { EdgePortInvalid, edgePorts } from '../../compose/edge';\nexport {\n\tComposeAppsUnhealthy,\n\ttype HealthProbe,\n\ttype HealthRequest,\n\tHealthRequestTimedOut,\n} from './health';\nexport {\n\ttype ComposeDeps,\n\ttype ComposeImage,\n\tComposePinNeedsPull,\n\tComposePushNeedsBuild,\n\ttype ComposeRun,\n\ttype ComposeRunOptions,\n\tgitRevision,\n\tNoGitRevision,\n\tRedisClientMissing,\n\tstackOverrideFile,\n} from './phases';\n\nexport interface ComposeTargetOptions\n\textends Partial<ComposeDeps>,\n\t\tComposeRunOptions {\n\t/** Handed the finished run — `gkm compose` prints and returns from it. */\n\treport?: (run: ComposeRun) => void;\n}\n\n/** The compose target, with its Docker, bundler and probe as given. */\nexport function composeTarget(\n\toptions: ComposeTargetOptions = {},\n): DeployTarget<undefined, ComposeRun> {\n\tconst { mode, push, pin, report, ...given } = options;\n\tconst deps: ComposeDeps = { ...defaultDeps, ...given };\n\n\treturn defineTarget<undefined, ComposeRun>({\n\t\tname: 'compose',\n\t\truntime: 'server',\n\t\tcapabilities: {\n\t\t\trollback: false,\n\t\t\tmigrations: 'target',\n\t\t\timages: true,\n\t\t\t// The local stage runs where the deploy does — the `gkm dev`\n\t\t\t// hostnames, behind gkm's local CA.\n\t\t\tlocalStage: true,\n\t\t\t// OpenObserve, in the stack, on loopback.\n\t\t\tselfHostedTelemetry: true,\n\t\t},\n\t\t// Images are pulled with this machine's own `docker login`, which\n\t\t// docker sends with each pull — on a server's engine too.\n\t\tcredentials: [],\n\t\t// Built from the checkout, an image is named after its commit.\n\t\ttag: ({ cwd }) => deps.revision(cwd),\n\t\tvalidate: (ctx) =>\n\t\t\tvalidateCompose(ctx, deps, {\n\t\t\t\t...(mode ? { mode } : {}),\n\t\t\t\t...(push ? { push } : {}),\n\t\t\t\t...(pin ? { pin } : {}),\n\t\t\t}),\n\t\tready: (ctx, run) => readyCompose(ctx, run, deps),\n\t\tplan: (ctx, run) => planCompose(ctx, run),\n\t\tprovision: (ctx, run) => provisionCompose(ctx, run, deps),\n\t\tbuild: (ctx, run) => buildCompose(ctx, run, deps),\n\t\trelease: (ctx, run) => releaseCompose(ctx, run, deps),\n\t\tverify: (ctx, run) => verifyCompose(ctx, run, deps),\n\t\tresult: (ctx, run) => {\n\t\t\treport?.(run);\n\t\t\treturn composeResult(ctx, run);\n\t\t},\n\t});\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCA,IAAa,uBAAb,cAA0CA,eAAAA,SAAS;CAExC;CACA;CAFV,YACC,OACA,SACC;EACD,MACC,YAAY,WACT,IAAI,MAAM,yMAGL,MAAM,uDACRC,kBAAAA,gBAAgB,2BAA2BA,kBAAAA,gBAAgB,kBACnD,MAAM,6BACjB,yBAAyB,MAAM,uBAAuB,MAAM,WACzDA,kBAAAA,gBAAgB,iDAChBA,kBAAAA,gBAAgB,kBAAkB,MAAM,kCAClB,MAAM,OACnC;EAfS,KAAA,QAAA;EACA,KAAA,UAAA;EAeT,KAAK,OAAO;CACb;AACD;;AAGA,IAAa,2BAAb,cAA8CD,eAAAA,SAAS;CAE5C;CACA;CAFV,YACC,QACA,QACC;EACD,MACC,6BAA6B,OAAO,uBAAuB,OAAO,KAAK,KAAK,UAAU,sBACjE,OAAO,0JAG7B;EARS,KAAA,SAAA;EACA,KAAA,SAAA;EAQT,KAAK,OAAO;CACb;AACD;;AAGA,IAAa,sBAAb,cAAyCA,eAAAA,SAAS;CAEvC;CACA;CACA;CAHV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