Fix webhook to run git pull directly in mounted repo
This commit is contained in:
@@ -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}")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user