This commit is contained in:
2026-08-10 02:04:45 +02:00
parent 39cb848f67
commit 593edf35fe
10 changed files with 394 additions and 33 deletions
+17 -27
View File
@@ -13,8 +13,12 @@
* prebuilt `sqlc` binary and still prefer ≥6GiB).
*/
import { spawnSync } from "node:child_process";
import fs from "node:fs";
import path from "node:path";
import {
detectHostProfile,
formatHostNote,
withGoLowMem,
} from "./lowmem-env.mjs";
import { loadRootEnv, repoRoot } from "./root-env.mjs";
const args = new Set(process.argv.slice(2));
@@ -26,7 +30,8 @@ const wantSqlc =
/** Prefer this much free/total RAM (MiB) before attempting sqlc go-run/wazero. */
const SQLC_MIN_RAM_MIB = Number(process.env.DESCRYBE_SQLC_MIN_RAM_MIB || 6144);
const env = loadRootEnv(process.env);
const profile = detectHostProfile();
const env = withGoLowMem(loadRootEnv(process.env), profile);
if (!env.DATABASE_URL) {
console.error(
"DATABASE_URL is required (set in monorepo-root .env or the shell; see .env.example)",
@@ -41,7 +46,8 @@ function run(command, cmdArgs, opts = {}) {
cwd: apiDir,
env,
stdio: "inherit",
shell: process.platform === "win32",
// Keep go argv intact on Windows (ldflags / module paths).
shell: process.platform === "win32" && command !== "go",
...opts,
});
if (r.error) {
@@ -53,31 +59,8 @@ function run(command, cmdArgs, opts = {}) {
}
}
/** Best-effort total RAM in MiB (Linux /proc, Windows wmic, or null). */
function totalRamMiB() {
try {
if (process.platform === "linux") {
const text = fs.readFileSync("/proc/meminfo", "utf8");
const m = text.match(/^MemTotal:\s+(\d+)\s+kB/m);
if (m) return Math.floor(Number(m[1]) / 1024);
}
if (process.platform === "win32") {
const r = spawnSync(
"powershell",
[
"-NoProfile",
"-Command",
"[int]((Get-CimInstance Win32_ComputerSystem).TotalPhysicalMemory/1MB)",
],
{ encoding: "utf8" },
);
const n = Number(String(r.stdout || "").trim());
if (Number.isFinite(n) && n > 0) return n;
}
} catch {
/* ignore */
}
return null;
return profile.totalMiB;
}
function hasSqlcBinary() {
@@ -89,6 +72,13 @@ function hasSqlcBinary() {
}
console.log("==> goose up (apps/api/sql/schema)");
console.log(`NOTE ${formatHostNote(profile)}`);
console.log(
`NOTE GOMAXPROCS=${env.GOMAXPROCS}` +
(env.GOMEMLIMIT ? ` GOMEMLIMIT=${env.GOMEMLIMIT}` : "") +
(env.GOGC ? ` GOGC=${env.GOGC}` : "") +
" (sqlc skipped by default; needs ≥6GiB)",
);
run("go", [
"run",
"github.com/pressly/goose/v3/cmd/goose@v3.24.3",