Align runtime with platform demo strategy
This commit is contained in:
@@ -1,6 +1,4 @@
|
||||
STRATEGY_ID=replace-with-platform-strategy-id
|
||||
MODELHUB_USER_ACCOUNT=replace-with-modelhub-account
|
||||
MODELHUB_USER_PASSWORD=replace-with-modelhub-password
|
||||
PORT=8080
|
||||
PIPELINE_RUN_MODE=resume
|
||||
PIPELINE_START_STEP=1
|
||||
|
||||
@@ -9,15 +9,12 @@ WORKDIR /app
|
||||
COPY requirements.txt .
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
COPY app.py modelhub_pipeline_resumable.py ./
|
||||
RUN mkdir -p /app/pipeline_outputs \
|
||||
&& chown -R 10001:0 /app
|
||||
|
||||
USER 10001
|
||||
COPY . .
|
||||
RUN mkdir -p /app/pipeline_outputs
|
||||
|
||||
EXPOSE 8080
|
||||
|
||||
HEALTHCHECK --interval=30s --timeout=3s --start-period=10s --retries=3 \
|
||||
CMD python -c "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8080/health', timeout=2).read()"
|
||||
|
||||
CMD ["python", "app.py"]
|
||||
CMD ["python", "main.py"]
|
||||
|
||||
16
README.md
16
README.md
@@ -8,8 +8,9 @@
|
||||
平台运行时必须提供:
|
||||
|
||||
- `STRATEGY_ID`:当前策略 ID,提交任务时写入 `strategyId`。
|
||||
- `MODELHUB_USER_ACCOUNT`:ModelHub 登录账号。
|
||||
- `MODELHUB_USER_PASSWORD`:ModelHub 登录密码。
|
||||
|
||||
ModelHub 登录账号和密码按照当前部署约定固定在
|
||||
`modelhub_pipeline_resumable.py` 中,不需要额外配置环境变量。
|
||||
|
||||
可选变量:
|
||||
|
||||
@@ -24,19 +25,18 @@
|
||||
|
||||
```powershell
|
||||
$env:STRATEGY_ID="your-strategy-id"
|
||||
$env:MODELHUB_USER_ACCOUNT="your-account"
|
||||
$env:MODELHUB_USER_PASSWORD="your-password"
|
||||
python app.py
|
||||
python main.py
|
||||
```
|
||||
|
||||
健康检查:
|
||||
|
||||
```text
|
||||
GET http://127.0.0.1:8080/health
|
||||
GET http://127.0.0.1:8080/
|
||||
```
|
||||
|
||||
只要策略服务进程存活,该端点返回 HTTP 200。响应同时包含后台流水线的
|
||||
运行状态,但不会返回账号、密码或令牌。
|
||||
只要策略服务进程存活,`/health` 返回 HTTP 200。根路径返回策略 ID 和
|
||||
后台流水线运行状态,但不会返回账号、密码或令牌。
|
||||
|
||||
## Docker
|
||||
|
||||
@@ -44,8 +44,6 @@ GET http://127.0.0.1:8080/health
|
||||
docker build -t new-pipeline .
|
||||
docker run --rm -p 8080:8080 \
|
||||
-e STRATEGY_ID=your-strategy-id \
|
||||
-e MODELHUB_USER_ACCOUNT=your-account \
|
||||
-e MODELHUB_USER_PASSWORD=your-password \
|
||||
new-pipeline
|
||||
```
|
||||
|
||||
|
||||
@@ -47,24 +47,37 @@ class RuntimeState:
|
||||
runtime_state = RuntimeState()
|
||||
|
||||
|
||||
class HealthHandler(BaseHTTPRequestHandler):
|
||||
class Handler(BaseHTTPRequestHandler):
|
||||
def do_GET(self) -> None:
|
||||
if self.path.split("?", 1)[0] != "/health":
|
||||
self._write_json(404, {"status": "not_found"})
|
||||
path = self.path.split("?", 1)[0]
|
||||
state = runtime_state.snapshot()
|
||||
|
||||
if path == "/health":
|
||||
self._write_json(
|
||||
200,
|
||||
{
|
||||
"status": "ok",
|
||||
"pipeline_status": state["pipeline_status"],
|
||||
},
|
||||
)
|
||||
return
|
||||
|
||||
state = runtime_state.snapshot()
|
||||
self._write_json(
|
||||
200,
|
||||
{
|
||||
"status": "ok",
|
||||
"strategy_id": STRATEGY_ID,
|
||||
"pipeline_status": state["pipeline_status"],
|
||||
"run_count": state["run_count"],
|
||||
"last_started_at": state["last_started_at"],
|
||||
"last_finished_at": state["last_finished_at"],
|
||||
},
|
||||
)
|
||||
if path == "/":
|
||||
self._write_json(
|
||||
200,
|
||||
{
|
||||
"name": "new-pipeline",
|
||||
"status": "running",
|
||||
"strategy_id": STRATEGY_ID,
|
||||
"pipeline_status": state["pipeline_status"],
|
||||
"run_count": state["run_count"],
|
||||
"last_started_at": state["last_started_at"],
|
||||
"last_finished_at": state["last_finished_at"],
|
||||
},
|
||||
)
|
||||
return
|
||||
|
||||
self._write_json(404, {"error": "not found"})
|
||||
|
||||
def _write_json(self, status_code: int, payload: Dict[str, Any]) -> None:
|
||||
body = json.dumps(payload, ensure_ascii=False).encode("utf-8")
|
||||
@@ -134,7 +147,7 @@ def main() -> None:
|
||||
)
|
||||
worker.start()
|
||||
|
||||
server = ThreadingHTTPServer((HOST, PORT), HealthHandler)
|
||||
server = ThreadingHTTPServer((HOST, PORT), Handler)
|
||||
server.timeout = 0.5
|
||||
print(f"健康检查服务已启动: http://{HOST}:{PORT}/health")
|
||||
|
||||
@@ -24,15 +24,9 @@ MODELHUB_DB_CHECK_ENDPOINT = "/api/computility/models/list/page/vo"
|
||||
TASK_TYPE = "text-generation"
|
||||
FRAMEWORK = "llamacpp"
|
||||
|
||||
# 账号密码只从环境变量读取,避免凭据进入镜像或 Git 仓库。
|
||||
# Linux/macOS:
|
||||
# export MODELHUB_USER_ACCOUNT="你的账号"
|
||||
# export MODELHUB_USER_PASSWORD="你的密码"
|
||||
# Windows PowerShell:
|
||||
# $env:MODELHUB_USER_ACCOUNT="你的账号"
|
||||
# $env:MODELHUB_USER_PASSWORD="你的密码"
|
||||
USER_ACCOUNT = os.getenv("MODELHUB_USER_ACCOUNT", "")
|
||||
USER_PASSWORD = os.getenv("MODELHUB_USER_PASSWORD", "")
|
||||
# 按当前策略部署约定,ModelHub 登录凭据固定写入策略代码。
|
||||
USER_ACCOUNT = "1326356020@qq.com"
|
||||
USER_PASSWORD = "4pdpassword"
|
||||
|
||||
# 不使用手动 token,统一用账号密码登录获取 token
|
||||
MODELHUB_TOKEN = ""
|
||||
@@ -576,8 +570,7 @@ def login() -> str:
|
||||
|
||||
if not USER_ACCOUNT or not USER_PASSWORD:
|
||||
raise RuntimeError(
|
||||
"没有设置账号密码。请设置环境变量 MODELHUB_USER_ACCOUNT / "
|
||||
"MODELHUB_USER_PASSWORD,或在脚本里填写 USER_ACCOUNT / USER_PASSWORD。"
|
||||
"没有设置账号密码,请在脚本中填写 USER_ACCOUNT / USER_PASSWORD。"
|
||||
)
|
||||
|
||||
payload = {
|
||||
|
||||
Reference in New Issue
Block a user