refactor: only builds & mixins should inherit

test are not working fully atmo
This commit is contained in:
Michael Jerger 2023-03-05 14:17:36 +01:00
parent 9dbc5f8ab0
commit dfddd5ee33
5 changed files with 18 additions and 11 deletions

View file

@ -6,7 +6,6 @@ classDiagram
DevopsBuild <|-- C4kMixin
DevopsBuild *-- BuildService
DevopsDockerBuild *-- BuildService
DevopsDockerBuild *-- DockerBuildService
C4kMixin *-- C4kBuildService
```

View file

@ -1,5 +1,11 @@
from .domain import Build, DockerBuild, C4kBuild
from .infrastructure import FileApi, ResourceApi, DockerApi
from os import chmod
import yaml
from .python_util import execute
from .credential import gopass_field_from_path, gopass_password_from_path
class BuildService:
@ -12,7 +18,6 @@ class BuildService:
class DockerBuildService:
def __init__(self):
self.build_service = BuildService()
self.file_api = FileApi()
self.resource_api = ResourceApi()
self.docker_api = DockerApi()
@ -32,7 +37,6 @@ class DockerBuildService:
self.file_api.cp_force(build.docker_build_commons_path(), build.build_path())
def initialize_build_dir(self, build: DockerBuild):
self.build_service.initialize_build_dir(build)
self.file_api.clean_dir(build.build_path() + "/image/resources")
if build.use_package_common_files:
self.__copy_build_resources_from_package__(build)
@ -67,7 +71,7 @@ class C4kBuildService:
with open(
c4k_build.build.build_path() + "/out_c4k_config.yaml", "w", encoding="utf-8"
) as output_file:
yaml.dump(c4k_build.c4k_mixin_config(), output_file)
yaml.dump(c4k_build.config(), output_file)
def write_c4k_auth(self, c4k_build: C4kBuild):
with open(

View file

@ -29,14 +29,15 @@ def add_c4k_mixin_config(config,
class C4kMixin(DevopsBuild):
def __init__(self, project, config):
self.build = C4kBuild(project, config)
super().__init__(project, config)
self.c4k_build = C4kBuild(project, config)
self.c4k_build_service = C4kBuildService()
def write_c4k_config(self):
self.c4k_build_service.write_c4k_config(self.build)
self.c4k_build_service.write_c4k_config(self.c4k_build)
def write_c4k_auth(self):
self.c4k_build_service.write_c4k_auth(self.build)
self.c4k_build_service.write_c4k_auth(self.c4k_build)
def c4k_apply(self, dry_run=False):
self.c4k_build_service.c4k_apply(self.build, dry_run)
self.c4k_build_service.c4k_apply(self.c4k_build, dry_run)

View file

@ -26,12 +26,15 @@ def create_devops_docker_build_config(stage,
class DevopsDockerBuild(DevopsBuild):
def __init__(self, project, config):
self.build = DockerBuild(project, config)
super().__init__(project, config)
self.docker_build = DockerBuild(project, config)
self.docker_build_service = DockerBuildService()
def initialize_build_dir(self):
self.docker_build_service.initialize_build_dir(self.build)
super().initialize_build_dir()
self.docker_build_service.initialize_build_dir(self.docker_build)
# TODO: use application from here on
def image(self):
run('docker build -t ' + self.name() +
' --file ' + self.build_path() + '/image/Dockerfile '

View file

@ -34,7 +34,7 @@ def test_c4k_mixin(tmp_path):
mixin.initialize_build_dir()
assert mixin.build_path() == f'{tmp_path_str}/{build_dir}/{project_name}/{module_name}'
mixin.put('fqdn', 'testing.test')
mixin.build.update_runtime_config('test.de', None, None)
mixin.write_c4k_config()
assert 'fqdn' in mixin.c4k_mixin_config