diff --git a/images/dashboard/src/models/boxes.py b/images/dashboard/src/models/boxes.py index 5a93b24..a12a021 100644 --- a/images/dashboard/src/models/boxes.py +++ b/images/dashboard/src/models/boxes.py @@ -19,6 +19,7 @@ class Boxes(Base): name = Column(String, nullable=False) subdomain = Column(String, nullable=False) resource_label = Column(String, nullable=False) + seed_data_file_url = Column(String, nullable=False) owner = Column(String, nullable=False) description = Column(String, nullable=False) state = Column(SQLEnum(StateEnum), nullable=False) diff --git a/images/dashboard/src/routes/boxes_routes.py b/images/dashboard/src/routes/boxes_routes.py index 1896257..5a9d63b 100644 --- a/images/dashboard/src/routes/boxes_routes.py +++ b/images/dashboard/src/routes/boxes_routes.py @@ -55,7 +55,7 @@ async def create_box( ) # Create values file - values_file = replace_placeholders_and_save(box.name, box.resource_label) + values_file = replace_placeholders_and_save(box.name, box.resource_label, box.seed_data_file_url) # Create a new box try: @@ -73,6 +73,7 @@ async def create_box( name=box.name, subdomain=f"{box.name}.{SANDBOX_DOMAIN}", resource_label=box.resource_label, + seed_data_file_url=box.seed_data_file_url, owner=token.username, description=box.description, state=StateEnum[state], @@ -228,6 +229,7 @@ async def get_boxes_history( state=box.state, age=box.age, resource_label=box.resource_label, + seed_data_file_url=box.seed_data_file_url, description=box.description, owner=box.owner, subdomain=box.subdomain, diff --git a/images/dashboard/src/schemas/boxes.py b/images/dashboard/src/schemas/boxes.py index 95554fa..187cee7 100644 --- a/images/dashboard/src/schemas/boxes.py +++ b/images/dashboard/src/schemas/boxes.py @@ -23,6 +23,12 @@ class BoxBase(BaseModel): description="Box's description", example="My new osm sandbox", ) + seed_data_file_url: Optional[str] = Field( + ..., + title="Seed data file URL", + description="(Optional) An absolute public URL to a PBF file or bzipped OSM XML file to seed the database with upon startup.", + example="https://example.com/template.pbf", + ) @validator("name") def validate_name(cls, value): @@ -39,6 +45,7 @@ class BoxResponse(BaseModel): name: str subdomain: str resource_label: str + seed_data_file_url: Optional[str] description: str owner: str state: str @@ -59,6 +66,7 @@ def from_orm(box: "Boxes") -> "BoxResponse": name=box.name, subdomain=box.subdomain, resource_label=box.resource_label, + seed_data_file_url=box.seed_data_file_url, description=box.description, owner=box.owner, state=box.state, diff --git a/images/dashboard/src/utils/helm.py b/images/dashboard/src/utils/helm.py index d6d4522..cec4a72 100644 --- a/images/dashboard/src/utils/helm.py +++ b/images/dashboard/src/utils/helm.py @@ -32,10 +32,13 @@ async def list_releases(namespace): return release_list -def replace_placeholders_and_save(box_name, label_value): +def replace_placeholders_and_save(box_name, label_value, seed_data_file_url): """Take a template YAML file and update it with the necessary values to deploy a box.""" os.environ["BOX_NAME"] = box_name os.environ["LABEL_VALUE"] = label_value + os.environ["SHOULD_POPULATE_DB"] = bool(seed_data_file_url) + os.environ["URL_FILE_TO_IMPORT"] = seed_data_file_url + values_file = f"values/values_{box_name}.yaml" with open("values/osm-seed.template.yaml", "r") as file: file_content = file.read() diff --git a/images/dashboard/src/values/osm-seed.template.yaml b/images/dashboard/src/values/osm-seed.template.yaml index a9b1ea9..a1ecd3c 100644 --- a/images/dashboard/src/values/osm-seed.template.yaml +++ b/images/dashboard/src/values/osm-seed.template.yaml @@ -62,13 +62,13 @@ osm-seed: cpuUtilization: 80 sharedMemorySize: 16Mi populateApidb: - enabled: true + enabled: {{SHOULD_POPULATE_DB}} nodeSelector: enabled: true label_key: nodegroup_type label_value: {{LABEL_VALUE}} env: - URL_FILE_TO_IMPORT: "https://github.com/osmus/osm-sandbox-data/raw/refs/heads/main/ncem/cumberland_buildings.osm.bz2" + URL_FILE_TO_IMPORT: {{URL_FILE_TO_IMPORT}} resources: enabled: false memcached: