Fix webhook to run git pull directly in mounted repo

This commit is contained in:
IGNY8 VPS (Salman)
2025-11-10 12:08:22 +00:00
parent 1923e42b27
commit ec1d64b710
2 changed files with 17 additions and 33 deletions

View File

@@ -530,42 +530,26 @@ def gitea_webhook(request):
logger.info(f"[Webhook] Processing push: {commit_count} commit(s) by {pusher} to {repo_full_name}")
# Pull latest code - use docker Python library to exec into gitea container
# Pull latest code - run git pull directly in the mounted repo
try:
import docker as docker_lib
import subprocess
logger.info(f"[Webhook] Pulling latest code...")
client = docker_lib.DockerClient(base_url='unix://var/run/docker.sock')
gitea_container = client.containers.get('gitea')
exec_result = gitea_container.exec_run(
'bash -c "git config --global --add safe.directory /deploy/igny8 2>/dev/null || true && '
'git -C /deploy/igny8 fetch origin main && '
'git -C /deploy/igny8 reset --hard origin/main"',
user='root'
result = subprocess.run(
['git', '-C', '/data/app/igny8', 'config', '--global', '--add', 'safe.directory', '/data/app/igny8'],
capture_output=True,
text=True,
timeout=5
)
if exec_result.exit_code == 0:
logger.info(f"[Webhook] Git pull successful")
result = subprocess.run(
['git', '-C', '/data/app/igny8', 'pull', 'origin', 'main'],
capture_output=True,
text=True,
timeout=30
)
if result.returncode == 0:
logger.info(f"[Webhook] Git pull successful: {result.stdout}")
else:
logger.error(f"[Webhook] Git pull failed: {exec_result.output.decode()}")
except ImportError:
# Fallback to subprocess if docker library not available
try:
import subprocess
logger.info(f"[Webhook] Pulling latest code (subprocess fallback)...")
result = subprocess.run(
['docker', 'exec', 'gitea', 'bash', '-c',
'git config --global --add safe.directory /deploy/igny8 2>/dev/null || true && '
'git -C /deploy/igny8 fetch origin main && '
'git -C /deploy/igny8 reset --hard origin/main'],
capture_output=True,
text=True,
timeout=30
)
if result.returncode == 0:
logger.info(f"[Webhook] Git pull successful")
else:
logger.error(f"[Webhook] Git pull failed: {result.stderr}")
except Exception as e:
logger.error(f"[Webhook] Git pull error: {e}")
logger.error(f"[Webhook] Git pull failed: {result.stderr}")
except Exception as e:
logger.error(f"[Webhook] Git pull error: {e}")

View File

@@ -43,7 +43,7 @@ services:
# SECRET_KEY should be set via environment variable in production
volumes:
- /data/app/igny8/backend:/app:rw
- /data/app/igny8:/data/app/igny8:ro
- /data/app/igny8:/data/app/igny8:rw
- /var/run/docker.sock:/var/run/docker.sock:ro
- /data/app/logs:/app/logs:rw
# Note: postgres and redis are external services from infra stack