From e90223735603ada35660c3a074fae4d556828f04 Mon Sep 17 00:00:00 2001 From: Zheng Zhi Yuan Date: Wed, 3 May 2023 16:50:39 +0800 Subject: [PATCH 1/4] fix: extension-fields parse error from compose spec #48 --- compose_viz/spec/compose_spec.py | 163 ++++++++++++++++++------------- 1 file changed, 93 insertions(+), 70 deletions(-) diff --git a/compose_viz/spec/compose_spec.py b/compose_viz/spec/compose_spec.py index d1e466e..33bc835 100644 --- a/compose_viz/spec/compose_spec.py +++ b/compose_viz/spec/compose_spec.py @@ -1,6 +1,6 @@ # generated by datamodel-codegen: # filename: compose-spec.json -# timestamp: 2023-01-10T13:17:45+00:00 +# timestamp: 2023-05-03T07:42:00+00:00 from __future__ import annotations @@ -17,7 +17,7 @@ class Cgroup(YamlStrEnum): class CredentialSpec(YamlModel): class Config: - extra = Extra.forbid + extra = Extra.allow config: Optional[str] = None file: Optional[str] = None @@ -32,14 +32,15 @@ class Condition(YamlStrEnum): class DependsOn(YamlModel): class Config: - extra = Extra.forbid + extra = Extra.allow + restart: Optional[bool] = None condition: Condition class Extend(YamlModel): class Config: - extra = Extra.forbid + extra = Extra.allow service: str file: Optional[str] = None @@ -47,15 +48,15 @@ class Extend(YamlModel): class Logging(YamlModel): class Config: - extra = Extra.forbid + extra = Extra.allow driver: Optional[str] = None - options: Optional[Dict[constr(regex=r"^.+$"), Optional[Union[str, float]]]] = None # type: ignore # noqa: F722 + options: Optional[Dict[constr(regex=r"^.+$"), Optional[Union[str, float]]]] = None class Port(YamlModel): class Config: - extra = Extra.forbid + extra = Extra.allow mode: Optional[str] = None host_ip: Optional[str] = None @@ -74,7 +75,7 @@ class PullPolicy(YamlStrEnum): class Ulimit(YamlModel): class Config: - extra = Extra.forbid + extra = Extra.allow hard: int soft: int @@ -87,7 +88,7 @@ class Selinux(YamlStrEnum): class Bind(YamlModel): class Config: - extra = Extra.forbid + extra = Extra.allow propagation: Optional[str] = None create_host_path: Optional[bool] = None @@ -96,22 +97,22 @@ class Bind(YamlModel): class AdditionalVolumeOption(YamlModel): class Config: - extra = Extra.forbid + extra = Extra.allow nocopy: Optional[bool] = None class Tmpfs(YamlModel): class Config: - extra = Extra.forbid + extra = Extra.allow - size: Optional[Union[conint(ge=0), str]] = None # type: ignore + size: Optional[Union[conint(ge=0), str]] = None mode: Optional[float] = None class ServiceVolume(YamlModel): class Config: - extra = Extra.forbid + extra = Extra.allow type: str source: Optional[str] = None @@ -125,7 +126,7 @@ class ServiceVolume(YamlModel): class Healthcheck(YamlModel): class Config: - extra = Extra.forbid + extra = Extra.allow disable: Optional[bool] = None interval: Optional[str] = None @@ -142,7 +143,7 @@ class Order(YamlStrEnum): class RollbackConfig(YamlModel): class Config: - extra = Extra.forbid + extra = Extra.allow parallelism: Optional[int] = None delay: Optional[str] = None @@ -151,15 +152,13 @@ class RollbackConfig(YamlModel): max_failure_ratio: Optional[float] = None order: Optional[Order] = None - class ConfigOrder(YamlStrEnum): start_first = "start-first" stop_first = "stop-first" - class UpdateConfig(YamlModel): class Config: - extra = Extra.forbid + extra = Extra.allow parallelism: Optional[int] = None delay: Optional[str] = None @@ -171,7 +170,7 @@ class UpdateConfig(YamlModel): class Limits(YamlModel): class Config: - extra = Extra.forbid + extra = Extra.allow cpus: Optional[Union[float, str]] = None memory: Optional[str] = None @@ -180,7 +179,7 @@ class Limits(YamlModel): class RestartPolicy(YamlModel): class Config: - extra = Extra.forbid + extra = Extra.allow condition: Optional[str] = None delay: Optional[str] = None @@ -190,14 +189,14 @@ class RestartPolicy(YamlModel): class Preference(YamlModel): class Config: - extra = Extra.forbid + extra = Extra.allow spread: Optional[str] = None class Placement(YamlModel): class Config: - extra = Extra.forbid + extra = Extra.allow constraints: Optional[List[str]] = None preferences: Optional[List[Preference]] = None @@ -206,7 +205,7 @@ class Placement(YamlModel): class DiscreteResourceSpec(YamlModel): class Config: - extra = Extra.forbid + extra = Extra.allow kind: Optional[str] = None value: Optional[float] = None @@ -214,48 +213,49 @@ class DiscreteResourceSpec(YamlModel): class GenericResource(YamlModel): class Config: - extra = Extra.forbid + extra = Extra.allow discrete_resource_spec: Optional[DiscreteResourceSpec] = None class GenericResources(YamlModel): + class Config: + extra = Extra.allow + __root__: List[GenericResource] class ConfigItem(YamlModel): class Config: - extra = Extra.forbid + extra = Extra.allow subnet: Optional[str] = None ip_range: Optional[str] = None gateway: Optional[str] = None - aux_addresses: Optional[Dict[constr(regex=r"^.+$"), str]] = None # type: ignore # noqa: F722 + aux_addresses: Optional[Dict[constr(regex=r"^.+$"), str]] = None class Ipam(YamlModel): class Config: - extra = Extra.forbid + extra = Extra.allow driver: Optional[str] = None config: Optional[List[ConfigItem]] = None - options: Optional[Dict[constr(regex=r"^.+$"), str]] = None # type: ignore # noqa: F722 + options: Optional[Dict[constr(regex=r"^.+$"), str]] = None class ExternalNetwork(YamlModel): class Config: - extra = Extra.forbid + extra = Extra.allow name: Optional[str] = None class ExternalVolume(YamlModel): class Config: - extra = Extra.forbid - + extra = Extra.allow name: Optional[str] = None - class ExternalSecret(YamlModel): name: Optional[str] = None @@ -263,20 +263,25 @@ class ExternalSecret(YamlModel): class ExternalConfig(YamlModel): name: Optional[str] = None - class ListOfStrings(YamlModel): + class Config: + extra = Extra.allow + __root__: List[str] = Field(..., unique_items=True) class ListOrDict(YamlModel): + class Config: + extra = Extra.allow + __root__: Union[ - Dict[constr(regex=r".+"), Optional[Union[str, float, bool]]], List[str] # type: ignore # noqa: F722 + Dict[constr(regex=r".+"), Optional[Union[str, float, bool]]], List[str] ] class BlkioLimit(YamlModel): class Config: - extra = Extra.forbid + extra = Extra.allow path: Optional[str] = None rate: Optional[Union[int, str]] = None @@ -284,7 +289,7 @@ class BlkioLimit(YamlModel): class BlkioWeight(YamlModel): class Config: - extra = Extra.forbid + extra = Extra.allow path: Optional[str] = None weight: Optional[int] = None @@ -292,7 +297,7 @@ class BlkioWeight(YamlModel): class ServiceConfigOrSecretItem(YamlModel): class Config: - extra = Extra.forbid + extra = Extra.allow source: Optional[str] = None target: Optional[str] = None @@ -302,25 +307,33 @@ class ServiceConfigOrSecretItem(YamlModel): class ServiceConfigOrSecret(YamlModel): + class Config: + extra = Extra.allow + __root__: List[Union[str, ServiceConfigOrSecretItem]] class Constraints(YamlModel): + class Config: + extra = Extra.allow + __root__: Any class BuildItem(YamlModel): class Config: - extra = Extra.forbid + extra = Extra.allow context: Optional[str] = None dockerfile: Optional[str] = None + dockerfile_inline: Optional[str] = None args: Optional[ListOrDict] = None ssh: Optional[ListOrDict] = None labels: Optional[ListOrDict] = None cache_from: Optional[List[str]] = None cache_to: Optional[List[str]] = None no_cache: Optional[bool] = None + additional_contexts: Optional[ListOrDict] = None network: Optional[str] = None pull: Optional[bool] = None target: Optional[str] = None @@ -335,7 +348,7 @@ class BuildItem(YamlModel): class BlkioConfig(YamlModel): class Config: - extra = Extra.forbid + extra = Extra.allow device_read_bps: Optional[List[BlkioLimit]] = None device_read_iops: Optional[List[BlkioLimit]] = None @@ -347,7 +360,7 @@ class BlkioConfig(YamlModel): class ServiceNetwork(YamlModel): class Config: - extra = Extra.forbid + extra = Extra.allow aliases: Optional[ListOfStrings] = None ipv4_address: Optional[str] = None @@ -358,7 +371,7 @@ class ServiceNetwork(YamlModel): class Device(YamlModel): class Config: - extra = Extra.forbid + extra = Extra.allow capabilities: Optional[ListOfStrings] = None count: Optional[Union[str, int]] = None @@ -368,18 +381,21 @@ class Device(YamlModel): class Devices(YamlModel): + class Config: + extra = Extra.allow + __root__: List[Device] class Network(YamlModel): class Config: - extra = Extra.forbid + extra = Extra.allow name: Optional[str] = None driver: Optional[str] = None - driver_opts: Optional[Dict[constr(regex=r"^.+$"), Union[str, float]]] = None # type: ignore # noqa: F722 + driver_opts: Optional[Dict[constr(regex=r"^.+$"), Union[str, float]]] = None ipam: Optional[Ipam] = None - external: Optional[bool | ExternalNetwork] = None + external: Optional[ExternalNetwork] = None internal: Optional[bool] = None enable_ipv6: Optional[bool] = None attachable: Optional[bool] = None @@ -388,18 +404,18 @@ class Network(YamlModel): class Volume(YamlModel): class Config: - extra = Extra.forbid + extra = Extra.allow name: Optional[str] = None driver: Optional[str] = None - driver_opts: Optional[Dict[constr(regex=r"^.+$"), Union[str, float]]] = None # type: ignore # noqa: F722 + driver_opts: Optional[Dict[constr(regex=r"^.+$"), Union[str, float]]] = None external: Optional[ExternalVolume] = None labels: Optional[ListOrDict] = None class Secret(YamlModel): class Config: - extra = Extra.forbid + extra = Extra.allow name: Optional[str] = None environment: Optional[str] = None @@ -407,13 +423,13 @@ class Secret(YamlModel): external: Optional[ExternalSecret] = None labels: Optional[ListOrDict] = None driver: Optional[str] = None - driver_opts: Optional[Dict[constr(regex=r"^.+$"), Union[str, float]]] = None # type: ignore # noqa: F722 + driver_opts: Optional[Dict[constr(regex=r"^.+$"), Union[str, float]]] = None template_driver: Optional[str] = None class Config(YamlModel): class Config: - extra = Extra.forbid + extra = Extra.allow name: Optional[str] = None file: Optional[str] = None @@ -423,12 +439,15 @@ class Config(YamlModel): class StringOrList(YamlModel): + class Config: + extra = Extra.allow + __root__: Union[str, ListOfStrings] class Reservations(YamlModel): class Config: - extra = Extra.forbid + extra = Extra.allow cpus: Optional[Union[float, str]] = None memory: Optional[str] = None @@ -438,7 +457,7 @@ class Reservations(YamlModel): class Resources(YamlModel): class Config: - extra = Extra.forbid + extra = Extra.allow limits: Optional[Limits] = None reservations: Optional[Reservations] = None @@ -446,7 +465,7 @@ class Resources(YamlModel): class Deployment(YamlModel): class Config: - extra = Extra.forbid + extra = Extra.allow mode: Optional[str] = None endpoint_mode: Optional[str] = None @@ -461,7 +480,7 @@ class Deployment(YamlModel): class Service(YamlModel): class Config: - extra = Extra.forbid + extra = Extra.allow deploy: Optional[Deployment] = None build: Optional[Union[str, BuildItem]] = None @@ -470,11 +489,11 @@ class Service(YamlModel): cap_drop: Optional[List[str]] = Field(None, unique_items=True) cgroup: Optional[Cgroup] = None cgroup_parent: Optional[str] = None - command: Optional[Union[str, List[str]]] = None + command: Optional[ExternalVolume] = None configs: Optional[ServiceConfigOrSecret] = None container_name: Optional[str] = None - cpu_count: Optional[conint(ge=0)] = None # type: ignore - cpu_percent: Optional[conint(ge=0, le=100)] = None # type: ignore + cpu_count: Optional[conint(ge=0)] = None + cpu_percent: Optional[conint(ge=0, le=100)] = None cpu_shares: Optional[Union[float, str]] = None cpu_quota: Optional[Union[float, str]] = None cpu_period: Optional[Union[float, str]] = None @@ -484,7 +503,7 @@ class Service(YamlModel): cpuset: Optional[str] = None credential_spec: Optional[CredentialSpec] = None depends_on: Optional[ - Union[ListOfStrings, Dict[constr(regex=r"^[a-zA-Z0-9._-]+$"), DependsOn]] # type: ignore # noqa: F722, E501 + Union[ListOfStrings, Dict[constr(regex=r"^[a-zA-Z0-9._-]+$"), DependsOn]] ] = None device_cgroup_rules: Optional[ListOfStrings] = None devices: Optional[List[str]] = Field(None, unique_items=True) @@ -492,7 +511,7 @@ class Service(YamlModel): dns_opt: Optional[List[str]] = Field(None, unique_items=True) dns_search: Optional[StringOrList] = None domainname: Optional[str] = None - entrypoint: Optional[Union[str, List[str]]] = None + entrypoint: Optional[ExternalVolume] = None env_file: Optional[StringOrList] = None environment: Optional[ListOrDict] = None expose: Optional[List[Union[str, float]]] = Field(None, unique_items=True) @@ -517,11 +536,11 @@ class Service(YamlModel): network_mode: Optional[str] = None networks: Optional[ Union[ - ListOfStrings, Dict[constr(regex=r"^[a-zA-Z0-9._-]+$"), Optional[ServiceNetwork]] # type: ignore # noqa: F722, E501 + ListOfStrings, Dict[constr(regex=r"^[a-zA-Z0-9._-]+$"), Optional[ServiceNetwork]] ] ] = None oom_kill_disable: Optional[bool] = None - oom_score_adj: Optional[conint(ge=-1000, le=1000)] = None # type: ignore + oom_score_adj: Optional[conint(ge=-1000, le=1000)] = None pid: Optional[str] = None pids_limit: Optional[Union[float, str]] = None platform: Optional[str] = None @@ -543,26 +562,30 @@ class Service(YamlModel): storage_opt: Optional[Dict[str, Any]] = None tmpfs: Optional[StringOrList] = None tty: Optional[bool] = None - ulimits: Optional[Dict[constr(regex=r"^[a-z]+$"), Union[int, Ulimit]]] = None # type: ignore # noqa: F722 + ulimits: Optional[Dict[constr(regex=r"^[a-z]+$"), Union[int, Ulimit]]] = None user: Optional[str] = None uts: Optional[str] = None userns_mode: Optional[str] = None - volumes: Optional[List[Union[str, ServiceVolume]]] = Field(None, unique_items=True) + volumes: Optional[List[Union[str, AdditionalVolumeOption]]] = Field(None, unique_items=True) volumes_from: Optional[List[str]] = Field(None, unique_items=True) working_dir: Optional[str] = None class ComposeSpecification(YamlModel): class Config: - extra = Extra.forbid + extra = Extra.allow - version: Optional[str] = Field(None, description="declared for backward compatibility, ignored.") - name: Optional[str] = Field( + version: Optional[str] = Field( + None, description="declared for backward compatibility, ignored." + ) + name: Optional[constr(regex=r"^[a-z0-9][a-z0-9_-]*$")] = Field( None, description="define the Compose project name, until user defines one explicitly.", ) - services: Optional[Dict[constr(regex=r"^[a-zA-Z0-9._-]+$"), Service]] = None # type: ignore # noqa: F722 - networks: Optional[Dict[constr(regex=r"^[a-zA-Z0-9._-]+$"), Optional[Network]]] = None # type: ignore # noqa: F722 - volumes: Optional[Dict[constr(regex=r"^[a-zA-Z0-9._-]+$"), Optional[Volume]]] = None # type: ignore # noqa: F722 - secrets: Optional[Dict[constr(regex=r"^[a-zA-Z0-9._-]+$"), Secret]] = None # type: ignore # noqa: F722 - configs: Optional[Dict[constr(regex=r"^[a-zA-Z0-9._-]+$"), Config]] = None # type: ignore # noqa: F722 + services: Optional[Dict[constr(regex=r"^[a-zA-Z0-9._-]+$"), Service]] = None + networks: Optional[ + Dict[constr(regex=r"^[a-zA-Z0-9._-]+$"), Optional[Network]] + ] = None + volumes: Optional[Dict[constr(regex=r"^[a-zA-Z0-9._-]+$"), Optional[Volume]]] = None + secrets: Optional[Dict[constr(regex=r"^[a-zA-Z0-9._-]+$"), Secret]] = None + configs: Optional[Dict[constr(regex=r"^[a-zA-Z0-9._-]+$"), Config]] = None From e649eac53933c89da869a347099570ff60367392 Mon Sep 17 00:00:00 2001 From: Zheng Zhi Yuan Date: Thu, 4 May 2023 00:00:19 +0800 Subject: [PATCH 2/4] fix: extension-fields parse error from compose spec #48 --- compose_viz/spec/compose-spec.json | 26 ++++++++------- compose_viz/spec/compose_spec.py | 53 +++++++++++++++--------------- 2 files changed, 41 insertions(+), 38 deletions(-) diff --git a/compose_viz/spec/compose-spec.json b/compose_viz/spec/compose-spec.json index 6f82797..c587125 100644 --- a/compose_viz/spec/compose-spec.json +++ b/compose_viz/spec/compose-spec.json @@ -13,6 +13,7 @@ "name": { "type": "string", + "pattern": "^[a-z0-9][a-z0-9_-]*$", "description": "define the Compose project name, until user defines one explicitly." }, @@ -90,12 +91,14 @@ "properties": { "context": {"type": "string"}, "dockerfile": {"type": "string"}, + "dockerfile_inline": {"type": "string"}, "args": {"$ref": "#/definitions/list_or_dict"}, "ssh": {"$ref": "#/definitions/list_or_dict"}, "labels": {"$ref": "#/definitions/list_or_dict"}, "cache_from": {"type": "array", "items": {"type": "string"}}, "cache_to": {"type": "array", "items": {"type": "string"}}, "no_cache": {"type": "boolean"}, + "additional_contexts": {"$ref": "#/definitions/list_or_dict"}, "network": {"type": "string"}, "pull": {"type": "boolean"}, "target": {"type": "string"}, @@ -143,12 +146,7 @@ "cap_drop": {"type": "array", "items": {"type": "string"}, "uniqueItems": true}, "cgroup": {"type": "string", "enum": ["host", "private"]}, "cgroup_parent": {"type": "string"}, - "command": { - "oneOf": [ - {"type": "string"}, - {"type": "array", "items": {"type": "string"}} - ] - }, + "command": {"$ref": "#/definitions/command"}, "configs": {"$ref": "#/definitions/service_config_or_secret"}, "container_name": {"type": "string"}, "cpu_count": {"type": "integer", "minimum": 0}, @@ -181,6 +179,7 @@ "type": "object", "additionalProperties": false, "properties": { + "restart": {"type": "boolean"}, "condition": { "type": "string", "enum": ["service_started", "service_healthy", "service_completed_successfully"] @@ -198,12 +197,7 @@ "dns_opt": {"type": "array","items": {"type": "string"}, "uniqueItems": true}, "dns_search": {"$ref": "#/definitions/string_or_list"}, "domainname": {"type": "string"}, - "entrypoint": { - "oneOf": [ - {"type": "string"}, - {"type": "array", "items": {"type": "string"}} - ] - }, + "entrypoint": {"$ref": "#/definitions/command"}, "env_file": {"$ref": "#/definitions/string_or_list"}, "environment": {"$ref": "#/definitions/list_or_dict"}, @@ -734,6 +728,14 @@ "patternProperties": {"^x-": {}} }, + "command": { + "oneOf": [ + {"type": "null"}, + {"type": "string"}, + {"type": "array","items": {"type": "string"}} + ] + }, + "string_or_list": { "oneOf": [ {"type": "string"}, diff --git a/compose_viz/spec/compose_spec.py b/compose_viz/spec/compose_spec.py index 33bc835..f4fe528 100644 --- a/compose_viz/spec/compose_spec.py +++ b/compose_viz/spec/compose_spec.py @@ -51,7 +51,7 @@ class Logging(YamlModel): extra = Extra.allow 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): @@ -106,7 +106,7 @@ class Tmpfs(YamlModel): class Config: 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 @@ -152,10 +152,12 @@ class RollbackConfig(YamlModel): max_failure_ratio: Optional[float] = None order: Optional[Order] = None + class ConfigOrder(YamlStrEnum): start_first = "start-first" stop_first = "stop-first" + class UpdateConfig(YamlModel): class Config: extra = Extra.allow @@ -232,7 +234,7 @@ class ConfigItem(YamlModel): subnet: Optional[str] = None ip_range: 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): @@ -241,7 +243,7 @@ class Ipam(YamlModel): driver: Optional[str] = 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): @@ -254,8 +256,10 @@ class ExternalNetwork(YamlModel): class ExternalVolume(YamlModel): class Config: extra = Extra.allow + name: Optional[str] = None + class ExternalSecret(YamlModel): name: Optional[str] = None @@ -263,6 +267,7 @@ class ExternalSecret(YamlModel): class ExternalConfig(YamlModel): name: Optional[str] = None + class ListOfStrings(YamlModel): class Config: extra = Extra.allow @@ -275,7 +280,7 @@ class ListOrDict(YamlModel): extra = Extra.allow __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 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 external: Optional[ExternalNetwork] = None internal: Optional[bool] = None @@ -408,7 +413,7 @@ class Volume(YamlModel): name: 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 labels: Optional[ListOrDict] = None @@ -423,7 +428,7 @@ class Secret(YamlModel): external: Optional[ExternalSecret] = None labels: Optional[ListOrDict] = 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 @@ -492,8 +497,8 @@ class Service(YamlModel): command: Optional[ExternalVolume] = None configs: Optional[ServiceConfigOrSecret] = None container_name: Optional[str] = None - cpu_count: Optional[conint(ge=0)] = None - cpu_percent: Optional[conint(ge=0, le=100)] = None + cpu_count: Optional[conint(ge=0)] = None # type: ignore + cpu_percent: Optional[conint(ge=0, le=100)] = None # type: ignore cpu_shares: Optional[Union[float, str]] = None cpu_quota: Optional[Union[float, str]] = None cpu_period: Optional[Union[float, str]] = None @@ -503,7 +508,7 @@ class Service(YamlModel): cpuset: Optional[str] = None credential_spec: Optional[CredentialSpec] = None 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 device_cgroup_rules: Optional[ListOfStrings] = None devices: Optional[List[str]] = Field(None, unique_items=True) @@ -536,11 +541,11 @@ class Service(YamlModel): network_mode: Optional[str] = None networks: Optional[ 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 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 pids_limit: Optional[Union[float, str]] = None platform: Optional[str] = None @@ -562,11 +567,11 @@ class Service(YamlModel): storage_opt: Optional[Dict[str, Any]] = None tmpfs: Optional[StringOrList] = 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 uts: 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) working_dir: Optional[str] = None @@ -575,17 +580,13 @@ class ComposeSpecification(YamlModel): class Config: extra = Extra.allow - version: Optional[str] = Field( - None, description="declared for backward compatibility, ignored." - ) - name: Optional[constr(regex=r"^[a-z0-9][a-z0-9_-]*$")] = Field( + version: Optional[str] = Field(None, description="declared for backward compatibility, ignored.") + name: Optional[constr(regex=r"^[a-z0-9][a-z0-9_-]*$")] = Field( # type: ignore # noqa: F722 None, description="define the Compose project name, until user defines one explicitly.", ) - services: Optional[Dict[constr(regex=r"^[a-zA-Z0-9._-]+$"), Service]] = None - networks: Optional[ - Dict[constr(regex=r"^[a-zA-Z0-9._-]+$"), Optional[Network]] - ] = None - volumes: Optional[Dict[constr(regex=r"^[a-zA-Z0-9._-]+$"), Optional[Volume]]] = None - secrets: Optional[Dict[constr(regex=r"^[a-zA-Z0-9._-]+$"), Secret]] = None - configs: Optional[Dict[constr(regex=r"^[a-zA-Z0-9._-]+$"), Config]] = None + services: Optional[Dict[constr(regex=r"^[a-zA-Z0-9._-]+$"), Service]] = None # type: ignore # noqa: F722 + networks: Optional[Dict[constr(regex=r"^[a-zA-Z0-9._-]+$"), Optional[Network]]] = None # type: ignore # noqa: F722 + volumes: Optional[Dict[constr(regex=r"^[a-zA-Z0-9._-]+$"), Optional[Volume]]] = None # type: ignore # noqa: F722 + secrets: Optional[Dict[constr(regex=r"^[a-zA-Z0-9._-]+$"), Secret]] = None # type: ignore # noqa: F722 + configs: Optional[Dict[constr(regex=r"^[a-zA-Z0-9._-]+$"), Config]] = None # type: ignore # noqa: F722 From 567961bd619c424fad2ca8ff99dee1eb125b3db5 Mon Sep 17 00:00:00 2001 From: Zheng Zhi Yuan Date: Thu, 4 May 2023 01:22:57 +0800 Subject: [PATCH 3/4] build: upgrade isort version to 5.12.0 --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 9b26d29..e5b88bf 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -18,7 +18,7 @@ repos: args: - "--max-line-length=120" - repo: https://github.com/pycqa/isort - rev: 5.10.1 + rev: 5.12.0 hooks: - id: isort - repo: https://github.com/psf/black From 78a7654339e4dc6eb7fbc288e77c8cc799e9044e Mon Sep 17 00:00:00 2001 From: Zheng Zhi Yuan Date: Thu, 4 May 2023 02:11:59 +0800 Subject: [PATCH 4/4] fix: extension-fields parse error from compose spec #48 --- compose_viz/spec/compose_spec.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/compose_viz/spec/compose_spec.py b/compose_viz/spec/compose_spec.py index f4fe528..a02282a 100644 --- a/compose_viz/spec/compose_spec.py +++ b/compose_viz/spec/compose_spec.py @@ -400,7 +400,7 @@ class Network(YamlModel): driver: Optional[str] = None driver_opts: Optional[Dict[constr(regex=r"^.+$"), Union[str, float]]] = None # type: ignore # noqa: F722 ipam: Optional[Ipam] = None - external: Optional[ExternalNetwork] = None + external: Optional[bool | ExternalNetwork] = None internal: Optional[bool] = None enable_ipv6: Optional[bool] = None attachable: Optional[bool] = None @@ -494,7 +494,7 @@ class Service(YamlModel): cap_drop: Optional[List[str]] = Field(None, unique_items=True) cgroup: Optional[Cgroup] = None cgroup_parent: Optional[str] = None - command: Optional[ExternalVolume] = None + command: Optional[Union[str, List[str]]] = None configs: Optional[ServiceConfigOrSecret] = None container_name: Optional[str] = None cpu_count: Optional[conint(ge=0)] = None # type: ignore @@ -516,7 +516,7 @@ class Service(YamlModel): dns_opt: Optional[List[str]] = Field(None, unique_items=True) dns_search: Optional[StringOrList] = None domainname: Optional[str] = None - entrypoint: Optional[ExternalVolume] = None + entrypoint: Optional[Union[str, List[str]]] = None env_file: Optional[StringOrList] = None environment: Optional[ListOrDict] = None expose: Optional[List[Union[str, float]]] = Field(None, unique_items=True)