-
Notifications
You must be signed in to change notification settings - Fork 2
/
dev_resources.py
57 lines (51 loc) · 1.48 KB
/
dev_resources.py
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
from pathlib import Path
from phi.docker.app.fastapi import FastApi
from phi.docker.app.postgres import PostgresDb
from phi.docker.resources import DockerResources
from phi.docker.resource.image import DockerImage
key = "phi-interview-questions"
ws_root = Path(__file__).parent.resolve()
# -*- Dev image
dev_image = DockerImage(
name="phidata/interview-questions",
tag="dev",
path=str(ws_root),
# Set to True to build the image locally
enabled=False,
)
# -*- Dev database running on port 5432
dev_db = PostgresDb(
name=f"db-{key}",
pg_user="phi",
pg_password="phi",
pg_database="phi",
# Connect to this db on port 5432
host_port=5432,
)
# -*- Dev API running on port 8000
dev_fastapi = FastApi(
name=f"api-{key}",
image=dev_image,
command="uvicorn api.main:app --reload",
port_number=8000,
debug_mode=True,
mount_workspace=True,
env_vars={
"RUNTIME_ENV": "dev",
# Database configuration
"DB_HOST": dev_db.get_db_host(),
"DB_PORT": dev_db.get_db_port(),
"DB_USER": dev_db.get_db_user(),
"DB_PASS": dev_db.get_db_password(),
"DB_DATABASE": dev_db.get_db_database(),
# Wait for database to be available before starting the server
"WAIT_FOR_DB": True,
# Migrate database on startup using alembic
"MIGRATE_DB": True,
},
)
# -*- Define the dev resources running on docker
dev_resources = DockerResources(
network=key,
apps=[dev_db, dev_fastapi],
)