Skip to content

Commit 64d9625

Browse files
committed
local docker compose option
1 parent 680e2ca commit 64d9625

File tree

1 file changed

+36
-4
lines changed

1 file changed

+36
-4
lines changed

tasks.py

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,49 @@
2525
INFRAHUB_SERVICE_CATALOG = (
2626
os.getenv("INFRAHUB_SERVICE_CATALOG", "false").lower() == "true"
2727
)
28+
INFRAHUB_GIT_LOCAL = os.getenv("INFRAHUB_GIT_LOCAL", "false").lower() == "true"
2829
MAIN_DIRECTORY_PATH = Path(__file__).parent
2930

3031

3132
# Download compose file and use with override
3233
def get_compose_command() -> str:
3334
"""Generate docker compose command with override support."""
35+
local_compose_file = MAIN_DIRECTORY_PATH / "docker-compose.yml"
36+
override_file = MAIN_DIRECTORY_PATH / "docker-compose.override.yml"
37+
38+
# Check if local docker-compose.yml exists
39+
if local_compose_file.exists():
40+
# Use local docker-compose.yml file
41+
if override_file.exists():
42+
return f"docker compose -p infrahub -f {local_compose_file} -f {override_file}"
43+
return f"docker compose -p infrahub -f {local_compose_file}"
44+
45+
# Fall back to downloading from infrahub.opsmill.io
3446
# Determine the base URL based on edition
3547
if INFRAHUB_ENTERPRISE:
3648
base_url = f"https://infrahub.opsmill.io/enterprise/{INFRAHUB_VERSION}"
3749
else:
3850
base_url = f"https://infrahub.opsmill.io/{INFRAHUB_VERSION}"
3951

40-
override_file = MAIN_DIRECTORY_PATH / "docker-compose.override.yml"
4152
if override_file.exists():
4253
return (
4354
f"curl -s {base_url} | docker compose -p infrahub -f - -f {override_file}"
4455
)
4556
return f"curl -s {base_url} | docker compose -p infrahub -f -"
4657

4758

59+
def get_compose_source() -> str:
60+
"""Get a human-readable description of the compose file source."""
61+
local_compose_file = MAIN_DIRECTORY_PATH / "docker-compose.yml"
62+
if local_compose_file.exists():
63+
return "Local (docker-compose.yml)"
64+
65+
edition = "Enterprise" if INFRAHUB_ENTERPRISE else "Community"
66+
return f"infrahub.opsmill.io ({edition} {INFRAHUB_VERSION})"
67+
68+
4869
COMPOSE_COMMAND = get_compose_command()
70+
COMPOSE_SOURCE = get_compose_source()
4971
CURRENT_DIRECTORY = Path(__file__).resolve()
5072
DOCUMENTATION_DIRECTORY = CURRENT_DIRECTORY.parent / "docs"
5173

@@ -99,10 +121,17 @@ def info(context: Context) -> None:
99121
"""Show current Infrahub configuration."""
100122
edition = "Enterprise" if INFRAHUB_ENTERPRISE else "Community"
101123

102-
info_panel = Panel(
124+
info_msg = (
103125
f"[cyan]Edition:[/cyan] {edition}\n"
104126
f"[cyan]Version:[/cyan] {INFRAHUB_VERSION}\n"
105-
f"[cyan]Command:[/cyan] [dim]{COMPOSE_COMMAND}[/dim]",
127+
f"[cyan]Compose Source:[/cyan] {COMPOSE_SOURCE}\n"
128+
f"[cyan]Service Catalog:[/cyan] {'Enabled' if INFRAHUB_SERVICE_CATALOG else 'Disabled'}\n"
129+
f"[cyan]Local Git Repository:[/cyan] {'Enabled' if INFRAHUB_GIT_LOCAL else 'Disabled'}\n"
130+
f"[cyan]Command:[/cyan] [dim]{COMPOSE_COMMAND}[/dim]"
131+
)
132+
133+
info_panel = Panel(
134+
info_msg,
106135
title="[bold]Infrahub Configuration[/bold]",
107136
border_style="blue",
108137
box=box.SIMPLE,
@@ -124,10 +153,13 @@ def start(context: Context, rebuild: bool = False) -> None:
124153

125154
console.print()
126155
status_msg = (
127-
f"[green]Starting Infrahub {edition}[/green] [dim]({INFRAHUB_VERSION})[/dim]"
156+
f"[green]Starting Infrahub {edition}[/green] [dim]({INFRAHUB_VERSION})[/dim]\n"
157+
f"[dim]Compose:[/dim] {COMPOSE_SOURCE}"
128158
)
129159
if INFRAHUB_SERVICE_CATALOG:
130160
status_msg += "\n[cyan]Service Catalog:[/cyan] Enabled"
161+
if INFRAHUB_GIT_LOCAL:
162+
status_msg += "\n[cyan]Local Git Repository:[/cyan] Enabled"
131163
if rebuild:
132164
status_msg += "\n[yellow]Rebuild:[/yellow] Enabled"
133165

0 commit comments

Comments
 (0)