This commit is contained in:
Michael Jerger 2023-03-05 13:59:40 +01:00
parent 4bdbccd722
commit 9dbc5f8ab0
2 changed files with 38 additions and 16 deletions

12
doc/architecture.md Normal file
View file

@ -0,0 +1,12 @@
```mermaid
classDiagram
DevopsBuild <|-- DevopsDockerBuild
DevopsBuild <|-- DevopsTerraformBuild
DevopsBuild <|-- C4kMixin
DevopsBuild *-- BuildService
DevopsDockerBuild *-- BuildService
DevopsDockerBuild *-- DockerBuildService
C4kMixin *-- C4kBuildService
```

View file

@ -2,14 +2,15 @@ from .domain import Build, DockerBuild, C4kBuild
from .infrastructure import FileApi, ResourceApi, DockerApi from .infrastructure import FileApi, ResourceApi, DockerApi
class BuildService(): class BuildService:
def __init__(self): def __init__(self):
self.file_api = FileApi() self.file_api = FileApi()
def initialize_build_dir(self, build: Build): def initialize_build_dir(self, build: Build):
self.file_api.clean_dir(build.build_path()) self.file_api.clean_dir(build.build_path())
class DockerBuildService():
class DockerBuildService:
def __init__(self): def __init__(self):
self.build_service = BuildService() self.build_service = BuildService()
self.file_api = FileApi() self.file_api = FileApi()
@ -17,25 +18,28 @@ class DockerBuildService():
self.docker_api = DockerApi() self.docker_api = DockerApi()
def __copy_build_resource_file_from_package__(self, build: DockerBuild): def __copy_build_resource_file_from_package__(self, build: DockerBuild):
data = self.resource_api.read_resource("src/main/resources/docker/" + build.name) data = self.resource_api.read_resource(
self.file_api.write_to_file(build.build_path() + '/' + build.name, data) "src/main/resources/docker/" + build.name
)
self.file_api.write_to_file(build.build_path() + "/" + build.name, data)
def __copy_build_resources_from_package__(self, build: DockerBuild): def __copy_build_resources_from_package__(self, build: DockerBuild):
self.__copy_build_resource_file_from_package__( self.__copy_build_resource_file_from_package__(
'image/resources/install_functions.sh') "image/resources/install_functions.sh"
)
def __copy_build_resources_from_dir__(self, build: DockerBuild): def __copy_build_resources_from_dir__(self, build: DockerBuild):
self.file_api.cp_force(build.docker_build_commons_path(), build.build_path()) self.file_api.cp_force(build.docker_build_commons_path(), build.build_path())
def initialize_build_dir(self, build: DockerBuild): def initialize_build_dir(self, build: DockerBuild):
self.build_service.initialize_build_dir(build) self.build_service.initialize_build_dir(build)
self.file_api.clean_dir(build.build_path() + '/image/resources') self.file_api.clean_dir(build.build_path() + "/image/resources")
if build.use_package_common_files: if build.use_package_common_files:
self.__copy_build_resources_from_package__(build) self.__copy_build_resources_from_package__(build)
else: else:
self.__copy_build_resources_from_dir__(build) self.__copy_build_resources_from_dir__(build)
self.file_api.cp_recursive('image', build.build_path()) self.file_api.cp_recursive("image", build.build_path())
self.file_api.cp_recursive('test', build.build_path()) self.file_api.cp_recursive("test", build.build_path())
def image(self, build: DockerBuild): def image(self, build: DockerBuild):
self.docker_api.image(build.name(), build.build_path()) self.docker_api.image(build.name(), build.build_path())
@ -47,33 +51,39 @@ class DockerBuildService():
self.docker_api.dockerhub_login(build.dockerhub_user, build.dockerhub_password) self.docker_api.dockerhub_login(build.dockerhub_user, build.dockerhub_password)
def dockerhub_publish(self, build: DockerBuild): def dockerhub_publish(self, build: DockerBuild):
self.docker_api.dockerhub_publish(build.name(), build.dockerhub_user, build.docker_publish_tag) self.docker_api.dockerhub_publish(
build.name(), build.dockerhub_user, build.docker_publish_tag
)
def test(self, build: DockerBuild): def test(self, build: DockerBuild):
self.docker_api.test(build.name(), build.build_path()) self.docker_api.test(build.name(), build.build_path())
class C4kBuildService(): # TODO: move infrastructure fktns to infra apis
class C4kBuildService:
def __init__(self): def __init__(self):
self.file_api = FileApi() self.file_api = FileApi()
def write_c4k_config(self, c4k_build: C4kBuild): def write_c4k_config(self, c4k_build: C4kBuild):
with open(c4k_build.build.build_path() + '/out_c4k_config.yaml', 'w', encoding="utf-8") as output_file: 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.c4k_mixin_config(), output_file)
def write_c4k_auth(self, c4k_build: C4kBuild): def write_c4k_auth(self, c4k_build: C4kBuild):
with open(c4k_build.build.build_path() + '/out_c4k_auth.yaml', 'w', encoding="utf-8") as output_file: with open(
c4k_build.build.build_path() + "/out_c4k_auth.yaml", "w", encoding="utf-8"
) as output_file:
yaml.dump(c4k_build.c4k_mixin_auth, output_file) yaml.dump(c4k_build.c4k_mixin_auth, output_file)
chmod(c4k_build.build.build_path() + '/out_c4k_auth.yaml', 0o600) chmod(c4k_build.build.build_path() + "/out_c4k_auth.yaml", 0o600)
def c4k_apply(self, c4k_build: C4kBuild, ry_run=False): def c4k_apply(self, c4k_build: C4kBuild, ry_run=False):
module = c4k_build.build.module module = c4k_build.build.module
build_path = c4k_build.build.build_path() build_path = c4k_build.build.build_path()
cmd = f'c4k-{module}-standalone.jar {build_path}/out_c4k_config.yaml {build_path}/out_c4k_auth.yaml > {build_path}/out_{module}.yaml' cmd = f"c4k-{module}-standalone.jar {build_path}/out_c4k_config.yaml {build_path}/out_c4k_auth.yaml > {build_path}/out_{module}.yaml"
output = '' output = ""
if dry_run: if dry_run:
print(cmd) print(cmd)
else: else:
output = execute(cmd, True) output = execute(cmd, True)
print(output) print(output)
return output return output