Skip to content

Commit

Permalink
🐛 Fix parsing of compose file configs with compose v2.24.7 (#563)
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrieldemarmiesse authored Mar 10, 2024
1 parent e45f0cd commit 68efb49
Show file tree
Hide file tree
Showing 3 changed files with 289 additions and 3 deletions.
7 changes: 4 additions & 3 deletions python_on_whales/components/compose/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
147 changes: 147 additions & 0 deletions tests/python_on_whales/components/jsons/compose/1.json
Original file line number Diff line number Diff line change
@@ -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
}
}
}
}
138 changes: 138 additions & 0 deletions tests/python_on_whales/components/jsons/compose/2.json
Original file line number Diff line number Diff line change
@@ -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"
}

0 comments on commit 68efb49

Please sign in to comment.