refactor to dedicated parameters
This commit is contained in:
parent
4eeaefc1a3
commit
7ba7cce801
6 changed files with 107 additions and 51 deletions
|
@ -10,7 +10,15 @@ classDiagram
|
||||||
build_dir_name
|
build_dir_name
|
||||||
}
|
}
|
||||||
|
|
||||||
class Docker
|
class Docker {
|
||||||
|
dockerhub_user
|
||||||
|
dockerhub_password
|
||||||
|
build_dir_name
|
||||||
|
use_package_common_files
|
||||||
|
build_commons_path
|
||||||
|
docker_build_commons_dir_name
|
||||||
|
docker_publish_tag
|
||||||
|
}
|
||||||
|
|
||||||
class C4k {
|
class C4k {
|
||||||
executabel_name
|
executabel_name
|
||||||
|
@ -25,6 +33,7 @@ classDiagram
|
||||||
}
|
}
|
||||||
|
|
||||||
C4k *-- DnsRecord
|
C4k *-- DnsRecord
|
||||||
|
Docker *-- Devops
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -8,43 +8,47 @@ class DockerBuildService:
|
||||||
self.resource_api = ResourceApi()
|
self.resource_api = ResourceApi()
|
||||||
self.docker_api = DockerApi()
|
self.docker_api = DockerApi()
|
||||||
|
|
||||||
def __copy_build_resource_file_from_package__(self, build: Docker):
|
def __copy_build_resource_file_from_package__(self, resource_name, docker: Docker):
|
||||||
data = self.resource_api.read_resource(
|
data = self.resource_api.read_resource(f"../../resources/docker/{resource_name}")
|
||||||
"src/main/resources/docker/" + build.name
|
self.file_api.write_data_to_file(
|
||||||
|
f"{docker.devops.build_path()}/{resource_name}", data
|
||||||
)
|
)
|
||||||
self.file_api.write_data_to_file(build.build_path() + "/" + build.name, data)
|
|
||||||
|
|
||||||
def __copy_build_resources_from_package__(self, build: Docker):
|
def __copy_build_resources_from_package__(self, docker: Docker):
|
||||||
self.__copy_build_resource_file_from_package__(
|
self.__copy_build_resource_file_from_package__(
|
||||||
"image/resources/install_functions.sh"
|
"image/resources/install_functions.sh", docker
|
||||||
)
|
)
|
||||||
|
|
||||||
def __copy_build_resources_from_dir__(self, build: Docker):
|
def __copy_build_resources_from_dir__(self, docker: Docker):
|
||||||
self.file_api.cp_force(build.docker_build_commons_path(), build.build_path())
|
self.file_api.cp_force(
|
||||||
|
docker.docker_build_commons_path(), docker.devops.build_path()
|
||||||
|
)
|
||||||
|
|
||||||
def initialize_build_dir(self, build: Devops, docker_build: Docker):
|
def initialize_build_dir(self, docker: Docker):
|
||||||
build_path = build.build_path()
|
build_path = docker.devops.build_path()
|
||||||
self.file_api.clean_dir(f"{build_path}/image/resources")
|
self.file_api.clean_dir(f"{build_path}/image/resources")
|
||||||
if docker_build.use_package_common_files:
|
if docker.use_package_common_files:
|
||||||
self.__copy_build_resources_from_package__(docker_build)
|
self.__copy_build_resources_from_package__(docker)
|
||||||
else:
|
else:
|
||||||
self.__copy_build_resources_from_dir__(docker_build)
|
self.__copy_build_resources_from_dir__(docker)
|
||||||
self.file_api.cp_recursive("image", build_path)
|
self.file_api.cp_recursive("image", build_path)
|
||||||
self.file_api.cp_recursive("test", build_path)
|
self.file_api.cp_recursive("test", build_path)
|
||||||
|
|
||||||
def image(self, build: Devops):
|
def image(self, docker: Docker):
|
||||||
self.docker_api.image(build.name(), build.build_path())
|
self.docker_api.image(docker.devops.name, docker.devops.build_path())
|
||||||
|
|
||||||
def drun(self, build: Docker):
|
def drun(self, docker: Devops):
|
||||||
self.docker_api.drun(build.name())
|
self.docker_api.drun(docker.devops.name)
|
||||||
|
|
||||||
def dockerhub_login(self, docker_build: Docker):
|
def dockerhub_login(self, docker: Docker):
|
||||||
self.docker_api.dockerhub_login(docker_build.dockerhub_user, docker_build.dockerhub_password)
|
self.docker_api.dockerhub_login(
|
||||||
|
docker.dockerhub_user, docker.dockerhub_password
|
||||||
def dockerhub_publish(self, build: Devops, docker_build: Docker):
|
|
||||||
self.docker_api.dockerhub_publish(
|
|
||||||
build.name(), docker_build.dockerhub_user, docker_build.docker_publish_tag
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def test(self, build: Devops):
|
def dockerhub_publish(self, docker: Docker):
|
||||||
self.docker_api.test(build.name(), build.build_path())
|
self.docker_api.dockerhub_publish(
|
||||||
|
docker.devops.name, docker.dockerhub_user, docker.docker_publish_tag
|
||||||
|
)
|
||||||
|
|
||||||
|
def test(self, docker: Docker):
|
||||||
|
self.docker_api.test(docker.devops.name, docker.devops.build_path())
|
||||||
|
|
|
@ -33,7 +33,6 @@ def create_devops_docker_build_config(
|
||||||
|
|
||||||
class DevopsDockerBuild(DevopsBuild):
|
class DevopsDockerBuild(DevopsBuild):
|
||||||
def __init__(self, project, config: map = None, docker: Docker = None):
|
def __init__(self, project, config: map = None, docker: Docker = None):
|
||||||
super().__init__(project, config)
|
|
||||||
self.docker_build_service = DockerBuildService()
|
self.docker_build_service = DockerBuildService()
|
||||||
if not docker:
|
if not docker:
|
||||||
docker = Docker(
|
docker = Docker(
|
||||||
|
@ -44,31 +43,32 @@ class DevopsDockerBuild(DevopsBuild):
|
||||||
docker_build_commons_dir_name=config["docker_build_commons_dir_name"],
|
docker_build_commons_dir_name=config["docker_build_commons_dir_name"],
|
||||||
docker_publish_tag=config["docker_publish_tag"],
|
docker_publish_tag=config["docker_publish_tag"],
|
||||||
)
|
)
|
||||||
|
super().__init__(project, config=config)
|
||||||
|
else:
|
||||||
|
super().__init__(project, devops=docker.devops)
|
||||||
self.repo.set_docker(self.project, docker)
|
self.repo.set_docker(self.project, docker)
|
||||||
|
|
||||||
def initialize_build_dir(self):
|
def initialize_build_dir(self):
|
||||||
super().initialize_build_dir()
|
super().initialize_build_dir()
|
||||||
build = self.repo.get_devops(self.project)
|
docker = self.repo.get_docker(self.project)
|
||||||
docker_build = self.repo.get_docker(self.project)
|
self.docker_build_service.initialize_build_dir(docker)
|
||||||
self.docker_build_service.initialize_build_dir(build, docker_build)
|
|
||||||
|
|
||||||
def image(self):
|
def image(self):
|
||||||
build = self.repo.get_devops(self.project)
|
docker = self.repo.get_docker(self.project)
|
||||||
self.docker_build_service.image(build)
|
self.docker_build_service.image(docker)
|
||||||
|
|
||||||
def drun(self):
|
def drun(self):
|
||||||
build = self.repo.get_devops(self.project)
|
docker = self.repo.get_docker(self.project)
|
||||||
self.docker_build_service.drun(build)
|
self.docker_build_service.drun(docker)
|
||||||
|
|
||||||
def dockerhub_login(self):
|
def dockerhub_login(self):
|
||||||
docker_build = self.repo.get_docker(self.project)
|
docker = self.repo.get_docker(self.project)
|
||||||
self.docker_build_service.dockerhub_login(docker_build)
|
self.docker_build_service.dockerhub_login(docker)
|
||||||
|
|
||||||
def dockerhub_publish(self):
|
def dockerhub_publish(self):
|
||||||
build = self.repo.get_devops(self.project)
|
docker = self.repo.get_docker(self.project)
|
||||||
docker_build = self.repo.get_docker(self.project)
|
self.docker_build_service.dockerhub_publish(docker)
|
||||||
self.docker_build_service.dockerhub_publish(build, docker_build)
|
|
||||||
|
|
||||||
def test(self):
|
def test(self):
|
||||||
build = self.repo.get_devops(self.project)
|
docker = self.repo.get_docker(self.project)
|
||||||
self.test.dockerhub_publish(build)
|
self.test.dockerhub_publish(docker)
|
||||||
|
|
|
@ -73,18 +73,20 @@ class Docker(Validateable):
|
||||||
self,
|
self,
|
||||||
dockerhub_user,
|
dockerhub_user,
|
||||||
dockerhub_password,
|
dockerhub_password,
|
||||||
|
devops: Devops,
|
||||||
build_dir_name="target",
|
build_dir_name="target",
|
||||||
use_package_common_files=True,
|
use_package_common_files=True,
|
||||||
build_commons_path=None,
|
build_commons_path=None,
|
||||||
docker_build_commons_dir_name="docker",
|
docker_build_commons_dir_name="docker",
|
||||||
docker_publish_tag=None,
|
docker_publish_tag=None,
|
||||||
):
|
):
|
||||||
self.dockerhub_user = (dockerhub_user,)
|
self.dockerhub_user = dockerhub_user
|
||||||
self.dockerhub_password = (dockerhub_password,)
|
self.dockerhub_password = dockerhub_password
|
||||||
self.use_package_common_files = (use_package_common_files,)
|
self.use_package_common_files = use_package_common_files
|
||||||
self.build_commons_path = (build_commons_path,)
|
self.build_commons_path = build_commons_path
|
||||||
self.docker_build_commons_dir_name = (docker_build_commons_dir_name,)
|
self.docker_build_commons_dir_name = docker_build_commons_dir_name
|
||||||
self.docker_publish_tag = (docker_publish_tag,)
|
self.docker_publish_tag = docker_publish_tag
|
||||||
|
self.devops = devops
|
||||||
|
|
||||||
def docker_build_commons_path(self):
|
def docker_build_commons_path(self):
|
||||||
list = [self.build_commons_path, self.docker_build_commons_dir_name]
|
list = [self.build_commons_path, self.docker_build_commons_dir_name]
|
||||||
|
|
24
src/test/python/test_docker_build.py
Normal file
24
src/test/python/test_docker_build.py
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
import os
|
||||||
|
from pybuilder.core import Project
|
||||||
|
from src.main.python.ddadevops.domain import Docker, Devops
|
||||||
|
from src.main.python.ddadevops.devops_docker_build import DevopsDockerBuild
|
||||||
|
|
||||||
|
|
||||||
|
def test_devops_docker_build(tmp_path):
|
||||||
|
build_dir = "build"
|
||||||
|
project_name = "testing-project"
|
||||||
|
module_name = "docker-test"
|
||||||
|
tmp_path_str = str(tmp_path)
|
||||||
|
|
||||||
|
project = Project(tmp_path_str, name=project_name)
|
||||||
|
devops = Devops(
|
||||||
|
stage="test",
|
||||||
|
project_root_path=tmp_path_str,
|
||||||
|
module=module_name,
|
||||||
|
name=project_name,
|
||||||
|
)
|
||||||
|
docker = Docker(dockerhub_user="user", dockerhub_password="password", devops=devops)
|
||||||
|
|
||||||
|
docker_build = DevopsDockerBuild(project, docker=docker)
|
||||||
|
# docker_build.initialize_build_dir()
|
||||||
|
# assert os.path.exists(f"{docker_build.build_path()}")
|
|
@ -1,5 +1,11 @@
|
||||||
from pybuilder.core import Project
|
from pybuilder.core import Project
|
||||||
from src.main.python.ddadevops.domain import Validateable, DnsRecord, C4k, Devops
|
from src.main.python.ddadevops.domain import (
|
||||||
|
Validateable,
|
||||||
|
DnsRecord,
|
||||||
|
C4k,
|
||||||
|
Devops,
|
||||||
|
Docker,
|
||||||
|
)
|
||||||
from src.main.python.ddadevops.c4k_mixin import add_c4k_mixin_config
|
from src.main.python.ddadevops.c4k_mixin import add_c4k_mixin_config
|
||||||
|
|
||||||
|
|
||||||
|
@ -62,6 +68,18 @@ def test_devops_buildpath():
|
||||||
assert "../../../target/meissa/cloud" == sut.build_path()
|
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 = Docker(
|
||||||
|
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",
|
||||||
|
@ -83,7 +101,7 @@ def test_c4k_build_should_update_fqdn():
|
||||||
grafana_cloud_user="user",
|
grafana_cloud_user="user",
|
||||||
grafana_cloud_password="password",
|
grafana_cloud_password="password",
|
||||||
)
|
)
|
||||||
|
|
||||||
sut = C4k(project_config)
|
sut = C4k(project_config)
|
||||||
sut.update_runtime_config(DnsRecord("test.de", ipv6="1::"))
|
sut.update_runtime_config(DnsRecord("test.de", ipv6="1::"))
|
||||||
|
|
||||||
|
@ -108,8 +126,7 @@ def test_c4k_build_should_update_fqdn():
|
||||||
|
|
||||||
|
|
||||||
def test_c4k_build_should_calculate_command():
|
def test_c4k_build_should_calculate_command():
|
||||||
devops = Devops(stage="test", project_root_path='',
|
devops = Devops(stage="test", project_root_path="", module="module", name="name")
|
||||||
module="module", name="name")
|
|
||||||
project_config = {
|
project_config = {
|
||||||
"stage": "test",
|
"stage": "test",
|
||||||
"name": "name",
|
"name": "name",
|
||||||
|
|
Loading…
Reference in a new issue