|
26 | 26 | INFRAHUB_SERVICE_CATALOG = os.getenv("INFRAHUB_SERVICE_CATALOG", "false").lower() == "true" |
27 | 27 | INFRAHUB_GIT_LOCAL = os.getenv("INFRAHUB_GIT_LOCAL", "false").lower() == "true" |
28 | 28 | MAIN_DIRECTORY_PATH = Path(__file__).parent |
| 29 | +INFRAHUB_PROJECT_NAME = os.getenv("INFRAHUB_PROJECT_NAME", MAIN_DIRECTORY_PATH.name) |
29 | 30 |
|
30 | 31 |
|
31 | 32 | # Download compose file and use with override |
32 | 33 | def get_compose_command() -> str: |
33 | | - """Generate docker compose command with override support.""" |
| 34 | + """Generate docker compose command with override support. |
| 35 | +
|
| 36 | + Supports layered compose files: |
| 37 | + 1. docker-compose.yml (base, downloaded or local) |
| 38 | + 2. docker-compose.override.yml (committed overrides) |
| 39 | + 3. docker-compose.local.yml (gitignored, for local port/project customization) |
| 40 | +
|
| 41 | + The project name is controlled by INFRAHUB_PROJECT_NAME env var, |
| 42 | + defaulting to the directory name. |
| 43 | + """ |
34 | 44 | local_compose_file = MAIN_DIRECTORY_PATH / "docker-compose.yml" |
35 | 45 | override_file = MAIN_DIRECTORY_PATH / "docker-compose.override.yml" |
| 46 | + local_file = MAIN_DIRECTORY_PATH / "docker-compose.local.yml" |
| 47 | + |
| 48 | + # Build list of compose file arguments |
| 49 | + compose_files: list[str] = [] |
| 50 | + |
| 51 | + # Check if local docker-compose.yml exists, otherwise use remote |
| 52 | + if local_compose_file.exists(): |
| 53 | + compose_files.append(str(local_compose_file)) |
| 54 | + else: |
| 55 | + # Will use curl pipe, handled separately below |
| 56 | + pass |
| 57 | + |
| 58 | + # Add optional override files |
| 59 | + if override_file.exists(): |
| 60 | + compose_files.append(str(override_file)) |
| 61 | + if local_file.exists(): |
| 62 | + compose_files.append(str(local_file)) |
36 | 63 |
|
37 | | - # Check if local docker-compose.yml exists |
| 64 | + # Build the file arguments string |
| 65 | + file_args = " ".join(f"-f {f}" for f in compose_files) |
| 66 | + base_cmd = f"docker compose -p {INFRAHUB_PROJECT_NAME}" |
| 67 | + |
| 68 | + # If we have a local compose file, use it directly |
38 | 69 | if local_compose_file.exists(): |
39 | | - # Use local docker-compose.yml file |
40 | | - if override_file.exists(): |
41 | | - return f"docker compose -p infrahub -f {local_compose_file} -f {override_file}" |
42 | | - return f"docker compose -p infrahub-bundle-dc -f {local_compose_file}" |
| 70 | + return f"{base_cmd} {file_args}" |
43 | 71 |
|
44 | 72 | # Fall back to downloading from infrahub.opsmill.io |
45 | | - # Determine the base URL based on edition |
46 | 73 | if INFRAHUB_ENTERPRISE: |
47 | 74 | base_url = f"https://infrahub.opsmill.io/enterprise/{INFRAHUB_VERSION}" |
48 | 75 | else: |
49 | 76 | base_url = f"https://infrahub.opsmill.io/{INFRAHUB_VERSION}" |
50 | 77 |
|
51 | | - if override_file.exists(): |
52 | | - return f"curl -s {base_url} | docker compose -p infrahub -f - -f {override_file}" |
53 | | - return f"curl -s {base_url} | docker compose -p infrahub -f -" |
| 78 | + # For curl pipe, stdin is the first file |
| 79 | + if file_args: |
| 80 | + return f"curl -s {base_url} | {base_cmd} -f - {file_args}" |
| 81 | + return f"curl -s {base_url} | {base_cmd} -f -" |
54 | 82 |
|
55 | 83 |
|
56 | 84 | def get_compose_source() -> str: |
@@ -119,6 +147,7 @@ def info(context: Context) -> None: |
119 | 147 | info_msg = ( |
120 | 148 | f"[cyan]Edition:[/cyan] {edition}\n" |
121 | 149 | f"[cyan]Version:[/cyan] {INFRAHUB_VERSION}\n" |
| 150 | + f"[cyan]Project Name:[/cyan] {INFRAHUB_PROJECT_NAME}\n" |
122 | 151 | f"[cyan]Compose Source:[/cyan] {COMPOSE_SOURCE}\n" |
123 | 152 | f"[cyan]Service Catalog:[/cyan] {'Enabled' if INFRAHUB_SERVICE_CATALOG else 'Disabled'}\n" |
124 | 153 | f"[cyan]Local Git Repository:[/cyan] {'Enabled' if INFRAHUB_GIT_LOCAL else 'Disabled'}\n" |
|
0 commit comments