fix(deployment): harden backend core recovery

This commit is contained in:
Codex
2026-05-17 11:36:10 +00:00
parent 6e5f33fac2
commit b281906e19
3 changed files with 18 additions and 3 deletions
+15
View File
@@ -27,6 +27,7 @@ export function isRebuildableService(value: string | undefined): value is Rebuil
}
export function resolveComposeCommand(config: UniDeskConfig, envFile: string): string[] {
assertCanonicalServerRoot(config);
const composeFile = rootPath(config.docker.composeFile);
if (commandOk(["docker", "compose", "version"], repoRoot)) {
return ["docker", "compose", "--env-file", envFile, "-f", composeFile, "-p", config.docker.projectName];
@@ -52,7 +53,21 @@ function envValue(value: string): string {
return JSON.stringify(value);
}
function assertCanonicalServerRoot(config: UniDeskConfig): void {
const canonicalRoot = resolve(config.providerGateway.upgrade.hostProjectRoot);
const currentRoot = resolve(repoRoot);
if (currentRoot !== canonicalRoot) {
throw new Error([
"Main-server Docker Compose commands must run from the canonical UniDesk root.",
`canonicalRoot=${canonicalRoot}`,
`currentRoot=${currentRoot}`,
`Run from the canonical root: cd ${canonicalRoot} && bun scripts/cli.ts server <start|status|logs|rebuild|stop>`,
].join(" "));
}
}
export function writeComposeEnv(config: UniDeskConfig, freshLogPrefix: boolean): ComposeRuntimeEnv {
assertCanonicalServerRoot(config);
const stateDir = rootPath(config.paths.stateDir);
mkdirSync(stateDir, { recursive: true });
const envFile = join(stateDir, "docker-compose.env");