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