From 2177c1a4068bd76460f223323313540034b89db5 Mon Sep 17 00:00:00 2001 From: bonamin Date: Fri, 27 Feb 2026 05:49:56 +0200 Subject: [PATCH] fix: trying to fix auto-pulls 17 ! --- backend/admin/router.py | 37 ++++++++++++++++++++++++------------- docker-compose.yml | 2 ++ 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/backend/admin/router.py b/backend/admin/router.py index 6af0cf6..9a2bb2d 100644 --- a/backend/admin/router.py +++ b/backend/admin/router.py @@ -43,24 +43,35 @@ async def deploy(request: Request): logger.info("Auto-deploy triggered via Gitea webhook") project_path = settings.deploy_project_path - cmd = ( - f"sleep 3 && " - f"git config --global --add safe.directory {project_path} && " - f"cd {project_path} && " - f"git fetch origin main && " - f"git reset --hard origin/main && " - f"docker-compose up -d --build" - f" > /proc/1/fd/1 2>&1" + # Write a deploy script to the host filesystem (via the mounted project path) + # then execute it with nsenter into the host's PID namespace so it runs as + # a host process — not a container child — and survives container restarts. + script_path = f"{project_path}/deploy.sh" + log_path = f"{project_path}/deploy.log" + script = ( + f"#!/bin/sh\n" + f"exec > {log_path} 2>&1\n" + f"echo \"Deploy started at $(date)\"\n" + f"git config --global --add safe.directory {project_path}\n" + f"cd {project_path}\n" + f"git fetch origin main\n" + f"git reset --hard origin/main\n" + f"docker-compose up -d --build\n" + f"echo \"Deploy finished at $(date)\"\n" ) - # Fire and forget — sleep gives uvicorn time to flush the HTTP response - # before docker-compose tears down and restarts this container. + with open(script_path, "w") as f: + f.write(script) + + # nsenter into host PID namespace (PID 1 = host init) so the process + # is owned by the host and survives this container restarting. + trigger_cmd = f"chmod +x {script_path} && nsenter -t 1 -m -u -i -n -p -- sh -c 'nohup {script_path} &'" + await asyncio.create_subprocess_shell( - cmd, + trigger_cmd, stdout=asyncio.subprocess.DEVNULL, stderr=asyncio.subprocess.DEVNULL, - start_new_session=True, ) - logger.info("Auto-deploy queued (starts in 3s)") + logger.info("Auto-deploy triggered on host via nsenter") return {"ok": True, "message": "Deploy started"} diff --git a/docker-compose.yml b/docker-compose.yml index 39239e0..2d5f4f1 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -13,6 +13,8 @@ services: # Auto-deploy: project root and Docker socket - /home/bellsystems/bellsystems-cp:/home/bellsystems/bellsystems-cp - /var/run/docker.sock:/var/run/docker.sock + pid: host + privileged: true ports: - "8000:8000" depends_on: []