introduce devops factory

This commit is contained in:
Michael Jerger 2023-04-28 14:49:23 +02:00
parent a28a1b43d3
commit 481d20a14c
5 changed files with 71 additions and 22 deletions

View file

@ -3,6 +3,7 @@
```mermaid ```mermaid
classDiagram classDiagram
class Devops { class Devops {
<<AggregateRoot>>
stage stage
name name
project_root_path project_root_path
@ -42,8 +43,10 @@ classDiagram
current_branch current_branch
} }
Devops *-- Image: spcialized_build
Devops *-- C4k: spcialized_build
Devops *-- Release: release
C4k *-- DnsRecord C4k *-- DnsRecord
Image *-- Devops
Release *-- "0..1" ReleaseContext Release *-- "0..1" ReleaseContext
``` ```

View file

@ -1,4 +1,4 @@
from .common import Validateable, DnsRecord, Devops from .common import Validateable, DnsRecord, Devops, DevopsFactory
from .image import Image from .image import Image
from .c4k import C4k from .c4k import C4k
from .release import Release, ReleaseContext, ReleaseType, Version, EnvironmentKeys from .release import Release, ReleaseContext, ReleaseType, Version, EnvironmentKeys

View file

@ -1,4 +1,6 @@
import deprecation import deprecation
from enum import Enum
# TODO: remove logging from domain!
import logging import logging
from typing import List from typing import List
@ -70,3 +72,40 @@ class Devops(Validateable):
for key in keys: for key in keys:
result[key] = self.__get__(key) result[key] = self.__get__(key)
return result 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

View file

@ -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()

View file

@ -62,26 +62,6 @@ def test_should_validate_DnsRecord():
sut = DnsRecord("name", ipv6="1::") sut = DnsRecord("name", ipv6="1::")
assert sut.is_valid() 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(): def test_c4k_build_should_update_fqdn():
project_config = { project_config = {
"stage": "test", "stage": "test",
@ -224,3 +204,14 @@ def test_release(tmp_path):
sut.set_release_context(ReleaseContext(ReleaseType.MINOR, Version("id", [1,2,3]), "main")) sut.set_release_context(ReleaseContext(ReleaseType.MINOR, Version("id", [1,2,3]), "main"))
assert sut.is_valid() 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()