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 typing import List
from .common import Devops, BuildType
from .image import (
Image,
)
from .image import Image
from .c4k import C4k
class DevopsFactory:
def __init__(self):
@ -16,8 +14,8 @@ class DevopsFactory:
specialized_builds = {}
if BuildType.IMAGE in build_types:
specialized_builds[BuildType.IMAGE] = Image(input)
elif BuildType.C4K in build_types:
pass
if BuildType.C4K in build_types:
specialized_builds[BuildType.C4K] = C4k(input)
devops = Devops(input, specialized_builds=specialized_builds)

View file

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

View file

@ -1,19 +1,27 @@
from src.main.python.ddadevops.domain import DevopsFactory, Devops
def devops_config(overrides: dict) -> dict:
default = {
"build_types": ["IMAGE"],
"name": "name",
"module": "module",
"stage": "test",
"project_root_path": "../../..",
"name": "mybuild",
"module": "test_image",
"dockerhub_user": "dockerhub_user",
"dockerhub_password": "dockerhub_password",
"docker_image_tag": "docker_image_tag",
"build_dir_name": "target",
"build_types": ["IMAGE", "C4K"],
"image_dockerhub_user": "dockerhub_user",
"image_dockerhub_password": "dockerhub_password",
"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.update(overrides)
return input
def build_devops(overrides: dict) -> Devops:
return DevopsFactory().build_devops(devops_config(overrides))

View file

@ -2,45 +2,50 @@ import os
from pybuilder.core import Project
from src.main.python.ddadevops.domain import DnsRecord
from src.main.python.ddadevops.c4k_build import C4kBuild, add_c4k_mixin_config
from .domain.test_helper import devops_config
class MyC4kBuild(C4kBuild):
pass
def test_c4k_mixin(tmp_path):
build_dir = 'build'
project_name = 'testing-project'
module_name = 'c4k-test'
def test_c4k_mixin(tmp_path):
build_dir = "build"
project_name = "testing-project"
module_name = "c4k-test"
tmp_path_str = str(tmp_path)
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',
'project_root_path': tmp_path_str,
'module': module_name,
'build_dir_name': build_dir
}
config = {'a': 1, 'b': 2}
auth = {'c': 3, 'd': 4}
sut.initialize_build_dir()
assert (
sut.build_path() == f"{tmp_path_str}/target/mybuild/c4k-test"
)
add_c4k_mixin_config(project_config, config, auth, grafana_cloud_user='user', grafana_cloud_password='password')
# TODO: mv this to domain test
# 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
assert project_config.get('C4kMixin') is not None
sut.write_c4k_config()
assert os.path.exists(f"{mixin.build_path()}/out_c4k_config.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')
sut.write_c4k_auth()
assert os.path.exists(f"{mixin.build_path()}/out_c4k_auth.yaml")