fix(dashboard): properly pass .env vars to docker compose subprocess
## Problem
When the dashboard called `docker compose up -d llama` etc., it relied on:
1. process.env inherited by the dashboard container — only contains the
vars explicitly listed in compose.yaml's environment: section
(HOST_PROJECT_PATH, PROJECT_DIR, LLAMA_MODELS_DIR, NODE_INSTANCE)
2. compose's own --env-file (.env) lookup — but this depends on CWD which
can differ
Critically, compose needs more than just HOST_PROJECT_PATH:
- TAILSCALE_HOSTNAME (used in container_name)
- TS_AUTHKEY (needed by tailscale service if started)
- WEBDAV_USER, WEBDAV_PASS (needed by webdav service)
- LLAMA_MODEL, LLAMA_EXTRA_ARGS (used by llama service command)
- COMFY_RUN_HOST, COMFY_BASE_HOST (used by comfyui service)
- COMFY_EXTRA_ARGS (used by comfyui service)
Previously these were silently absent. `gpuctl` shells handle this by
explicitly exporting them before `docker compose` — the dashboard now does
the same.
## Fix
### `dashboard/src/lib/docker.ts`
- Added `loadEnvFile()` and `readEnvSync()` — parse `/project/.env` once
and cache it. Handles quoted values, comments, blank lines.
- Added `envOrFile(key, fallback)` — resolves env value from process.env
first, then .env file, then fallback.
- `HOST_PROJECT_PATH` and `TAILSCALE_HOSTNAME` now resolved via envOrFile
(was hardcoded fallback to '/project').
- Added `validateComposeEnv()` — returns null if all required vars are set,
or an error message describing the first missing var. Mirrors
`require_host_project_path` in ssh/scripts/common.sh.
- `composeEnv()` now includes:
* process.env (for PATH, HOME, etc.)
* .env file contents (TS_AUTHKEY, WEBDAV_*, etc.)
* Explicit overrides for TAILSCALE_HOSTNAME, HOST_PROJECT_PATH, NODE_INSTANCE
* Caller-provided extras (LLAMA_MODEL, LLAMA_EXTRA_ARGS, COMFY_EXTRA_ARGS)
- `runCompose()` now calls `validateComposeEnv()` before any `up`/`start`
operation. If validation fails, returns a clear error instead of letting
compose silently resolve ${HOST_PROJECT_PATH:-./} to './'.
- `writeEnvLlamaConfig()` invalidates the .env cache after writing, so the
next composeEnv() picks up the new LLAMA_MODEL/LLAMA_EXTRA_ARGS.
### `compose.yaml` — dashboard service
- Added `TAILSCALE_HOSTNAME: ${TAILSCALE_HOSTNAME:-gpu-node}` to the
environment: section. Was previously missing — dashboard couldn't see the
hostname without reading .env.
### `dashboard/src/app/api/debug/route.ts`
- Now also returns:
* TAILSCALE_HOSTNAME in env block
* comfyTypes (list of subdirs under gpu/comfy/models)
* envValidation: { ok, error } — result of validateComposeEnv()
* Whether LLAMA_MODELS_DIR actually exists and has files
After deploy, `curl http://gpu-node:8090/api/debug` will show:
- Whether HOST_PROJECT_PATH is the real host path or just '/project'
- Whether .env has all the vars compose needs
- Whether /project/gpu/llama_models has any .gguf files
- What subdirs /project/gpu/comfy/models has
This commit is contained in:
@@ -6,8 +6,10 @@ import {
|
||||
HOST_PROJECT_PATH,
|
||||
LLAMA_MODELS_DIR,
|
||||
NODE_INSTANCE,
|
||||
TAILSCALE_HOSTNAME,
|
||||
ENV_FILE_PATH,
|
||||
DASHBOARD_CONFIG_PATH,
|
||||
validateComposeEnv,
|
||||
} from "@/lib/docker";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
@@ -21,6 +23,7 @@ export const runtime = "nodejs";
|
||||
* - Whether key paths exist
|
||||
* - Directory listings of PROJECT_DIR and LLAMA_MODELS_DIR
|
||||
* - Contents of .env (if present) — useful for verifying HOST_PROJECT_PATH was set
|
||||
* - Validation result: are all env vars needed by `docker compose` actually set?
|
||||
*
|
||||
* Useful for diagnosing "models not visible" type issues.
|
||||
*/
|
||||
@@ -58,7 +61,20 @@ export async function GET() {
|
||||
entries: await listDirSafe(comfyModelsDir),
|
||||
});
|
||||
|
||||
// 4. .env file
|
||||
// 4. Comfy subdirs (model types)
|
||||
let comfyTypes: string[] = [];
|
||||
if (await isDirSafe(comfyModelsDir)) {
|
||||
try {
|
||||
const entries = await fs.readdir(comfyModelsDir, { withFileTypes: true });
|
||||
comfyTypes = entries
|
||||
.filter((e) => e.isDirectory() && !e.isSymbolicLink())
|
||||
.map((e) => e.name);
|
||||
} catch {
|
||||
/* ignore */
|
||||
}
|
||||
}
|
||||
|
||||
// 5. .env file (raw contents + parsed)
|
||||
const envExists = await existsSafe(ENV_FILE_PATH);
|
||||
let envContents: string | null = null;
|
||||
if (envExists) {
|
||||
@@ -69,15 +85,19 @@ export async function GET() {
|
||||
}
|
||||
}
|
||||
|
||||
// 5. Dashboard config
|
||||
// 6. Dashboard config
|
||||
const configExists = await existsSafe(DASHBOARD_CONFIG_PATH);
|
||||
|
||||
// 7. Validate env — are all vars needed by docker compose actually set?
|
||||
const envError = await validateComposeEnv();
|
||||
|
||||
return NextResponse.json({
|
||||
env: {
|
||||
PROJECT_DIR,
|
||||
HOST_PROJECT_PATH,
|
||||
LLAMA_MODELS_DIR,
|
||||
NODE_INSTANCE,
|
||||
TAILSCALE_HOSTNAME,
|
||||
ENV_FILE_PATH,
|
||||
DASHBOARD_CONFIG_PATH,
|
||||
// Also expose relevant process.env for debugging
|
||||
@@ -91,8 +111,15 @@ export async function GET() {
|
||||
},
|
||||
},
|
||||
checks,
|
||||
envFile: envExists ? { exists: true, contents: envContents } : { exists: false },
|
||||
comfyTypes,
|
||||
envFile: envExists
|
||||
? { exists: true, contents: envContents }
|
||||
: { exists: false },
|
||||
dashboardConfig: { exists: configExists, path: DASHBOARD_CONFIG_PATH },
|
||||
envValidation: {
|
||||
ok: envError === null,
|
||||
error: envError,
|
||||
},
|
||||
timestamp: new Date().toISOString(),
|
||||
});
|
||||
}
|
||||
@@ -123,3 +150,4 @@ async function listDirSafe(p: string): Promise<string[] | undefined> {
|
||||
return [`[error: ${(err as Error).message}]`];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user