This commit is contained in:
2026-05-28 14:26:02 +07:00
parent b0443d5950
commit 991d6f5257
13 changed files with 464 additions and 22 deletions

View File

@@ -6,9 +6,17 @@ from pydantic import BaseModel, ConfigDict, Field, field_validator, model_valida
from app.utils.validators import (
validate_app_id,
validate_container_name,
validate_docker_digest,
validate_docker_image,
validate_docker_tag,
validate_env_name,
validate_package_name,
validate_port_mapping,
validate_restart_policy,
validate_service_name,
validate_sha256,
validate_volume_mapping,
validate_version,
)
@@ -168,6 +176,69 @@ class DebComponent(CamelModel):
return validate_service_name(value)
class DockerComponent(CamelModel):
component_id: str = Field(alias="componentId")
type: Literal["docker"] = "docker"
install_order: int = Field(default=10, alias="installOrder")
required: bool = True
image: str
tag: str | None = None
digest: str | None = None
container_name: str | None = Field(default=None, alias="containerName")
restart_policy: str = Field(default="unless-stopped", alias="restartPolicy")
ports: list[str] = Field(default_factory=list)
volumes: list[str] = Field(default_factory=list)
env: dict[str, str] = Field(default_factory=dict)
@field_validator("component_id")
@classmethod
def _component_id(cls, value: str) -> str:
return validate_app_id(value)
@field_validator("image")
@classmethod
def _image(cls, value: str) -> str:
return validate_docker_image(value)
@field_validator("tag")
@classmethod
def _tag(cls, value: str | None) -> str | None:
return validate_docker_tag(value)
@field_validator("digest")
@classmethod
def _digest(cls, value: str | None) -> str | None:
return validate_docker_digest(value)
@field_validator("restart_policy")
@classmethod
def _restart_policy(cls, value: str | None) -> str:
return validate_restart_policy(value)
@field_validator("ports")
@classmethod
def _ports(cls, values: list[str]) -> list[str]:
return [validate_port_mapping(value) for value in values]
@field_validator("volumes")
@classmethod
def _volumes(cls, values: list[str]) -> list[str]:
return [validate_volume_mapping(value) for value in values]
@field_validator("env")
@classmethod
def _env(cls, values: dict[str, Any]) -> dict[str, str]:
normalized: dict[str, str] = {}
for key, value in values.items():
normalized[validate_env_name(str(key))] = str(value)
return normalized
@model_validator(mode="after")
def _container_name(self) -> "DockerComponent":
self.container_name = validate_container_name(self.container_name or self.component_id)
return self
class RawComponent(CamelModel):
component_id: str = Field(alias="componentId")
type: ComponentType