fix: trying to fix auto-pulls 17 !

This commit is contained in:
2026-02-27 05:49:56 +02:00
parent 463034770e
commit 2177c1a406
2 changed files with 26 additions and 13 deletions

View File

@@ -43,24 +43,35 @@ async def deploy(request: Request):
logger.info("Auto-deploy triggered via Gitea webhook") logger.info("Auto-deploy triggered via Gitea webhook")
project_path = settings.deploy_project_path project_path = settings.deploy_project_path
cmd = ( # Write a deploy script to the host filesystem (via the mounted project path)
f"sleep 3 && " # then execute it with nsenter into the host's PID namespace so it runs as
f"git config --global --add safe.directory {project_path} && " # a host process — not a container child — and survives container restarts.
f"cd {project_path} && " script_path = f"{project_path}/deploy.sh"
f"git fetch origin main && " log_path = f"{project_path}/deploy.log"
f"git reset --hard origin/main && " script = (
f"docker-compose up -d --build" f"#!/bin/sh\n"
f" > /proc/1/fd/1 2>&1" 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 with open(script_path, "w") as f:
# before docker-compose tears down and restarts this container. 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( await asyncio.create_subprocess_shell(
cmd, trigger_cmd,
stdout=asyncio.subprocess.DEVNULL, stdout=asyncio.subprocess.DEVNULL,
stderr=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"} return {"ok": True, "message": "Deploy started"}

View File

@@ -13,6 +13,8 @@ services:
# Auto-deploy: project root and Docker socket # Auto-deploy: project root and Docker socket
- /home/bellsystems/bellsystems-cp:/home/bellsystems/bellsystems-cp - /home/bellsystems/bellsystems-cp:/home/bellsystems/bellsystems-cp
- /var/run/docker.sock:/var/run/docker.sock - /var/run/docker.sock:/var/run/docker.sock
pid: host
privileged: true
ports: ports:
- "8000:8000" - "8000:8000"
depends_on: [] depends_on: []