Skip to content

Commit f0beb88

Browse files
committed
add git local dir for development
1 parent 282a3eb commit f0beb88

File tree

6 files changed

+80
-10
lines changed

6 files changed

+80
-10
lines changed

.env.example

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,17 @@ export INFRAHUB_VERSION=1.5.1
2525
# Set to "true" to enable enterprise features, "false" for community edition
2626
export INFRAHUB_ENTERPRISE=false
2727

28+
# Use local git repository instead of GitHub
29+
# Set to "true" to mount the current directory as the git repository in Infrahub
30+
# This is useful for local development and testing of generator/transform changes
31+
# When enabled:
32+
# - Infrahub will use /upstream (the mounted current directory) as the repo
33+
# - Bootstrap script loads objects/git-repo/local-dev.yml
34+
# When disabled (default):
35+
# - Infrahub will clone from GitHub
36+
# - Bootstrap script loads objects/git-repo/github.yml
37+
export INFRAHUB_GIT_LOCAL=false
38+
2839
# =============================================================================
2940
# Service Catalog Configuration
3041
# =============================================================================

CLAUDE.md

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,10 @@ uv run infrahubctl object load objects/bootstrap --branch main
4545
# Load security data
4646
uv run infrahubctl object load objects/security/ --branch main
4747

48-
# Add demo repository
49-
uv run infrahubctl repository add DEMO https://github.com/opsmill/infrahub-bundle-dc.git --read-only --ref main
48+
# Add bundle-dc repository (loaded from objects/git-repo/*.yml based on INFRAHUB_GIT_LOCAL)
49+
# - objects/git-repo/github.yml for GitHub (default)
50+
# - objects/git-repo/local-dev.yml for local /upstream mount
51+
uv run infrahubctl object load objects/git-repo/github.yml --branch main
5052

5153
# Load event actions (optional)
5254
uv run infrahubctl object load objects/events/ --branch main
@@ -344,7 +346,22 @@ INFRAHUB_ADDRESS="http://localhost:8000"
344346
INFRAHUB_API_TOKEN="06438eb2-8019-4776-878c-0941b1f1d1ec"
345347
```
346348

347-
Note: The token above is a demo token for local development only.
349+
Optional environment variables for development:
350+
351+
```bash
352+
# Use local git repository instead of GitHub (for development/testing)
353+
INFRAHUB_GIT_LOCAL="true" # Default: false
354+
```
355+
356+
When `INFRAHUB_GIT_LOCAL=true`:
357+
358+
- Infrahub will use the current directory mounted at `/upstream` as the git repository
359+
- Useful for testing generator, transform, and check changes without pushing to GitHub
360+
- The volume mount is configured in `docker-compose.override.yml`
361+
- Bootstrap script automatically loads `objects/git-repo/local-dev.yml` (pointing to `/upstream`)
362+
- When disabled (default), bootstrap loads `objects/git-repo/github.yml` (pointing to GitHub URL)
363+
364+
Note: The API token above is a demo token for local development only.
348365

349366
## Bootstrap Process
350367

@@ -366,8 +383,8 @@ uv run infrahubctl object load objects/bootstrap
366383
# 5. Load security data (optional)
367384
uv run infrahubctl object load objects/security/
368385
369-
# 6. Add repository
370-
uv run infrahubctl repository add DEMO https://github.com/opsmill/infrahub-bundle-dc.git --read-only --ref main
386+
# 6. Add repository (loaded from objects/git-repo/*.yml based on INFRAHUB_GIT_LOCAL)
387+
uv run infrahubctl object load objects/git-repo/github.yml --branch main
371388
372389
# 7. Load event actions (optional)
373390
uv run infrahubctl object load objects/events/
@@ -446,6 +463,9 @@ The project includes a Streamlit-based service catalog application:
446463
- `18_devices.yml` - Pre-configured devices (corp-firewall, cisco-switch-01, etc.)
447464
- `19_docs.yml` - Documentation links
448465
- `objects/dc/` - Data center demo scenario files (Arista, Cisco, Juniper, SONiC)
466+
- `objects/git-repo/` - Repository configuration objects
467+
- `github.yml` - GitHub repository configuration (default)
468+
- `local-dev.yml` - Local development repository configuration (when INFRAHUB_GIT_LOCAL=true)
449469
- `objects/security/` - Security-related demo data
450470
- `objects/cloud_security/` - Cloud security examples
451471
- `objects/events/` - Event action definitions

docker-compose.override.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@ services:
99
- NEO4J_dbms_memory_heap_max__size=4g
1010
- NEO4J_dbms_memory_pagecache_size=2g
1111

12+
# Mount local repository for local development
13+
# Used when INFRAHUB_GIT_LOCAL=true to work with local generator/transform changes
14+
infrahub-git:
15+
volumes:
16+
- ./:/upstream
17+
18+
task-worker:
19+
volumes:
20+
- ./:/upstream
21+
1222
streamlit-service-catalog:
1323
build:
1424
context: ./service_catalog

objects/git-repo/github.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
apiVersion: infrahub.app/v1
3+
kind: Object
4+
spec:
5+
kind: CoreRepository
6+
data:
7+
- name: bundle-dc
8+
location: "https://github.com/opsmill/infrahub-bundle-dc.git"
9+
default_branch: "main"

objects/git-repo/local-dev.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
apiVersion: infrahub.app/v1
3+
kind: Object
4+
spec:
5+
kind: CoreRepository
6+
data:
7+
- name: bundle-dc
8+
location: "/upstream"
9+
default_branch: "main"

scripts/bootstrap.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
- Bootstrap data (locations, platforms, roles)
99
- Security data
1010
- User accounts and roles (emma, otto)
11-
- Demo repository
11+
- Bundle-dc repository
1212
- Event actions
1313
1414
Features:
@@ -25,6 +25,7 @@
2525
"""
2626

2727
import argparse
28+
import os
2829
import subprocess
2930
import sys
3031
import time
@@ -46,6 +47,7 @@
4647
console = Console()
4748

4849
INFRAHUB_ADDRESS = "http://localhost:8000"
50+
INFRAHUB_GIT_LOCAL = os.getenv("INFRAHUB_GIT_LOCAL", "false").lower() == "true"
4951

5052

5153
def check_infrahub_ready(max_retries: int = 30, sleep_time: int = 2) -> bool:
@@ -157,14 +159,14 @@ def main(branch: str = "main") -> int:
157159
console.print()
158160
console.print(
159161
Panel(
160-
f"[bold bright_blue]🚀 Infrahub Demo Bootstrap[/bold bright_blue]\n"
162+
f"[bold bright_blue]🚀 Infrahub bundle-dc Bootstrap[/bold bright_blue]\n"
161163
f"[bright_cyan]Branch:[/bright_cyan] [bold yellow]{branch}[/bold yellow]\n\n"
162164
"[dim]This will load:[/dim]\n"
163165
" [blue]•[/blue] Schemas\n"
164166
" [magenta]•[/magenta] Menu definitions\n"
165167
" [yellow]•[/yellow] Bootstrap data\n"
166168
" [green]•[/green] Security data\n"
167-
" [bright_magenta]•[/bright_magenta] Demo repository",
169+
" [bright_magenta]•[/bright_magenta] bundle-dc repository",
168170
border_style="bright_blue",
169171
box=box.SIMPLE,
170172
title="[bold bright_blue]Bootstrap Process[/bold bright_blue]",
@@ -238,10 +240,19 @@ def main(branch: str = "main") -> int:
238240

239241
# Add repository (may already exist)
240242
console.print(
241-
"\n[bold bright_magenta on black][7/8][/bold bright_magenta on black] 📚 [bold white]Adding demo repository[/bold white]"
243+
"\n[bold bright_magenta on black][7/8][/bold bright_magenta on black] 📚 [bold white]Adding bundle-dc repository[/bold white]"
242244
)
245+
246+
# Use local repository if INFRAHUB_GIT_LOCAL is enabled, otherwise use GitHub
247+
if INFRAHUB_GIT_LOCAL:
248+
repo_file = "objects/git-repo/local-dev.yml"
249+
console.print("[dim]Using local repository: /upstream[/dim]")
250+
else:
251+
repo_file = "objects/git-repo/github.yml"
252+
console.print("[dim]Using GitHub repository: https://github.com/opsmill/infrahub-bundle-dc.git[/dim]")
253+
243254
result = subprocess.run(
244-
"uv run infrahubctl repository add DEMO https://github.com/opsmill/infrahub-bundle-dc.git --ref main --read-only --ref main",
255+
f"uv run infrahubctl object load {repo_file} --branch {branch}",
245256
shell=True,
246257
capture_output=True,
247258
text=True,

0 commit comments

Comments
 (0)