Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/lib/nim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,33 @@ export function detectGpu(): GpuDetection | null {
return null;
}

export function isNgcLoggedIn(): boolean {
try {
const os = require("os");
const fs = require("fs");
const path = require("path");
const config = path.join(os.homedir(), ".docker", "config.json");
const data = fs.readFileSync(config, "utf-8");
const parsed = JSON.parse(data);
if (parsed?.credHelpers?.["nvcr.io"]) return true;
const auths = parsed?.auths || {};
const entry = auths["nvcr.io"] || auths["https://nvcr.io"];
return Boolean(entry && (entry.auth || entry.token));
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
} catch {
return false;
}
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

export function dockerLoginNgc(apiKey: string): boolean {
const { spawnSync } = require("child_process");
const result = spawnSync("docker", ["login", "nvcr.io", "-u", "$oauthtoken", "--password-stdin"], {
input: apiKey,
encoding: "utf-8",
stdio: ["pipe", "pipe", "pipe"],
});
return result.status === 0;
}

export function pullNimImage(model: string): string {
const image = getImageForModel(model);
if (!image) {
Expand Down
28 changes: 28 additions & 0 deletions src/lib/onboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4020,6 +4020,34 @@ async function setupNim(gpu) {
}
model = sel.name;

// Ensure Docker is logged in to NGC registry before pulling NIM images.
if (!nim.isNgcLoggedIn()) {
if (isNonInteractive()) {
console.error(
" Docker is not logged in to nvcr.io. In non-interactive mode, run `docker login nvcr.io` first and retry.",
);
process.exit(1);
}
console.log("");
console.log(" NGC API Key required to pull NIM images.");
console.log(" Get one from: https://org.ngc.nvidia.com/setup/api-key");
console.log("");
let ngcKey = normalizeCredentialValue(await prompt(" NGC API Key: ", { secret: true }));
if (!ngcKey) {
console.error(" NGC API Key is required for Local NIM.");
process.exit(1);
}
if (!nim.dockerLoginNgc(ngcKey)) {
console.error(" Failed to login to NGC registry. Check your API key and try again.");
console.log("");
ngcKey = normalizeCredentialValue(await prompt(" NGC API Key: ", { secret: true }));
if (!ngcKey || !nim.dockerLoginNgc(ngcKey)) {
console.error(" NGC login failed. Cannot pull NIM images.");
process.exit(1);
}
}
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

console.log(` Pulling NIM image for ${model}...`);
nim.pullNimImage(model);

Expand Down
1 change: 1 addition & 0 deletions test/onboard-selection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3066,6 +3066,7 @@ nimMod.pullNimImage = () => {};
nimMod.containerName = () => "nemoclaw-nim-test";
nimMod.startNimContainerByName = () => "container-123";
nimMod.waitForNimHealth = () => true;
nimMod.isNgcLoggedIn = () => true;

// Select option 7 (nim-local), then model 1
const answers = ["7", "1"];
Expand Down
Loading