Skip to content

Commit c6fb161

Browse files
committed
restructured the code to understand the composition in service object
1 parent eb85fb9 commit c6fb161

23 files changed

+359
-406
lines changed

__init__.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,17 @@
33
Expose commonly used factories and types for simpler imports.
44
"""
55

6-
from .builders.core import BuilderFactory, BuilderType
7-
from .deployers.core import DeployerFactory, DeployerType, DeployerEnv
6+
from .builders.factory import BuilderFactory, BuilderType
7+
from .deployers.deployer import DeployerFactory, DeployerType, DeployerEnv
88
from .service import Service
9+
from .repo import Repo
910

10-
__all__ = ["BuilderFactory", "BuilderType", "DeployerFactory", "DeployerType", "DeployerEnv", "Service"]
11+
__all__ = [
12+
"BuilderFactory",
13+
"BuilderType",
14+
"DeployerFactory",
15+
"DeployerType",
16+
"DeployerEnv",
17+
"Service",
18+
"Repo",
19+
]

builders/__init__.py

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,2 @@
1-
"""Builder package: core types and plugin registry.
2-
Import builders.{core,docker,bake,...} for specific implementations.
3-
Re-exports core types for backward compatibility."""
4-
5-
from .core import ( # noqa: F401
6-
BuilderType,
7-
Builder,
8-
BuilderFactory,
9-
register_builder,
10-
)
11-
12-
import pkgutil
13-
from importlib import import_module
14-
15-
__all__ = []
16-
for finder, name, ispkg in pkgutil.iter_modules(__path__):
17-
if name != "core": # core already imported above
18-
import_module(f"{__name__}.{name}")
19-
__all__.append(name)
1+
from .builder import Builder # type: ignore
2+
from .factory import BuilderFactory, BuilderType # type: ignore

builders/bake.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
from .core import Builder, BuilderType, register_builder
1+
from .builder import Builder
22

33

44
class BakeBuilder(Builder):
55
"""Bake (Buildx Bake) builder example."""
66

77
def build(self) -> None:
88
print("setting the bake builder")
9-
10-
11-
register_builder(BuilderType.BAKE, BakeBuilder)

builders/builder.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"""Builder types and plugin registry.
2+
See sibling modules for concrete implementations."""
3+
4+
from enum import Enum, auto
5+
from dataclasses import dataclass
6+
from abc import abstractmethod
7+
8+
# DockerBuilder will be imported dynamically to avoid circular dependency
9+
10+
11+
class BuilderType(Enum):
12+
DOCKER = auto()
13+
BAKE = auto()
14+
GCLOUD = auto()
15+
HELM = auto()
16+
17+
18+
@dataclass
19+
class Builder:
20+
type: BuilderType
21+
22+
@abstractmethod
23+
def build(self) -> None: ...

builders/core.py

Lines changed: 0 additions & 33 deletions
This file was deleted.

builders/docker.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
1-
from .core import Builder, BuilderType, register_builder
1+
from dataclasses import dataclass
22

3+
from .builder import Builder
34

5+
6+
@dataclass
47
class DockerBuilder(Builder):
58
"""Dockerfile-based builder example."""
69

10+
dockerfile: str
11+
dockerfile_path: str
12+
context_path: str
13+
registry: str
14+
tags: list[str]
15+
push: bool
16+
717
def build(self) -> None:
818
print("setting the docker builder")
9-
10-
11-
# register on import
12-
register_builder(BuilderType.DOCKER, DockerBuilder)

builders/factory.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
from typing import Any, Type
2+
3+
from .builder import BuilderType, Builder
4+
from .docker import DockerBuilder
5+
from .helm import HelmBuilder
6+
from .gcloud import GCloudBuilder
7+
8+
_BUILDER_DISPATCH: dict[BuilderType, Type[Builder]] = {
9+
BuilderType.DOCKER: DockerBuilder,
10+
BuilderType.HELM: HelmBuilder,
11+
BuilderType.GCLOUD: GCloudBuilder,
12+
}
13+
14+
15+
class BuilderFactory:
16+
@staticmethod
17+
def create_builder(builder_type: str, **kwargs: Any | dict[str, Any]) -> Builder:
18+
builder_class = _BUILDER_DISPATCH.get(BuilderType[builder_type.upper()])
19+
if not builder_class:
20+
raise ValueError(f"Unknown builder type: {builder_type}")
21+
return builder_class(type=BuilderType[builder_type.upper()], **kwargs)
22+
23+
24+
def main() -> None:
25+
builder = BuilderFactory.create_builder(
26+
builder_type="gcloud",
27+
)
28+
29+
print(f"Created builder: {builder}")
30+
builder.build()
31+
32+
33+
if __name__ == "__main__":
34+
main()

builders/gcloud.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
from .core import Builder, BuilderType, register_builder
1+
from .builder import Builder
22

33

44
class GCloudBuilder(Builder):
55
"""Google Cloud Build builder example."""
66

77
def build(self) -> None:
88
print("setting the gcloud builder")
9-
10-
11-
register_builder(BuilderType.GCloudBuild, GCloudBuilder)

builders/helm.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
from .core import Builder, BuilderType, register_builder
1+
from dataclasses import dataclass
22

3+
from .builder import Builder
34

5+
6+
@dataclass
47
class HelmBuilder(Builder):
5-
"""Helm builder example."""
8+
chart_directory: str
9+
app_version: str
10+
chart_version: str
11+
registry: str
12+
push: bool
613

714
def build(self) -> None:
815
print("setting the helm builder")
9-
10-
11-
register_builder(BuilderType.HELM, HelmBuilder)

deployers/__init__.py

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,2 @@
1-
"""Deployer package: core types and plugin registry.
2-
Import deployers.{core,kustomize,argocd,...} for specific implementations.
3-
Re-exports core types for backward compatibility."""
4-
5-
from .core import ( # noqa: F401
6-
DeployerType,
7-
DeployerEnv,
8-
Deployer,
9-
DeployerFactory,
10-
register_deployer,
11-
)
12-
13-
import pkgutil
14-
from importlib import import_module
15-
16-
__all__ = []
17-
for finder, name, ispkg in pkgutil.iter_modules(__path__):
18-
if name != "core": # core already imported above
19-
import_module(f"{__name__}.{name}")
20-
__all__.append(name)
1+
from .deployer import Deployer # type: ignore
2+
from .factory import DeployerFactory # type: ignore

0 commit comments

Comments
 (0)