mirror of
https://github.com/aaPanel/aaPanel.git
synced 2026-12-04 03:23:29 +01:00
58 lines
2.0 KiB
Python
58 lines
2.0 KiB
Python
#!/www/server/panel/pyenv/bin/python
|
|
# coding: utf-8
|
|
# -------------------------------------------------------------------
|
|
# aaPanel
|
|
# -------------------------------------------------------------------
|
|
# docker compose - 从 git 部署:webhook 插件回调入口
|
|
# 由 plugin/webhook 的 shell 脚本调用,只做“写入排队记录 + 拉起 worker”,
|
|
# 立即退出(插件对回调脚本有 600s 超时,实际构建由独立 worker 完成)。
|
|
# -------------------------------------------------------------------
|
|
import sys
|
|
|
|
if "/www/server/panel" not in sys.path:
|
|
sys.path.insert(0, "/www/server/panel")
|
|
if "/www/server/panel/class" not in sys.path:
|
|
sys.path.insert(0, "/www/server/panel/class")
|
|
if "/www/server/panel/class_v2" not in sys.path:
|
|
sys.path.insert(0, "/www/server/panel/class_v2")
|
|
|
|
import public
|
|
|
|
|
|
def enqueue(project_key):
|
|
from mod.project.docker.compose_git.deploy_manage import ComposeGitDeploy
|
|
worker = ComposeGitDeploy()
|
|
binding = worker.resolve_hook_binding(project_key)
|
|
if not binding:
|
|
public.print_log(
|
|
"compose git hook ignored: project_key={} auto_deploy disabled or not linked".format(
|
|
project_key))
|
|
return False
|
|
project_id = int(binding.get("project_id") or 0)
|
|
branch = str(binding.get("branch") or "")
|
|
if not project_id or not branch:
|
|
public.print_log(
|
|
"compose git hook ignored: binding incomplete for project_key={}".format(
|
|
project_key))
|
|
return False
|
|
try:
|
|
worker.enqueue(project_id, "webhook", "git_latest", branch)
|
|
except Exception as exc:
|
|
public.print_log("compose git hook enqueue failed: {}".format(exc))
|
|
return False
|
|
return True
|
|
|
|
|
|
def main():
|
|
project_key = sys.argv[1].strip() if len(sys.argv) > 1 else ""
|
|
if not project_key:
|
|
return
|
|
enqueue(project_key)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
try:
|
|
main()
|
|
except Exception:
|
|
public.print_log(public.get_error_info())
|