From 481d20a14ce5911ef9a1abf10a4d8bd12a5efc43 Mon Sep 17 00:00:00 2001 From: Michael Jerger Date: Fri, 28 Apr 2023 14:49:23 +0200 Subject: [PATCH] introduce devops factory --- doc/architecture/Domain.md | 5 ++- src/main/python/ddadevops/domain/__init__.py | 2 +- src/main/python/ddadevops/domain/common.py | 39 ++++++++++++++++++++ src/test/python/domain/test_devops.py | 16 ++++++++ src/test/python/domain/test_domain.py | 31 ++++++---------- 5 files changed, 71 insertions(+), 22 deletions(-) create mode 100644 src/test/python/domain/test_devops.py diff --git a/doc/architecture/Domain.md b/doc/architecture/Domain.md index dd5687f..92d12dc 100644 --- a/doc/architecture/Domain.md +++ b/doc/architecture/Domain.md @@ -3,6 +3,7 @@ ```mermaid classDiagram class Devops { + <> stage name project_root_path @@ -42,8 +43,10 @@ classDiagram current_branch } + Devops *-- Image: spcialized_build + Devops *-- C4k: spcialized_build + Devops *-- Release: release C4k *-- DnsRecord - Image *-- Devops Release *-- "0..1" ReleaseContext ``` diff --git a/src/main/python/ddadevops/domain/__init__.py b/src/main/python/ddadevops/domain/__init__.py index 2e4f6b1..9601d03 100644 --- a/src/main/python/ddadevops/domain/__init__.py +++ b/src/main/python/ddadevops/domain/__init__.py @@ -1,4 +1,4 @@ -from .common import Validateable, DnsRecord, Devops +from .common import Validateable, DnsRecord, Devops, DevopsFactory from .image import Image from .c4k import C4k from .release import Release, ReleaseContext, ReleaseType, Version, EnvironmentKeys diff --git a/src/main/python/ddadevops/domain/common.py b/src/main/python/ddadevops/domain/common.py index b077512..d038ec6 100644 --- a/src/main/python/ddadevops/domain/common.py +++ b/src/main/python/ddadevops/domain/common.py @@ -1,4 +1,6 @@ import deprecation +from enum import Enum +# TODO: remove logging from domain! import logging from typing import List @@ -70,3 +72,40 @@ class Devops(Validateable): for key in keys: result[key] = self.__get__(key) return result + + +class BuildType(Enum): + IMAGE = 0 + C4K = 1 + +class DevopsFactory(): + def __init__(self): + pass + + def build_devops(self, input) -> Devops: + build_type = BuildType[input['build_type']] + specialized_build = None + if build_type == BuildType.IMAGE: + specialized_build = Image( + dockerhub_user=input['dockerhub_user'], + dockerhub_password=input['dockerhub_password'], + docker_publish_tag=input['tag'] + ) + elif build_type == BuildType.C4K: + pass + + devops = Devops( + stage=input['stage'], + project_root_path=input['project_root_path'], + module=input['module'], + name=input['name'], + specialized_build=specialized_build + ) + + # TODO: validate devops + + return devops + + def merge(input, autorization, context) -> dict: + pass + diff --git a/src/test/python/domain/test_devops.py b/src/test/python/domain/test_devops.py new file mode 100644 index 0000000..3889454 --- /dev/null +++ b/src/test/python/domain/test_devops.py @@ -0,0 +1,16 @@ +import pytest +from src.main.python.ddadevops.domain.common import ( + Devops, + DevopsFactory, +) + +def test_devops_factory(): + with pytest.raises(Exception): + DevopsFactory().build_devops({'build_type': 'NOTEXISTING'}) + + +def test_devops_buildpath(): + sut = Devops( + stage="test", project_root_path="../../..", module="cloud", name="meissa" + ) + assert "../../../target/meissa/cloud" == sut.build_path() diff --git a/src/test/python/domain/test_domain.py b/src/test/python/domain/test_domain.py index b94b492..230e130 100644 --- a/src/test/python/domain/test_domain.py +++ b/src/test/python/domain/test_domain.py @@ -62,26 +62,6 @@ def test_should_validate_DnsRecord(): sut = DnsRecord("name", ipv6="1::") assert sut.is_valid() - -def test_devops_buildpath(): - sut = Devops( - stage="test", project_root_path="../../..", module="cloud", name="meissa" - ) - assert "../../../target/meissa/cloud" == sut.build_path() - - -def test_devops_build_commons_path(): - devops = Devops( - stage="test", project_root_path="../../..", module="cloud", name="meissa" - ) - sut = Image( - dockerhub_user="user", - dockerhub_password="password", - devops = devops, - ) - assert "docker/" == sut.docker_build_commons_path() - - def test_c4k_build_should_update_fqdn(): project_config = { "stage": "test", @@ -224,3 +204,14 @@ def test_release(tmp_path): sut.set_release_context(ReleaseContext(ReleaseType.MINOR, Version("id", [1,2,3]), "main")) assert sut.is_valid() + +def test_devops_build_commons_path(): + devops = Devops( + stage="test", project_root_path="../../..", module="cloud", name="meissa" + ) + sut = Image( + dockerhub_user="user", + dockerhub_password="password", + devops = devops, + ) + assert "docker/" == sut.docker_build_commons_path()