From 0f1f40f2e0c6071317f334660c33882f1cda1c0b Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Fri, 18 Jul 2025 11:42:05 +0200 Subject: [PATCH] Optimized deployment script --- Makefile | 17 ++++++++++------- cli/create/role.py | 7 +++++-- cli/deploy.py | 18 ++++++++++++------ 3 files changed, 27 insertions(+), 15 deletions(-) diff --git a/Makefile b/Makefile index 79c78fdf..fe5c4fcf 100644 --- a/Makefile +++ b/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." diff --git a/cli/create/role.py b/cli/create/role.py index b8f86b17..c986ab68 100644 --- a/cli/create/role.py +++ b/cli/create/role.py @@ -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) diff --git a/cli/deploy.py b/cli/deploy.py index 8ff6d420..83b682b6 100644 --- a/cli/deploy.py +++ b/cli/deploy.py @@ -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",