Skip to content

Commit

Permalink
Add box.seed_data_file_url parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
quincylvania committed Oct 7, 2024
1 parent ad3a5a6 commit 04d1590
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 4 deletions.
1 change: 1 addition & 0 deletions images/dashboard/src/models/boxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion images/dashboard/src/routes/boxes_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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],
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 8 additions & 0 deletions images/dashboard/src/schemas/boxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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
Expand All @@ -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,
Expand Down
5 changes: 4 additions & 1 deletion images/dashboard/src/utils/helm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions images/dashboard/src/values/osm-seed.template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 04d1590

Please sign in to comment.