Skip to content

Commit 5bff76f

Browse files
committed
Merge branch 'fix/macos-monitoring-cleanup' into 'main'
fix(cli): macOS compatibility, cleanup, and image tag handling See merge request postgres-ai/postgres_ai!147
2 parents 4cdc1d6 + cd7e538 commit 5bff76f

2 files changed

Lines changed: 42 additions & 4 deletions

File tree

cli/bin/postgres-ai.ts

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,8 +1155,14 @@ async function runCompose(args: string[], grafanaPassword?: string): Promise<num
11551155
}
11561156
}
11571157

1158+
// On macOS, node-exporter can't mount host root filesystem - skip it
1159+
const finalArgs = [...args];
1160+
if (process.platform === "darwin" && args.includes("up")) {
1161+
finalArgs.push("--scale", "node-exporter=0");
1162+
}
1163+
11581164
return new Promise<number>((resolve) => {
1159-
const child = spawn(cmd[0], [...cmd.slice(1), "-f", composeFile, ...args], {
1165+
const child = spawn(cmd[0], [...cmd.slice(1), "-f", composeFile, ...finalArgs], {
11601166
stdio: "inherit",
11611167
env: env,
11621168
cwd: projectDir
@@ -1215,8 +1221,8 @@ mon
12151221
if (pwdMatch) existingPassword = pwdMatch[1].trim();
12161222
}
12171223

1218-
// Priority: CLI --tag flag > existing .env > package version
1219-
const imageTag = opts.tag || existingTag || pkg.version;
1224+
// Priority: CLI --tag flag > PGAI_TAG env var > existing .env > package version
1225+
const imageTag = opts.tag || process.env.PGAI_TAG || existingTag || pkg.version;
12201226

12211227
const envLines: string[] = [`PGAI_TAG=${imageTag}`];
12221228
if (existingRegistry) {
@@ -1527,6 +1533,34 @@ mon
15271533
if (code !== 0) process.exitCode = code;
15281534
});
15291535

1536+
// Known container names for cleanup
1537+
const MONITORING_CONTAINERS = [
1538+
"postgres-ai-config-init",
1539+
"node-exporter",
1540+
"cadvisor",
1541+
"grafana-with-datasources",
1542+
"sink-postgres",
1543+
"sink-prometheus",
1544+
"target-db",
1545+
"pgwatch-postgres",
1546+
"pgwatch-prometheus",
1547+
"postgres-exporter-sink",
1548+
"flask-pgss-api",
1549+
"sources-generator",
1550+
"postgres-reports",
1551+
];
1552+
1553+
/** Remove orphaned containers that docker compose down might miss */
1554+
async function removeOrphanedContainers(): Promise<void> {
1555+
for (const container of MONITORING_CONTAINERS) {
1556+
try {
1557+
await execFilePromise("docker", ["rm", "-f", container]);
1558+
} catch {
1559+
// Container doesn't exist, ignore
1560+
}
1561+
}
1562+
}
1563+
15301564
mon
15311565
.command("stop")
15321566
.description("stop monitoring services")
@@ -1784,6 +1818,10 @@ mon
17841818
console.log("⚠ Could not stop services (may not be running)");
17851819
}
17861820

1821+
// Remove any orphaned containers that docker compose down missed
1822+
await removeOrphanedContainers();
1823+
console.log("✓ Removed orphaned containers");
1824+
17871825
// Remove orphaned volumes from previous installs with different project names
17881826
if (!options.keepVolumes) {
17891827
const volumePatterns = [

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ services:
232232
- "--path.rootfs=/host"
233233
- "--collector.filesystem.mount-points-exclude=^/(sys|proc|dev|host|etc)($$|/)"
234234
volumes:
235-
- /:/host:ro
235+
- /:/host:ro,rslave
236236
restart: unless-stopped
237237

238238
# Postgres Exporter - Metrics for sink-postgres database

0 commit comments

Comments
 (0)