Skip to content

Commit

Permalink
needs separation of PR concerns
Browse files Browse the repository at this point in the history
  • Loading branch information
sanderegg committed Jul 3, 2023
1 parent ffc8a71 commit 68a20fc
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 7 deletions.
30 changes: 26 additions & 4 deletions packages/models-library/src/models_library/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,18 @@ class SimcoreServiceDockerLabelKeys(BaseModel):
project_id: ProjectID = Field(..., alias="study_id")
node_id: NodeID = Field(..., alias="uuid")

product_name: ProductName
simcore_user_agent: str
product_name: ProductName = "osparc"
simcore_user_agent: str = "undefined"

# None is for backwards compatibility, can be removed in a few sprints
memory_limit: ByteSize | None
cpu_limit: float | None

def to_docker_labels(self) -> dict[str, str]:
def to_docker_labels(self) -> dict[DockerLabelKey, str]:
"""returns a dictionary of strings as required by docker"""
std_export = self.dict(by_alias=True)
return {
f"{_SIMCORE_CONTAINER_PREFIX}{k.replace('_', '-')}": f"{v}"
DockerLabelKey(f"{_SIMCORE_CONTAINER_PREFIX}{k.replace('_', '-')}"): f"{v}"
for k, v in sorted(std_export.items())
}

Expand All @@ -59,3 +59,25 @@ def from_docker_task(cls, docker_task: Task) -> "SimcoreServiceDockerLabelKeys":

class Config:
allow_population_by_field_name = True
schema_extra = {
"examples": [
# legacy with no limits (a.k.a all dynamic services)
{
"uuid": "1f963626-66e1-43f1-a777-33955c08b909",
"study_id": "29f393fc-1410-47b3-b4b9-61dfce21a2a6",
"user_id": "5",
"product_name": "osparc",
"simcore_user_agent": "puppeteer",
},
# modern both dynamic-sidecar services and computational services
{
"io.simcore.container.node-id": "1f963626-66e1-43f1-a777-33955c08b909",
"io.simcore.container.project-id": "29f393fc-1410-47b3-b4b9-61dfce21a2a6",
"io.simcore.container.user-id": "5",
"io.simcore.container.product-name": "osparc",
"io.simcore.container.simcore-user-agent": "puppeteer",
"io.simcore.container.memory-limit": "1073741824",
"io.simcore.container.cpu-limit": "2.4",
},
]
}
16 changes: 13 additions & 3 deletions packages/models-library/tests/test_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,17 +114,27 @@ def test_docker_generic_tag(image_name: str, valid: bool):
"project_id": _faker.uuid4(),
"node_id": _faker.uuid4(),
},
id="parse_existing_service_labels",
id="parse_existing_service_labels-and-legacy",
),
pytest.param(
{
"user_id": _faker.pyint(),
"project_id": _faker.uuid4(),
"node_id": _faker.uuid4(),
"product": "test_p",
"product_name": "test_p",
"simcore_user_agent": "a-test-puppet",
},
id="parse_new_service_labels",
id="parse_new_service_labels-soon-to-removed",
),
pytest.param(
{
"io.simcore.container.user_id": _faker.pyint(),
"io.simcore.container.project_id": _faker.uuid4(),
"io.simcore.container.node_id": _faker.uuid4(),
"io.simcore.container.product-name": "test_p",
"io.simcore.container.simcore_user_agent": "a-test-puppet",
},
id="labels following docker rules",
),
],
)
Expand Down

0 comments on commit 68a20fc

Please sign in to comment.