Skip to content

Commit e96c6ed

Browse files
sebastian-l0huxiaoyu.612
andauthored
feat(vetemplate): take simple-blog project as faas web template (#135)
* feat: take web project as template,init command support template type * feat: take web project as template,init command support template type --------- Co-authored-by: huxiaoyu.612 <huxiaoyu.612@bytedance.com>
1 parent d08aac9 commit e96c6ed

File tree

24 files changed

+138
-17
lines changed

24 files changed

+138
-17
lines changed

veadk/cli/cli_init.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,12 @@ def _render_prompts() -> dict[str, Any]:
6464

6565

6666
@click.command()
67-
def init() -> None:
67+
@click.option(
68+
"--vefaas-template-type", default="template", help="Expected template type"
69+
)
70+
def init(
71+
vefaas_template_type: str,
72+
) -> None:
6873
"""Init a veadk project that can be deployed to Volcengine VeFaaS."""
6974
import shutil
7075
from pathlib import Path
@@ -73,9 +78,14 @@ def init() -> None:
7378

7479
import veadk.integrations.ve_faas as vefaas
7580

76-
click.echo(
77-
"Welcome use VeADK to create your project. We will generate a `weather-reporter` application for you."
78-
)
81+
if vefaas_template_type == "web_template":
82+
click.echo(
83+
"Welcome use VeADK to create your project. We will generate a `simple-blog` web application for you."
84+
)
85+
else:
86+
click.echo(
87+
"Welcome use VeADK to create your project. We will generate a `weather-reporter` application for you."
88+
)
7989

8090
cwd = Path.cwd()
8191
local_dir_name = click.prompt("Local directory name", default="veadk-cloud-proj")
@@ -91,7 +101,10 @@ def init() -> None:
91101
settings = _render_prompts()
92102
settings["local_dir_name"] = local_dir_name
93103

94-
template_dir_path = Path(vefaas.__file__).parent / "template"
104+
if not vefaas_template_type:
105+
vefaas_template_type = "template"
106+
107+
template_dir_path = Path(vefaas.__file__).parent / vefaas_template_type
95108

96109
cookiecutter(
97110
template=str(template_dir_path),

veadk/integrations/ve_faas/template/web/run.sh

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"local_dir_name": "veadk_vefaas_web_proj",
3+
"app_name": "simple-blog",
4+
"vefaas_application_name": "simple-blog",
5+
"veapig_instance_name": "",
6+
"veapig_service_name": "",
7+
"veapig_upstream_name": "",
8+
"use_adk_web": false,
9+
"veadk_version": "",
10+
"_copy_without_render": [
11+
"*.html",
12+
"*.css",
13+
"*.js",
14+
"static/**/*",
15+
"templates/**/*"
16+
]
17+
}
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.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
from veadk.cloud.cloud_app import CloudApp
16+
17+
def main() -> None:
18+
cloud_app = CloudApp(vefaas_application_name="{{cookiecutter.vefaas_application_name}}")
19+
cloud_app.delete_self()
20+
21+
22+
if __name__ == "__main__":
23+
main()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
VOLCENGINE_ACCESS_KEY:
2+
VOLCENGINE_SECRET_KEY:
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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 asyncio
16+
from pathlib import Path
17+
18+
from veadk.cloud.cloud_agent_engine import CloudAgentEngine
19+
20+
async def main():
21+
engine = CloudAgentEngine()
22+
23+
cloud_app = engine.deploy(
24+
path=str(Path(__file__).parent / "src"),
25+
application_name="{{cookiecutter.vefaas_application_name}}",
26+
gateway_name="{{cookiecutter.veapig_instance_name}}",
27+
gateway_service_name="{{cookiecutter.veapig_service_name}}",
28+
gateway_upstream_name="{{cookiecutter.veapig_upstream_name}}",
29+
use_adk_web={{cookiecutter.use_adk_web}},
30+
local_test=False, # Set to True for local testing before deploy to VeFaaS
31+
)
32+
print(f"VeFaaS application ID: {cloud_app.vefaas_application_id}")
33+
34+
if {{cookiecutter.use_adk_web}}:
35+
print(f"Web is running at: {cloud_app.vefaas_endpoint}")
36+
else:
37+
print(f"Web template does not support use_adk_web=False")
38+
39+
40+
if __name__ == "__main__":
41+
asyncio.run(main())
File renamed without changes.
File renamed without changes.

veadk/integrations/ve_faas/template/web/Dockerfile renamed to veadk/integrations/ve_faas/web_template/{{cookiecutter.local_dir_name}}/src/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ ENV FLASK_ENV=production
1717
ENV PYTHONUNBUFFERED=1
1818

1919
# 暴露端口
20-
EXPOSE 5000
20+
EXPOSE 8000
2121

2222
# 启动命令
2323
CMD ["bash", "run.sh"]

0 commit comments

Comments
 (0)