Skip to content

Commit 41c6fde

Browse files
committed
feat(compose): add union type input for networks
1 parent b9e4ed1 commit 41c6fde

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

app/media/MyCompose/docker-compose.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ services:
44
build:
55
context: .
66
dockerfile: DockerFile
7+
args:
8+
foo: bar
79
image: nginx:latest
810
container_name: web_server
911
command: command...
@@ -15,14 +17,14 @@ services:
1517
- 80:80
1618
networks:
1719
- app_network
18-
args:
19-
foo: bar
2020
depends_on:
2121
- service 0
2222
web2:
2323
build:
2424
context: .
2525
dockerfile: DockerFile
26+
args:
27+
foo: bar
2628
image: nginx:latest
2729
container_name: web_server
2830
command: command...
@@ -34,8 +36,6 @@ services:
3436
- 80:80
3537
networks:
3638
- app_network
37-
args:
38-
foo: bar
3939
depends_on:
4040
- service 0
4141
networks:

app/models/compose_models.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
from typing import Dict, List, Optional
1+
from typing import Dict, List, Optional,Union
22
from pydantic import BaseModel, model_validator
33

44
class Build(BaseModel):
55
context: str = "."
66
dockerfile: str = "DockerFile"
7-
7+
args: Optional[Dict[str, str]] = {"foo":"bar"}
88
class Service(BaseModel):
99
build: Optional[Build] = Build()
1010
image: Optional[str] = "nginx:latest"
@@ -14,7 +14,7 @@ class Service(BaseModel):
1414
environment: Optional[Dict[str, str]] = {"foo":"bar"}
1515
ports: Optional[List[str]] = ["80:80"]
1616
networks: Optional[List[str]] = ["app_network"]
17-
args: Optional[Dict[str, str]] = {"foo":"bar"}
17+
1818
depends_on: Optional[List[str]] = ['service 0']
1919

2020
@model_validator(mode="after")
@@ -26,8 +26,11 @@ def validator(self):
2626
class Network(BaseModel):
2727
driver: str = "bridge"
2828

29+
class PreCreatedNetwork(BaseModel):
30+
name:str = "net1"
31+
external:bool = True
2932
class DockerCompose(BaseModel):
3033
version: str = "3"
3134
services: Dict[str, Service] = {"web":Service(), "web2":Service()}
32-
networks: Optional[Dict[str, Network]] = {"app_network": {"driver":"bridge"}}
33-
35+
networks: Union[Optional[Dict[str, PreCreatedNetwork]],Optional[Dict[str, Network]]] = {"app_network": {"driver":"bridge"}}
36+

0 commit comments

Comments
 (0)