35 lines
1.2 KiB
JavaScript
35 lines
1.2 KiB
JavaScript
import { spawnSync } from "node:child_process";
|
|
import { existsSync, readFileSync } from "node:fs";
|
|
import { dirname, resolve } from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
|
|
const repoDir = resolve(dirname(fileURLToPath(import.meta.url)), "..");
|
|
|
|
function loadDotEnvValue(name) {
|
|
if (process.env[name]) return process.env[name];
|
|
const envPath = resolve(repoDir, ".env");
|
|
if (!existsSync(envPath)) return "";
|
|
for (const row of readFileSync(envPath, "utf8").split(/\r?\n/)) {
|
|
if (!row.startsWith(`${name}=`)) continue;
|
|
let value = row.slice(name.length + 1);
|
|
if (
|
|
(value.startsWith("'") && value.endsWith("'")) ||
|
|
(value.startsWith('"') && value.endsWith('"'))
|
|
) {
|
|
value = value.slice(1, -1);
|
|
}
|
|
return value;
|
|
}
|
|
return "";
|
|
}
|
|
|
|
const password = loadDotEnvValue("COMPUTER_USER_PASSWORD");
|
|
const args = ["build", "-t", "rakazo/computer:local", "infra/sandboxes/computer"];
|
|
const env = { ...process.env, DOCKER_BUILDKIT: "1" };
|
|
if (password) {
|
|
env.COMPUTER_USER_PASSWORD = password;
|
|
args.splice(1, 0, "--secret", "id=computer_password,env=COMPUTER_USER_PASSWORD");
|
|
}
|
|
const result = spawnSync("docker", args, { stdio: "inherit", env, cwd: repoDir });
|
|
process.exit(result.status ?? 1);
|