modalDeploy/README.md

64 lines
1.7 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Modal
## 部署
```bash
modal deploy -m cluster.app --env dev
```
## 本地验证fastapi部署
```bash
uvicorn BowongModalFunctions.api:web_app --host 0.0.0.0 --port 8080
```
## Cloudflare_KV
dev : f24d396e0daa418e89a1d7074b435c24
test : 527a61fea05543f2a49d62889ba868c5
prod : f3fce39ab6f4484cb65bc5cc2e7343e2
# Pip
## 构建
确保当前路径在`/src`同级下运行以下命令
```bash
uv sync
```
## 推送到coding私有制品库
依据[制品库](https://g-ldyi2063.coding.net/p/dev/artifacts/23892503/pypi/packages) 创建本地使用的.pypirc配置文件
其中包含访问密钥,严禁提交到代码库
```bash
py -m twine upload --config-file=.pypirc --repository=coding-pypi dist/*
```
## 安装
```bash
uv pip install bowong-modal-functions --index-url=https://<用户名>:<密钥>@g-ldyi2063-pypi.pkg.coding.net/dev/packages/simple
```
已踩坑:
```
原因已经定位:你本机 modal 1.1.4 和这个项目写法不兼容,导致函数没有被注册,所以看起来是“空镜像”。
我本地验证结果:
- modal 1.1.4 下cluster.web 的 registered_functions = 0、registered_web_endpoints = 0
- modal 1.1.1 下:同一代码变成 registered_functions = 1、registered_web_endpoints = 1
- 用 1.1.1 部署时,能正常创建完整函数列表(我已实测成功)
直接可用命令(临时方案):
uv run --with modal==1.1.1 modal deploy -m cluster.app --env dev
你同事能正常部署,大概率就是因为他用的是 1.1.1。
根因代码点是:很多 @app.function 定义放在 with image.imports(): 里面,在你当前版本下不会按预期注册。长期建议是把函数定
义移出这个 with 块,只把 import 留在里面。
```