mirror of
https://github.com/Dokploy/dokploy.git
synced 2026-07-28 09:15:24 +02:00
perf: share db, docker and auth singletons across duplicated bundles
The @dokploy/server modules get bundled multiple times per process (esbuild inline copy, compiled node_modules copy, and several Next.js chunks via transpilePackages), so every module-level side effect ran once per copy: up to 6 postgres pools, 6 dockerode clients and 6 better-auth instances in the server process, plus the repeated 'Using Docker socket' logs at boot. - db/index.ts: use the globalThis cache in production too (one pool per process) - constants/index.ts: cache the dockerode client on globalThis - lib/auth.ts: wrap betterAuth() in a factory and cache the instance - Dockerfile: exec node directly instead of leaving pnpm resident (~100MB RSS)
This commit is contained in:
@@ -81,7 +81,17 @@ const getDockerConfig = (): Docker => {
|
||||
return new Docker({ ...versionOption });
|
||||
};
|
||||
|
||||
export const docker = getDockerConfig();
|
||||
// Igual que db: el módulo se evalúa una vez por copia bundleada, el cache
|
||||
// evita crear un cliente (y loguear la detección del socket) por cada una.
|
||||
const globalForDocker = globalThis as unknown as {
|
||||
docker?: Docker;
|
||||
};
|
||||
|
||||
if (!globalForDocker.docker) {
|
||||
globalForDocker.docker = getDockerConfig();
|
||||
}
|
||||
|
||||
export const docker = globalForDocker.docker;
|
||||
|
||||
export const paths = (isServer = false) => {
|
||||
const BASE_PATH =
|
||||
|
||||
Reference in New Issue
Block a user