From 68efb49d00360b39f7d44112679bc67552a4c32e Mon Sep 17 00:00:00 2001 From: Gabriel de Marmiesse Date: Sun, 10 Mar 2024 11:01:22 +0100 Subject: [PATCH] :bug: Fix parsing of compose file configs with compose v2.24.7 (#563) --- python_on_whales/components/compose/models.py | 7 +- .../components/jsons/compose/1.json | 147 ++++++++++++++++++ .../components/jsons/compose/2.json | 138 ++++++++++++++++ 3 files changed, 289 insertions(+), 3 deletions(-) create mode 100644 tests/python_on_whales/components/jsons/compose/1.json create mode 100644 tests/python_on_whales/components/jsons/compose/2.json diff --git a/python_on_whales/components/compose/models.py b/python_on_whales/components/compose/models.py index d81ed707..526b4830 100644 --- a/python_on_whales/components/compose/models.py +++ b/python_on_whales/components/compose/models.py @@ -67,14 +67,15 @@ class ComposeConfigService(BaseModel): cap_add: Annotated[Optional[List[str]], Field(default_factory=list)] cap_drop: Annotated[Optional[List[str]], Field(default_factory=list)] cgroup_parent: Optional[str] = None - command: Optional[List[str]] = None + command: Union[List[str], str, None] = None configs: Any = None container_name: Optional[str] = None depends_on: Annotated[Dict[str, DependencyCondition], Field(default_factory=dict)] device_cgroup_rules: Annotated[List[str], Field(default_factory=list)] devices: Any = None - environment: Optional[Dict[str, Optional[str]]] = None - entrypoint: Optional[List[str]] = None + environment: Union[Dict[str, Union[str, int, None]], List[str], None] = None + expose: Annotated[Union[List[int], List[str]], Field(default_factory=list)] + entrypoint: Union[List[str], str, None] = None image: Optional[str] = None labels: Annotated[Optional[Dict[str, str]], Field(default_factory=dict)] ports: Optional[List[ComposeServicePort]] = None diff --git a/tests/python_on_whales/components/jsons/compose/1.json b/tests/python_on_whales/components/jsons/compose/1.json new file mode 100644 index 00000000..aa69c46f --- /dev/null +++ b/tests/python_on_whales/components/jsons/compose/1.json @@ -0,0 +1,147 @@ +{ + "name": "python-on-whales", + "networks": { + "factory-net": { + "name": "factory-net", + "ipam": {}, + "external": true + } + }, + "services": { + "broker": { + "command": null, + "container_name": "broker", + "depends_on": { + "zookeeper": { + "condition": "service_started", + "required": true + } + }, + "entrypoint": null, + "environment": { + "KAFKA_ADVERTISED_LISTENERS": "PLAINTEXT://localhost:9092,PLAINTEXT_INTERNAL://broker:29092", + "KAFKA_BROKER_ID": "1", + "KAFKA_LISTENER_SECURITY_PROTOCOL_MAP": "PLAINTEXT:PLAINTEXT,PLAINTEXT_INTERNAL:PLAINTEXT", + "KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR": "1", + "KAFKA_TRANSACTION_STATE_LOG_MIN_ISR": "1", + "KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR": "1", + "KAFKA_ZOOKEEPER_CONNECT": "zookeeper:2181" + }, + "expose": [ + "29092" + ], + "healthcheck": { + "test": [ + "CMD-SHELL", + "nc -z localhost 9092 || exit -1" + ], + "timeout": "10s", + "interval": "5s", + "retries": 10, + "start_period": "15s" + }, + "image": "confluentinc/cp-kafka:7.4.0", + "networks": { + "factory-net": null + }, + "ports": [ + { + "mode": "ingress", + "target": 9092, + "published": "9092", + "protocol": "tcp" + } + ] + }, + "ksqldb-cli": { + "command": null, + "container_name": "ksqldb-cli", + "depends_on": { + "broker": { + "condition": "service_healthy", + "required": true + }, + "ksqldb-server": { + "condition": "service_healthy", + "required": true + } + }, + "entrypoint": [ + "bash", + "-c", + "source ./scripts/start_ksql.sh; tail -F anything" + ], + "environment": { + "KSQL_START_SCRIPTS": "mtcdevices.sql" + }, + "image": "confluentinc/ksqldb-cli:0.29.0", + "networks": { + "factory-net": null + }, + "tty": true, + "volumes": [ + { + "type": "bind", + "source": "/projects/open_source/python-on-whales/scripts", + "target": "/home/appuser/scripts", + "bind": { + "create_host_path": true + } + } + ] + }, + "ksqldb-server": { + "command": null, + "container_name": "ksqldb-server", + "depends_on": { + "broker": { + "condition": "service_healthy", + "required": true + } + }, + "entrypoint": null, + "environment": { + "KSQL_BOOTSTRAP_SERVERS": "broker:29092", + "KSQL_KSQL_LOGGING_PROCESSING_STREAM_AUTO_CREATE": "true", + "KSQL_KSQL_LOGGING_PROCESSING_TOPIC_AUTO_CREATE": "true", + "KSQL_LISTENERS": "http://0.0.0.0:8088" + }, + "hostname": "ksqldb-server", + "healthcheck": { + "test": [ + "CMD-SHELL", + "nc -z localhost 8088 || exit -1" + ], + "timeout": "10s", + "interval": "5s", + "retries": 10, + "start_period": "15s" + }, + "image": "confluentinc/ksqldb-server:0.29.0", + "networks": { + "factory-net": null + }, + "ports": [ + { + "mode": "ingress", + "target": 8088, + "published": "8088", + "protocol": "tcp" + } + ] + }, + "zookeeper": { + "command": null, + "container_name": "zookeeper", + "entrypoint": null, + "environment": { + "ZOOKEEPER_CLIENT_PORT": "2181", + "ZOOKEEPER_TICK_TIME": "2000" + }, + "image": "confluentinc/cp-zookeeper:7.4.0", + "networks": { + "factory-net": null + } + } + } +} \ No newline at end of file diff --git a/tests/python_on_whales/components/jsons/compose/2.json b/tests/python_on_whales/components/jsons/compose/2.json new file mode 100644 index 00000000..b2ccde39 --- /dev/null +++ b/tests/python_on_whales/components/jsons/compose/2.json @@ -0,0 +1,138 @@ +{ + "name": "test", + "networks": { + "default": { + "name": "test_default" + }, + "factory-net": { + "external": true, + "name": "factory-net" + } + }, + "services": { + "broker": { + "container_name": "broker", + "depends_on": { + "zookeeper": { + "condition": "service_started", + "required": true + } + }, + "environment": { + "KAFKA_ADVERTISED_LISTENERS": "PLAINTEXT://localhost:9092,PLAINTEXT_INTERNAL://broker:29092", + "KAFKA_BROKER_ID": 1, + "KAFKA_LISTENER_SECURITY_PROTOCOL_MAP": "PLAINTEXT:PLAINTEXT,PLAINTEXT_INTERNAL:PLAINTEXT", + "KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR": 1, + "KAFKA_TRANSACTION_STATE_LOG_MIN_ISR": 1, + "KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR": 1, + "KAFKA_ZOOKEEPER_CONNECT": "zookeeper:2181" + }, + "expose": [ + 29092 + ], + "healthcheck": { + "interval": "5s", + "retries": 10, + "start_period": "15s", + "test": "nc -z localhost 9092 || exit -1", + "timeout": "10s" + }, + "image": "confluentinc/cp-kafka:7.4.0", + "networks": { + "factory-net": null + }, + "ports": [ + { + "mode": "ingress", + "protocol": "tcp", + "published": "9092", + "target": 9092 + } + ] + }, + "ksqldb-cli": { + "container_name": "ksqldb-cli", + "depends_on": { + "broker": { + "condition": "service_healthy", + "required": true + }, + "ksqldb-server": { + "condition": "service_healthy", + "required": true + } + }, + "entrypoint": "bash -c \"source ./scripts/start_ksql.sh; tail -F anything\"", + "environment": [ + "KSQL_START_SCRIPTS=mtcdevices.sql" + ], + "image": "confluentinc/ksqldb-cli:0.29.0", + "networks": { + "factory-net": null + }, + "tty": true, + "volumes": [ + { + "bind": { + "create_host_path": true + }, + "source": "/tmp/test/scripts", + "target": "/home/appuser/scripts", + "type": "bind" + } + ] + }, + "ksqldb-server": { + "command": [ + "hello", + "world" + ], + "container_name": "ksqldb-server", + "depends_on": { + "broker": { + "condition": "service_healthy", + "required": true + } + }, + "environment": { + "KSQL_BOOTSTRAP_SERVERS": "broker:29092", + "KSQL_KSQL_LOGGING_PROCESSING_STREAM_AUTO_CREATE": "true", + "KSQL_KSQL_LOGGING_PROCESSING_TOPIC_AUTO_CREATE": "true", + "KSQL_LISTENERS": "http://0.0.0.0:8088" + }, + "healthcheck": { + "interval": "5s", + "retries": 10, + "start_period": "15s", + "test": "nc -z localhost 8088 || exit -1", + "timeout": "10s" + }, + "hostname": "ksqldb-server", + "image": "confluentinc/ksqldb-server:0.29.0", + "networks": { + "factory-net": null + }, + "ports": [ + { + "mode": "ingress", + "protocol": "tcp", + "published": "8088", + "target": 8088 + } + ] + }, + "zookeeper": { + "command": "hello world", + "container_name": "zookeeper", + "environment": { + "ZOOKEEPER_CLIENT_PORT": 2181, + "ZOOKEEPER_TICK_TIME": 2000 + }, + "image": "confluentinc/cp-zookeeper:7.4.0", + "networks": { + "factory-net": null + } + } + }, + "version": "3.9" + } \ No newline at end of file