-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathapps.py
More file actions
58 lines (40 loc) · 1.82 KB
/
apps.py
File metadata and controls
58 lines (40 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import logging
from pathlib import Path
from pydantic import BaseModel
logger = logging.getLogger("fastapi_cli")
class AppConfig(BaseModel):
app_id: str
team_id: str
def get_app_config(path_to_deploy: Path) -> AppConfig | None:
config_path = path_to_deploy / ".fastapicloud/cloud.json"
logger.debug("Looking for app config at: %s", config_path)
if not config_path.exists():
logger.debug("App config file doesn't exist")
return None
logger.debug("App config loaded successfully")
return AppConfig.model_validate_json(config_path.read_text(encoding="utf-8"))
README = """
> Why do I have a folder named ".fastapicloud" in my project? 🤔
The ".fastapicloud" folder is created when you link a directory to a FastAPI Cloud project.
> What does the "cloud.json" file contain?
The "cloud.json" file contains:
- The ID of the FastAPI app that you linked ("app_id")
- The ID of the team your FastAPI Cloud project is owned by ("team_id")
> Should I commit the ".fastapicloud" folder?
No, you should not commit the ".fastapicloud" folder to your version control system.
That's why there's a ".gitignore" file in this folder.
"""
def write_app_config(path_to_deploy: Path, app_config: AppConfig) -> None:
config_path = path_to_deploy / ".fastapicloud/cloud.json"
readme_path = path_to_deploy / ".fastapicloud/README.md"
gitignore_path = path_to_deploy / ".fastapicloud/.gitignore"
logger.debug("Writing app config to: %s", config_path)
logger.debug("App config data: %s", app_config)
config_path.parent.mkdir(parents=True, exist_ok=True)
config_path.write_text(
app_config.model_dump_json(),
encoding="utf-8",
)
readme_path.write_text(README, encoding="utf-8")
gitignore_path.write_text("*")
logger.debug("App config files written successfully")