mirror of
				https://github.com/kevinveenbirkenbach/computer-playbook.git
				synced 2025-10-31 10:19:09 +00:00 
			
		
		
		
	Optimized deployment script
This commit is contained in:
		
							
								
								
									
										17
									
								
								Makefile
									
									
									
									
									
								
							
							
						
						
									
										17
									
								
								Makefile
									
									
									
									
									
								
							| @@ -41,7 +41,7 @@ dockerignore: | ||||
| 	cat .gitignore > .dockerignore | ||||
| 	echo ".git" >> .dockerignore  | ||||
|  | ||||
| build: clean dockerignore | ||||
| messy-build: dockerignore | ||||
| 	@echo "🔧 Generating users defaults → $(USERS_OUT)…" | ||||
| 	python3 $(USERS_SCRIPT) \ | ||||
| 	  --roles-dir $(ROLES_DIR) \ | ||||
| @@ -65,14 +65,17 @@ build: clean dockerignore | ||||
| 	  echo "  ✅ $$out"; \ | ||||
| 	) | ||||
|  | ||||
| install: build | ||||
| 	@echo "⚙️  Install complete." | ||||
|  | ||||
| messy-test: | ||||
| messy-test:  | ||||
| 	@echo "🧪 Running Python tests…" | ||||
| 	PYTHONPATH=. python -m unittest discover -s tests | ||||
| 	@echo "📑 Checking Ansible syntax…" | ||||
| 	ansible-playbook playbook.yml --syntax-check | ||||
|  | ||||
| test: build partial-test | ||||
| 	@echo "Full test with build terminated." | ||||
| install: build | ||||
| 	@echo "⚙️  Install complete." | ||||
|  | ||||
| build: clean messy-build | ||||
| 	@echo "Full build with cleanup before was executed." | ||||
|  | ||||
| test: build messy-test | ||||
| 	@echo "Full test with build before was executed." | ||||
|   | ||||
| @@ -1,13 +1,15 @@ | ||||
| #!/usr/bin/env python3 | ||||
| import argparse | ||||
| import os | ||||
| import shutil | ||||
| import sys | ||||
| import ipaddress | ||||
| import difflib | ||||
| from jinja2 import Environment, FileSystemLoader | ||||
| from ruamel.yaml import YAML | ||||
|  | ||||
| import sys, os | ||||
| sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) | ||||
| from module_utils.entity_name_utils import get_entity_name | ||||
|  | ||||
| # Paths to the group-vars files | ||||
| PORTS_FILE = './group_vars/all/09_ports.yml' | ||||
| NETWORKS_FILE = './group_vars/all/10_networks.yml' | ||||
| @@ -65,6 +67,7 @@ def prompt_conflict(dst_file): | ||||
| def render_templates(src_dir, dst_dir, context): | ||||
|     env = Environment(loader=FileSystemLoader(src_dir), keep_trailing_newline=True, autoescape=False) | ||||
|     env.filters['bool'] = lambda x: bool(x) | ||||
|     env.filters['get_entity_name'] = get_entity_name | ||||
|  | ||||
|     for root, _, files in os.walk(src_dir): | ||||
|         rel = os.path.relpath(root, src_dir) | ||||
|   | ||||
| @@ -15,14 +15,20 @@ def run_ansible_playbook( | ||||
|     verbose=0, | ||||
|     skip_tests=False, | ||||
|     skip_validation=False, | ||||
|     skip_build=False,   # <-- new parameter | ||||
|     skip_build=False, | ||||
| ): | ||||
|     start_time = datetime.datetime.now() | ||||
|     print(f"\n▶️ Script started at: {start_time.isoformat()}\n") | ||||
|  | ||||
|     if not skip_build: | ||||
|         print("\n🛠️  Building project (make build)...\n") | ||||
|         subprocess.run(["make", "build"], check=True) | ||||
|         print("\n🧹 Cleaning up project (make clean)...\n") | ||||
|         subprocess.run(["make", "clean"], check=True) | ||||
|     else: | ||||
|         print("\n⚠️ Skipping build as requested.\n") | ||||
|  | ||||
|     if not skip_build: | ||||
|         print("\n🛠️  Building project (make messy-build)...\n") | ||||
|         subprocess.run(["make", "messy-build"], check=True) | ||||
|     else: | ||||
|         print("\n⚠️ Skipping build as requested.\n") | ||||
|  | ||||
| @@ -50,8 +56,8 @@ def run_ansible_playbook( | ||||
|         print("\n⚠️ Skipping inventory validation as requested.\n") | ||||
|  | ||||
|     if not skip_tests: | ||||
|         print("\n🧪 Running tests (make test)...\n") | ||||
|         subprocess.run(["make", "test"], check=True) | ||||
|         print("\n🧪 Running tests (make messy-test)...\n") | ||||
|         subprocess.run(["make", "messy-test"], check=True) | ||||
|  | ||||
|     # Build ansible-playbook command | ||||
|     cmd = ["ansible-playbook", "-i", inventory, playbook] | ||||
| @@ -140,7 +146,7 @@ def main(): | ||||
|     ) | ||||
|     parser.add_argument( | ||||
|         "-c", "--cleanup", action="store_true", | ||||
|         help="Clean up unused files and outdated configurations after all tasks are complete." | ||||
|         help="Clean up unused files and outdated configurations after all tasks are complete. Also cleans up the repository before the deployment procedure." | ||||
|     ) | ||||
|     parser.add_argument( | ||||
|         "-d", "--debug", action="store_true", | ||||
|   | ||||
		Reference in New Issue
	
	Block a user