fix: extension-fields parse error from compose spec #48

This commit is contained in:
Zheng Zhi Yuan 2023-05-04 00:00:19 +08:00
parent e902237356
commit e649eac539
2 changed files with 41 additions and 38 deletions

View file

@ -13,6 +13,7 @@
"name": { "name": {
"type": "string", "type": "string",
"pattern": "^[a-z0-9][a-z0-9_-]*$",
"description": "define the Compose project name, until user defines one explicitly." "description": "define the Compose project name, until user defines one explicitly."
}, },
@ -90,12 +91,14 @@
"properties": { "properties": {
"context": {"type": "string"}, "context": {"type": "string"},
"dockerfile": {"type": "string"}, "dockerfile": {"type": "string"},
"dockerfile_inline": {"type": "string"},
"args": {"$ref": "#/definitions/list_or_dict"}, "args": {"$ref": "#/definitions/list_or_dict"},
"ssh": {"$ref": "#/definitions/list_or_dict"}, "ssh": {"$ref": "#/definitions/list_or_dict"},
"labels": {"$ref": "#/definitions/list_or_dict"}, "labels": {"$ref": "#/definitions/list_or_dict"},
"cache_from": {"type": "array", "items": {"type": "string"}}, "cache_from": {"type": "array", "items": {"type": "string"}},
"cache_to": {"type": "array", "items": {"type": "string"}}, "cache_to": {"type": "array", "items": {"type": "string"}},
"no_cache": {"type": "boolean"}, "no_cache": {"type": "boolean"},
"additional_contexts": {"$ref": "#/definitions/list_or_dict"},
"network": {"type": "string"}, "network": {"type": "string"},
"pull": {"type": "boolean"}, "pull": {"type": "boolean"},
"target": {"type": "string"}, "target": {"type": "string"},
@ -143,12 +146,7 @@
"cap_drop": {"type": "array", "items": {"type": "string"}, "uniqueItems": true}, "cap_drop": {"type": "array", "items": {"type": "string"}, "uniqueItems": true},
"cgroup": {"type": "string", "enum": ["host", "private"]}, "cgroup": {"type": "string", "enum": ["host", "private"]},
"cgroup_parent": {"type": "string"}, "cgroup_parent": {"type": "string"},
"command": { "command": {"$ref": "#/definitions/command"},
"oneOf": [
{"type": "string"},
{"type": "array", "items": {"type": "string"}}
]
},
"configs": {"$ref": "#/definitions/service_config_or_secret"}, "configs": {"$ref": "#/definitions/service_config_or_secret"},
"container_name": {"type": "string"}, "container_name": {"type": "string"},
"cpu_count": {"type": "integer", "minimum": 0}, "cpu_count": {"type": "integer", "minimum": 0},
@ -181,6 +179,7 @@
"type": "object", "type": "object",
"additionalProperties": false, "additionalProperties": false,
"properties": { "properties": {
"restart": {"type": "boolean"},
"condition": { "condition": {
"type": "string", "type": "string",
"enum": ["service_started", "service_healthy", "service_completed_successfully"] "enum": ["service_started", "service_healthy", "service_completed_successfully"]
@ -198,12 +197,7 @@
"dns_opt": {"type": "array","items": {"type": "string"}, "uniqueItems": true}, "dns_opt": {"type": "array","items": {"type": "string"}, "uniqueItems": true},
"dns_search": {"$ref": "#/definitions/string_or_list"}, "dns_search": {"$ref": "#/definitions/string_or_list"},
"domainname": {"type": "string"}, "domainname": {"type": "string"},
"entrypoint": { "entrypoint": {"$ref": "#/definitions/command"},
"oneOf": [
{"type": "string"},
{"type": "array", "items": {"type": "string"}}
]
},
"env_file": {"$ref": "#/definitions/string_or_list"}, "env_file": {"$ref": "#/definitions/string_or_list"},
"environment": {"$ref": "#/definitions/list_or_dict"}, "environment": {"$ref": "#/definitions/list_or_dict"},
@ -734,6 +728,14 @@
"patternProperties": {"^x-": {}} "patternProperties": {"^x-": {}}
}, },
"command": {
"oneOf": [
{"type": "null"},
{"type": "string"},
{"type": "array","items": {"type": "string"}}
]
},
"string_or_list": { "string_or_list": {
"oneOf": [ "oneOf": [
{"type": "string"}, {"type": "string"},

View file

@ -51,7 +51,7 @@ class Logging(YamlModel):
extra = Extra.allow extra = Extra.allow
driver: Optional[str] = None driver: Optional[str] = None
options: Optional[Dict[constr(regex=r"^.+$"), Optional[Union[str, float]]]] = None options: Optional[Dict[constr(regex=r"^.+$"), Optional[Union[str, float]]]] = None # type: ignore # noqa: F722
class Port(YamlModel): class Port(YamlModel):
@ -106,7 +106,7 @@ class Tmpfs(YamlModel):
class Config: class Config:
extra = Extra.allow extra = Extra.allow
size: Optional[Union[conint(ge=0), str]] = None size: Optional[Union[conint(ge=0), str]] = None # type: ignore
mode: Optional[float] = None mode: Optional[float] = None
@ -152,10 +152,12 @@ class RollbackConfig(YamlModel):
max_failure_ratio: Optional[float] = None max_failure_ratio: Optional[float] = None
order: Optional[Order] = None order: Optional[Order] = None
class ConfigOrder(YamlStrEnum): class ConfigOrder(YamlStrEnum):
start_first = "start-first" start_first = "start-first"
stop_first = "stop-first" stop_first = "stop-first"
class UpdateConfig(YamlModel): class UpdateConfig(YamlModel):
class Config: class Config:
extra = Extra.allow extra = Extra.allow
@ -232,7 +234,7 @@ class ConfigItem(YamlModel):
subnet: Optional[str] = None subnet: Optional[str] = None
ip_range: Optional[str] = None ip_range: Optional[str] = None
gateway: Optional[str] = None gateway: Optional[str] = None
aux_addresses: Optional[Dict[constr(regex=r"^.+$"), str]] = None aux_addresses: Optional[Dict[constr(regex=r"^.+$"), str]] = None # type: ignore # noqa: F722
class Ipam(YamlModel): class Ipam(YamlModel):
@ -241,7 +243,7 @@ class Ipam(YamlModel):
driver: Optional[str] = None driver: Optional[str] = None
config: Optional[List[ConfigItem]] = None config: Optional[List[ConfigItem]] = None
options: Optional[Dict[constr(regex=r"^.+$"), str]] = None options: Optional[Dict[constr(regex=r"^.+$"), str]] = None # type: ignore # noqa: F722
class ExternalNetwork(YamlModel): class ExternalNetwork(YamlModel):
@ -254,8 +256,10 @@ class ExternalNetwork(YamlModel):
class ExternalVolume(YamlModel): class ExternalVolume(YamlModel):
class Config: class Config:
extra = Extra.allow extra = Extra.allow
name: Optional[str] = None name: Optional[str] = None
class ExternalSecret(YamlModel): class ExternalSecret(YamlModel):
name: Optional[str] = None name: Optional[str] = None
@ -263,6 +267,7 @@ class ExternalSecret(YamlModel):
class ExternalConfig(YamlModel): class ExternalConfig(YamlModel):
name: Optional[str] = None name: Optional[str] = None
class ListOfStrings(YamlModel): class ListOfStrings(YamlModel):
class Config: class Config:
extra = Extra.allow extra = Extra.allow
@ -275,7 +280,7 @@ class ListOrDict(YamlModel):
extra = Extra.allow extra = Extra.allow
__root__: Union[ __root__: Union[
Dict[constr(regex=r".+"), Optional[Union[str, float, bool]]], List[str] Dict[constr(regex=r".+"), Optional[Union[str, float, bool]]], List[str] # type: ignore # noqa: F722
] ]
@ -393,7 +398,7 @@ class Network(YamlModel):
name: Optional[str] = None name: Optional[str] = None
driver: Optional[str] = None driver: Optional[str] = None
driver_opts: Optional[Dict[constr(regex=r"^.+$"), Union[str, float]]] = None driver_opts: Optional[Dict[constr(regex=r"^.+$"), Union[str, float]]] = None # type: ignore # noqa: F722
ipam: Optional[Ipam] = None ipam: Optional[Ipam] = None
external: Optional[ExternalNetwork] = None external: Optional[ExternalNetwork] = None
internal: Optional[bool] = None internal: Optional[bool] = None
@ -408,7 +413,7 @@ class Volume(YamlModel):
name: Optional[str] = None name: Optional[str] = None
driver: Optional[str] = None driver: Optional[str] = None
driver_opts: Optional[Dict[constr(regex=r"^.+$"), Union[str, float]]] = None driver_opts: Optional[Dict[constr(regex=r"^.+$"), Union[str, float]]] = None # type: ignore # noqa: F722
external: Optional[ExternalVolume] = None external: Optional[ExternalVolume] = None
labels: Optional[ListOrDict] = None labels: Optional[ListOrDict] = None
@ -423,7 +428,7 @@ class Secret(YamlModel):
external: Optional[ExternalSecret] = None external: Optional[ExternalSecret] = None
labels: Optional[ListOrDict] = None labels: Optional[ListOrDict] = None
driver: Optional[str] = None driver: Optional[str] = None
driver_opts: Optional[Dict[constr(regex=r"^.+$"), Union[str, float]]] = None driver_opts: Optional[Dict[constr(regex=r"^.+$"), Union[str, float]]] = None # type: ignore # noqa: F722
template_driver: Optional[str] = None template_driver: Optional[str] = None
@ -492,8 +497,8 @@ class Service(YamlModel):
command: Optional[ExternalVolume] = None command: Optional[ExternalVolume] = None
configs: Optional[ServiceConfigOrSecret] = None configs: Optional[ServiceConfigOrSecret] = None
container_name: Optional[str] = None container_name: Optional[str] = None
cpu_count: Optional[conint(ge=0)] = None cpu_count: Optional[conint(ge=0)] = None # type: ignore
cpu_percent: Optional[conint(ge=0, le=100)] = None cpu_percent: Optional[conint(ge=0, le=100)] = None # type: ignore
cpu_shares: Optional[Union[float, str]] = None cpu_shares: Optional[Union[float, str]] = None
cpu_quota: Optional[Union[float, str]] = None cpu_quota: Optional[Union[float, str]] = None
cpu_period: Optional[Union[float, str]] = None cpu_period: Optional[Union[float, str]] = None
@ -503,7 +508,7 @@ class Service(YamlModel):
cpuset: Optional[str] = None cpuset: Optional[str] = None
credential_spec: Optional[CredentialSpec] = None credential_spec: Optional[CredentialSpec] = None
depends_on: Optional[ depends_on: Optional[
Union[ListOfStrings, Dict[constr(regex=r"^[a-zA-Z0-9._-]+$"), DependsOn]] Union[ListOfStrings, Dict[constr(regex=r"^[a-zA-Z0-9._-]+$"), DependsOn]] # type: ignore # noqa: F722, E501
] = None ] = None
device_cgroup_rules: Optional[ListOfStrings] = None device_cgroup_rules: Optional[ListOfStrings] = None
devices: Optional[List[str]] = Field(None, unique_items=True) devices: Optional[List[str]] = Field(None, unique_items=True)
@ -536,11 +541,11 @@ class Service(YamlModel):
network_mode: Optional[str] = None network_mode: Optional[str] = None
networks: Optional[ networks: Optional[
Union[ Union[
ListOfStrings, Dict[constr(regex=r"^[a-zA-Z0-9._-]+$"), Optional[ServiceNetwork]] ListOfStrings, Dict[constr(regex=r"^[a-zA-Z0-9._-]+$"), Optional[ServiceNetwork]] # type: ignore # noqa: F722, E501
] ]
] = None ] = None
oom_kill_disable: Optional[bool] = None oom_kill_disable: Optional[bool] = None
oom_score_adj: Optional[conint(ge=-1000, le=1000)] = None oom_score_adj: Optional[conint(ge=-1000, le=1000)] = None # type: ignore
pid: Optional[str] = None pid: Optional[str] = None
pids_limit: Optional[Union[float, str]] = None pids_limit: Optional[Union[float, str]] = None
platform: Optional[str] = None platform: Optional[str] = None
@ -562,11 +567,11 @@ class Service(YamlModel):
storage_opt: Optional[Dict[str, Any]] = None storage_opt: Optional[Dict[str, Any]] = None
tmpfs: Optional[StringOrList] = None tmpfs: Optional[StringOrList] = None
tty: Optional[bool] = None tty: Optional[bool] = None
ulimits: Optional[Dict[constr(regex=r"^[a-z]+$"), Union[int, Ulimit]]] = None ulimits: Optional[Dict[constr(regex=r"^[a-z]+$"), Union[int, Ulimit]]] = None # type: ignore # noqa: F722
user: Optional[str] = None user: Optional[str] = None
uts: Optional[str] = None uts: Optional[str] = None
userns_mode: Optional[str] = None userns_mode: Optional[str] = None
volumes: Optional[List[Union[str, AdditionalVolumeOption]]] = Field(None, unique_items=True) volumes: Optional[List[Union[str, ServiceVolume]]] = Field(None, unique_items=True)
volumes_from: Optional[List[str]] = Field(None, unique_items=True) volumes_from: Optional[List[str]] = Field(None, unique_items=True)
working_dir: Optional[str] = None working_dir: Optional[str] = None
@ -575,17 +580,13 @@ class ComposeSpecification(YamlModel):
class Config: class Config:
extra = Extra.allow extra = Extra.allow
version: Optional[str] = Field( version: Optional[str] = Field(None, description="declared for backward compatibility, ignored.")
None, description="declared for backward compatibility, ignored." name: Optional[constr(regex=r"^[a-z0-9][a-z0-9_-]*$")] = Field( # type: ignore # noqa: F722
)
name: Optional[constr(regex=r"^[a-z0-9][a-z0-9_-]*$")] = Field(
None, None,
description="define the Compose project name, until user defines one explicitly.", description="define the Compose project name, until user defines one explicitly.",
) )
services: Optional[Dict[constr(regex=r"^[a-zA-Z0-9._-]+$"), Service]] = None services: Optional[Dict[constr(regex=r"^[a-zA-Z0-9._-]+$"), Service]] = None # type: ignore # noqa: F722
networks: Optional[ networks: Optional[Dict[constr(regex=r"^[a-zA-Z0-9._-]+$"), Optional[Network]]] = None # type: ignore # noqa: F722
Dict[constr(regex=r"^[a-zA-Z0-9._-]+$"), Optional[Network]] volumes: Optional[Dict[constr(regex=r"^[a-zA-Z0-9._-]+$"), Optional[Volume]]] = None # type: ignore # noqa: F722
] = None secrets: Optional[Dict[constr(regex=r"^[a-zA-Z0-9._-]+$"), Secret]] = None # type: ignore # noqa: F722
volumes: Optional[Dict[constr(regex=r"^[a-zA-Z0-9._-]+$"), Optional[Volume]]] = None configs: Optional[Dict[constr(regex=r"^[a-zA-Z0-9._-]+$"), Config]] = None # type: ignore # noqa: F722
secrets: Optional[Dict[constr(regex=r"^[a-zA-Z0-9._-]+$"), Secret]] = None
configs: Optional[Dict[constr(regex=r"^[a-zA-Z0-9._-]+$"), Config]] = None