Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e0aa51bac3 | |||
| 94d0b989d0 | |||
| 2780b065d2 | |||
| ef691a4308 | |||
| 0fe68cc6df | |||
| 314393d61a |
@@ -232,25 +232,110 @@ def trigger_update(config: Any, db_path: str) -> dict:
|
||||
build_env.get("GIT_BRANCH", "?"),
|
||||
)
|
||||
|
||||
# 5. Fire-and-forget docker compose rebuild — the container will restart itself
|
||||
# Use the correct project name so compose finds/replaces the right container.
|
||||
# Only rebuild the app service — docker-socket-proxy must not be recreated.
|
||||
compose_cmd = [
|
||||
# 5. Two-phase rebuild: Build image first, then swap container.
|
||||
# The swap will kill this process (we ARE the container), so we must
|
||||
# ensure the compose-up runs detached on the Docker host via a wrapper.
|
||||
log_path = Path(BACKUP_DIR) / "update_rebuild.log"
|
||||
|
||||
# Phase A — build the new image (does NOT stop anything)
|
||||
build_cmd = [
|
||||
"docker", "compose",
|
||||
"-p", "netbirdmsp-appliance",
|
||||
"-f", f"{SOURCE_DIR}/docker-compose.yml",
|
||||
"up", "--build", "--no-deps", "-d",
|
||||
"build", "--no-cache",
|
||||
"netbird-msp-appliance",
|
||||
]
|
||||
log_path = Path(BACKUP_DIR) / "update_rebuild.log"
|
||||
log_file = open(log_path, "w")
|
||||
subprocess.Popen(
|
||||
compose_cmd,
|
||||
stdout=log_file,
|
||||
stderr=log_file,
|
||||
env=build_env,
|
||||
)
|
||||
logger.info("docker compose up --build -d triggered — container will restart shortly.")
|
||||
logger.info("Phase A: building new image …")
|
||||
try:
|
||||
build_result = subprocess.run(
|
||||
build_cmd,
|
||||
capture_output=True, text=True,
|
||||
timeout=600,
|
||||
env=build_env,
|
||||
)
|
||||
with open(log_path, "w") as f:
|
||||
f.write(build_result.stdout)
|
||||
f.write(build_result.stderr)
|
||||
if build_result.returncode != 0:
|
||||
logger.error("Image build failed: %s", build_result.stderr[:500])
|
||||
return {
|
||||
"ok": False,
|
||||
"message": f"Image build failed: {build_result.stderr[:300]}",
|
||||
"backup": backup_path,
|
||||
}
|
||||
except subprocess.TimeoutExpired:
|
||||
return {"ok": False, "message": "Image build timed out after 600s.", "backup": backup_path}
|
||||
|
||||
logger.info("Phase A complete — image built successfully.")
|
||||
|
||||
# Phase B — swap the container using a helper container.
|
||||
# When compose recreates our container, ALL processes inside die (PID namespace
|
||||
# is destroyed). So we launch a *separate* helper container via 'docker run -d'
|
||||
# that has access to the Docker socket and runs 'docker compose up -d'.
|
||||
# This helper lives outside our container and survives our restart.
|
||||
|
||||
# Discover the host-side path of /app-source (docker volumes use host paths)
|
||||
try:
|
||||
inspect_result = subprocess.run(
|
||||
["docker", "inspect", "netbird-msp-appliance",
|
||||
"--format", '{{range .Mounts}}{{if eq .Destination "/app-source"}}{{.Source}}{{end}}{{end}}'],
|
||||
capture_output=True, text=True, timeout=10,
|
||||
)
|
||||
host_source_dir = inspect_result.stdout.strip()
|
||||
if not host_source_dir:
|
||||
raise ValueError("Could not find /app-source mount")
|
||||
except Exception as exc:
|
||||
logger.error("Failed to discover host source path: %s", exc)
|
||||
return {"ok": False, "message": f"Could not find host source path: {exc}", "backup": backup_path}
|
||||
|
||||
logger.info("Host source directory: %s", host_source_dir)
|
||||
|
||||
env_flags = []
|
||||
for key in ("GIT_TAG", "GIT_COMMIT", "GIT_BRANCH", "GIT_COMMIT_DATE"):
|
||||
val = build_env.get(key, "unknown")
|
||||
env_flags.extend(["-e", f"{key}={val}"])
|
||||
|
||||
# Use the same image we're already running (it has docker CLI + compose plugin)
|
||||
own_image = "netbirdmsp-appliance-netbird-msp-appliance:latest"
|
||||
|
||||
helper_cmd = [
|
||||
"docker", "run", "-d",
|
||||
"--name", "msp-updater",
|
||||
"-v", "/var/run/docker.sock:/var/run/docker.sock",
|
||||
"-v", f"{host_source_dir}:{host_source_dir}:ro",
|
||||
*env_flags,
|
||||
own_image,
|
||||
"sh", "-c",
|
||||
(
|
||||
"sleep 3 && "
|
||||
"docker compose -p netbirdmsp-appliance "
|
||||
f"-f {host_source_dir}/docker-compose.yml "
|
||||
"up --force-recreate --no-deps -d netbird-msp-appliance"
|
||||
),
|
||||
]
|
||||
try:
|
||||
# Remove stale updater container if any
|
||||
subprocess.run(
|
||||
["docker", "rm", "-f", "msp-updater"],
|
||||
capture_output=True, timeout=10,
|
||||
)
|
||||
result = subprocess.run(
|
||||
helper_cmd,
|
||||
capture_output=True, text=True,
|
||||
timeout=30,
|
||||
env=build_env,
|
||||
)
|
||||
if result.returncode != 0:
|
||||
logger.error("Failed to start updater container: %s", result.stderr.strip())
|
||||
return {
|
||||
"ok": False,
|
||||
"message": f"Update-Container konnte nicht gestartet werden: {result.stderr.strip()[:200]}",
|
||||
"backup": backup_path,
|
||||
}
|
||||
logger.info("Phase B: updater container started — this container will restart in ~5s.")
|
||||
except Exception as exc:
|
||||
logger.error("Failed to launch updater: %s", exc)
|
||||
return {"ok": False, "message": f"Updater launch failed: {exc}", "backup": backup_path}
|
||||
|
||||
return {
|
||||
"ok": True,
|
||||
|
||||
8
containers.txt
Normal file
8
containers.txt
Normal file
@@ -0,0 +1,8 @@
|
||||
msp-updater Exited (2) 11 seconds ago netbirdmsp-appliance-netbird-msp-appliance:latest 15 seconds ago
|
||||
netbird-msp-appliance Up 6 minutes (healthy) 07c60529cf9f 6 minutes ago
|
||||
netbird-kunde1-caddy Up 2 hours caddy:2-alpine 3 hours ago
|
||||
netbird-kunde1-signal Up 2 hours netbirdio/signal:latest 3 hours ago
|
||||
netbird-kunde1-dashboard Up 2 hours netbirdio/dashboard:latest 3 hours ago
|
||||
netbird-kunde1-relay Up 2 hours netbirdio/relay:latest 3 hours ago
|
||||
netbird-kunde1-management Up 2 hours netbirdio/management:latest 3 hours ago
|
||||
docker-socket-proxy Up 2 hours tecnativa/docker-socket-proxy:latest 3 days ago
|
||||
1
helper.txt
Normal file
1
helper.txt
Normal file
@@ -0,0 +1 @@
|
||||
Error response from daemon: No such container: msp-updater
|
||||
40
logs.txt
Normal file
40
logs.txt
Normal file
@@ -0,0 +1,40 @@
|
||||
INFO: Application startup complete.
|
||||
INFO: Uvicorn running on http://0.0.0.0:8000 (Press CTRL+C to quit)
|
||||
INFO: 127.0.0.1:60204 - "GET /api/health HTTP/1.1" 200 OK
|
||||
INFO: 127.0.0.1:37702 - "GET /api/health HTTP/1.1" 200 OK
|
||||
INFO: 127.0.0.1:34872 - "GET /api/health HTTP/1.1" 200 OK
|
||||
INFO: 127.0.0.1:49808 - "GET /api/health HTTP/1.1" 200 OK
|
||||
2026-02-22 14:16:10,300 [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 14:16:10,306 [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:53698 - "GET /api/settings/version HTTP/1.1" 200 OK
|
||||
2026-02-22 14:16:13,790 [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 14:16:13,796 [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:53698 - "GET /api/settings/version HTTP/1.1" 200 OK
|
||||
INFO: 127.0.0.1:55164 - "GET /api/health HTTP/1.1" 200 OK
|
||||
INFO: 172.18.0.1:55590 - "GET / HTTP/1.1" 200 OK
|
||||
INFO: 172.18.0.1:55590 - "GET /js/app.js HTTP/1.1" 304 Not Modified
|
||||
INFO: 172.18.0.1:55590 - "GET /lang/en.json HTTP/1.1" 304 Not Modified
|
||||
INFO: 172.18.0.1:55590 - "GET /lang/de.json HTTP/1.1" 304 Not Modified
|
||||
INFO: 172.18.0.1:55590 - "GET /favicon.ico HTTP/1.1" 404 Not Found
|
||||
INFO: 172.18.0.1:55590 - "GET /api/settings/branding HTTP/1.1" 200 OK
|
||||
INFO: 172.18.0.1:55590 - "GET /api/auth/azure/config HTTP/1.1" 200 OK
|
||||
INFO: 172.18.0.1:55590 - "GET /api/auth/me HTTP/1.1" 200 OK
|
||||
INFO: 172.18.0.1:55590 - "GET /api/monitoring/status HTTP/1.1" 200 OK
|
||||
INFO: 172.18.0.1:55588 - "GET /api/customers?page=1&per_page=25 HTTP/1.1" 200 OK
|
||||
INFO: 172.18.0.1:37544 - "GET /api/settings/system HTTP/1.1" 200 OK
|
||||
INFO: 172.18.0.1:37544 - "GET /api/auth/mfa/status HTTP/1.1" 200 OK
|
||||
2026-02-22 14:16:58,896 [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 14:16:58,906 [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:37552 - "GET /api/settings/version HTTP/1.1" 200 OK
|
||||
INFO: 127.0.0.1:57972 - "GET /api/health HTTP/1.1" 200 OK
|
||||
INFO: 127.0.0.1:59030 - "GET /api/health HTTP/1.1" 200 OK
|
||||
2026-02-22 14:17:44,793 [INFO] app.services.update_service: Database backed up to /app/backups/netbird_msp_20260222_141744.db
|
||||
2026-02-22 14:17:45,142 [INFO] app.services.update_service: git pull succeeded: Already up to date.
|
||||
2026-02-22 14:17:45,160 [INFO] app.services.update_service: Rebuilding with GIT_TAG=alpha-1.5 GIT_COMMIT=94d0b98 GIT_BRANCH=unstable
|
||||
2026-02-22 14:17:45,160 [INFO] app.services.update_service: Phase A: building new image …
|
||||
2026-02-22 14:20:39,486 [INFO] app.services.update_service: Phase A complete — image built successfully.
|
||||
2026-02-22 14:20:39,507 [INFO] app.services.update_service: Host source directory: /home/sascha/NetBirdMSP-Appliance
|
||||
2026-02-22 14:20:40,068 [INFO] app.services.update_service: Phase B: updater container started — this container will restart in ~5s.
|
||||
2026-02-22 14:20:40,069 [INFO] app.routers.settings: Update triggered by admin.
|
||||
INFO: 172.18.0.1:51826 - "POST /api/settings/update HTTP/1.1" 200 OK
|
||||
INFO: 127.0.0.1:36054 - "GET /api/health HTTP/1.1" 200 OK
|
||||
10
out.txt
Normal file
10
out.txt
Normal file
@@ -0,0 +1,10 @@
|
||||
[unstable 94d0b98] alpha-1.5: trigger update
|
||||
remote:
|
||||
remote: Create a new pull request for 'unstable':
|
||||
remote: https://git.0x26.ch/BurgerGames/NetBirdMSP-Appliance/pulls/new/unstable
|
||||
remote:
|
||||
remote: .. Processing 2 references
|
||||
remote: Processed 2 references in total
|
||||
To https://git.0x26.ch/BurgerGames/NetBirdMSP-Appliance.git
|
||||
2780b06..94d0b98 unstable -> unstable
|
||||
* [new tag] alpha-1.5 -> alpha-1.5
|
||||
1
update_helper.txt
Normal file
1
update_helper.txt
Normal file
@@ -0,0 +1 @@
|
||||
sh: 1: cannot create /home/sascha/NetBirdMSP-Appliance/app/backups/updater.log: Directory nonexistent
|
||||
Reference in New Issue
Block a user