Skip to content

Commit a7a69e4

Browse files
author
Andrei Neagu
committed
extend ooil to support depends_on
1 parent 082ec0b commit a7a69e4

File tree

3 files changed

+31
-14
lines changed

3 files changed

+31
-14
lines changed

packages/service-integration/src/service_integration/osparc_image_specs.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
33
"""
44

5+
from typing import Any
56

7+
from service_integration._compose_spec_model_autogenerated import ListOrDict
68
from service_integration.compose_spec_model import (
79
BuildItem,
810
ComposeSpecification,
@@ -26,7 +28,7 @@ def create_image_spec(
2628
2729
- the image-spec simplifies building an image to ``docker compose build``
2830
"""
29-
labels = {**meta_cfg.to_labels_annotations()}
31+
labels: dict[str, str | float | bool | None] = {**meta_cfg.to_labels_annotations()}
3032
if extra_labels:
3133
labels.update(extra_labels)
3234
if runtime_cfg:
@@ -36,19 +38,26 @@ def create_image_spec(
3638

3739
assert docker_compose_overwrite_cfg.services # nosec
3840

39-
if not docker_compose_overwrite_cfg.services[service_name].build.context:
40-
docker_compose_overwrite_cfg.services[service_name].build.context = "./"
41+
build = docker_compose_overwrite_cfg.services[service_name].build
42+
assert isinstance(build, BuildItem) # nosec
43+
if not build.context:
44+
build.context = "./"
4145

42-
docker_compose_overwrite_cfg.services[service_name].build.labels = labels
46+
build.labels = ListOrDict(root=labels)
4347

44-
overwrite_options = docker_compose_overwrite_cfg.services[
45-
service_name
46-
].build.model_dump(exclude_none=True, serialize_as_any=True)
48+
overwrite_options = build.model_dump(exclude_none=True, serialize_as_any=True)
4749
build_spec = BuildItem(**overwrite_options)
4850

51+
service_kwargs: dict[str, Any] = {
52+
"image": meta_cfg.image_name(settings),
53+
"build": build_spec,
54+
}
55+
if docker_compose_overwrite_cfg.services[service_name].depends_on:
56+
service_kwargs["depends_on"] = docker_compose_overwrite_cfg.services[
57+
service_name
58+
].depends_on
59+
4960
return ComposeSpecification(
5061
version=settings.COMPOSE_VERSION,
51-
services={
52-
service_name: Service(image=meta_cfg.image_name(settings), build=build_spec)
53-
},
62+
services={service_name: Service(**service_kwargs)},
5463
)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
services:
22
osparc-python-runner:
3+
depends_on:
4+
- another-service
35
build:
46
dockerfile: Dockerfile

packages/service-integration/tests/test_command_compose.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,22 @@
33
# pylint: disable=unused-variable
44

55
import os
6+
import traceback
67
from collections.abc import Callable
78
from pathlib import Path
89

910
import yaml
11+
from click.testing import Result
1012
from service_integration.compose_spec_model import ComposeSpecification
1113
from service_integration.osparc_config import MetadataConfig
1214

1315

16+
def _format_cli_error(result: Result) -> str:
17+
assert result.exception
18+
tb_message = "\n".join(traceback.format_tb(result.exception.__traceback__))
19+
return f"Below exception was raised by the cli:\n{tb_message}"
20+
21+
1422
def test_make_docker_compose_meta(
1523
run_program_with_args: Callable,
1624
docker_compose_overwrite_path: Path,
@@ -33,7 +41,7 @@ def test_make_docker_compose_meta(
3341
"--to-spec-file",
3442
target_compose_specs,
3543
)
36-
assert result.exit_code == os.EX_OK, result.output
44+
assert result.exit_code == os.EX_OK, _format_cli_error(result)
3745

3846
# produces a compose spec
3947
assert target_compose_specs.exists()
@@ -50,6 +58,4 @@ def test_make_docker_compose_meta(
5058
assert compose_labels
5159
assert isinstance(compose_labels.root, dict)
5260

53-
assert (
54-
MetadataConfig.from_labels_annotations(compose_labels.root) == metadata_cfg
55-
)
61+
assert MetadataConfig.from_labels_annotations(compose_labels.root) == metadata_cfg

0 commit comments

Comments
 (0)