bizy-deploy 0.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 SiliconFlow
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,168 @@
1
+ Metadata-Version: 2.4
2
+ Name: bizy-deploy
3
+ Version: 0.2.0
4
+ Summary: BizyAir FaaS automated deployment tool
5
+ Author-email: SiliconFlow <bizyair@siliconflow.cn>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/siliconflow/BizyDeploy
8
+ Project-URL: Repository, https://github.com/siliconflow/BizyDeploy
9
+ Project-URL: Issues, https://github.com/siliconflow/BizyDeploy/issues
10
+ Keywords: faas,deploy,siliconflow,bizyair
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Topic :: Software Development :: Build Tools
19
+ Requires-Python: >=3.10
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Requires-Dist: requests
23
+ Requires-Dist: hydra-core
24
+ Requires-Dist: loguru
25
+ Requires-Dist: pyyaml
26
+ Provides-Extra: scripts
27
+ Requires-Dist: httpx; extra == "scripts"
28
+ Requires-Dist: pillow; extra == "scripts"
29
+ Provides-Extra: dev
30
+ Requires-Dist: pytest; extra == "dev"
31
+ Requires-Dist: pytest-cov; extra == "dev"
32
+ Requires-Dist: build; extra == "dev"
33
+ Requires-Dist: twine; extra == "dev"
34
+ Dynamic: license-file
35
+
36
+ ## 安装
37
+ ## 1. 安装(二选一)
38
+
39
+ ```bash
40
+ # 公有仓库
41
+ pip install git+https://<TOKEN>@github.com/siliconflow/BizyDeploy.git
42
+ ```
43
+
44
+ ```bash
45
+ # 私有仓库
46
+ pip install git+ssh://git@github.com/siliconflow/BizyDeploy.git
47
+ ```
48
+
49
+ ## 使用
50
+
51
+ ```bash
52
+ export SF_FAAS_TOKEN=xxxxx
53
+ ```
54
+
55
+ ### 场景1: 仅更新faas云函数部署
56
+ ```
57
+ bizy-deploy \
58
+ pipeline=cgr_uat \
59
+ service.sf_faas_token="$SF_FAAS_TOKEN" \
60
+ ++env.function_id=fnjfvlqpdt \
61
+ ++env.deployment_id=fdqd9p8te5 \
62
+ ++func_def.spec.comment="upgrade"
63
+ ```
64
+
65
+ ### 场景2: 仅更新镜像版本 (最常用)
66
+
67
+ 下面镜像对应云函数地址: https://cloud.siliconflow.cn/sft-d1s6t1r3jrms73f3ltpg/dedicated/functions/fnjfvlqpdt?tab=definition
68
+
69
+ 命令行中的 ++func_def.spec.data 对应控制台“函数定义”中的 YAML 结构
70
+
71
+ ```bash
72
+ bizy-deploy \
73
+ debug=false \
74
+ pipeline=cgr_prod \
75
+ service.sf_faas_token="$SF_FAAS_TOKEN" \
76
+ ++env.function_id=fnjfvlqpdt \
77
+ ++env.deployment_id=fdqd9p8te5 \
78
+ ++func_def.spec.comment="update image to v20251222" \
79
+ ++func_def.spec.data.cgrService.image="hub.6scloud.com/xxx/comfygridruntime:v20251222"
80
+ ```
81
+
82
+ ### 场景: 云函数模版相关操作
83
+
84
+ #### 获取 {org_id}/{template_id} 对应云函数模版
85
+ ```bash
86
+ bizy-deploy \
87
+ pipeline=faas_api_op \
88
+ debug=true \
89
+ ++pipeline.0.action='get_template' \
90
+ ++pipeline.0.params.org_id=d1s6t1r3jrms73f3ltpg \
91
+ ++pipeline.0.params.template_id=bizydraft-backend \
92
+ service.sf_faas_token="$SF_FAAS_TOKEN"
93
+ ```
94
+
95
+ ### 场景4: 从源云函数上获取配置,修改指定参数后上传到目标云函数,并部署等待就绪
96
+
97
+ ```bash
98
+ bizy-deploy \
99
+ pipeline=cgr_uat \
100
+ ++pipeline.0.params.function_id=fna5m4t5ky \
101
+ ++env.function_id=fn1tioyopg \
102
+ ++env.deployment_id=fdg8skissk \
103
+ ++func_def.spec.data.comfyagentService.nodeRegisterConfigUrl="https://storage.bizyair.cn/config/comfyagent_node_config_chenchaonan.json" \
104
+ ++func_def.spec.data.comfyuiService.image="hub.6scloud.com/d1s6t1r3jrms73f3ltpg/comfyui-gpu-torch2dot5:v202512241113-feature-add-plugins-default-a8dc7ab" \
105
+ service.sf_faas_token="$SF_FAAS_TOKEN"
106
+ ```
107
+ ### 场景5: 得到一个函数的最新定义,创建一个新的定义,修改部署的参数后部署并等待就绪
108
+
109
+ ```bash
110
+ bizy-deploy \
111
+ pipeline=faas_api_op \
112
+ ++pipeline.0.action='get_latest_function_definition' \
113
+ ++pipeline.0.params.function_id=fn1tioyopg \
114
+ ++pipeline.0.save_result_as='latest_func_def' \
115
+ ++pipeline.1.action='create_function_definition' \
116
+ ++pipeline.1.params.function_id=fn1tioyopg \
117
+ ++pipeline.1.params.merged_def='${pipe.ctx:latest_func_def}' \
118
+ ++pipeline.1.save_result_as="new_version" \
119
+ ++pipeline.2.action='deploy' \
120
+ ++pipeline.2.params.version='${pipe.ctx:new_version}' \
121
+ ++pipeline.2.params.overrides.spec.siliconServices.0.minReplicas=2 \
122
+ ++pipeline.2.params.overrides.spec.siliconServices.0.maxReplicas=5 \
123
+ ++pipeline.2.params.function_id=fn1tioyopg \
124
+ ++pipeline.2.params.deployment_id="fdg8skissk" \
125
+ ++pipeline.3.action='wait_ready' \
126
+ ++pipeline.3.params.function_id=fn1tioyopg \
127
+ ++pipeline.3.params.deployment_id=fdg8skissk \
128
+ service.sf_faas_token="$SF_FAAS_TOKEN"
129
+
130
+ ```python
131
+ python scripts/save_template.py -tpl d1s6t1r3jrms73f3ltpg/bizydraft-backend
132
+ ```
133
+
134
+ <details open>
135
+ <summary> Output </summary>
136
+
137
+ ```
138
+ ✔ Template saved: d1s6t1r3jrms73f3ltpg/bizydraft-backend ->
139
+ outputs/d1s6t1r3jrms73f3ltpg---bizydraft-backend.yaml
140
+ ```
141
+
142
+ </details>
143
+
144
+
145
+ #### 更新模版
146
+
147
+ ```bash
148
+ bizy-deploy \
149
+ pipeline=faas_api_op \
150
+ ++pipeline.0.action='update_template' \
151
+ ++pipeline.0.params.name=<template_id> \
152
+ ++pipeline.0.params.data.files=<TemplateYamlPath> \
153
+ service.sf_faas_token="<SF_FAAS_TOKEN>"
154
+ ```
155
+
156
+ #### 前端更新完成后清理缓存
157
+
158
+ ```bash
159
+ # 通过环境变量设置使用
160
+ export BIZYAIR_TOKEN=sk-xxx # 设置bizyair的token,必须
161
+ export SILICONFLOW_FASS_DEPLOY_DOMAIN=foo.bar:8192 # 设置内网域名,必须
162
+ export BIZYAIR_GROUP_ID=123 # 设置id( https://console.bizyair.cn/comfy-draft/exclusive-instances 的实例组id),必须
163
+ ./scripts/ready_instance.sh
164
+
165
+
166
+ # 通过位置参数使用
167
+ ./scripts/ready_instance.sh sk-xxx foo.bar:8192 123 # 带参使用脚本,传参顺序:token,内网域名,id
168
+ ```
@@ -0,0 +1,133 @@
1
+ ## 安装
2
+ ## 1. 安装(二选一)
3
+
4
+ ```bash
5
+ # 公有仓库
6
+ pip install git+https://<TOKEN>@github.com/siliconflow/BizyDeploy.git
7
+ ```
8
+
9
+ ```bash
10
+ # 私有仓库
11
+ pip install git+ssh://git@github.com/siliconflow/BizyDeploy.git
12
+ ```
13
+
14
+ ## 使用
15
+
16
+ ```bash
17
+ export SF_FAAS_TOKEN=xxxxx
18
+ ```
19
+
20
+ ### 场景1: 仅更新faas云函数部署
21
+ ```
22
+ bizy-deploy \
23
+ pipeline=cgr_uat \
24
+ service.sf_faas_token="$SF_FAAS_TOKEN" \
25
+ ++env.function_id=fnjfvlqpdt \
26
+ ++env.deployment_id=fdqd9p8te5 \
27
+ ++func_def.spec.comment="upgrade"
28
+ ```
29
+
30
+ ### 场景2: 仅更新镜像版本 (最常用)
31
+
32
+ 下面镜像对应云函数地址: https://cloud.siliconflow.cn/sft-d1s6t1r3jrms73f3ltpg/dedicated/functions/fnjfvlqpdt?tab=definition
33
+
34
+ 命令行中的 ++func_def.spec.data 对应控制台“函数定义”中的 YAML 结构
35
+
36
+ ```bash
37
+ bizy-deploy \
38
+ debug=false \
39
+ pipeline=cgr_prod \
40
+ service.sf_faas_token="$SF_FAAS_TOKEN" \
41
+ ++env.function_id=fnjfvlqpdt \
42
+ ++env.deployment_id=fdqd9p8te5 \
43
+ ++func_def.spec.comment="update image to v20251222" \
44
+ ++func_def.spec.data.cgrService.image="hub.6scloud.com/xxx/comfygridruntime:v20251222"
45
+ ```
46
+
47
+ ### 场景: 云函数模版相关操作
48
+
49
+ #### 获取 {org_id}/{template_id} 对应云函数模版
50
+ ```bash
51
+ bizy-deploy \
52
+ pipeline=faas_api_op \
53
+ debug=true \
54
+ ++pipeline.0.action='get_template' \
55
+ ++pipeline.0.params.org_id=d1s6t1r3jrms73f3ltpg \
56
+ ++pipeline.0.params.template_id=bizydraft-backend \
57
+ service.sf_faas_token="$SF_FAAS_TOKEN"
58
+ ```
59
+
60
+ ### 场景4: 从源云函数上获取配置,修改指定参数后上传到目标云函数,并部署等待就绪
61
+
62
+ ```bash
63
+ bizy-deploy \
64
+ pipeline=cgr_uat \
65
+ ++pipeline.0.params.function_id=fna5m4t5ky \
66
+ ++env.function_id=fn1tioyopg \
67
+ ++env.deployment_id=fdg8skissk \
68
+ ++func_def.spec.data.comfyagentService.nodeRegisterConfigUrl="https://storage.bizyair.cn/config/comfyagent_node_config_chenchaonan.json" \
69
+ ++func_def.spec.data.comfyuiService.image="hub.6scloud.com/d1s6t1r3jrms73f3ltpg/comfyui-gpu-torch2dot5:v202512241113-feature-add-plugins-default-a8dc7ab" \
70
+ service.sf_faas_token="$SF_FAAS_TOKEN"
71
+ ```
72
+ ### 场景5: 得到一个函数的最新定义,创建一个新的定义,修改部署的参数后部署并等待就绪
73
+
74
+ ```bash
75
+ bizy-deploy \
76
+ pipeline=faas_api_op \
77
+ ++pipeline.0.action='get_latest_function_definition' \
78
+ ++pipeline.0.params.function_id=fn1tioyopg \
79
+ ++pipeline.0.save_result_as='latest_func_def' \
80
+ ++pipeline.1.action='create_function_definition' \
81
+ ++pipeline.1.params.function_id=fn1tioyopg \
82
+ ++pipeline.1.params.merged_def='${pipe.ctx:latest_func_def}' \
83
+ ++pipeline.1.save_result_as="new_version" \
84
+ ++pipeline.2.action='deploy' \
85
+ ++pipeline.2.params.version='${pipe.ctx:new_version}' \
86
+ ++pipeline.2.params.overrides.spec.siliconServices.0.minReplicas=2 \
87
+ ++pipeline.2.params.overrides.spec.siliconServices.0.maxReplicas=5 \
88
+ ++pipeline.2.params.function_id=fn1tioyopg \
89
+ ++pipeline.2.params.deployment_id="fdg8skissk" \
90
+ ++pipeline.3.action='wait_ready' \
91
+ ++pipeline.3.params.function_id=fn1tioyopg \
92
+ ++pipeline.3.params.deployment_id=fdg8skissk \
93
+ service.sf_faas_token="$SF_FAAS_TOKEN"
94
+
95
+ ```python
96
+ python scripts/save_template.py -tpl d1s6t1r3jrms73f3ltpg/bizydraft-backend
97
+ ```
98
+
99
+ <details open>
100
+ <summary> Output </summary>
101
+
102
+ ```
103
+ ✔ Template saved: d1s6t1r3jrms73f3ltpg/bizydraft-backend ->
104
+ outputs/d1s6t1r3jrms73f3ltpg---bizydraft-backend.yaml
105
+ ```
106
+
107
+ </details>
108
+
109
+
110
+ #### 更新模版
111
+
112
+ ```bash
113
+ bizy-deploy \
114
+ pipeline=faas_api_op \
115
+ ++pipeline.0.action='update_template' \
116
+ ++pipeline.0.params.name=<template_id> \
117
+ ++pipeline.0.params.data.files=<TemplateYamlPath> \
118
+ service.sf_faas_token="<SF_FAAS_TOKEN>"
119
+ ```
120
+
121
+ #### 前端更新完成后清理缓存
122
+
123
+ ```bash
124
+ # 通过环境变量设置使用
125
+ export BIZYAIR_TOKEN=sk-xxx # 设置bizyair的token,必须
126
+ export SILICONFLOW_FASS_DEPLOY_DOMAIN=foo.bar:8192 # 设置内网域名,必须
127
+ export BIZYAIR_GROUP_ID=123 # 设置id( https://console.bizyair.cn/comfy-draft/exclusive-instances 的实例组id),必须
128
+ ./scripts/ready_instance.sh
129
+
130
+
131
+ # 通过位置参数使用
132
+ ./scripts/ready_instance.sh sk-xxx foo.bar:8192 123 # 带参使用脚本,传参顺序:token,内网域名,id
133
+ ```
@@ -0,0 +1,50 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "bizy-deploy"
7
+ version = "0.2.0"
8
+ description = "BizyAir FaaS automated deployment tool"
9
+ license = "MIT"
10
+ authors = [{name = "SiliconFlow", email = "bizyair@siliconflow.cn"}]
11
+ keywords = ["faas", "deploy", "siliconflow", "bizyair"]
12
+ classifiers = [
13
+ "Development Status :: 4 - Beta",
14
+ "Intended Audience :: Developers",
15
+ "Programming Language :: Python :: 3",
16
+ "Programming Language :: Python :: 3.10",
17
+ "Programming Language :: Python :: 3.11",
18
+ "Programming Language :: Python :: 3.12",
19
+ "Programming Language :: Python :: 3.13",
20
+ "Topic :: Software Development :: Build Tools",
21
+ ]
22
+ requires-python = ">=3.10"
23
+ dependencies = ["requests", "hydra-core", "loguru", "pyyaml"]
24
+ readme = "README.md"
25
+
26
+
27
+ [project.scripts]
28
+ bizy-deploy = "bizy_deploy.cli:main"
29
+
30
+ [project.urls]
31
+ Homepage = "https://github.com/siliconflow/BizyDeploy"
32
+ Repository = "https://github.com/siliconflow/BizyDeploy"
33
+ Issues = "https://github.com/siliconflow/BizyDeploy/issues"
34
+
35
+ [project.optional-dependencies]
36
+ scripts = ["httpx", "pillow"]
37
+ dev = ["pytest", "pytest-cov", "build", "twine"]
38
+
39
+ [tool.setuptools.packages.find]
40
+ where = ["src"]
41
+ include = ["*"]
42
+
43
+ [tool.setuptools.package-data]
44
+ "bizy_deploy" = ["*.yaml", "**/*.yaml", "conf/**/*"]
45
+
46
+ [tool.pytest.ini_options]
47
+ testpaths = ["tests"]
48
+ python_files = ["test_*.py"]
49
+ python_classes = ["Test*"]
50
+ python_functions = ["test_*"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1 @@
1
+ from .core import FaasClient, save_jinja_template_yaml
@@ -0,0 +1,79 @@
1
+ from pathlib import Path
2
+
3
+ import hydra
4
+ from omegaconf import DictConfig, OmegaConf
5
+
6
+ from .core.faas_actions import FaaSActionProvider
7
+ from loguru import logger
8
+
9
+ # 模块级别的解析器支持,允许多次创建 WorkflowEngine
10
+ _current_engine = None
11
+
12
+
13
+ def _pipe_ctx_resolver(key: str):
14
+ """OmegaConf resolver for pipe.ctx — 引用流水线上一步的结果"""
15
+ global _current_engine
16
+ if _current_engine is None:
17
+ raise RuntimeError("No WorkflowEngine initialized")
18
+ attrs = key.split(".")
19
+ key_first = attrs[0]
20
+ if key_first not in _current_engine.context:
21
+ logger.warning(f'"{key}" not found in pipe.ctx; using literal value')
22
+ ret = _current_engine.context[key_first]
23
+ for attr in attrs[1:]:
24
+ ret = getattr(ret, attr)
25
+ return ret
26
+
27
+
28
+ # 注册 resolver(仅一次)
29
+ resolver_key = "pipe.ctx"
30
+ if not OmegaConf.has_resolver(resolver_key):
31
+ OmegaConf.register_new_resolver(resolver_key, _pipe_ctx_resolver, use_cache=False)
32
+
33
+
34
+ class WorkflowEngine:
35
+ def __init__(self, conf: DictConfig):
36
+ global _current_engine
37
+ _current_engine = self
38
+ self.conf = conf
39
+ self.context = {}
40
+ self.provider = FaaSActionProvider(conf)
41
+
42
+ def run(self):
43
+ pipeline = self.conf.get("pipeline", [])
44
+ if isinstance(pipeline, DictConfig):
45
+ sorted_keys = sorted(pipeline.keys())
46
+ sorted_list = [pipeline[k] for k in sorted_keys]
47
+ pipeline = sorted_list
48
+
49
+ for step in pipeline:
50
+ action_name = step.action
51
+
52
+ params = step.get("params", {})
53
+ resolved_params = self._resolve_params(params)
54
+
55
+ if "output" in step:
56
+ resolved_params["output"] = step.output
57
+
58
+ action_func = getattr(self.provider, action_name)
59
+ result = action_func(**resolved_params)
60
+
61
+ if "save_result_as" in step:
62
+ self.context[step.save_result_as] = result
63
+
64
+ def _resolve_params(self, params):
65
+ resolved_params = OmegaConf.to_container(OmegaConf.create(params), resolve=True)
66
+ return resolved_params
67
+
68
+
69
+ config_path = Path(__file__).parent / "conf"
70
+
71
+
72
+ @hydra.main(version_base=None, config_path=str(config_path), config_name="config")
73
+ def main(conf: DictConfig) -> None:
74
+ engine = WorkflowEngine(conf)
75
+ engine.run()
76
+
77
+
78
+ if __name__ == "__main__":
79
+ main()
@@ -0,0 +1,9 @@
1
+ defaults:
2
+ - _self_
3
+ - pipeline: cgr_uat
4
+
5
+ service:
6
+ sf_faas_token: xxxxx
7
+ base_url: https://busy-bear.siliconflow.cn/api/v1
8
+
9
+ debug: false
@@ -0,0 +1,23 @@
1
+ - action: "get_latest_function_definition"
2
+ desc: "获取生产环境函数的最新定义"
3
+ save_result_as: "latest_func_def"
4
+
5
+ - action: "update_function_definition"
6
+ desc: "修改配置"
7
+ params:
8
+ latest_func_def: "${pipe.ctx:latest_func_def}" # 使用上一步的结果
9
+ save_result_as: "merged_def"
10
+
11
+ - action: "create_function_definition"
12
+ desc: "在当前函数创建新版本定义"
13
+ params:
14
+ merged_def: "${pipe.ctx:merged_def}"
15
+ save_result_as: "new_version"
16
+
17
+ - action: "deploy" # 部署最新版本
18
+ desc: "触发部署"
19
+ params:
20
+ version: "${pipe.ctx:new_version}" # 动态引用上一步的结果
21
+
22
+ - action: "wait_ready"
23
+ desc: "等待部署完成"
@@ -0,0 +1,9 @@
1
+ # faas_api_op pipeline - 通过 ++pipeline.N.action='action_name' 动态指定操作
2
+ # 此文件保持纯注释(YAML 加载为 null),Hydra 的 ++ 语法会动态创建列表条目
3
+ #
4
+ # 用法示例:
5
+ # bizy-deploy pipeline=faas_api_op \
6
+ # ++pipeline.0.action='get_template' \
7
+ # ++pipeline.0.params.org_id=xxx \
8
+ # ++pipeline.0.params.template_id=yyy \
9
+ # service.sf_faas_token="$SF_FAAS_TOKEN"
@@ -0,0 +1,2 @@
1
+ from .faas_client import FaasClient
2
+ from .utils import save_jinja_template_yaml