implement

This commit is contained in:
Michael Jerger 2023-04-29 16:45:17 +02:00
parent ea77c84948
commit 2a4a2d25d8
4 changed files with 62 additions and 50 deletions

View file

@ -2,10 +2,8 @@ import deprecation
from enum import Enum from enum import Enum
from typing import List from typing import List
from .common import Devops, BuildType from .common import Devops, BuildType
from .image import ( from .image import Image
Image, from .c4k import C4k
)
class DevopsFactory: class DevopsFactory:
def __init__(self): def __init__(self):
@ -16,8 +14,8 @@ class DevopsFactory:
specialized_builds = {} specialized_builds = {}
if BuildType.IMAGE in build_types: if BuildType.IMAGE in build_types:
specialized_builds[BuildType.IMAGE] = Image(input) specialized_builds[BuildType.IMAGE] = Image(input)
elif BuildType.C4K in build_types: if BuildType.C4K in build_types:
pass specialized_builds[BuildType.C4K] = C4k(input)
devops = Devops(input, specialized_builds=specialized_builds) devops = Devops(input, specialized_builds=specialized_builds)

View file

@ -9,16 +9,17 @@ from .common import (
class Image(Validateable): class Image(Validateable):
def __init__( def __init__(
self, self,
input, input: dict,
): ):
self.dockerhub_user = input.get("dockerhub_user") self.dockerhub_user = input.get("image_dockerhub_user")
self.dockerhub_password = input.get("dockerhub_password") self.dockerhub_password = input.get("image_dockerhub_password")
self.docker_publish_tag = input.get("docker_publish_tag") # TODO: rename to image_tag
self.build_commons_path = input.get("build_commons_path") self.docker_publish_tag = input.get("image_tag")
self.docker_publish_tag = input.get("docker_publish_tag") self.build_commons_path = input.get("image_build_commons_path")
self.use_package_common_files = input.get("use_package_common_files", True) self.use_package_common_files = input.get("image_use_package_common_files", True)
# TODO: rename to image_build_commons_dir_name
self.docker_build_commons_dir_name = input.get( self.docker_build_commons_dir_name = input.get(
"docker_build_commons_dir_name", "docker" "image_build_commons_dir_name", "docker"
) )
def validate(self) -> List[str]: def validate(self) -> List[str]:

View file

@ -1,19 +1,27 @@
from src.main.python.ddadevops.domain import DevopsFactory, Devops from src.main.python.ddadevops.domain import DevopsFactory, Devops
def devops_config(overrides: dict) -> dict: def devops_config(overrides: dict) -> dict:
default = { default = {
"build_types": ["IMAGE"], "name": "name",
"module": "module",
"stage": "test", "stage": "test",
"project_root_path": "../../..", "project_root_path": "../../..",
"name": "mybuild", "build_dir_name": "target",
"module": "test_image", "build_types": ["IMAGE", "C4K"],
"dockerhub_user": "dockerhub_user", "image_dockerhub_user": "dockerhub_user",
"dockerhub_password": "dockerhub_password", "image_dockerhub_password": "dockerhub_password",
"docker_image_tag": "docker_image_tag", "image_tag": "image_tag",
'c4k_config': {},
"c4k_grafana_cloud_user": "user",
"c4k_grafana_cloud_password": "password",
"c4k_grafana_cloud_url": "https://prometheus-prod-01-eu-west-0.grafana.net/api/prom/push",
'c4k_auth': {},
} }
input = default.copy() input = default.copy()
input.update(overrides) input.update(overrides)
return input return input
def build_devops(overrides: dict) -> Devops: def build_devops(overrides: dict) -> Devops:
return DevopsFactory().build_devops(devops_config(overrides)) return DevopsFactory().build_devops(devops_config(overrides))

View file

@ -2,45 +2,50 @@ import os
from pybuilder.core import Project from pybuilder.core import Project
from src.main.python.ddadevops.domain import DnsRecord from src.main.python.ddadevops.domain import DnsRecord
from src.main.python.ddadevops.c4k_build import C4kBuild, add_c4k_mixin_config from src.main.python.ddadevops.c4k_build import C4kBuild, add_c4k_mixin_config
from .domain.test_helper import devops_config
class MyC4kBuild(C4kBuild): class MyC4kBuild(C4kBuild):
pass pass
def test_c4k_mixin(tmp_path):
build_dir = 'build' def test_c4k_mixin(tmp_path):
project_name = 'testing-project' build_dir = "build"
module_name = 'c4k-test' project_name = "testing-project"
module_name = "c4k-test"
tmp_path_str = str(tmp_path) tmp_path_str = str(tmp_path)
project = Project(tmp_path_str, name=project_name) project = Project(tmp_path_str, name=project_name)
sut = MyC4kBuild(
project,
devops_config(
{
"build_types": ["C4K"],
"project_root_path": tmp_path_str,
"module": "c4k-test",
"c4k_config": {"a": 1, "b": 2},
"c4k_auth": {"c": 3, "d": 4},
"grafana_cloud_user": "user",
"grafana_cloud_password": "password",
'grafana_cloud_url': "https://prometheus-prod-01-eu-west-0.grafana.net/api/prom/push",
}
),
)
project_config = {
'stage': 'test', sut.initialize_build_dir()
'project_root_path': tmp_path_str, assert (
'module': module_name, sut.build_path() == f"{tmp_path_str}/target/mybuild/c4k-test"
'build_dir_name': build_dir )
}
config = {'a': 1, 'b': 2} # TODO: mv this to domain test
auth = {'c': 3, 'd': 4} # sut.update_runtime_config(DnsRecord("test.de", ipv6="1::"))
# assert "fqdn" in sut.specialized_builds[BuildType.C4K].config()
# assert "mon-cfg" in sut.specialized_builds[BuildType.C4K].config()
# assert "mon-auth" in sut.specialized_builds[BuildType.C4K].c4k_mixin_auth
add_c4k_mixin_config(project_config, config, auth, grafana_cloud_user='user', grafana_cloud_password='password') sut.write_c4k_config()
assert os.path.exists(f"{mixin.build_path()}/out_c4k_config.yaml")
assert project_config.get('C4kMixin') is not None sut.write_c4k_auth()
assert os.path.exists(f"{mixin.build_path()}/out_c4k_auth.yaml")
mixin = MyC4kBuild(project, project_config)
mixin.initialize_build_dir()
assert mixin.build_path() == f'{tmp_path_str}/{build_dir}/{project_name}/{module_name}'
mixin.update_runtime_config(DnsRecord('test.de', ipv6="1::"))
sut = mixin.repo.get_c4k(mixin.project)
assert 'fqdn' in sut.config()
assert 'mon-cfg' in sut.config()
assert 'mon-auth' in sut.c4k_mixin_auth
mixin.write_c4k_config()
assert os.path.exists(f'{mixin.build_path()}/out_c4k_config.yaml')
mixin.write_c4k_auth()
assert os.path.exists(f'{mixin.build_path()}/out_c4k_auth.yaml')