From fc9589b6f93365a7b63ee9e8446c1834c175914a Mon Sep 17 00:00:00 2001 From: Sascha Lustenberger Date: Sun, 22 Feb 2026 14:32:08 +0100 Subject: [PATCH] =?UTF-8?q?fix:=20trigger=5Fupdate=20setzt=20GIT=5FTAG/GIT?= =?UTF-8?q?=5FCOMMIT=20env=20vars=20f=C3=BCr=20docker=20compose=20rebuild?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/update_service.py | 43 +++++++++++++++++++++++++++-- dockerlogs.txt | 50 ++++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+), 3 deletions(-) create mode 100644 dockerlogs.txt diff --git a/app/services/update_service.py b/app/services/update_service.py index 1ba811c..bd3132f 100644 --- a/app/services/update_service.py +++ b/app/services/update_service.py @@ -2,6 +2,7 @@ import json import logging +import os import shutil import subprocess from datetime import datetime @@ -198,16 +199,52 @@ def trigger_update(config: Any, db_path: str) -> dict: logger.info("git pull succeeded: %s", result.stdout.strip()[:200]) - # 4. Fire-and-forget docker compose rebuild — the container will restart itself + # 4. Read version info from the freshly-pulled source + build_env = os.environ.copy() + try: + build_env["GIT_COMMIT"] = subprocess.run( + ["git", "-C", SOURCE_DIR, "rev-parse", "--short", "HEAD"], + capture_output=True, text=True, timeout=10, + ).stdout.strip() or "unknown" + + build_env["GIT_BRANCH"] = subprocess.run( + ["git", "-C", SOURCE_DIR, "rev-parse", "--abbrev-ref", "HEAD"], + capture_output=True, text=True, timeout=10, + ).stdout.strip() or "unknown" + + build_env["GIT_COMMIT_DATE"] = subprocess.run( + ["git", "-C", SOURCE_DIR, "log", "-1", "--format=%cI"], + capture_output=True, text=True, timeout=10, + ).stdout.strip() or "unknown" + + tag_result = subprocess.run( + ["git", "-C", SOURCE_DIR, "describe", "--tags", "--abbrev=0"], + capture_output=True, text=True, timeout=10, + ) + build_env["GIT_TAG"] = tag_result.stdout.strip() if tag_result.returncode == 0 else "unknown" + except Exception as exc: + logger.warning("Could not read version info from source: %s", exc) + + logger.info( + "Rebuilding with GIT_TAG=%s GIT_COMMIT=%s GIT_BRANCH=%s", + build_env.get("GIT_TAG", "?"), + build_env.get("GIT_COMMIT", "?"), + build_env.get("GIT_BRANCH", "?"), + ) + + # 5. Fire-and-forget docker compose rebuild — the container will restart itself compose_cmd = [ "docker", "compose", "-f", f"{SOURCE_DIR}/docker-compose.yml", "up", "--build", "-d", ] + log_path = Path(BACKUP_DIR) / "update_rebuild.log" + log_file = open(log_path, "w") subprocess.Popen( compose_cmd, - stdout=subprocess.DEVNULL, - stderr=subprocess.DEVNULL, + stdout=log_file, + stderr=log_file, + env=build_env, ) logger.info("docker compose up --build -d triggered — container will restart shortly.") diff --git a/dockerlogs.txt b/dockerlogs.txt new file mode 100644 index 0000000..964353c --- /dev/null +++ b/dockerlogs.txt @@ -0,0 +1,50 @@ +INFO: 172.18.0.1:33288 - "GET /api/settings/version HTTP/1.1" 200 OK +2026-02-22 13:27:28,812 [INFO] httpx: HTTP Request: GET https://git.0x26.ch/api/v1/repos/BurgerGames/NetBirdMSP-Appliance/branches/unstable "HTTP/1.1 200 OK" +2026-02-22 13:27:28,818 [INFO] httpx: HTTP Request: GET https://git.0x26.ch/api/v1/repos/BurgerGames/NetBirdMSP-Appliance/tags?limit=1 "HTTP/1.1 200 OK" +INFO: 172.18.0.1:33288 - "GET /api/settings/version HTTP/1.1" 200 OK +2026-02-22 13:27:29,463 [INFO] httpx: HTTP Request: GET https://git.0x26.ch/api/v1/repos/BurgerGames/NetBirdMSP-Appliance/branches/unstable "HTTP/1.1 200 OK" +2026-02-22 13:27:29,473 [INFO] httpx: HTTP Request: GET https://git.0x26.ch/api/v1/repos/BurgerGames/NetBirdMSP-Appliance/tags?limit=1 "HTTP/1.1 200 OK" +INFO: 172.18.0.1:33288 - "GET /api/settings/version HTTP/1.1" 200 OK +2026-02-22 13:27:33,352 [INFO] httpx: HTTP Request: GET https://git.0x26.ch/api/v1/repos/BurgerGames/NetBirdMSP-Appliance/branches/unstable "HTTP/1.1 200 OK" +2026-02-22 13:27:33,358 [INFO] httpx: HTTP Request: GET https://git.0x26.ch/api/v1/repos/BurgerGames/NetBirdMSP-Appliance/tags?limit=1 "HTTP/1.1 200 OK" +INFO: 172.18.0.1:33288 - "GET /api/settings/version HTTP/1.1" 200 OK +2026-02-22 13:27:34,899 [INFO] httpx: HTTP Request: GET https://git.0x26.ch/api/v1/repos/BurgerGames/NetBirdMSP-Appliance/branches/unstable "HTTP/1.1 200 OK" +2026-02-22 13:27:34,905 [INFO] httpx: HTTP Request: GET https://git.0x26.ch/api/v1/repos/BurgerGames/NetBirdMSP-Appliance/tags?limit=1 "HTTP/1.1 200 OK" +INFO: 172.18.0.1:33288 - "GET /api/settings/version HTTP/1.1" 200 OK +INFO: 172.18.0.1:33288 - "GET /api/settings/system HTTP/1.1" 200 OK +INFO: 172.18.0.1:33288 - "GET /api/auth/mfa/status HTTP/1.1" 200 OK +INFO: 172.18.0.1:33288 - "GET /api/monitoring/resources HTTP/1.1" 200 OK +INFO: 172.18.0.1:38946 - "GET /api/monitoring/customers HTTP/1.1" 200 OK +INFO: 172.18.0.1:38946 - "GET /api/monitoring/customers HTTP/1.1" 200 OK +INFO: 172.18.0.1:33288 - "GET /api/monitoring/resources HTTP/1.1" 200 OK +INFO: 172.18.0.1:33288 - "GET /api/settings/system HTTP/1.1" 200 OK +INFO: 172.18.0.1:38946 - "GET /api/auth/mfa/status HTTP/1.1" 200 OK +2026-02-22 13:27:49,427 [INFO] httpx: HTTP Request: GET https://git.0x26.ch/api/v1/repos/BurgerGames/NetBirdMSP-Appliance/branches/unstable "HTTP/1.1 200 OK" +2026-02-22 13:27:49,433 [INFO] httpx: HTTP Request: GET https://git.0x26.ch/api/v1/repos/BurgerGames/NetBirdMSP-Appliance/tags?limit=1 "HTTP/1.1 200 OK" +INFO: 172.18.0.1:33288 - "GET /api/settings/version HTTP/1.1" 200 OK +INFO: 172.18.0.1:33288 - "GET / HTTP/1.1" 200 OK +INFO: 172.18.0.1:38946 - "GET /api/settings/branding HTTP/1.1" 200 OK +INFO: 172.18.0.1:38946 - "GET /api/auth/azure/config HTTP/1.1" 200 OK +INFO: 172.18.0.1:38946 - "GET /api/auth/me HTTP/1.1" 200 OK +INFO: 172.18.0.1:38946 - "GET /api/monitoring/status HTTP/1.1" 200 OK +INFO: 172.18.0.1:45440 - "GET /api/customers?page=1&per_page=25 HTTP/1.1" 200 OK +INFO: 127.0.0.1:35528 - "GET /api/health HTTP/1.1" 200 OK +INFO: 172.18.0.1:33288 - "GET /api/settings/system HTTP/1.1" 200 OK +INFO: 172.18.0.1:38946 - "GET /api/auth/mfa/status HTTP/1.1" 200 OK +2026-02-22 13:27:56,795 [INFO] httpx: HTTP Request: GET https://git.0x26.ch/api/v1/repos/BurgerGames/NetBirdMSP-Appliance/branches/unstable "HTTP/1.1 200 OK" +2026-02-22 13:27:56,802 [INFO] httpx: HTTP Request: GET https://git.0x26.ch/api/v1/repos/BurgerGames/NetBirdMSP-Appliance/tags?limit=1 "HTTP/1.1 200 OK" +INFO: 172.18.0.1:33288 - "GET /api/settings/version HTTP/1.1" 200 OK +2026-02-22 13:27:59,507 [INFO] httpx: HTTP Request: GET https://git.0x26.ch/api/v1/repos/BurgerGames/NetBirdMSP-Appliance/branches/unstable "HTTP/1.1 200 OK" +2026-02-22 13:27:59,514 [INFO] httpx: HTTP Request: GET https://git.0x26.ch/api/v1/repos/BurgerGames/NetBirdMSP-Appliance/tags?limit=1 "HTTP/1.1 200 OK" +INFO: 172.18.0.1:33288 - "GET /api/settings/version HTTP/1.1" 200 OK +2026-02-22 13:28:09,172 [INFO] app.services.update_service: Database backed up to /app/backups/netbird_msp_20260222_132809.db +2026-02-22 13:28:09,264 [INFO] app.services.update_service: git pull succeeded: Already up to date. +2026-02-22 13:28:09,265 [INFO] app.services.update_service: docker compose up --build -d triggered — container will restart shortly. +2026-02-22 13:28:09,265 [INFO] app.routers.settings: Update triggered by admin. +INFO: 172.18.0.1:57990 - "POST /api/settings/update HTTP/1.1" 200 OK +INFO: 127.0.0.1:51474 - "GET /api/health HTTP/1.1" 200 OK +2026-02-22 13:28:49,056 [INFO] httpx: HTTP Request: GET https://git.0x26.ch/api/v1/repos/BurgerGames/NetBirdMSP-Appliance/branches/unstable "HTTP/1.1 200 OK" +2026-02-22 13:28:49,062 [INFO] httpx: HTTP Request: GET https://git.0x26.ch/api/v1/repos/BurgerGames/NetBirdMSP-Appliance/tags?limit=1 "HTTP/1.1 200 OK" +INFO: 172.18.0.1:44506 - "GET /api/settings/version HTTP/1.1" 200 OK +INFO: 127.0.0.1:53966 - "GET /api/health HTTP/1.1" 200 OK +INFO: 127.0.0.1:35452 - "GET /api/health HTTP/1.1" 200 OK