From ae3b73a73f655e9a5f36f08fa862fba316212732 Mon Sep 17 00:00:00 2001 From: DDSRem <1448139087@qq.com> Date: Fri, 8 Sep 2023 19:49:10 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E9=87=8D=E5=90=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 3 ++- app/utils/system.py | 2 +- entrypoint | 4 ++++ haproxy.cfg | 52 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 haproxy.cfg diff --git a/Dockerfile b/Dockerfile index d245e254..e9386c95 100644 --- a/Dockerfile +++ b/Dockerfile @@ -48,6 +48,7 @@ RUN apt-get update \ busybox \ dumb-init \ jq \ + haproxy \ && \ if [ "$(uname -m)" = "x86_64" ]; \ then ln -s /usr/lib/x86_64-linux-musl/libc.so /lib/libc.musl-x86_64.so.1; \ @@ -82,5 +83,5 @@ RUN apt-get update \ /var/lib/apt/lists/* \ /var/tmp/* EXPOSE 3000 -VOLUME ["/config", "/var/run/docker.sock"] +VOLUME [ "/config" ] ENTRYPOINT [ "/entrypoint" ] diff --git a/app/utils/system.py b/app/utils/system.py index 72c96a39..86c54b1f 100644 --- a/app/utils/system.py +++ b/app/utils/system.py @@ -309,7 +309,7 @@ class SystemUtils: """ try: # 创建 Docker 客户端 - client = docker.from_env() + client = docker.DockerClient(base_url='tcp://127.0.0.1:2375') # 获取当前容器的 ID container_id = open("/proc/self/cgroup", "r").read().split("/")[-1] if not container_id: diff --git a/entrypoint b/entrypoint index 3e3e5975..2335a875 100644 --- a/entrypoint +++ b/entrypoint @@ -26,6 +26,10 @@ chown moviepilot:moviepilot /etc/hosts /tmp gosu moviepilot:moviepilot playwright install chromium # 启动前端nginx服务 nginx +# 启动haproxy +if [ -f "/var/run/docker.sock" ]; then + haproxy -f /etc/haproxy/haproxy.cfg +fi # 设置后端服务权限掩码 umask ${UMASK} # 启动后端服务 diff --git a/haproxy.cfg b/haproxy.cfg new file mode 100644 index 00000000..87a5dd94 --- /dev/null +++ b/haproxy.cfg @@ -0,0 +1,52 @@ +global + log stdout format raw daemon info + + user root + group root + + daemon + + pidfile /run/haproxy.pid + maxconn 4000 + + # Turn on stats unix socket + server-state-file /var/lib/haproxy/server-state + +defaults + mode http + log global + option httplog + option dontlognull + option http-server-close + option redispatch + retries 3 + timeout http-request 10s + timeout queue 1m + timeout connect 10s + timeout client 10m + timeout server 10m + timeout http-keep-alive 10s + timeout check 10s + maxconn 3000 + + # Allow seamless reloads + load-server-state-from-file global + + # Use provided example error pages + errorfile 400 /etc/haproxy/errors/400.http + errorfile 403 /etc/haproxy/errors/403.http + errorfile 408 /etc/haproxy/errors/408.http + errorfile 500 /etc/haproxy/errors/500.http + errorfile 502 /etc/haproxy/errors/502.http + errorfile 503 /etc/haproxy/errors/503.http + errorfile 504 /etc/haproxy/errors/504.http + +backend dockerbackend + server dockersocket /var/run/docker.sock + +frontend dockerfrontend + bind :2375 + http-request allow + http-request allow if { path,url_dec -m reg -i ^(/v[\d\.]+)?/containers/[a-zA-Z0-9_.-]+/((stop)|(restart)|(kill)) } + http-request deny + default_backend dockerbackend \ No newline at end of file