|
14 | 14 |
|
15 | 15 | import click |
16 | 16 |
|
| 17 | +TEMP_PATH = "/tmp" |
| 18 | + |
17 | 19 |
|
18 | 20 | @click.command() |
19 | 21 | @click.option( |
|
26 | 28 | default=None, |
27 | 29 | help="Volcengine secret key", |
28 | 30 | ) |
29 | | -@click.option("--name", help="Expected Volcengine FaaS application name") |
| 31 | +@click.option("--vefaas-app-name", help="Expected Volcengine FaaS application name") |
| 32 | +@click.option("--veapig-instance-name", help="Expected Volcengine APIG instance name") |
| 33 | +@click.option("--veapig-service-name", help="Expected Volcengine APIG service name") |
| 34 | +@click.option("--veapig-upstream-name", help="Expected Volcengine APIG upstream name") |
| 35 | +@click.option( |
| 36 | + "--short-term-memory-backend", |
| 37 | + default="local", |
| 38 | + type=click.Choice(["local", "mysql"]), |
| 39 | + help="Backend for short-term memory", |
| 40 | +) |
| 41 | +@click.option("--use-adk-web", is_flag=True, help="Whether to use ADK Web") |
30 | 42 | @click.option("--path", default=".", help="Local project path") |
31 | | -def deploy(access_key: str, secret_key: str, name: str, path: str) -> None: |
| 43 | +def deploy( |
| 44 | + access_key: str, |
| 45 | + secret_key: str, |
| 46 | + vefaas_app_name: str, |
| 47 | + veapig_instance_name: str, |
| 48 | + veapig_service_name: str, |
| 49 | + veapig_upstream_name: str, |
| 50 | + short_term_memory_backend: str, |
| 51 | + use_adk_web: bool, |
| 52 | + path: str, |
| 53 | +) -> None: |
32 | 54 | """Deploy a user project to Volcengine FaaS application.""" |
| 55 | + import shutil |
33 | 56 | from pathlib import Path |
34 | 57 |
|
| 58 | + from cookiecutter.main import cookiecutter |
| 59 | + |
| 60 | + import veadk.integrations.ve_faas as vefaas |
35 | 61 | from veadk.config import getenv |
36 | | - from veadk.integrations.ve_faas.ve_faas import VeFaaS |
| 62 | + from veadk.utils.misc import formatted_timestamp |
37 | 63 |
|
38 | 64 | if not access_key: |
39 | 65 | access_key = getenv("VOLCENGINE_ACCESS_KEY") |
40 | 66 | if not secret_key: |
41 | 67 | secret_key = getenv("VOLCENGINE_SECRET_KEY") |
42 | 68 |
|
43 | 69 | user_proj_abs_path = Path(path).resolve() |
| 70 | + template_dir_path = Path(vefaas.__file__).parent / "template" |
| 71 | + |
| 72 | + tmp_dir_name = f"{user_proj_abs_path.name}_{formatted_timestamp()}" |
| 73 | + |
| 74 | + settings = { |
| 75 | + "local_dir_name": tmp_dir_name, |
| 76 | + "app_name": user_proj_abs_path.name, |
| 77 | + "agent_module_name": user_proj_abs_path.name, |
| 78 | + "requirement_file_path": str(user_proj_abs_path / "requirements.txt"), |
| 79 | + "short_term_memory_backend": short_term_memory_backend, |
| 80 | + "vefaas_application_name": vefaas_app_name, |
| 81 | + "veapig_instance_name": veapig_instance_name, |
| 82 | + "veapig_service_name": veapig_service_name, |
| 83 | + "veapig_upstream_name": veapig_upstream_name, |
| 84 | + "use_adk_web": use_adk_web, |
| 85 | + } |
| 86 | + |
| 87 | + print(settings) |
| 88 | + |
| 89 | + cookiecutter( |
| 90 | + template=str(template_dir_path), |
| 91 | + output_dir=TEMP_PATH, |
| 92 | + no_input=True, |
| 93 | + extra_context=settings, |
| 94 | + ) |
| 95 | + |
| 96 | + agent_dir = ( |
| 97 | + Path(TEMP_PATH) |
| 98 | + / tmp_dir_name |
| 99 | + / "src" |
| 100 | + / user_proj_abs_path.name.replace("-", "_") |
| 101 | + ) |
| 102 | + |
| 103 | + # remove /tmp/tmp_dir_name/src/user_proj_abs_path.name |
| 104 | + shutil.rmtree(agent_dir) |
| 105 | + agent_dir.mkdir(parents=True, exist_ok=True) |
| 106 | + |
| 107 | + # mv |
| 108 | + shutil.copytree(user_proj_abs_path, agent_dir, dirs_exist_ok=True) |
| 109 | + |
| 110 | + # mv requirements.txt and config.yaml if have |
| 111 | + if (user_proj_abs_path / "requirements.txt").exists(): |
| 112 | + shutil.copy( |
| 113 | + user_proj_abs_path / "requirements.txt", |
| 114 | + f"{TEMP_PATH}/{tmp_dir_name}/requirements.txt", |
| 115 | + ) |
| 116 | + # remove file |
44 | 117 |
|
45 | | - ve_faas = VeFaaS(access_key=access_key, secret_key=secret_key) |
46 | | - ve_faas.deploy(name=name, path=str(user_proj_abs_path)) |
| 118 | + if (user_proj_abs_path / "config.yaml").exists(): |
| 119 | + shutil.copy( |
| 120 | + user_proj_abs_path / "config.yaml", |
| 121 | + f"{TEMP_PATH}/{tmp_dir_name}/config.yaml", |
| 122 | + ) |
| 123 | + # remove file |
0 commit comments