|
15 | 15 |
|
16 | 16 | import click |
17 | 17 |
|
18 | | -from veadk.version import VERSION |
19 | 18 |
|
20 | 19 | TEMP_PATH = "/tmp" |
21 | 20 |
|
22 | 21 |
|
23 | 22 | @click.command() |
24 | 23 | @click.option( |
25 | | - "--access-key", |
| 24 | + "--volcengine-access-key", |
26 | 25 | default=None, |
27 | 26 | help="Volcengine access key", |
28 | 27 | ) |
29 | 28 | @click.option( |
30 | | - "--secret-key", |
| 29 | + "--volcengine-secret-key", |
31 | 30 | default=None, |
32 | 31 | help="Volcengine secret key", |
33 | 32 | ) |
| 33 | +@click.option("--project-path", default=".", help="Local project path") |
34 | 34 | @click.option( |
35 | | - "--vefaas-app-name", required=True, help="Expected Volcengine FaaS application name" |
| 35 | + "--deploy-config-file", default="./deploy.yaml", help="Deploy config file path" |
36 | 36 | ) |
37 | | -@click.option( |
38 | | - "--veapig-instance-name", default="", help="Expected Volcengine APIG instance name" |
39 | | -) |
40 | | -@click.option( |
41 | | - "--veapig-service-name", default="", help="Expected Volcengine APIG service name" |
42 | | -) |
43 | | -@click.option( |
44 | | - "--veapig-upstream-name", default="", help="Expected Volcengine APIG upstream name" |
45 | | -) |
46 | | -@click.option( |
47 | | - "--short-term-memory-backend", |
48 | | - default="local", |
49 | | - type=click.Choice(["local", "mysql"]), |
50 | | - help="Backend for short-term memory", |
51 | | -) |
52 | | -@click.option("--use-adk-web", is_flag=True, help="Whether to use ADK Web") |
53 | | -@click.option("--path", default=".", help="Local project path") |
54 | 37 | def deploy( |
55 | | - access_key: str, |
56 | | - secret_key: str, |
57 | | - vefaas_app_name: str, |
58 | | - veapig_instance_name: str, |
59 | | - veapig_service_name: str, |
60 | | - veapig_upstream_name: str, |
61 | | - short_term_memory_backend: str, |
62 | | - use_adk_web: bool, |
63 | | - path: str, |
| 38 | + volcengine_access_key: str, |
| 39 | + volcengine_secret_key: str, |
| 40 | + project_path: str, |
| 41 | + deploy_config_file: str, |
64 | 42 | ) -> None: |
65 | | - """Deploy a user project to Volcengine FaaS application.""" |
66 | | - import asyncio |
67 | | - import shutil |
68 | | - from pathlib import Path |
69 | | - |
70 | | - from cookiecutter.main import cookiecutter |
71 | | - |
72 | | - import veadk.integrations.ve_faas as vefaas |
73 | | - from veadk.config import getenv |
74 | | - from veadk.utils.logger import get_logger |
75 | | - from veadk.utils.misc import formatted_timestamp, load_module_from_file |
76 | | - |
77 | | - logger = get_logger(__name__) |
78 | | - |
79 | | - if not access_key: |
80 | | - access_key = getenv("VOLCENGINE_ACCESS_KEY") |
81 | | - if not secret_key: |
82 | | - secret_key = getenv("VOLCENGINE_SECRET_KEY") |
83 | | - |
84 | | - user_proj_abs_path = Path(path).resolve() |
85 | | - template_dir_path = Path(vefaas.__file__).parent / "template" |
86 | | - |
87 | | - tmp_dir_name = f"{user_proj_abs_path.name}_{formatted_timestamp()}" |
88 | | - |
89 | | - settings = { |
90 | | - "local_dir_name": tmp_dir_name.replace("-", "_"), |
91 | | - "app_name": user_proj_abs_path.name.replace("-", "_"), |
92 | | - "agent_module_name": user_proj_abs_path.name, |
93 | | - "short_term_memory_backend": short_term_memory_backend, |
94 | | - "vefaas_application_name": vefaas_app_name, |
95 | | - "veapig_instance_name": veapig_instance_name, |
96 | | - "veapig_service_name": veapig_service_name, |
97 | | - "veapig_upstream_name": veapig_upstream_name, |
98 | | - "use_adk_web": use_adk_web, |
99 | | - "veadk_version": VERSION, |
100 | | - } |
101 | | - |
102 | | - cookiecutter( |
103 | | - template=str(template_dir_path), |
104 | | - output_dir=TEMP_PATH, |
105 | | - no_input=True, |
106 | | - extra_context=settings, |
107 | | - ) |
108 | | - logger.debug(f"Create a template project at {TEMP_PATH}/{tmp_dir_name}") |
109 | | - |
110 | | - agent_dir = ( |
111 | | - Path(TEMP_PATH) |
112 | | - / tmp_dir_name |
113 | | - / "src" |
114 | | - / user_proj_abs_path.name.replace("-", "_") |
115 | | - ) |
116 | | - |
117 | | - # remove /tmp/tmp_dir_name/src/user_proj_abs_path.name |
118 | | - shutil.rmtree(agent_dir) |
119 | | - agent_dir.mkdir(parents=True, exist_ok=True) |
120 | | - |
121 | | - # copy |
122 | | - shutil.copytree(user_proj_abs_path, agent_dir, dirs_exist_ok=True) |
123 | | - logger.debug(f"Remove agent module from {user_proj_abs_path} to {agent_dir}") |
124 | | - |
125 | | - # copy requirements.txt |
126 | | - if (user_proj_abs_path / "requirements.txt").exists(): |
127 | | - logger.debug( |
128 | | - f"Find a requirements.txt in {user_proj_abs_path}/requirements.txt, copy it to temp project." |
129 | | - ) |
130 | | - shutil.copy( |
131 | | - user_proj_abs_path / "requirements.txt", |
132 | | - Path(TEMP_PATH) / tmp_dir_name / "src" / "requirements.txt", |
133 | | - ) |
134 | | - else: |
135 | | - logger.warning( |
136 | | - "No requirements.txt found in the user project, we will use a default one." |
137 | | - ) |
138 | | - |
139 | | - # avoid upload user's config.yaml |
140 | | - if (user_proj_abs_path / "config.yaml").exists(): |
141 | | - logger.warning( |
142 | | - f"Find a config.yaml in {user_proj_abs_path}/config.yaml, we will not upload it by default." |
143 | | - ) |
144 | | - shutil.move(agent_dir / "config.yaml", Path(TEMP_PATH) / tmp_dir_name) |
145 | | - else: |
146 | | - logger.info( |
147 | | - "No config.yaml found in the user project. Some environment variables may not be set." |
148 | | - ) |
149 | | - |
150 | | - # load |
151 | | - logger.debug( |
152 | | - f"Load deploy module from {Path(TEMP_PATH) / tmp_dir_name / 'deploy.py'}" |
153 | | - ) |
154 | | - deploy_module = load_module_from_file( |
155 | | - module_name="deploy_module", |
156 | | - file_path=str(Path(TEMP_PATH) / tmp_dir_name / "deploy.py"), |
157 | | - ) |
158 | | - logger.info(f"Begin deploy from {Path(TEMP_PATH) / tmp_dir_name / 'src'}") |
159 | | - asyncio.run(deploy_module.main()) |
160 | | - |
161 | | - # remove tmp file |
162 | | - logger.info("Deploy done. Delete temp dir.") |
163 | | - shutil.rmtree(Path(TEMP_PATH) / tmp_dir_name) |
| 43 | + # """Deploy a user project to Volcengine FaaS application.""" |
| 44 | + # import asyncio |
| 45 | + # import shutil |
| 46 | + # from pathlib import Path |
| 47 | + |
| 48 | + # from cookiecutter.main import cookiecutter |
| 49 | + |
| 50 | + # import veadk.integrations.ve_faas as vefaas |
| 51 | + # from veadk.config import getenv |
| 52 | + # from veadk.utils.logger import get_logger |
| 53 | + # from veadk.utils.misc import formatted_timestamp, load_module_from_file |
| 54 | + |
| 55 | + # logger = get_logger(__name__) |
| 56 | + |
| 57 | + # if not volcengine_access_key: |
| 58 | + # access_key = getenv("VOLCENGINE_ACCESS_KEY") |
| 59 | + # if not volcengine_secret_key: |
| 60 | + # secret_key = getenv("VOLCENGINE_SECRET_KEY") |
| 61 | + |
| 62 | + # user_proj_abs_path = Path(path).resolve() |
| 63 | + # template_dir_path = Path(vefaas.__file__).parent / "template" |
| 64 | + |
| 65 | + # tmp_dir_name = f"{user_proj_abs_path.name}_{formatted_timestamp()}" |
| 66 | + |
| 67 | + # settings = { |
| 68 | + # "local_dir_name": tmp_dir_name.replace("-", "_"), |
| 69 | + # "app_name": user_proj_abs_path.name.replace("-", "_"), |
| 70 | + # "agent_module_name": user_proj_abs_path.name, |
| 71 | + # "short_term_memory_backend": short_term_memory_backend, |
| 72 | + # "vefaas_application_name": vefaas_app_name, |
| 73 | + # "veapig_instance_name": veapig_instance_name, |
| 74 | + # "veapig_service_name": veapig_service_name, |
| 75 | + # "veapig_upstream_name": veapig_upstream_name, |
| 76 | + # "use_adk_web": use_adk_web, |
| 77 | + # "veadk_version": VERSION, |
| 78 | + # } |
| 79 | + |
| 80 | + # cookiecutter( |
| 81 | + # template=str(template_dir_path), |
| 82 | + # output_dir=TEMP_PATH, |
| 83 | + # no_input=True, |
| 84 | + # extra_context=settings, |
| 85 | + # ) |
| 86 | + # logger.debug(f"Create a template project at {TEMP_PATH}/{tmp_dir_name}") |
| 87 | + |
| 88 | + # agent_dir = ( |
| 89 | + # Path(TEMP_PATH) |
| 90 | + # / tmp_dir_name |
| 91 | + # / "src" |
| 92 | + # / user_proj_abs_path.name.replace("-", "_") |
| 93 | + # ) |
| 94 | + |
| 95 | + # # remove /tmp/tmp_dir_name/src/user_proj_abs_path.name |
| 96 | + # shutil.rmtree(agent_dir) |
| 97 | + # agent_dir.mkdir(parents=True, exist_ok=True) |
| 98 | + |
| 99 | + # # copy |
| 100 | + # shutil.copytree(user_proj_abs_path, agent_dir, dirs_exist_ok=True) |
| 101 | + # logger.debug(f"Remove agent module from {user_proj_abs_path} to {agent_dir}") |
| 102 | + |
| 103 | + # # copy requirements.txt |
| 104 | + # if (user_proj_abs_path / "requirements.txt").exists(): |
| 105 | + # logger.debug( |
| 106 | + # f"Find a requirements.txt in {user_proj_abs_path}/requirements.txt, copy it to temp project." |
| 107 | + # ) |
| 108 | + # shutil.copy( |
| 109 | + # user_proj_abs_path / "requirements.txt", |
| 110 | + # Path(TEMP_PATH) / tmp_dir_name / "src" / "requirements.txt", |
| 111 | + # ) |
| 112 | + # else: |
| 113 | + # logger.warning( |
| 114 | + # "No requirements.txt found in the user project, we will use a default one." |
| 115 | + # ) |
| 116 | + |
| 117 | + # # avoid upload user's config.yaml |
| 118 | + # if (user_proj_abs_path / "config.yaml").exists(): |
| 119 | + # logger.warning( |
| 120 | + # f"Find a config.yaml in {user_proj_abs_path}/config.yaml, we will not upload it by default." |
| 121 | + # ) |
| 122 | + # shutil.move(agent_dir / "config.yaml", Path(TEMP_PATH) / tmp_dir_name) |
| 123 | + # else: |
| 124 | + # logger.info( |
| 125 | + # "No config.yaml found in the user project. Some environment variables may not be set." |
| 126 | + # ) |
| 127 | + |
| 128 | + # # load |
| 129 | + # logger.debug( |
| 130 | + # f"Load deploy module from {Path(TEMP_PATH) / tmp_dir_name / 'deploy.py'}" |
| 131 | + # ) |
| 132 | + # deploy_module = load_module_from_file( |
| 133 | + # module_name="deploy_module", |
| 134 | + # file_path=str(Path(TEMP_PATH) / tmp_dir_name / "deploy.py"), |
| 135 | + # ) |
| 136 | + # logger.info(f"Begin deploy from {Path(TEMP_PATH) / tmp_dir_name / 'src'}") |
| 137 | + # asyncio.run(deploy_module.main()) |
| 138 | + |
| 139 | + # # remove tmp file |
| 140 | + # logger.info("Deploy done. Delete temp dir.") |
| 141 | + # shutil.rmtree(Path(TEMP_PATH) / tmp_dir_name) |
| 142 | + pass |
0 commit comments