Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🎨 extend ooil to support depends_on keyword in overwrites #7041

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
1 change: 1 addition & 0 deletions packages/service-integration/requirements/prod.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# installs base + tests requirements
--requirement _base.txt

simcore-common-library @ ../common-library/
simcore-models-library @ ../models-library

# current module
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from ._compose_spec_model_autogenerated import ( # type:ignore
BuildItem,
ComposeSpecification,
ListOrDict,
Service,
Volume1,
)
Expand All @@ -23,6 +24,7 @@
__all__: tuple[str, ...] = (
"BuildItem",
"ComposeSpecification",
"ListOrDict",
"SCHEMA_VERSION",
"Service",
"ServiceVolume",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ class LabelSchemaAnnotations(BaseModel):
@classmethod
def create_from_env(cls) -> "LabelSchemaAnnotations":
data = {}
for field_name in cls.model_fields:
for field_name in cls.model_fields: # pylint: disable=not-an-iterable
if value := os.environ.get(field_name.upper()):
data[field_name] = value
return cls.model_validate(data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

"""

from typing import Any

from service_integration.compose_spec_model import (
BuildItem,
ComposeSpecification,
ListOrDict,
Service,
)

Expand All @@ -26,7 +28,7 @@ def create_image_spec(

- the image-spec simplifies building an image to ``docker compose build``
"""
labels = {**meta_cfg.to_labels_annotations()}
labels: dict[str, str | float | bool | None] = {**meta_cfg.to_labels_annotations()}
GitHK marked this conversation as resolved.
Show resolved Hide resolved
GitHK marked this conversation as resolved.
Show resolved Hide resolved
if extra_labels:
labels.update(extra_labels)
if runtime_cfg:
Expand All @@ -36,19 +38,26 @@ def create_image_spec(

assert docker_compose_overwrite_cfg.services # nosec

if not docker_compose_overwrite_cfg.services[service_name].build.context:
docker_compose_overwrite_cfg.services[service_name].build.context = "./"
build = docker_compose_overwrite_cfg.services[service_name].build
assert isinstance(build, BuildItem) # nosec
if not build.context:
build.context = "./"

docker_compose_overwrite_cfg.services[service_name].build.labels = labels
build.labels = ListOrDict(root=labels)

overwrite_options = docker_compose_overwrite_cfg.services[
service_name
].build.model_dump(exclude_none=True, serialize_as_any=True)
overwrite_options = build.model_dump(exclude_none=True, serialize_as_any=True)
build_spec = BuildItem(**overwrite_options)

service_kwargs: dict[str, Any] = {
"image": meta_cfg.image_name(settings),
"build": build_spec,
}
if docker_compose_overwrite_cfg.services[service_name].depends_on:
service_kwargs["depends_on"] = docker_compose_overwrite_cfg.services[
service_name
].depends_on

return ComposeSpecification(
version=settings.COMPOSE_VERSION,
services={
service_name: Service(image=meta_cfg.image_name(settings), build=build_spec)
},
services={service_name: Service(**service_kwargs)},
)
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
services:
osparc-python-runner:
depends_on:
- another-service
build:
dockerfile: Dockerfile
14 changes: 10 additions & 4 deletions packages/service-integration/tests/test_command_compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,22 @@
# pylint: disable=unused-variable

import os
import traceback
from collections.abc import Callable
from pathlib import Path

import yaml
from click.testing import Result
from service_integration.compose_spec_model import ComposeSpecification
from service_integration.osparc_config import MetadataConfig


def _format_cli_error(result: Result) -> str:
assert result.exception
tb_message = "\n".join(traceback.format_tb(result.exception.__traceback__))
return f"Below exception was raised by the cli:\n{tb_message}"


def test_make_docker_compose_meta(
run_program_with_args: Callable,
docker_compose_overwrite_path: Path,
Expand All @@ -33,7 +41,7 @@ def test_make_docker_compose_meta(
"--to-spec-file",
target_compose_specs,
)
assert result.exit_code == os.EX_OK, result.output
assert result.exit_code == os.EX_OK, _format_cli_error(result)

# produces a compose spec
assert target_compose_specs.exists()
Expand All @@ -50,6 +58,4 @@ def test_make_docker_compose_meta(
assert compose_labels
assert isinstance(compose_labels.root, dict)

assert (
MetadataConfig.from_labels_annotations(compose_labels.root) == metadata_cfg
)
assert MetadataConfig.from_labels_annotations(compose_labels.root) == metadata_cfg
Loading