fix: 降级 D601 host compose status 入口
This commit is contained in:
+92
-2
@@ -20,6 +20,29 @@ export interface ContainerStatus {
|
||||
ports: string;
|
||||
}
|
||||
|
||||
export interface DeprecatedHostComposeEntry {
|
||||
ok: false;
|
||||
error: "deprecated-host-compose-entry";
|
||||
runnerDisposition: "business-failed";
|
||||
hostRole: "d601-provider-host";
|
||||
composeProject: string;
|
||||
cwd: string;
|
||||
message: string;
|
||||
decision: {
|
||||
hostComposeRetained: false;
|
||||
disposition: "deprecated";
|
||||
reason: string;
|
||||
};
|
||||
evidence: {
|
||||
containers: ContainerStatus[];
|
||||
publicPorts: Array<{ name: string; port: number; listening: boolean }>;
|
||||
conflictingListeners: Array<{ name: string; port: number; listening: boolean; expected: string }>;
|
||||
logDir: string;
|
||||
};
|
||||
correctEntrypoints: Record<string, string>;
|
||||
references: string[];
|
||||
}
|
||||
|
||||
const rebuildableServices = ["backend-core", "frontend", "dev-frontend-proxy", "provider-gateway", "todo-note", "project-manager", "baidu-netdisk", "oa-event-flow", "code-queue-mgr"] as const;
|
||||
export type RebuildableService = typeof rebuildableServices[number];
|
||||
|
||||
@@ -103,6 +126,16 @@ function envValue(value: string): string {
|
||||
return JSON.stringify(value);
|
||||
}
|
||||
|
||||
function composeRuntimeEnvPreview(config: UniDeskConfig): ComposeRuntimeEnv {
|
||||
const parts = localDateParts(new Date());
|
||||
return {
|
||||
envFile: join(rootPath(config.paths.stateDir), "docker-compose.env"),
|
||||
logDir: "not-created-on-deprecated-d601-host-compose-entry",
|
||||
logDay: parts.day,
|
||||
logPrefix: parts.stamp,
|
||||
};
|
||||
}
|
||||
|
||||
export function writeComposeEnv(config: UniDeskConfig, freshLogPrefix: boolean): ComposeRuntimeEnv {
|
||||
const stateDir = rootPath(config.paths.stateDir);
|
||||
mkdirSync(stateDir, { recursive: true });
|
||||
@@ -290,9 +323,11 @@ export function composeConfig(config: UniDeskConfig): { runtimeEnv: ComposeRunti
|
||||
}
|
||||
|
||||
export function startStack(config: UniDeskConfig): unknown {
|
||||
const containers = dockerContainers(config);
|
||||
const deprecatedEntry = deprecatedD601HostComposeEntry(config, composeRuntimeEnvPreview(config), containers);
|
||||
if (deprecatedEntry !== null) return deprecatedEntry;
|
||||
const runtimeEnv = writeComposeEnv(config, true);
|
||||
const compose = resolveComposeCommand(config, runtimeEnv.envFile);
|
||||
const containers = dockerContainers(config);
|
||||
const occupiedPorts = fixedPorts(config).filter((item) => item.listening);
|
||||
if (occupiedPorts.length > 0 && containers.length === 0) {
|
||||
throw new Error(`Fixed UniDesk port is occupied before start: ${occupiedPorts.map((p) => `${p.name}:${p.port}`).join(", ")}`);
|
||||
@@ -528,6 +563,9 @@ function dockerExec(config: UniDeskConfig, container: string, command: string[])
|
||||
}
|
||||
|
||||
export async function stackStatus(config: UniDeskConfig): Promise<unknown> {
|
||||
const containers = dockerContainers(config);
|
||||
const deprecatedEntry = deprecatedD601HostComposeEntry(config, composeRuntimeEnvPreview(config), containers);
|
||||
if (deprecatedEntry !== null) return deprecatedEntry;
|
||||
const runtimeEnv = writeComposeEnv(config, false);
|
||||
const runtimeRaw = existsSync(runtimeEnv.envFile) ? readFileSync(runtimeEnv.envFile, "utf8") : "";
|
||||
const runtimeValue = (key: string): string => runtimeRaw.match(new RegExp(`^${key}=(.*)$`, "m"))?.[1]?.replace(/^"|"$/g, "") ?? "";
|
||||
@@ -569,7 +607,7 @@ export async function stackStatus(config: UniDeskConfig): Promise<unknown> {
|
||||
{ name: "baidu-netdisk", containerPort: 4244, hostPort: null },
|
||||
{ name: "oa-event-flow", containerPort: 4255, hostPort: null },
|
||||
],
|
||||
containers: dockerContainers(config),
|
||||
containers,
|
||||
health: {
|
||||
core: coreHealth,
|
||||
frontend: await probe(`http://127.0.0.1:${config.network.frontend.port}/health`),
|
||||
@@ -590,6 +628,58 @@ export async function stackStatus(config: UniDeskConfig): Promise<unknown> {
|
||||
};
|
||||
}
|
||||
|
||||
export function deprecatedD601HostComposeEntryForTest(config: UniDeskConfig, runtimeEnv: ComposeRuntimeEnv, containers: ContainerStatus[], currentRoot: string): DeprecatedHostComposeEntry | null {
|
||||
return deprecatedD601HostComposeEntry(config, runtimeEnv, containers, currentRoot);
|
||||
}
|
||||
|
||||
function deprecatedD601HostComposeEntry(config: UniDeskConfig, runtimeEnv: ComposeRuntimeEnv, containers: ContainerStatus[], currentRoot = repoRoot): DeprecatedHostComposeEntry | null {
|
||||
const cwd = resolve(currentRoot);
|
||||
const d601Workspaces = ["/home/ubuntu/unidesk", "/home/ubuntu/workspace/unidesk-dev", "/workspace/unidesk"];
|
||||
const cwdLooksD601 = d601Workspaces.some((workspace) => cwd === workspace || cwd.startsWith(`${workspace}/.worktree/`));
|
||||
const upgradeRootLooksMainServer = config.providerGateway.upgrade.hostProjectRoot === "/root/unidesk";
|
||||
if (!cwdLooksD601 || !upgradeRootLooksMainServer || containers.length > 0) return null;
|
||||
const publicPorts = fixedPorts(config);
|
||||
const conflictingListeners = publicPorts
|
||||
.filter((item) => item.listening)
|
||||
.map((item) => ({
|
||||
name: item.name,
|
||||
port: item.port,
|
||||
listening: item.listening,
|
||||
expected: "ignored-on-deprecated-d601-host-compose-entry",
|
||||
}));
|
||||
return {
|
||||
ok: false,
|
||||
error: "deprecated-host-compose-entry",
|
||||
runnerDisposition: "business-failed",
|
||||
hostRole: "d601-provider-host",
|
||||
composeProject: config.docker.projectName,
|
||||
cwd,
|
||||
message: "D601 host Compose is not the UniDesk server acceptance path. This command is deprecated here and does not start or validate the main-server stack.",
|
||||
decision: {
|
||||
hostComposeRetained: false,
|
||||
disposition: "deprecated",
|
||||
reason: "D601 owns provider-local Docker services and native k3s workloads; main-server Compose remains rooted at /root/unidesk on the main server.",
|
||||
},
|
||||
evidence: {
|
||||
containers,
|
||||
publicPorts,
|
||||
conflictingListeners,
|
||||
logDir: runtimeEnv.logDir,
|
||||
},
|
||||
correctEntrypoints: {
|
||||
mainServerStatus: "run bun scripts/cli.ts server status from /root/unidesk on the main server",
|
||||
d601NativeK3s: "trans D601:k3s kubectl get deploy,svc,pod,endpoints -n unidesk -o wide",
|
||||
decisionCenter: "bun scripts/cli.ts microservice health decision-center",
|
||||
d601DevDeploy: "bun scripts/cli.ts deploy plan --env dev --service <service>",
|
||||
},
|
||||
references: [
|
||||
"docs/reference/deployment.md#docker-compose-runtime",
|
||||
"docs/reference/dev-environment.md#d601-unidesk-workspace",
|
||||
"docs/reference/deploy.md#d601-native-k3s-emergency-guard",
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
function listLogFiles(root: string): string[] {
|
||||
if (!existsSync(root)) return [];
|
||||
const entries = readdirSync(root, { withFileTypes: true });
|
||||
|
||||
Reference in New Issue
Block a user