disable webhook container restart
This commit is contained in:
@@ -670,83 +670,87 @@ def gitea_webhook(request):
|
||||
deployment_success = False
|
||||
deployment_error = None
|
||||
|
||||
try:
|
||||
# Try to use docker Python library first, fallback to subprocess
|
||||
try:
|
||||
import docker as docker_lib
|
||||
client = docker_lib.DockerClient(base_url='unix://var/run/docker.sock')
|
||||
|
||||
# Restart frontend container (don't restart backend from within itself)
|
||||
logger.info(f"[Webhook] Restarting frontend container...")
|
||||
frontend_container = client.containers.get("igny8_frontend")
|
||||
frontend_container.restart(timeout=30)
|
||||
logger.info(f"[Webhook] Frontend container restarted successfully")
|
||||
|
||||
# Schedule backend restart via subprocess in background (non-blocking)
|
||||
# This avoids deadlock from restarting the container we're running in
|
||||
logger.info(f"[Webhook] Scheduling backend container restart...")
|
||||
import threading
|
||||
def restart_backend():
|
||||
import time
|
||||
time.sleep(2) # Give webhook time to respond
|
||||
try:
|
||||
backend_container = client.containers.get("igny8_backend")
|
||||
backend_container.restart(timeout=30)
|
||||
logger.info(f"[Webhook] Backend container restarted successfully (delayed)")
|
||||
except Exception as e:
|
||||
logger.error(f"[Webhook] Delayed backend restart failed: {e}")
|
||||
|
||||
restart_thread = threading.Thread(target=restart_backend, daemon=True)
|
||||
restart_thread.start()
|
||||
|
||||
deployment_success = True
|
||||
|
||||
except ImportError:
|
||||
# Fallback to subprocess with docker command
|
||||
logger.info(f"[Webhook] Docker library not available, using subprocess...")
|
||||
|
||||
# Try /usr/bin/docker or docker in PATH
|
||||
docker_cmd = "/usr/bin/docker"
|
||||
import shutil
|
||||
if not os.path.exists(docker_cmd):
|
||||
docker_cmd = shutil.which("docker") or "docker"
|
||||
|
||||
# Restart backend container
|
||||
logger.info(f"[Webhook] Restarting backend container...")
|
||||
backend_result = subprocess.run(
|
||||
[docker_cmd, "restart", "igny8_backend"],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
timeout=30
|
||||
)
|
||||
|
||||
if backend_result.returncode != 0:
|
||||
raise Exception(f"Backend restart failed: {backend_result.stderr}")
|
||||
logger.info(f"[Webhook] Backend container restarted successfully")
|
||||
|
||||
# Restart frontend container
|
||||
logger.info(f"[Webhook] Restarting frontend container...")
|
||||
frontend_result = subprocess.run(
|
||||
[docker_cmd, "restart", "igny8_frontend"],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
timeout=30
|
||||
)
|
||||
|
||||
if frontend_result.returncode != 0:
|
||||
raise Exception(f"Frontend restart failed: {frontend_result.stderr}")
|
||||
logger.info(f"[Webhook] Frontend container restarted successfully")
|
||||
|
||||
deployment_success = True
|
||||
|
||||
logger.info(f"[Webhook] Deployment completed: containers restarted")
|
||||
|
||||
except subprocess.TimeoutExpired as e:
|
||||
deployment_error = f"Deployment timeout: {str(e)}"
|
||||
logger.error(f"[Webhook] {deployment_error}")
|
||||
except Exception as deploy_error:
|
||||
deployment_error = str(deploy_error)
|
||||
logger.error(f"[Webhook] Deployment error: {deploy_error}", exc_info=True)
|
||||
# COMMENTED OUT: Container restart disabled to prevent auto-restart on git commits
|
||||
logger.info(f"[Webhook] Container restart is DISABLED - code updated but containers not restarted")
|
||||
deployment_success = True
|
||||
|
||||
# try:
|
||||
# # Try to use docker Python library first, fallback to subprocess
|
||||
# try:
|
||||
# import docker as docker_lib
|
||||
# client = docker_lib.DockerClient(base_url='unix://var/run/docker.sock')
|
||||
#
|
||||
# # Restart frontend container (don't restart backend from within itself)
|
||||
# logger.info(f"[Webhook] Restarting frontend container...")
|
||||
# frontend_container = client.containers.get("igny8_frontend")
|
||||
# frontend_container.restart(timeout=30)
|
||||
# logger.info(f"[Webhook] Frontend container restarted successfully")
|
||||
#
|
||||
# # Schedule backend restart via subprocess in background (non-blocking)
|
||||
# # This avoids deadlock from restarting the container we're running in
|
||||
# logger.info(f"[Webhook] Scheduling backend container restart...")
|
||||
# import threading
|
||||
# def restart_backend():
|
||||
# import time
|
||||
# time.sleep(2) # Give webhook time to respond
|
||||
# try:
|
||||
# backend_container = client.containers.get("igny8_backend")
|
||||
# backend_container.restart(timeout=30)
|
||||
# logger.info(f"[Webhook] Backend container restarted successfully (delayed)")
|
||||
# except Exception as e:
|
||||
# logger.error(f"[Webhook] Delayed backend restart failed: {e}")
|
||||
#
|
||||
# restart_thread = threading.Thread(target=restart_backend, daemon=True)
|
||||
# restart_thread.start()
|
||||
#
|
||||
# deployment_success = True
|
||||
#
|
||||
# except ImportError:
|
||||
# # Fallback to subprocess with docker command
|
||||
# logger.info(f"[Webhook] Docker library not available, using subprocess...")
|
||||
#
|
||||
# # Try /usr/bin/docker or docker in PATH
|
||||
# docker_cmd = "/usr/bin/docker"
|
||||
# import shutil
|
||||
# if not os.path.exists(docker_cmd):
|
||||
# docker_cmd = shutil.which("docker") or "docker"
|
||||
#
|
||||
# # Restart backend container
|
||||
# logger.info(f"[Webhook] Restarting backend container...")
|
||||
# backend_result = subprocess.run(
|
||||
# [docker_cmd, "restart", "igny8_backend"],
|
||||
# capture_output=True,
|
||||
# text=True,
|
||||
# timeout=30
|
||||
# )
|
||||
#
|
||||
# if backend_result.returncode != 0:
|
||||
# raise Exception(f"Backend restart failed: {backend_result.stderr}")
|
||||
# logger.info(f"[Webhook] Backend container restarted successfully")
|
||||
#
|
||||
# # Restart frontend container
|
||||
# logger.info(f"[Webhook] Restarting frontend container...")
|
||||
# frontend_result = subprocess.run(
|
||||
# [docker_cmd, "restart", "igny8_frontend"],
|
||||
# capture_output=True,
|
||||
# text=True,
|
||||
# timeout=30
|
||||
# )
|
||||
#
|
||||
# if frontend_result.returncode != 0:
|
||||
# raise Exception(f"Frontend restart failed: {frontend_result.stderr}")
|
||||
# logger.info(f"[Webhook] Frontend container restarted successfully")
|
||||
#
|
||||
# deployment_success = True
|
||||
#
|
||||
# logger.info(f"[Webhook] Deployment completed: containers restarted")
|
||||
#
|
||||
# except subprocess.TimeoutExpired as e:
|
||||
# deployment_error = f"Deployment timeout: {str(e)}"
|
||||
# logger.error(f"[Webhook] {deployment_error}")
|
||||
# except Exception as deploy_error:
|
||||
# deployment_error = str(deploy_error)
|
||||
# logger.error(f"[Webhook] Deployment error: {deploy_error}", exc_info=True)
|
||||
|
||||
return success_response(
|
||||
data={
|
||||
|
||||
@@ -197,6 +197,12 @@ export default defineConfig(({ mode, command }) => {
|
||||
'**/build/**',
|
||||
'**/.vscode/**',
|
||||
'**/.idea/**',
|
||||
'**/Dockerfile*', // Ignore all Dockerfiles
|
||||
'**/Caddyfile*', // Ignore Caddyfiles
|
||||
'**/*.md', // Ignore markdown files
|
||||
'**/container_startup.sh', // Ignore startup script
|
||||
'**/.dockerignore',
|
||||
'**/.gitignore',
|
||||
],
|
||||
interval: 1000, // Poll every 1 second (default is 100ms)
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user