Skip to content

Commit 846dd5d

Browse files
committed
feat: vefaas pipeline
1 parent 9e9902d commit 846dd5d

File tree

5 files changed

+753
-0
lines changed

5 files changed

+753
-0
lines changed

veadk/cli/cli.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from veadk.cli.cli_init import init
2020
from veadk.cli.cli_prompt import prompt
2121
from veadk.cli.cli_web import web
22+
from veadk.cli.cli_pipeline import pipeline
2223
from veadk.version import VERSION
2324

2425

@@ -35,6 +36,7 @@ def veadk():
3536
veadk.add_command(init)
3637
veadk.add_command(prompt)
3738
veadk.add_command(web)
39+
veadk.add_command(pipeline)
3840

3941
if __name__ == "__main__":
4042
veadk()

veadk/cli/cli_pipeline.py

Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
# Copyright (c) 2025 Beijing Volcano Engine Technology Co., Ltd. and/or its affiliates.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import warnings
16+
17+
import click
18+
from veadk.config import getenv
19+
from veadk.integrations.ve_code_pipeline.ve_code_pipeline import VeCodePipeline
20+
from veadk.integrations.ve_faas.ve_faas import VeFaaS
21+
22+
warnings.filterwarnings(
23+
"ignore", category=UserWarning, module="pydantic._internal._fields"
24+
)
25+
26+
27+
def _render_volcengine_prompts() -> dict[str, str]:
28+
volcengine_access_key = click.prompt(
29+
"Volcengine Access Key", default="", show_default=False
30+
)
31+
if not volcengine_access_key:
32+
click.echo(
33+
"No Volcengine Access Key provided, will try to get it from environment variable VOLCENGINE_ACCESS_KEY."
34+
)
35+
volcengine_access_key = getenv("VOLCENGINE_ACCESS_KEY")
36+
37+
volcengine_secret_key = click.prompt(
38+
"Volcengine Secret Key", default="", show_default=False
39+
)
40+
if not volcengine_secret_key:
41+
click.echo(
42+
"No Volcengine Secret Key provided, will try to get it from environment variable VOLCENGINE_SECRET_KEY."
43+
)
44+
volcengine_secret_key = getenv("VOLCENGINE_SECRET_KEY")
45+
46+
volcengine_region = click.prompt("Volcengine Region", default="cn-beijing")
47+
return {
48+
"volcengine_access_key": volcengine_access_key,
49+
"volcengine_secret_key": volcengine_secret_key,
50+
"volcengine_region": volcengine_region,
51+
}
52+
53+
54+
def _render_cr_prompts() -> dict[str, str] | None:
55+
cr_domain, cr_namespace_name, cr_region, cr_instance_name, cr_repo = (
56+
"",
57+
"",
58+
"",
59+
"",
60+
"",
61+
)
62+
cr_fields = [cr_domain, cr_namespace_name, cr_region, cr_instance_name, cr_repo]
63+
filled_fields = [field for field in cr_fields if field.strip()]
64+
65+
while len(filled_fields) < len(cr_fields):
66+
click.echo(
67+
"Please provide all the Container Registry (CR) information, "
68+
"or press Enter to leave them all blank and let VeADK create the CR automatically."
69+
)
70+
cr_domain = click.prompt(
71+
"Container Registry domain", default="", show_default=False
72+
)
73+
cr_namespace_name = click.prompt(
74+
"Container Registry namespace name", default="", show_default=False
75+
)
76+
cr_region = click.prompt(
77+
"Container Registry region", default="", show_default=False
78+
)
79+
cr_instance_name = click.prompt(
80+
"Container Registry instance name", default="", show_default=False
81+
)
82+
cr_repo = click.prompt(
83+
"Container Registry repo", default="", show_default=False
84+
)
85+
86+
cr_fields = [cr_domain, cr_namespace_name, cr_region, cr_instance_name, cr_repo]
87+
filled_fields = [field for field in cr_fields if field.strip()]
88+
89+
if len(filled_fields) == 0:
90+
return None
91+
92+
return {
93+
"cr_domain": cr_domain,
94+
"cr_namespace_name": cr_namespace_name,
95+
"cr_region": cr_region,
96+
"cr_instance_name": cr_instance_name,
97+
"cr_repo": cr_repo,
98+
}
99+
100+
101+
@click.command()
102+
def pipeline() -> None:
103+
"""Integrate a veadk project to volcengine pipeline for CI/CD"""
104+
105+
click.echo(
106+
"Welcome use VeADK to integrate your project to volcengine pipeline for CI/CD."
107+
)
108+
109+
base_image_tag_options = ["preview", "0.0.1", "latest"]
110+
base_image_tag = click.prompt(
111+
"Choose a base image tag:", type=click.Choice(base_image_tag_options)
112+
)
113+
114+
github_url = click.prompt("Github url", default="", show_default=False)
115+
while not github_url:
116+
click.echo("Please enter your github url.")
117+
github_url = click.prompt("Github url", default="", show_default=False)
118+
119+
github_branch = click.prompt("Github branch", default="main")
120+
121+
github_token = click.prompt("Github token", default="", show_default=False)
122+
while not github_token:
123+
click.echo("Please enter your github token.")
124+
github_token = click.prompt("Github token", default="", show_default=False)
125+
126+
volcengine_settings = _render_volcengine_prompts()
127+
128+
cr_settings = _render_cr_prompts()
129+
130+
if cr_settings is None:
131+
click.echo("No CR information provided, will auto-create one.")
132+
# cr_settings = _auto_create_cr_config() # TODO
133+
134+
# Using hardcoded values for demonstration
135+
cr_settings = {
136+
"cr_domain": "test-veadk-cn-beijing.cr.volces.com",
137+
"cr_namespace_name": "veadk",
138+
"cr_region": "cn-beijing",
139+
"cr_instance_name": "test-veadk",
140+
"cr_repo": "cicd-weather-test",
141+
}
142+
click.echo("Using the following auto-created CR configuration:")
143+
click.echo(f"Container Registry domain: {cr_settings['cr_domain']}")
144+
click.echo(
145+
f"Container Registry namespace name: {cr_settings['cr_namespace_name']}"
146+
)
147+
click.echo(f"Container Registry region: {cr_settings['cr_region']}")
148+
click.echo(
149+
f"Container Registry instance name: {cr_settings['cr_instance_name']}"
150+
)
151+
click.echo(f"Container Registry repo: {cr_settings['cr_repo']}")
152+
153+
function_id = click.prompt(
154+
"Volcengine FaaS function ID", default="", show_default=False
155+
)
156+
157+
if not function_id:
158+
click.echo("Function ID not provided, will auto-create one.")
159+
function_name = click.prompt(
160+
"Function name", default="veadk-function", show_default=False
161+
)
162+
vefaas_client = VeFaaS(
163+
access_key=volcengine_settings["volcengine_access_key"],
164+
secret_key=volcengine_settings["volcengine_secret_key"],
165+
region=volcengine_settings["volcengine_region"],
166+
)
167+
_, _, function_id = vefaas_client.deploy_image(
168+
name=function_name,
169+
image="veadk-cn-beijing.cr.volces.com/veadk/simple-fastapi:0.1",
170+
)
171+
click.echo(f"Created function {function_name} with ID: {function_id}")
172+
173+
client = VeCodePipeline(
174+
volcengine_access_key=volcengine_settings["volcengine_access_key"],
175+
volcengine_secret_key=volcengine_settings["volcengine_secret_key"],
176+
region=volcengine_settings["volcengine_region"],
177+
)
178+
client.deploy(
179+
base_image_tag=base_image_tag,
180+
github_url=github_url,
181+
github_branch=github_branch,
182+
github_token=github_token,
183+
cr_domain=cr_settings["cr_domain"],
184+
cr_namespace_name=cr_settings["cr_namespace_name"],
185+
cr_region=cr_settings["cr_region"],
186+
cr_instance_name=cr_settings["cr_instance_name"],
187+
cr_repo=cr_settings["cr_repo"],
188+
function_id=function_id,
189+
)
190+
191+
click.echo("Pipeline has been created successfully.")
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Copyright (c) 2025 Beijing Volcano Engine Technology Co., Ltd. and/or its affiliates.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.

0 commit comments

Comments
 (0)