MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / resolve_from

Function resolve_from

crates/openshell-cli/src/run.rs:2394–2465  ·  view source on GitHub ↗

Classify the `--from` value into an image reference or a Dockerfile that needs building. Resolution order: 1. Existing file whose name contains "Dockerfile" → build from file. 2. Existing directory that contains a `Dockerfile` → build from directory. 3. Missing explicit local paths → local error, not image pull. 4. Value contains `/`, `:`, or `.` → treat as a full image reference. 5. Otherwise →

(value: &str)

Source from the content-addressed store, hash-verified

2392/// 4. Value contains `/`, `:`, or `.` → treat as a full image reference.
2393/// 5. Otherwise → community sandbox name, expanded via the registry prefix.
2394fn resolve_from(value: &str) -> Result<ResolvedSource> {
2395 let path = Path::new(value);
2396
2397 // 1. Existing file that looks like a Dockerfile.
2398 if path.is_file() {
2399 if filename_looks_like_dockerfile(path) {
2400 let dockerfile = path
2401 .canonicalize()
2402 .into_diagnostic()
2403 .wrap_err_with(|| format!("failed to resolve path: {}", path.display()))?;
2404 let context = dockerfile
2405 .parent()
2406 .ok_or_else(|| miette::miette!("Dockerfile has no parent directory"))?
2407 .to_path_buf();
2408 return Ok(ResolvedSource::Dockerfile {
2409 dockerfile,
2410 context,
2411 });
2412 }
2413
2414 if value_looks_like_local_source(value) {
2415 return Err(miette::miette!(
2416 "local --from file is not a Dockerfile: {}",
2417 path.display()
2418 ));
2419 }
2420 }
2421
2422 // 2. Existing directory containing a Dockerfile.
2423 if path.is_dir() {
2424 let candidate = path.join("Dockerfile");
2425 if candidate.is_file() {
2426 let context = path
2427 .canonicalize()
2428 .into_diagnostic()
2429 .wrap_err_with(|| format!("failed to resolve path: {}", path.display()))?;
2430 let dockerfile = context.join("Dockerfile");
2431 return Ok(ResolvedSource::Dockerfile {
2432 dockerfile,
2433 context,
2434 });
2435 }
2436 return Err(miette::miette!(
2437 "No Dockerfile found in directory: {}",
2438 path.display()
2439 ));
2440 }
2441
2442 if path.exists() {
2443 return Err(miette::miette!(
2444 "local --from path is not a regular file or directory: {}",
2445 path.display()
2446 ));
2447 }
2448
2449 // 3. Missing explicit local paths should fail locally. Otherwise values
2450 // like `./Dockerfile` reach the gateway as image references and fail as
2451 // Docker pull errors.

Calls 5

ImageClass · 0.85
resolve_community_imageFunction · 0.85
existsMethod · 0.80