3737
3838# Third-Party
3939from jinja2 import Environment , FileSystemLoader
40- from rich .console import Console
4140import yaml
4241
4342# First-Party
4443from cforge .commands .deploy .builder .schema import MCPStackConfig
45-
46- console = Console ()
44+ from cforge .common import get_console
4745
4846
4947def get_deploy_dir () -> Path :
@@ -472,17 +470,17 @@ def generate_kubernetes_manifests(config: MCPStackConfig, output_dir: Path, verb
472470 if result .returncode == 0 and result .stdout .strip ():
473471 openshift_domain = result .stdout .strip ()
474472 if verbose :
475- console .print (f"[dim]Auto-detected OpenShift domain: { openshift_domain } [/dim]" )
473+ get_console () .print (f"[dim]Auto-detected OpenShift domain: { openshift_domain } [/dim]" )
476474 else :
477475 # Fallback to common OpenShift Local domain
478476 openshift_domain = "apps-crc.testing"
479477 if verbose :
480- console .print (f"[yellow]Could not auto-detect OpenShift domain, using default: { openshift_domain } [/yellow]" )
478+ get_console () .print (f"[yellow]Could not auto-detect OpenShift domain, using default: { openshift_domain } [/yellow]" )
481479 except Exception :
482480 # Fallback to common OpenShift Local domain
483481 openshift_domain = "apps-crc.testing"
484482 if verbose :
485- console .print (f"[yellow]Could not auto-detect OpenShift domain, using default: { openshift_domain } [/yellow]" )
483+ get_console () .print (f"[yellow]Could not auto-detect OpenShift domain, using default: { openshift_domain } [/yellow]" )
486484
487485 route_manifest = route_template .render (namespace = namespace , openshift_domain = openshift_domain , tls_termination = openshift_config .tls_termination )
488486 (output_dir / "gateway-route.yaml" ).write_text (route_manifest )
@@ -807,16 +805,16 @@ def handle_registry_operations(component, component_name: str, image_tag: str, c
807805
808806 # Tag image for registry
809807 if verbose :
810- console .print (f"[dim]Tagging { image_tag } as { registry_image } [/dim]" )
808+ get_console () .print (f"[dim]Tagging { image_tag } as { registry_image } [/dim]" )
811809 tag_cmd = [container_runtime , "tag" , image_tag , registry_image ]
812810 result = subprocess .run (tag_cmd , capture_output = True , text = True , check = True ) # nosec B603, B607
813811 if result .stdout and verbose :
814- console .print (result .stdout )
812+ get_console () .print (result .stdout )
815813
816814 # Push to registry if enabled
817815 if registry_config .push :
818816 if verbose :
819- console .print (f"[blue]Pushing { registry_image } to registry...[/blue]" )
817+ get_console () .print (f"[blue]Pushing { registry_image } to registry...[/blue]" )
820818
821819 # Build push command with TLS options
822820 push_cmd = [container_runtime , "push" ]
@@ -831,14 +829,14 @@ def handle_registry_operations(component, component_name: str, image_tag: str, c
831829 try :
832830 result = subprocess .run (push_cmd , capture_output = True , text = True , check = True ) # nosec B603, B607
833831 if result .stdout and verbose :
834- console .print (result .stdout )
835- console .print (f"[green]✓ Pushed to registry: { registry_image } [/green]" )
832+ get_console () .print (result .stdout )
833+ get_console () .print (f"[green]✓ Pushed to registry: { registry_image } [/green]" )
836834 except subprocess .CalledProcessError as e :
837- console .print (f"[red]✗ Failed to push to registry: { e } [/red]" )
835+ get_console () .print (f"[red]✗ Failed to push to registry: { e } [/red]" )
838836 if e .stderr :
839- console .print (f"[red]Error output: { e .stderr } [/red]" )
840- console .print ("[yellow]Tip: Authenticate to the registry first:[/yellow]" )
841- console .print (f" { container_runtime } login { registry_config .url } " )
837+ get_console () .print (f"[red]Error output: { e .stderr } [/red]" )
838+ get_console () .print ("[yellow]Tip: Authenticate to the registry first:[/yellow]" )
839+ get_console () .print (f" { container_runtime } login { registry_config .url } " )
842840 raise
843841
844842 # Update component image reference to use registry path for manifests
@@ -951,17 +949,17 @@ def run_compose(compose_file: Path, args: List[str], verbose: bool = False, chec
951949 full_cmd = compose_cmd + ["-f" , str (compose_file )] + args
952950
953951 if verbose :
954- console .print (f"[dim]Running: { ' ' .join (full_cmd )} [/dim]" )
952+ get_console () .print (f"[dim]Running: { ' ' .join (full_cmd )} [/dim]" )
955953
956954 try :
957955 result = subprocess .run (full_cmd , capture_output = True , text = True , check = check ) # nosec B603, B607
958956 return result
959957 except subprocess .CalledProcessError as e :
960- console .print ("\n [red bold]Docker Compose command failed:[/red bold]" )
958+ get_console () .print ("\n [red bold]Docker Compose command failed:[/red bold]" )
961959 if e .stdout :
962- console .print (f"[yellow]Output:[/yellow]\n { e .stdout } " )
960+ get_console () .print (f"[yellow]Output:[/yellow]\n { e .stdout } " )
963961 if e .stderr :
964- console .print (f"[red]Error:[/red]\n { e .stderr } " )
962+ get_console () .print (f"[red]Error:[/red]\n { e .stderr } " )
965963 raise RuntimeError (f"Docker Compose failed with exit code { e .returncode } " ) from e
966964
967965
@@ -990,8 +988,8 @@ def deploy_compose(compose_file: Path, verbose: bool = False) -> None:
990988 """
991989 result = run_compose (compose_file , ["up" , "-d" ], verbose = verbose )
992990 if result .stdout and verbose :
993- console .print (result .stdout )
994- console .print ("[green]✓ Deployed with Docker Compose[/green]" )
991+ get_console () .print (result .stdout )
992+ get_console () .print ("[green]✓ Deployed with Docker Compose[/green]" )
995993
996994
997995def verify_compose (compose_file : Path , verbose : bool = False ) -> str :
@@ -1048,14 +1046,14 @@ def destroy_compose(compose_file: Path, verbose: bool = False) -> None:
10481046 True
10491047 """
10501048 if not compose_file .exists ():
1051- console .print (f"[yellow]Compose file not found: { compose_file } [/yellow]" )
1052- console .print ("[yellow]Nothing to destroy[/yellow]" )
1049+ get_console () .print (f"[yellow]Compose file not found: { compose_file } [/yellow]" )
1050+ get_console () .print ("[yellow]Nothing to destroy[/yellow]" )
10531051 return
10541052
10551053 result = run_compose (compose_file , ["down" , "-v" ], verbose = verbose )
10561054 if result .stdout and verbose :
1057- console .print (result .stdout )
1058- console .print ("[green]✓ Destroyed Docker Compose deployment[/green]" )
1055+ get_console () .print (result .stdout )
1056+ get_console () .print ("[green]✓ Destroyed Docker Compose deployment[/green]" )
10591057
10601058
10611059# Kubernetes kubectl utilities
@@ -1118,7 +1116,7 @@ def deploy_kubernetes(manifests_dir: Path, verbose: bool = False) -> None:
11181116 for manifest in deployment_files :
11191117 result = subprocess .run (["kubectl" , "apply" , "-f" , str (manifest )], capture_output = True , text = True , check = False ) # nosec B603, B607
11201118 if result .stdout and verbose :
1121- console .print (result .stdout )
1119+ get_console () .print (result .stdout )
11221120 if result .returncode != 0 :
11231121 raise RuntimeError (f"kubectl apply failed: { result .stderr } " )
11241122
@@ -1127,21 +1125,21 @@ def deploy_kubernetes(manifests_dir: Path, verbose: bool = False) -> None:
11271125 if cert_manager_certs .exists ():
11281126 result = subprocess .run (["kubectl" , "apply" , "-f" , str (cert_manager_certs )], capture_output = True , text = True , check = False ) # nosec B603, B607
11291127 if result .stdout and verbose :
1130- console .print (result .stdout )
1128+ get_console () .print (result .stdout )
11311129 if result .returncode != 0 :
11321130 raise RuntimeError (f"kubectl apply failed: { result .stderr } " )
11331131 elif cert_secrets .exists ():
11341132 result = subprocess .run (["kubectl" , "apply" , "-f" , str (cert_secrets )], capture_output = True , text = True , check = False ) # nosec B603, B607
11351133 if result .stdout and verbose :
1136- console .print (result .stdout )
1134+ get_console () .print (result .stdout )
11371135 if result .returncode != 0 :
11381136 raise RuntimeError (f"kubectl apply failed: { result .stderr } " )
11391137
11401138 # 3. Apply ConfigMaps (needed by deployments)
11411139 if plugins_configmap .exists ():
11421140 result = subprocess .run (["kubectl" , "apply" , "-f" , str (plugins_configmap )], capture_output = True , text = True , check = False ) # nosec B603, B607
11431141 if result .stdout and verbose :
1144- console .print (result .stdout )
1142+ get_console () .print (result .stdout )
11451143 if result .returncode != 0 :
11461144 raise RuntimeError (f"kubectl apply failed: { result .stderr } " )
11471145
@@ -1150,7 +1148,7 @@ def deploy_kubernetes(manifests_dir: Path, verbose: bool = False) -> None:
11501148 if infra_file .exists ():
11511149 result = subprocess .run (["kubectl" , "apply" , "-f" , str (infra_file )], capture_output = True , text = True , check = False ) # nosec B603, B607
11521150 if result .stdout and verbose :
1153- console .print (result .stdout )
1151+ get_console () .print (result .stdout )
11541152 if result .returncode != 0 :
11551153 raise RuntimeError (f"kubectl apply failed: { result .stderr } " )
11561154
@@ -1159,13 +1157,13 @@ def deploy_kubernetes(manifests_dir: Path, verbose: bool = False) -> None:
11591157 if gateway_route .exists ():
11601158 result = subprocess .run (["kubectl" , "apply" , "-f" , str (gateway_route )], capture_output = True , text = True , check = False ) # nosec B603, B607
11611159 if result .stdout and verbose :
1162- console .print (result .stdout )
1160+ get_console () .print (result .stdout )
11631161 if result .returncode != 0 :
11641162 # Don't fail on Route errors (may not be on OpenShift)
11651163 if verbose :
1166- console .print (f"[yellow]Warning: Could not apply Route (may not be on OpenShift): { result .stderr } [/yellow]" )
1164+ get_console () .print (f"[yellow]Warning: Could not apply Route (may not be on OpenShift): { result .stderr } [/yellow]" )
11671165
1168- console .print ("[green]✓ Deployed to Kubernetes[/green]" )
1166+ get_console () .print ("[green]✓ Deployed to Kubernetes[/green]" )
11691167
11701168
11711169def verify_kubernetes (namespace : str , wait : bool = False , timeout : int = 300 , verbose : bool = False ) -> str :
@@ -1212,7 +1210,7 @@ def verify_kubernetes(namespace: str, wait: bool = False, timeout: int = 300, ve
12121210 if wait :
12131211 result = subprocess .run (["kubectl" , "wait" , "--for=condition=Ready" , "pod" , "--all" , "-n" , namespace , f"--timeout={ timeout } s" ], capture_output = True , text = True , check = False ) # nosec B603, B607
12141212 if result .stdout and verbose :
1215- console .print (result .stdout )
1213+ get_console () .print (result .stdout )
12161214 if result .returncode != 0 :
12171215 raise RuntimeError (f"kubectl wait failed: { result .stderr } " )
12181216
@@ -1250,8 +1248,8 @@ def destroy_kubernetes(manifests_dir: Path, verbose: bool = False) -> None:
12501248 raise RuntimeError ("kubectl not found. Cannot destroy Kubernetes deployment." )
12511249
12521250 if not manifests_dir .exists ():
1253- console .print (f"[yellow]Manifests directory not found: { manifests_dir } [/yellow]" )
1254- console .print ("[yellow]Nothing to destroy[/yellow]" )
1251+ get_console () .print (f"[yellow]Manifests directory not found: { manifests_dir } [/yellow]" )
1252+ get_console () .print ("[yellow]Nothing to destroy[/yellow]" )
12551253 return
12561254
12571255 # Delete all manifests except plugins-config.yaml
@@ -1261,8 +1259,8 @@ def destroy_kubernetes(manifests_dir: Path, verbose: bool = False) -> None:
12611259 for manifest in all_manifests :
12621260 result = subprocess .run (["kubectl" , "delete" , "-f" , str (manifest ), "--ignore-not-found=true" ], capture_output = True , text = True , check = False ) # nosec B603, B607
12631261 if result .stdout and verbose :
1264- console .print (result .stdout )
1262+ get_console () .print (result .stdout )
12651263 if result .returncode != 0 and "NotFound" not in result .stderr :
1266- console .print (f"[yellow]Warning: { result .stderr } [/yellow]" )
1264+ get_console () .print (f"[yellow]Warning: { result .stderr } [/yellow]" )
12671265
1268- console .print ("[green]✓ Destroyed Kubernetes deployment[/green]" )
1266+ get_console () .print ("[green]✓ Destroyed Kubernetes deployment[/green]" )
0 commit comments