Skip to content

Commit f857d62

Browse files
author
Phillip Simonds
committed
Add local docker-compose file and unique project name to compose command.
1 parent b1d2cb7 commit f857d62

File tree

4 files changed

+85
-10
lines changed

4 files changed

+85
-10
lines changed

.env.example

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ export INFRAHUB_ENTERPRISE=false
3636
# - Bootstrap script loads objects/git-repo/github.yml
3737
export INFRAHUB_GIT_LOCAL=false
3838

39+
# Docker Compose project name
40+
# Used to namespace Docker containers. Set different values for each instance
41+
# when running multiple copies of this project in parallel.
42+
# Defaults to the directory name if not set.
43+
# Example: infrahub-bug1, infrahub-bug2, etc.
44+
# export INFRAHUB_PROJECT_NAME=infrahub-bundle-dc
45+
3946
# =============================================================================
4047
# Service Catalog Configuration
4148
# =============================================================================

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
**/*.clab.yml.bak
1515
**/*.tar.xz
1616
docker-compose.yml
17+
docker-compose.local.yml
1718
generated-configs/
1819
infrahub_backups/
1920
infrahub_bundle_dc.egg-info

docker-compose.local.yml.example

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
# Local Docker Compose overrides (gitignored)
3+
#
4+
# Copy this file to docker-compose.local.yml to customize ports and other
5+
# settings for running multiple instances of this project in parallel.
6+
#
7+
# This file is layered on top of docker-compose.yml and docker-compose.override.yml,
8+
# so you only need to specify the settings you want to change.
9+
#
10+
# Example: To run a second instance on different ports:
11+
# 1. Clone the repo to a different directory (e.g., infrahub-bundle-dc-2)
12+
# 2. Copy this file to docker-compose.local.yml
13+
# 3. Set INFRAHUB_PROJECT_NAME in your .env (e.g., infrahub-2)
14+
# 4. Uncomment and adjust the ports below
15+
#
16+
# Common port offsets for multiple instances:
17+
# Instance 1: 8000, 4200, 8501 (default)
18+
# Instance 2: 8100, 4201, 8502
19+
# Instance 3: 8200, 4202, 8503
20+
21+
services:
22+
# Infrahub server (default: 8000)
23+
infrahub-server:
24+
ports:
25+
- "8100:8000"
26+
27+
# Prefect task manager UI (default: 4200)
28+
task-manager:
29+
ports:
30+
- "4201:4200"
31+
32+
# Service catalog Streamlit app (default: 8501)
33+
streamlit-service-catalog:
34+
ports:
35+
- "8502:8501"
36+
environment:
37+
# Update this to match your Infrahub server port
38+
- INFRAHUB_UI_URL=http://localhost:8100

tasks.py

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,31 +26,59 @@
2626
INFRAHUB_SERVICE_CATALOG = os.getenv("INFRAHUB_SERVICE_CATALOG", "false").lower() == "true"
2727
INFRAHUB_GIT_LOCAL = os.getenv("INFRAHUB_GIT_LOCAL", "false").lower() == "true"
2828
MAIN_DIRECTORY_PATH = Path(__file__).parent
29+
INFRAHUB_PROJECT_NAME = os.getenv("INFRAHUB_PROJECT_NAME", MAIN_DIRECTORY_PATH.name)
2930

3031

3132
# Download compose file and use with override
3233
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+
"""
3444
local_compose_file = MAIN_DIRECTORY_PATH / "docker-compose.yml"
3545
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))
3663

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
3869
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}"
4371

4472
# Fall back to downloading from infrahub.opsmill.io
45-
# Determine the base URL based on edition
4673
if INFRAHUB_ENTERPRISE:
4774
base_url = f"https://infrahub.opsmill.io/enterprise/{INFRAHUB_VERSION}"
4875
else:
4976
base_url = f"https://infrahub.opsmill.io/{INFRAHUB_VERSION}"
5077

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 -"
5482

5583

5684
def get_compose_source() -> str:
@@ -119,6 +147,7 @@ def info(context: Context) -> None:
119147
info_msg = (
120148
f"[cyan]Edition:[/cyan] {edition}\n"
121149
f"[cyan]Version:[/cyan] {INFRAHUB_VERSION}\n"
150+
f"[cyan]Project Name:[/cyan] {INFRAHUB_PROJECT_NAME}\n"
122151
f"[cyan]Compose Source:[/cyan] {COMPOSE_SOURCE}\n"
123152
f"[cyan]Service Catalog:[/cyan] {'Enabled' if INFRAHUB_SERVICE_CATALOG else 'Disabled'}\n"
124153
f"[cyan]Local Git Repository:[/cyan] {'Enabled' if INFRAHUB_GIT_LOCAL else 'Disabled'}\n"

0 commit comments

Comments
 (0)