Skip to content

Commit c33faef

Browse files
committed
feat(vefaas): yaml deploy test
1 parent a329598 commit c33faef

File tree

6 files changed

+177
-151
lines changed

6 files changed

+177
-151
lines changed

veadk/cli/cli_deploy.py

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from yaml import safe_load
2121

2222
import veadk.integrations.ve_faas as vefaas
23+
from veadk.integrations.ve_faas.ve_faas import VeFaaS
2324
from veadk.configs.deploy_config import VeDeployConfig
2425
from veadk.utils.logger import get_logger
2526

@@ -84,9 +85,7 @@ def _get_user_configs() -> dict:
8485
help="Volcengine secret key",
8586
)
8687
@click.option("--project-path", default=".", help="Local project path")
87-
@click.option(
88-
"--deploy-config-file", default="./deploy.yaml", help="Deploy config file path"
89-
)
88+
@click.option("--deploy-config-file", default=None, help="Deploy config file path")
9089
def deploy(
9190
volcengine_access_key: str,
9291
volcengine_secret_key: str,
@@ -98,6 +97,9 @@ def deploy(
9897
if not volcengine_access_key or not volcengine_secret_key:
9998
raise Exception("Volcengine access key and secret key must be set.")
10099

100+
deploy_config_file = (
101+
deploy_config_file if deploy_config_file else Path(project_path) / "deploy.yaml"
102+
)
101103
if not Path(deploy_config_file).exists():
102104
click.echo(f"Deployment configuration file not found in {deploy_config_file}.")
103105

@@ -124,23 +126,16 @@ def deploy(
124126
click.echo("Deployment configuration file generated.")
125127

126128
# read deploy.yaml
127-
with open(output_path, "r", encoding="utf-8") as yaml_file:
129+
# with open(output_path, "r", encoding="utf-8") as yaml_file:
130+
# deploy_config_dict = safe_load(yaml_file)
131+
with open(deploy_config_file, "r", encoding="utf-8") as yaml_file:
128132
deploy_config_dict = safe_load(yaml_file)
129133

130134
deploy_config = VeDeployConfig(**deploy_config_dict)
135+
import veadk.config
136+
137+
deploy_config.vefaas.function_envs.update(veadk.config.veadk_environments)
138+
139+
vefaas_client = VeFaaS(deploy_config=deploy_config)
131140

132-
# vefaas_client = VeFaaS(
133-
# access_key=volcengine_access_key,
134-
# secret_key=volcengine_secret_key,
135-
# region="cn-beijing",
136-
# )
137-
138-
print(deploy_config)
139-
140-
# vefaas_client.deploy(
141-
# name=deploy_config.vefaas.application_name,
142-
# path=project_path,
143-
# gateway_name=deploy_config.veapig.gateway_name,
144-
# gateway_service_name=deploy_config.veapig.gateway_service_name,
145-
# gateway_upstream_name=deploy_config.veapig.gateway_upstream_name,
146-
# )
141+
vefaas_client.deploy()

veadk/cloud/cloud_agent_engine.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,19 @@
2222
from pydantic import BaseModel
2323

2424
from veadk.cloud.cloud_app import CloudApp
25-
from veadk.config import getenv
2625
from veadk.integrations.ve_faas.ve_faas import VeFaaS
2726
from veadk.utils.logger import get_logger
2827
from veadk.utils.misc import formatted_timestamp
28+
from veadk.configs.deploy_config import VeDeployConfig
2929

3030
logger = get_logger(__name__)
3131

3232

3333
class CloudAgentEngine(BaseModel):
34-
volcengine_access_key: str = getenv("VOLCENGINE_ACCESS_KEY")
35-
volcengine_secret_key: str = getenv("VOLCENGINE_SECRET_KEY")
36-
region: str = "cn-beijing"
34+
deploy_config: VeDeployConfig = VeDeployConfig()
3735

3836
def model_post_init(self, context: Any, /) -> None:
39-
self._vefaas_service = VeFaaS(
40-
access_key=self.volcengine_access_key,
41-
secret_key=self.volcengine_secret_key,
42-
region=self.region,
43-
)
37+
self._vefaas_service = VeFaaS(deploy_config=self.deploy_config)
4438

4539
def _prepare(self, path: str, name: str):
4640
# basic check

veadk/cloud/cloud_app.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
import json
1616
import time
17-
from typing import Any
17+
from typing import Any, Optional
1818
from uuid import uuid4
1919

2020
import httpx
@@ -48,6 +48,12 @@ def __init__(
4848
self.vefaas_application_name = vefaas_application_name
4949
self.use_agent_card = use_agent_card
5050

51+
from veadk.configs.deploy_config import VeDeployConfig
52+
import veadk.config
53+
54+
self.deploy_config = VeDeployConfig()
55+
self.deploy_config.vefaas.function_envs.update(veadk.config.veadk_environments)
56+
5157
# vefaas must be set one of three
5258
if (
5359
not vefaas_endpoint
@@ -79,12 +85,12 @@ def __init__(
7985

8086
def _get_vefaas_endpoint(
8187
self,
82-
volcengine_ak: str = getenv("VOLCENGINE_ACCESS_KEY"),
83-
volcengine_sk: str = getenv("VOLCENGINE_SECRET_KEY"),
88+
volcengine_ak: Optional[str] = getenv("VOLCENGINE_ACCESS_KEY"),
89+
volcengine_sk: Optional[str] = getenv("VOLCENGINE_SECRET_KEY"),
8490
) -> str:
8591
from veadk.integrations.ve_faas.ve_faas import VeFaaS
8692

87-
vefaas_client = VeFaaS(access_key=volcengine_ak, secret_key=volcengine_sk)
93+
vefaas_client = VeFaaS(self.deploy_config)
8894

8995
app = vefaas_client.get_application_details(
9096
app_id=self.vefaas_application_id,
@@ -111,10 +117,7 @@ def _get_vefaas_application_id_by_name(self) -> str:
111117
)
112118
from veadk.integrations.ve_faas.ve_faas import VeFaaS
113119

114-
vefaas_client = VeFaaS(
115-
access_key=getenv("VOLCENGINE_ACCESS_KEY"),
116-
secret_key=getenv("VOLCENGINE_SECRET_KEY"),
117-
)
120+
vefaas_client = VeFaaS(self.deploy_config)
118121
vefaas_application_id = vefaas_client.find_app_id_by_name(
119122
self.vefaas_application_name
120123
)
@@ -151,8 +154,8 @@ def update_self(
151154

152155
def delete_self(
153156
self,
154-
volcengine_ak: str = getenv("VOLCENGINE_ACCESS_KEY"),
155-
volcengine_sk: str = getenv("VOLCENGINE_SECRET_KEY"),
157+
volcengine_ak: Optional[str] = getenv("VOLCENGINE_ACCESS_KEY"),
158+
volcengine_sk: Optional[str] = getenv("VOLCENGINE_SECRET_KEY"),
156159
):
157160
if not volcengine_ak or not volcengine_sk:
158161
raise ValueError("Volcengine access key and secret key must be set.")
@@ -169,7 +172,7 @@ def delete_self(
169172
else:
170173
from veadk.integrations.ve_faas.ve_faas import VeFaaS
171174

172-
vefaas_client = VeFaaS(access_key=volcengine_ak, secret_key=volcengine_sk)
175+
vefaas_client = VeFaaS(self.deploy_config)
173176
vefaas_client.delete(self.vefaas_application_id)
174177
print(
175178
f"Cloud app {self.vefaas_application_id} delete request has been sent to VeFaaS"

veadk/configs/deploy_config.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66

77
class CreateVeFaaSConfig(BaseModel):
8-
region: Optional[str] = ""
8+
region: Optional[str] = "cn-beijing"
99

1010
application_name: Optional[str] = ""
1111

@@ -15,14 +15,9 @@ class CreateVeFaaSConfig(BaseModel):
1515
"Created by Volcengine Agent Development Kit (VeADK)"
1616
)
1717

18-
function_startup_command: str = "bash ./run.sh"
18+
function_startup_command: str = "bash run.sh"
1919

20-
function_envs: list[dict[str, Any]] = Field(
21-
default_factory=lambda: [
22-
{"VOLCENGINE_ACCESS_KEY": None},
23-
{"VOLCENGINE_SECRET_KEY": None},
24-
]
25-
)
20+
function_envs: dict[str, Any] = Field(default_factory=dict)
2621
"""Environment variables for the function instance."""
2722

2823
function_tags: dict[str, str] = {"provider": "veadk"}
@@ -55,7 +50,7 @@ class VeDeployConfig(BaseModel):
5550

5651
entrypoint_agent: Optional[str] = ""
5752

58-
ignore_files: list[str] = Field(default_factory=lambda: ["*.pyc", "__pycache__"])
53+
ignore_files: list[str] = Field(default_factory=list)
5954

6055
deploy_mode: Union[Literal["A2A/MCP", "WEB"], int] = "A2A/MCP"
6156
"""0 for `A2A/MCP` mode, 1 for `WEB` mode. Or, use literal to define this attribute."""

0 commit comments

Comments
 (0)