fix: trying to fix auto-pulls 17 !
This commit is contained in:
@@ -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"}
|
||||
|
||||
Reference in New Issue
Block a user