@@ -561,7 +561,8 @@ User: "deploy this service"
561561
562562 // Build deployment config request
563563 // Derive dockerfile path and build context from DockerfileInfo
564- // NOTE: When analyzing a subdirectory (args.path), paths must be relative to repo root
564+ // For monorepos: context = service folder, dockerfile = full path from repo root
565+ // This matches what the manual wizard sends when user selects the service folder
565566 let ( dockerfile_path, build_context) = analysis. docker_analysis
566567 . as_ref ( )
567568 . and_then ( |d| d. dockerfiles . first ( ) )
@@ -571,41 +572,40 @@ User: "deploy this service"
571572 . map ( |n| n. to_string_lossy ( ) . to_string ( ) )
572573 . unwrap_or_else ( || "Dockerfile" . to_string ( ) ) ;
573574
574- // Derive build context from dockerfile path relative to analysis_path
575- // The parent directory of the Dockerfile is typically the build context
576- let analysis_relative_context = df. path . parent ( )
575+ // Derive dockerfile's directory relative to analysis_path
576+ let analysis_relative_dir = df. path . parent ( )
577577 . and_then ( |p| p. strip_prefix ( & analysis_path) . ok ( ) )
578- . map ( |p| {
579- let s = p. to_string_lossy ( ) . to_string ( ) ;
580- if s. is_empty ( ) { "." . to_string ( ) } else { s }
581- } )
582- . unwrap_or_else ( || "." . to_string ( ) ) ;
583-
584- // If we analyzed a subdirectory (args.path), prepend it to get repo-root-relative paths
585- // Otherwise, the context from analyzer is already relative to project root
586- let repo_relative_context = if let Some ( ref subpath) = args. path {
587- // Combine subpath with the analysis-relative build context
588- if analysis_relative_context == "." {
589- subpath. clone ( )
590- } else {
591- format ! ( "{}/{}" , subpath, analysis_relative_context)
578+ . map ( |p| p. to_string_lossy ( ) . to_string ( ) )
579+ . unwrap_or_default ( ) ;
580+
581+ // Build paths relative to repo root
582+ // If we analyzed a subdirectory (args.path), prepend it
583+ match ( & args. path , analysis_relative_dir. as_str ( ) ) {
584+ ( Some ( subpath) , "" ) | ( Some ( subpath) , "." ) => {
585+ // Dockerfile is at the root of the analyzed subpath
586+ // dockerfile: "services/foo/Dockerfile", context: "services/foo"
587+ ( format ! ( "{}/{}" , subpath, dockerfile_name) , subpath. clone ( ) )
592588 }
593- } else {
594- analysis_relative_context
595- } ;
596-
597- // Construct dockerfile path: context/Dockerfile
598- // Following orchestrator.rs pattern (see commit 3cb8698)
599- let df_path = if repo_relative_context == "." || repo_relative_context. is_empty ( ) {
600- dockerfile_name
601- } else {
602- format ! ( "{}/{}" , repo_relative_context, dockerfile_name)
603- } ;
604-
605- ( df_path, repo_relative_context)
589+ ( Some ( subpath) , rel_dir) => {
590+ // Dockerfile is nested within the analyzed subpath
591+ // dockerfile: "services/foo/nested/Dockerfile", context: "services/foo/nested"
592+ let context = format ! ( "{}/{}" , subpath, rel_dir) ;
593+ ( format ! ( "{}/{}" , context, dockerfile_name) , context)
594+ }
595+ ( None , "" ) | ( None , "." ) => {
596+ // Dockerfile at repo root
597+ // dockerfile: "Dockerfile", context: "."
598+ ( dockerfile_name, "." . to_string ( ) )
599+ }
600+ ( None , rel_dir) => {
601+ // Dockerfile in subdirectory from repo root
602+ // dockerfile: "subdir/Dockerfile", context: "subdir"
603+ ( format ! ( "{}/{}" , rel_dir, dockerfile_name) , rel_dir. to_string ( ) )
604+ }
605+ }
606606 } )
607607 . unwrap_or_else ( || {
608- // No dockerfile found - use subpath if provided, else defaults
608+ // No dockerfile found - construct path from subpath if provided
609609 if let Some ( ref subpath) = args. path {
610610 ( format ! ( "{}/Dockerfile" , subpath) , subpath. clone ( ) )
611611 } else {
0 commit comments