diff --git a/app_new/__init__.py b/app_new/__init__.py index 098ecb7..43cf9d7 100644 --- a/app_new/__init__.py +++ b/app_new/__init__.py @@ -62,6 +62,12 @@ def create_app(config_name='default'): config_class = config_dict[config_name] app.config.from_object(config_class) config_class.init_app(app) + + # Affiché notamment dans le setup wizard afin d'identifier sans ambiguïté + # le code réellement exécuté par un conteneur, même avant installation. + from .core.build_info import get_build_commit + app.config['GIT_COMMIT'] = get_build_commit() + app.context_processor(lambda: {'build_commit': app.config['GIT_COMMIT']}) # Initialisation des extensions db.init_app(app) diff --git a/app_new/core/build_info.py b/app_new/core/build_info.py new file mode 100644 index 0000000..8005dc2 --- /dev/null +++ b/app_new/core/build_info.py @@ -0,0 +1,33 @@ +"""Informations sur le build actuellement exécuté.""" + +import os +import subprocess +from pathlib import Path + + +def get_build_commit(): + """Retourne l'identifiant du commit déployé. + + En production, le dépôt Git n'est pas forcément présent dans l'image : + les variables d'environnement sont donc prioritaires. Le fallback Git + permet de conserver un affichage utile en développement. + """ + for variable in ("GIT_COMMIT", "COMMIT_SHA", "SOURCE_VERSION"): + value = (os.environ.get(variable) or "").strip() + if value: + return value + + repository = Path(__file__).resolve().parents[2] + try: + result = subprocess.run( + ["git", "rev-parse", "HEAD"], + cwd=repository, + check=True, + capture_output=True, + text=True, + timeout=1, + ) + except (OSError, subprocess.SubprocessError): + return "inconnu" + commit = result.stdout.strip() + return commit or "inconnu" diff --git a/app_new/templates/setup_wizard/index.html b/app_new/templates/setup_wizard/index.html index 196f692..d373e82 100644 --- a/app_new/templates/setup_wizard/index.html +++ b/app_new/templates/setup_wizard/index.html @@ -6,6 +6,7 @@
{{ build_commit }}Le système GMAO a déjà été configuré.
+Commit déployé : {{ build_commit }}