Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions veadk/cli/cli_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,12 @@ def _render_prompts() -> dict[str, Any]:


@click.command()
def init() -> None:
@click.option(
"--vefaas-template-type", default="template", help="Expected template type"
)
def init(
vefaas_template_type: str,
) -> None:
"""Init a veadk project that can be deployed to Volcengine VeFaaS."""
import shutil
from pathlib import Path
Expand All @@ -73,9 +78,14 @@ def init() -> None:

import veadk.integrations.ve_faas as vefaas

click.echo(
"Welcome use VeADK to create your project. We will generate a `weather-reporter` application for you."
)
if vefaas_template_type == "web_template":
click.echo(
"Welcome use VeADK to create your project. We will generate a `simple-blog` web application for you."
)
else:
click.echo(
"Welcome use VeADK to create your project. We will generate a `weather-reporter` application for you."
)

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

template_dir_path = Path(vefaas.__file__).parent / "template"
if not vefaas_template_type:
vefaas_template_type = "template"

template_dir_path = Path(vefaas.__file__).parent / vefaas_template_type

cookiecutter(
template=str(template_dir_path),
Expand Down
11 changes: 0 additions & 11 deletions veadk/integrations/ve_faas/template/web/run.sh

This file was deleted.

17 changes: 17 additions & 0 deletions veadk/integrations/ve_faas/web_template/cookiecutter.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"local_dir_name": "veadk_vefaas_web_proj",
"app_name": "simple-blog",
"vefaas_application_name": "simple-blog",
"veapig_instance_name": "",
"veapig_service_name": "",
"veapig_upstream_name": "",
"use_adk_web": false,
"veadk_version": "",
"_copy_without_render": [
"*.html",
"*.css",
"*.js",
"static/**/*",
"templates/**/*"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright (c) 2025 Beijing Volcano Engine Technology Co., Ltd. and/or its affiliates.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright (c) 2025 Beijing Volcano Engine Technology Co., Ltd. and/or its affiliates.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from veadk.cloud.cloud_app import CloudApp

def main() -> None:
cloud_app = CloudApp(vefaas_application_name="{{cookiecutter.vefaas_application_name}}")
cloud_app.delete_self()


if __name__ == "__main__":
main()
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
VOLCENGINE_ACCESS_KEY:
VOLCENGINE_SECRET_KEY:
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright (c) 2025 Beijing Volcano Engine Technology Co., Ltd. and/or its affiliates.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import asyncio
from pathlib import Path

from veadk.cloud.cloud_agent_engine import CloudAgentEngine

async def main():
engine = CloudAgentEngine()

cloud_app = engine.deploy(
path=str(Path(__file__).parent / "src"),
application_name="{{cookiecutter.vefaas_application_name}}",
gateway_name="{{cookiecutter.veapig_instance_name}}",
gateway_service_name="{{cookiecutter.veapig_service_name}}",
gateway_upstream_name="{{cookiecutter.veapig_upstream_name}}",
use_adk_web={{cookiecutter.use_adk_web}},
local_test=False, # Set to True for local testing before deploy to VeFaaS
)
print(f"VeFaaS application ID: {cloud_app.vefaas_application_id}")

if {{cookiecutter.use_adk_web}}:
print(f"Web is running at: {cloud_app.vefaas_endpoint}")
else:
print(f"Web template does not support use_adk_web=False")


if __name__ == "__main__":
asyncio.run(main())
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ ENV FLASK_ENV=production
ENV PYTHONUNBUFFERED=1

# 暴露端口
EXPOSE 5000
EXPOSE 8000

# 启动命令
CMD ["bash", "run.sh"]
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
app.config['SECRET_KEY'] = 'your-secret-key-here'
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///blog.db'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.instance_path = os.path.join("/tmp", "flask_instance")
os.makedirs(app.instance_path, exist_ok=True)

db.init_app(app)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

# 兼容源码部署到faas & 镜像部署到faas
pip install -r requirements.txt

HOST="0.0.0.0"
PORT="${_FAAS_RUNTIME_PORT:-8000}"

export SERVER_HOST=$HOST
export SERVER_PORT=$PORT

# 设置环境变量
export FLASK_APP=app.py
export FLASK_ENV=production

# 初始化数据库
python init_db.py

echo "Starting Web application..."
# 启动应用,使用生产服务器配置
exec python -m gunicorn -w 4 -b $SERVER_HOST:$SERVER_PORT app:app
Loading