Merge pull request #49 from kevinjone25/main

fix: extension-fields parse error from compose spec #48
This commit is contained in:
Xyphuz 2023-05-04 02:15:38 +08:00 committed by GitHub
commit 75d442acaa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 80 additions and 54 deletions

View file

@ -18,7 +18,7 @@ repos:
args: args:
- "--max-line-length=120" - "--max-line-length=120"
- repo: https://github.com/pycqa/isort - repo: https://github.com/pycqa/isort
rev: 5.10.1 rev: 5.12.0
hooks: hooks:
- id: isort - id: isort
- repo: https://github.com/psf/black - repo: https://github.com/psf/black

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

@ -1,6 +1,6 @@
# generated by datamodel-codegen: # generated by datamodel-codegen:
# filename: compose-spec.json # filename: compose-spec.json
# timestamp: 2023-01-10T13:17:45+00:00 # timestamp: 2023-05-03T07:42:00+00:00
from __future__ import annotations from __future__ import annotations
@ -17,7 +17,7 @@ class Cgroup(YamlStrEnum):
class CredentialSpec(YamlModel): class CredentialSpec(YamlModel):
class Config: class Config:
extra = Extra.forbid extra = Extra.allow
config: Optional[str] = None config: Optional[str] = None
file: Optional[str] = None file: Optional[str] = None
@ -32,14 +32,15 @@ class Condition(YamlStrEnum):
class DependsOn(YamlModel): class DependsOn(YamlModel):
class Config: class Config:
extra = Extra.forbid extra = Extra.allow
restart: Optional[bool] = None
condition: Condition condition: Condition
class Extend(YamlModel): class Extend(YamlModel):
class Config: class Config:
extra = Extra.forbid extra = Extra.allow
service: str service: str
file: Optional[str] = None file: Optional[str] = None
@ -47,7 +48,7 @@ class Extend(YamlModel):
class Logging(YamlModel): class Logging(YamlModel):
class Config: class Config:
extra = Extra.forbid extra = Extra.allow
driver: Optional[str] = None 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 # type: ignore # noqa: F722
@ -55,7 +56,7 @@ class Logging(YamlModel):
class Port(YamlModel): class Port(YamlModel):
class Config: class Config:
extra = Extra.forbid extra = Extra.allow
mode: Optional[str] = None mode: Optional[str] = None
host_ip: Optional[str] = None host_ip: Optional[str] = None
@ -74,7 +75,7 @@ class PullPolicy(YamlStrEnum):
class Ulimit(YamlModel): class Ulimit(YamlModel):
class Config: class Config:
extra = Extra.forbid extra = Extra.allow
hard: int hard: int
soft: int soft: int
@ -87,7 +88,7 @@ class Selinux(YamlStrEnum):
class Bind(YamlModel): class Bind(YamlModel):
class Config: class Config:
extra = Extra.forbid extra = Extra.allow
propagation: Optional[str] = None propagation: Optional[str] = None
create_host_path: Optional[bool] = None create_host_path: Optional[bool] = None
@ -96,14 +97,14 @@ class Bind(YamlModel):
class AdditionalVolumeOption(YamlModel): class AdditionalVolumeOption(YamlModel):
class Config: class Config:
extra = Extra.forbid extra = Extra.allow
nocopy: Optional[bool] = None nocopy: Optional[bool] = None
class Tmpfs(YamlModel): class Tmpfs(YamlModel):
class Config: 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 # type: ignore
mode: Optional[float] = None mode: Optional[float] = None
@ -111,7 +112,7 @@ class Tmpfs(YamlModel):
class ServiceVolume(YamlModel): class ServiceVolume(YamlModel):
class Config: class Config:
extra = Extra.forbid extra = Extra.allow
type: str type: str
source: Optional[str] = None source: Optional[str] = None
@ -125,7 +126,7 @@ class ServiceVolume(YamlModel):
class Healthcheck(YamlModel): class Healthcheck(YamlModel):
class Config: class Config:
extra = Extra.forbid extra = Extra.allow
disable: Optional[bool] = None disable: Optional[bool] = None
interval: Optional[str] = None interval: Optional[str] = None
@ -142,7 +143,7 @@ class Order(YamlStrEnum):
class RollbackConfig(YamlModel): class RollbackConfig(YamlModel):
class Config: class Config:
extra = Extra.forbid extra = Extra.allow
parallelism: Optional[int] = None parallelism: Optional[int] = None
delay: Optional[str] = None delay: Optional[str] = None
@ -159,7 +160,7 @@ class ConfigOrder(YamlStrEnum):
class UpdateConfig(YamlModel): class UpdateConfig(YamlModel):
class Config: class Config:
extra = Extra.forbid extra = Extra.allow
parallelism: Optional[int] = None parallelism: Optional[int] = None
delay: Optional[str] = None delay: Optional[str] = None
@ -171,7 +172,7 @@ class UpdateConfig(YamlModel):
class Limits(YamlModel): class Limits(YamlModel):
class Config: class Config:
extra = Extra.forbid extra = Extra.allow
cpus: Optional[Union[float, str]] = None cpus: Optional[Union[float, str]] = None
memory: Optional[str] = None memory: Optional[str] = None
@ -180,7 +181,7 @@ class Limits(YamlModel):
class RestartPolicy(YamlModel): class RestartPolicy(YamlModel):
class Config: class Config:
extra = Extra.forbid extra = Extra.allow
condition: Optional[str] = None condition: Optional[str] = None
delay: Optional[str] = None delay: Optional[str] = None
@ -190,14 +191,14 @@ class RestartPolicy(YamlModel):
class Preference(YamlModel): class Preference(YamlModel):
class Config: class Config:
extra = Extra.forbid extra = Extra.allow
spread: Optional[str] = None spread: Optional[str] = None
class Placement(YamlModel): class Placement(YamlModel):
class Config: class Config:
extra = Extra.forbid extra = Extra.allow
constraints: Optional[List[str]] = None constraints: Optional[List[str]] = None
preferences: Optional[List[Preference]] = None preferences: Optional[List[Preference]] = None
@ -206,7 +207,7 @@ class Placement(YamlModel):
class DiscreteResourceSpec(YamlModel): class DiscreteResourceSpec(YamlModel):
class Config: class Config:
extra = Extra.forbid extra = Extra.allow
kind: Optional[str] = None kind: Optional[str] = None
value: Optional[float] = None value: Optional[float] = None
@ -214,18 +215,21 @@ class DiscreteResourceSpec(YamlModel):
class GenericResource(YamlModel): class GenericResource(YamlModel):
class Config: class Config:
extra = Extra.forbid extra = Extra.allow
discrete_resource_spec: Optional[DiscreteResourceSpec] = None discrete_resource_spec: Optional[DiscreteResourceSpec] = None
class GenericResources(YamlModel): class GenericResources(YamlModel):
class Config:
extra = Extra.allow
__root__: List[GenericResource] __root__: List[GenericResource]
class ConfigItem(YamlModel): class ConfigItem(YamlModel):
class Config: class Config:
extra = Extra.forbid extra = Extra.allow
subnet: Optional[str] = None subnet: Optional[str] = None
ip_range: Optional[str] = None ip_range: Optional[str] = None
@ -235,7 +239,7 @@ class ConfigItem(YamlModel):
class Ipam(YamlModel): class Ipam(YamlModel):
class Config: class Config:
extra = Extra.forbid extra = Extra.allow
driver: Optional[str] = None driver: Optional[str] = None
config: Optional[List[ConfigItem]] = None config: Optional[List[ConfigItem]] = None
@ -244,14 +248,14 @@ class Ipam(YamlModel):
class ExternalNetwork(YamlModel): class ExternalNetwork(YamlModel):
class Config: class Config:
extra = Extra.forbid extra = Extra.allow
name: Optional[str] = None name: Optional[str] = None
class ExternalVolume(YamlModel): class ExternalVolume(YamlModel):
class Config: class Config:
extra = Extra.forbid extra = Extra.allow
name: Optional[str] = None name: Optional[str] = None
@ -265,10 +269,16 @@ class ExternalConfig(YamlModel):
class ListOfStrings(YamlModel): class ListOfStrings(YamlModel):
class Config:
extra = Extra.allow
__root__: List[str] = Field(..., unique_items=True) __root__: List[str] = Field(..., unique_items=True)
class ListOrDict(YamlModel): class ListOrDict(YamlModel):
class Config:
extra = Extra.allow
__root__: Union[ __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] # type: ignore # noqa: F722
] ]
@ -276,7 +286,7 @@ class ListOrDict(YamlModel):
class BlkioLimit(YamlModel): class BlkioLimit(YamlModel):
class Config: class Config:
extra = Extra.forbid extra = Extra.allow
path: Optional[str] = None path: Optional[str] = None
rate: Optional[Union[int, str]] = None rate: Optional[Union[int, str]] = None
@ -284,7 +294,7 @@ class BlkioLimit(YamlModel):
class BlkioWeight(YamlModel): class BlkioWeight(YamlModel):
class Config: class Config:
extra = Extra.forbid extra = Extra.allow
path: Optional[str] = None path: Optional[str] = None
weight: Optional[int] = None weight: Optional[int] = None
@ -292,7 +302,7 @@ class BlkioWeight(YamlModel):
class ServiceConfigOrSecretItem(YamlModel): class ServiceConfigOrSecretItem(YamlModel):
class Config: class Config:
extra = Extra.forbid extra = Extra.allow
source: Optional[str] = None source: Optional[str] = None
target: Optional[str] = None target: Optional[str] = None
@ -302,25 +312,33 @@ class ServiceConfigOrSecretItem(YamlModel):
class ServiceConfigOrSecret(YamlModel): class ServiceConfigOrSecret(YamlModel):
class Config:
extra = Extra.allow
__root__: List[Union[str, ServiceConfigOrSecretItem]] __root__: List[Union[str, ServiceConfigOrSecretItem]]
class Constraints(YamlModel): class Constraints(YamlModel):
class Config:
extra = Extra.allow
__root__: Any __root__: Any
class BuildItem(YamlModel): class BuildItem(YamlModel):
class Config: class Config:
extra = Extra.forbid extra = Extra.allow
context: Optional[str] = None context: Optional[str] = None
dockerfile: Optional[str] = None dockerfile: Optional[str] = None
dockerfile_inline: Optional[str] = None
args: Optional[ListOrDict] = None args: Optional[ListOrDict] = None
ssh: Optional[ListOrDict] = None ssh: Optional[ListOrDict] = None
labels: Optional[ListOrDict] = None labels: Optional[ListOrDict] = None
cache_from: Optional[List[str]] = None cache_from: Optional[List[str]] = None
cache_to: Optional[List[str]] = None cache_to: Optional[List[str]] = None
no_cache: Optional[bool] = None no_cache: Optional[bool] = None
additional_contexts: Optional[ListOrDict] = None
network: Optional[str] = None network: Optional[str] = None
pull: Optional[bool] = None pull: Optional[bool] = None
target: Optional[str] = None target: Optional[str] = None
@ -335,7 +353,7 @@ class BuildItem(YamlModel):
class BlkioConfig(YamlModel): class BlkioConfig(YamlModel):
class Config: class Config:
extra = Extra.forbid extra = Extra.allow
device_read_bps: Optional[List[BlkioLimit]] = None device_read_bps: Optional[List[BlkioLimit]] = None
device_read_iops: Optional[List[BlkioLimit]] = None device_read_iops: Optional[List[BlkioLimit]] = None
@ -347,7 +365,7 @@ class BlkioConfig(YamlModel):
class ServiceNetwork(YamlModel): class ServiceNetwork(YamlModel):
class Config: class Config:
extra = Extra.forbid extra = Extra.allow
aliases: Optional[ListOfStrings] = None aliases: Optional[ListOfStrings] = None
ipv4_address: Optional[str] = None ipv4_address: Optional[str] = None
@ -358,7 +376,7 @@ class ServiceNetwork(YamlModel):
class Device(YamlModel): class Device(YamlModel):
class Config: class Config:
extra = Extra.forbid extra = Extra.allow
capabilities: Optional[ListOfStrings] = None capabilities: Optional[ListOfStrings] = None
count: Optional[Union[str, int]] = None count: Optional[Union[str, int]] = None
@ -368,12 +386,15 @@ class Device(YamlModel):
class Devices(YamlModel): class Devices(YamlModel):
class Config:
extra = Extra.allow
__root__: List[Device] __root__: List[Device]
class Network(YamlModel): class Network(YamlModel):
class Config: class Config:
extra = Extra.forbid extra = Extra.allow
name: Optional[str] = None name: Optional[str] = None
driver: Optional[str] = None driver: Optional[str] = None
@ -388,7 +409,7 @@ class Network(YamlModel):
class Volume(YamlModel): class Volume(YamlModel):
class Config: class Config:
extra = Extra.forbid extra = Extra.allow
name: Optional[str] = None name: Optional[str] = None
driver: Optional[str] = None driver: Optional[str] = None
@ -399,7 +420,7 @@ class Volume(YamlModel):
class Secret(YamlModel): class Secret(YamlModel):
class Config: class Config:
extra = Extra.forbid extra = Extra.allow
name: Optional[str] = None name: Optional[str] = None
environment: Optional[str] = None environment: Optional[str] = None
@ -413,7 +434,7 @@ class Secret(YamlModel):
class Config(YamlModel): class Config(YamlModel):
class Config: class Config:
extra = Extra.forbid extra = Extra.allow
name: Optional[str] = None name: Optional[str] = None
file: Optional[str] = None file: Optional[str] = None
@ -423,12 +444,15 @@ class Config(YamlModel):
class StringOrList(YamlModel): class StringOrList(YamlModel):
class Config:
extra = Extra.allow
__root__: Union[str, ListOfStrings] __root__: Union[str, ListOfStrings]
class Reservations(YamlModel): class Reservations(YamlModel):
class Config: class Config:
extra = Extra.forbid extra = Extra.allow
cpus: Optional[Union[float, str]] = None cpus: Optional[Union[float, str]] = None
memory: Optional[str] = None memory: Optional[str] = None
@ -438,7 +462,7 @@ class Reservations(YamlModel):
class Resources(YamlModel): class Resources(YamlModel):
class Config: class Config:
extra = Extra.forbid extra = Extra.allow
limits: Optional[Limits] = None limits: Optional[Limits] = None
reservations: Optional[Reservations] = None reservations: Optional[Reservations] = None
@ -446,7 +470,7 @@ class Resources(YamlModel):
class Deployment(YamlModel): class Deployment(YamlModel):
class Config: class Config:
extra = Extra.forbid extra = Extra.allow
mode: Optional[str] = None mode: Optional[str] = None
endpoint_mode: Optional[str] = None endpoint_mode: Optional[str] = None
@ -461,7 +485,7 @@ class Deployment(YamlModel):
class Service(YamlModel): class Service(YamlModel):
class Config: class Config:
extra = Extra.forbid extra = Extra.allow
deploy: Optional[Deployment] = None deploy: Optional[Deployment] = None
build: Optional[Union[str, BuildItem]] = None build: Optional[Union[str, BuildItem]] = None
@ -554,10 +578,10 @@ class Service(YamlModel):
class ComposeSpecification(YamlModel): class ComposeSpecification(YamlModel):
class Config: class Config:
extra = Extra.forbid extra = Extra.allow
version: Optional[str] = Field(None, description="declared for backward compatibility, ignored.") version: Optional[str] = Field(None, description="declared for backward compatibility, ignored.")
name: Optional[str] = Field( name: Optional[constr(regex=r"^[a-z0-9][a-z0-9_-]*$")] = Field( # type: ignore # noqa: F722
None, None,
description="define the Compose project name, until user defines one explicitly.", description="define the Compose project name, until user defines one explicitly.",
) )