feat: add d601 dev core manifests
This commit is contained in:
@@ -138,11 +138,34 @@ function readMicroservicesEnv(): MicroserviceConfig[] {
|
||||
return parsed.map(parseMicroserviceConfig);
|
||||
}
|
||||
|
||||
function optionalEnv(name: string): string {
|
||||
return process.env[name]?.trim() ?? "";
|
||||
}
|
||||
|
||||
function databaseNameFromUrl(databaseUrl: string): string {
|
||||
try {
|
||||
return new URL(databaseUrl).pathname.replace(/^\/+/u, "");
|
||||
} catch {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
export function readConfig(): RuntimeConfig {
|
||||
const databaseUrl = requiredEnv("DATABASE_URL");
|
||||
return {
|
||||
port: readNumberEnv("PORT"),
|
||||
providerPort: readNumberEnv("PROVIDER_PORT"),
|
||||
databaseUrl: requiredEnv("DATABASE_URL"),
|
||||
databaseUrl,
|
||||
identity: {
|
||||
environment: optionalEnv("UNIDESK_ENV") || "prod",
|
||||
namespace: optionalEnv("UNIDESK_NAMESPACE"),
|
||||
databaseName: optionalEnv("UNIDESK_DATABASE_NAME") || optionalEnv("UNIDESK_DEV_DATABASE_NAME") || databaseNameFromUrl(databaseUrl),
|
||||
deployRef: optionalEnv("UNIDESK_DEPLOY_REF"),
|
||||
serviceId: optionalEnv("UNIDESK_DEPLOY_SERVICE_ID") || "backend-core",
|
||||
repo: optionalEnv("UNIDESK_DEPLOY_REPO"),
|
||||
commit: optionalEnv("UNIDESK_DEPLOY_COMMIT"),
|
||||
requestedCommit: optionalEnv("UNIDESK_DEPLOY_REQUESTED_COMMIT"),
|
||||
},
|
||||
providerToken: requiredEnv("PROVIDER_TOKEN"),
|
||||
heartbeatTimeoutMs: readNumberEnv("HEARTBEAT_TIMEOUT_MS"),
|
||||
taskPendingTimeoutMs: readOptionalNumberEnv("TASK_PENDING_TIMEOUT_MS", 10 * 60 * 1000),
|
||||
|
||||
@@ -146,11 +146,3 @@ export function closeEgressTcpConnectionsForSocket(provider: ProviderSocket): vo
|
||||
connection.socket.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
export function closeEgressTcpConnectionsForSocket(provider: ProviderSocket): void {
|
||||
for (const [key, connection] of ctx.activeEgressTcpConnections) {
|
||||
if (connection.provider !== provider) continue;
|
||||
ctx.activeEgressTcpConnections.delete(key);
|
||||
connection.socket.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,6 +42,30 @@ ctx.sql = postgres(runtimeConfig.databaseUrl, {
|
||||
}
|
||||
})();
|
||||
|
||||
function isDevIdentity(): boolean {
|
||||
const identity = config().identity;
|
||||
return identity.environment === "dev" || identity.namespace === "unidesk-dev";
|
||||
}
|
||||
|
||||
function healthPayload(): Record<string, unknown> {
|
||||
const base = { ok: true, service: "unidesk-core", dbReady: ctx.dbReady, startedAt: ctx.serviceStartedAt.toISOString() };
|
||||
if (!isDevIdentity()) return base;
|
||||
const identity = config().identity;
|
||||
return {
|
||||
...base,
|
||||
environment: identity.environment,
|
||||
namespace: identity.namespace,
|
||||
databaseName: identity.databaseName,
|
||||
serviceId: identity.serviceId,
|
||||
deployRef: identity.deployRef,
|
||||
deploy: {
|
||||
repo: identity.repo,
|
||||
commit: identity.commit,
|
||||
requestedCommit: identity.requestedCommit,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
async function routeInner(req: Request, server: Server<WsData>): Promise<Response | undefined> {
|
||||
const url = new URL(req.url);
|
||||
if (req.method === "OPTIONS") return jsonResponse({ ok: true });
|
||||
@@ -49,7 +73,7 @@ async function routeInner(req: Request, server: Server<WsData>): Promise<Respons
|
||||
try {
|
||||
if (url.pathname === "/ws/ssh") return sshRoute(req, server);
|
||||
if (url.pathname === "/" || url.pathname === "/health") {
|
||||
return jsonResponse({ ok: true, service: "unidesk-core", dbReady: ctx.dbReady, startedAt: ctx.serviceStartedAt.toISOString() });
|
||||
return jsonResponse(healthPayload());
|
||||
}
|
||||
if (!ctx.dbReady && url.pathname.startsWith("/api/")) {
|
||||
return jsonResponse({ ok: false, error: "database not ready" }, 503);
|
||||
|
||||
@@ -7,6 +7,7 @@ export interface RuntimeConfig {
|
||||
port: number;
|
||||
providerPort: number;
|
||||
databaseUrl: string;
|
||||
identity: RuntimeIdentity;
|
||||
providerToken: string;
|
||||
heartbeatTimeoutMs: number;
|
||||
taskPendingTimeoutMs: number;
|
||||
@@ -19,6 +20,17 @@ export interface RuntimeConfig {
|
||||
databasePoolMax: number;
|
||||
}
|
||||
|
||||
export interface RuntimeIdentity {
|
||||
environment: string;
|
||||
namespace: string;
|
||||
databaseName: string;
|
||||
deployRef: string;
|
||||
serviceId: string;
|
||||
repo: string;
|
||||
commit: string;
|
||||
requestedCommit: string;
|
||||
}
|
||||
|
||||
export interface MicroserviceConfig {
|
||||
id: string;
|
||||
name: string;
|
||||
|
||||
Reference in New Issue
Block a user