Commit 28521298 by imwangxiaozhou

build: 拆分调度任务为独立服务并更新相关配置与依赖

新增专用调度任务启动脚本start-scheduler.sh,将numpy版本固定为1.26.4以解决兼容性问题。简化开发与生产启动脚本,移除内置的调度任务进程。更新Dockerfile与docker-compose配置,新增scheduler独立服务并完善构建依赖
1 parent c7a5cc1e
...@@ -8,12 +8,16 @@ WORKDIR /app ...@@ -8,12 +8,16 @@ WORKDIR /app
# 安装系统依赖(如有需要编译的 Python 包) # 安装系统依赖(如有需要编译的 Python 包)
RUN apt-get update && apt-get install -y --no-install-recommends \ RUN apt-get update && apt-get install -y --no-install-recommends \
gcc \ build-essential \
gfortran \
pkg-config \
libopenblas-dev \
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
# 安装 Python 依赖(先拷贝 requirements 利用 Docker 缓存层) # 安装 Python 依赖(先拷贝 requirements 利用 Docker 缓存层)
COPY requirements.txt . COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt RUN pip install --no-cache-dir --upgrade pip setuptools wheel \
&& PIP_NO_BINARY=numpy pip install --no-cache-dir -r requirements.txt
# 拷贝项目文件(开发时会被 volume 覆盖) # 拷贝项目文件(开发时会被 volume 覆盖)
COPY app/ ./app/ COPY app/ ./app/
...@@ -22,7 +26,7 @@ COPY skills/ ./skills/ ...@@ -22,7 +26,7 @@ COPY skills/ ./skills/
COPY scripts/ ./scripts/ COPY scripts/ ./scripts/
COPY sitecustomize.py ./ COPY sitecustomize.py ./
RUN chmod +x /app/scripts/start-dev.sh /app/scripts/start-prod.sh RUN chmod +x /app/scripts/start-dev.sh /app/scripts/start-prod.sh /app/scripts/start-scheduler.sh
EXPOSE 8082 EXPOSE 8082
......
...@@ -5,12 +5,16 @@ WORKDIR /build ...@@ -5,12 +5,16 @@ WORKDIR /build
# 安装编译依赖 # 安装编译依赖
RUN apt-get update && apt-get install -y --no-install-recommends \ RUN apt-get update && apt-get install -y --no-install-recommends \
gcc \ build-essential \
gfortran \
pkg-config \
libopenblas-dev \
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
# 安装 Python 依赖到指定目录(便于后续拷贝) # 安装 Python 依赖到指定目录(便于后续拷贝)
COPY requirements.txt . COPY requirements.txt .
RUN pip install --no-cache-dir --prefix=/install -r requirements.txt RUN pip install --no-cache-dir --upgrade pip setuptools wheel \
&& PIP_NO_BINARY=numpy pip install --no-cache-dir --prefix=/install -r requirements.txt
# ============ Stage 2: Runtime ============ # ============ Stage 2: Runtime ============
...@@ -34,7 +38,7 @@ COPY sitecustomize.py ./ ...@@ -34,7 +38,7 @@ COPY sitecustomize.py ./
# 创建非 root 用户并切换 # 创建非 root 用户并切换
RUN groupadd -r appuser && useradd -r -g appuser -d /app -s /sbin/nologin appuser \ RUN groupadd -r appuser && useradd -r -g appuser -d /app -s /sbin/nologin appuser \
&& chown -R appuser:appuser /app \ && chown -R appuser:appuser /app \
&& chmod +x /app/scripts/start-dev.sh /app/scripts/start-prod.sh && chmod +x /app/scripts/start-dev.sh /app/scripts/start-prod.sh /app/scripts/start-scheduler.sh
USER appuser USER appuser
EXPOSE 8082 EXPOSE 8082
......
...@@ -16,11 +16,34 @@ services: ...@@ -16,11 +16,34 @@ services:
- DOWNSTREAM_CHAT_HOST=127.0.0.1 - DOWNSTREAM_CHAT_HOST=127.0.0.1
- DOWNSTREAM_CHAT_PORT=8082 - DOWNSTREAM_CHAT_PORT=8082
restart: always restart: always
command: ["sh", "/app/scripts/start-prod.sh"]
deploy: deploy:
resources: resources:
limits: limits:
memory: 2G memory: 2G
cpus: "2.0" cpus: "2.0"
scheduler:
build:
context: .
dockerfile: Dockerfile.prod
volumes: []
env_file:
- path: .env
required: false
environment:
- DATABASE_URL=${DATABASE_URL}
- IM_BASE_URL=${IM_BASE_URL:-http://yjy.dev.glsx.com.cn/webim}
- USE_CONSOLE_IM=${USE_CONSOLE_IM:-false}
- DOWNSTREAM_CHAT_HOST=127.0.0.1
- DOWNSTREAM_CHAT_PORT=8082
restart: always
command: ["sh", "/app/scripts/start-scheduler.sh"]
deploy:
resources:
limits:
memory: 1G
cpus: "1.0"
im-service: im-service:
image: ${IM_IMAGE:-nginx:alpine} image: ${IM_IMAGE:-nginx:alpine}
...@@ -23,6 +23,31 @@ services: ...@@ -23,6 +23,31 @@ services:
restart: always restart: always
depends_on: depends_on:
- im-service - im-service
command: ["sh", "/app/scripts/start-dev.sh"]
scheduler:
build:
context: .
dockerfile: Dockerfile.dev
volumes:
- ./app:/app/app
- ./config:/app/config
- ./skills:/app/skills
- ./scripts:/app/scripts
- ./tests:/app/tests
env_file:
- path: .env
required: false
environment:
- DATABASE_URL=${DATABASE_URL:-sqlite:///./dev.db}
- IM_BASE_URL=${IM_BASE_URL:-http://yjy.dev.glsx.com.cn/webim}
- USE_CONSOLE_IM=${USE_CONSOLE_IM:-false}
- DOWNSTREAM_CHAT_HOST=127.0.0.1
- DOWNSTREAM_CHAT_PORT=8082
restart: always
depends_on:
- im-service
command: ["sh", "/app/scripts/start-scheduler.sh"]
im-service: im-service:
image: nginx:alpine image: nginx:alpine
......
...@@ -25,7 +25,7 @@ pytest-mock==3.15.1 ...@@ -25,7 +25,7 @@ pytest-mock==3.15.1
openai>=1.0.0 openai>=1.0.0
dashscope>=1.20.0 dashscope>=1.20.0
agentscope>=1.0.0 agentscope>=1.0.0
numpy>=1.26.0 numpy==1.26.4
# Document processing # Document processing
python-docx>=1.1.0 python-docx>=1.1.0
......
#!/bin/sh #!/bin/sh
set -eu set -eu
uvicorn app.main:app --host 0.0.0.0 --port 8082 --reload & exec uvicorn app.main:app --host 0.0.0.0 --port 8082 --reload
WEB_PID=$!
python -m app.jobs.scheduler &
SCHED_PID=$!
cleanup() {
kill "$WEB_PID" "$SCHED_PID" 2>/dev/null || true
}
trap cleanup INT TERM
while true; do
if ! kill -0 "$WEB_PID" 2>/dev/null; then
kill "$SCHED_PID" 2>/dev/null || true
wait "$WEB_PID" || true
wait "$SCHED_PID" || true
exit 1
fi
if ! kill -0 "$SCHED_PID" 2>/dev/null; then
kill "$WEB_PID" 2>/dev/null || true
wait "$WEB_PID" || true
wait "$SCHED_PID" || true
exit 1
fi
sleep 2
done
#!/bin/sh #!/bin/sh
set -eu set -eu
uvicorn app.main:app --host 0.0.0.0 --port 8082 --workers 4 & exec uvicorn app.main:app --host 0.0.0.0 --port 8082 --workers 4
WEB_PID=$!
python -m app.jobs.scheduler &
SCHED_PID=$!
cleanup() {
kill "$WEB_PID" "$SCHED_PID" 2>/dev/null || true
}
trap cleanup INT TERM
while true; do
if ! kill -0 "$WEB_PID" 2>/dev/null; then
kill "$SCHED_PID" 2>/dev/null || true
wait "$WEB_PID" || true
wait "$SCHED_PID" || true
exit 1
fi
if ! kill -0 "$SCHED_PID" 2>/dev/null; then
kill "$WEB_PID" 2>/dev/null || true
wait "$WEB_PID" || true
wait "$SCHED_PID" || true
exit 1
fi
sleep 2
done
#!/bin/sh
set -eu
exec python -m app.jobs.scheduler
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!