switch image build to new structure

This commit is contained in:
Michael Jerger 2023-04-29 12:09:23 +02:00
parent 462be0d49a
commit e2c0ae3a54
3 changed files with 51 additions and 51 deletions

View file

@ -1,4 +1,4 @@
from src.main.python.ddadevops.domain import Image
from src.main.python.ddadevops.domain import Image, Devops
from src.main.python.ddadevops.infrastructure import FileApi, ResourceApi, ImageApi
@ -6,49 +6,55 @@ class ImageBuildService:
def __init__(self):
self.file_api = FileApi()
self.resource_api = ResourceApi()
self.docker_api = ImageApi()
self.image_api = ImageApi()
def __copy_build_resource_file_from_package__(self, resource_name, docker: Image):
def __copy_build_resource_file_from_package__(self, resource_name, image: Image):
data = self.resource_api.read_resource(f"src/main/resources/docker/{resource_name}")
self.file_api.write_data_to_file(
f"{docker.devops.build_path()}/{resource_name}", data
f"{image.devops.build_path()}/{resource_name}", data
)
def __copy_build_resources_from_package__(self, docker: Image):
def __copy_build_resources_from_package__(self, image: Image):
self.__copy_build_resource_file_from_package__(
"image/resources/install_functions.sh", docker
"image/resources/install_functions.sh", image
)
def __copy_build_resources_from_dir__(self, docker: Image):
def __copy_build_resources_from_dir__(self, image: Image):
self.file_api.cp_force(
docker.docker_build_commons_path(), docker.devops.build_path()
image.docker_build_commons_path(), image.devops.build_path()
)
def initialize_build_dir(self, docker: Image):
build_path = docker.devops.build_path()
def initialize_build_dir(self, devops: Devops):
image = devops.specialized_build
build_path = image.devops.build_path()
self.file_api.clean_dir(f"{build_path}/image/resources")
if docker.use_package_common_files:
self.__copy_build_resources_from_package__(docker)
if image.use_package_common_files:
self.__copy_build_resources_from_package__(image)
else:
self.__copy_build_resources_from_dir__(docker)
self.__copy_build_resources_from_dir__(image)
self.file_api.cp_recursive("image", build_path)
self.file_api.cp_recursive("test", build_path)
def image(self, docker: Image):
self.docker_api.image(docker.devops.name, docker.devops.build_path())
def image(self, devops: Devops):
image = devops.specialized_build
self.image_api.image(image.devops.name, image.devops.build_path())
def drun(self, docker: Image):
self.docker_api.drun(docker.devops.name)
def drun(self, devops: Devops):
image = devops.specialized_build
self.image_api.drun(image.devops.name)
def dockerhub_login(self, docker: Image):
self.docker_api.dockerhub_login(
docker.dockerhub_user, docker.dockerhub_password
def dockerhub_login(self, devops: Devops):
image = devops.specialized_build
self.image_api.dockerhub_login(
image.dockerhub_user, image.dockerhub_password
)
def dockerhub_publish(self, docker: Image):
self.docker_api.dockerhub_publish(
docker.devops.name, docker.dockerhub_user, docker.docker_publish_tag
def dockerhub_publish(self, devops: Devops):
image = devops.specialized_build
self.image_api.dockerhub_publish(
image.devops.name, image.dockerhub_user, image.docker_publish_tag
)
def test(self, docker: Image):
self.docker_api.test(docker.devops.name, docker.devops.build_path())
def test(self, devops: Devops):
image = devops.specialized_build
self.image_api.test(image.devops.name, image.devops.build_path())

View file

@ -1,11 +1,11 @@
from typing import Optional
import deprecation
from .domain import Image
from .domain import BuildType
from .application import ImageBuildService
from .devops_build import DevopsBuild, create_devops_build_config
@deprecation.deprecated(deprecated_in="3.2", details="create objects direct instead")
@deprecation.deprecated(deprecated_in="3.2", details="use direct dict instead")
def create_devops_docker_build_config(
stage,
project_root_path,
@ -36,28 +36,31 @@ class DevopsImageBuild(DevopsBuild):
def __init__(self, project, input: dict):
super().__init__(project, input)
self.image_build_service = ImageBuildService()
devops = self.repo.get_devops(self.project)
if devops.build_type != BuildType.IMAGE:
raise ValueError(f"ImageBuild requires BuildType.IMAGE but was: {devops.build_type}")
def initialize_build_dir(self):
super().initialize_build_dir()
image = self.repo.get_docker(self.project)
self.image_build_service.initialize_build_dir(image)
devops = self.repo.get_devops(self.project)
self.image_build_service.initialize_build_dir(devops)
def image(self):
image = self.repo.get_docker(self.project)
self.image_build_service.image(image)
devops = self.repo.get_devops(self.project)
self.image_build_service.image(devops)
def drun(self):
image = self.repo.get_docker(self.project)
self.image_build_service.drun(image)
devops = self.repo.get_devops(self.project)
self.image_build_service.drun(devops)
def dockerhub_login(self):
image = self.repo.get_docker(self.project)
self.image_build_service.dockerhub_login(image)
devops = self.repo.get_devops(self.project)
self.image_build_service.dockerhub_login(devops)
def dockerhub_publish(self):
image = self.repo.get_docker(self.project)
self.image_build_service.dockerhub_publish(image)
devops = self.repo.get_devops(self.project)
self.image_build_service.dockerhub_publish(devops)
def test(self):
image = self.repo.get_docker(self.project)
self.image_build_service.test(image)
devops = self.repo.get_devops(self.project)
self.image_build_service.test(devops)

View file

@ -2,6 +2,7 @@ import os
from pybuilder.core import Project
from src.main.python.ddadevops.domain import Image, Devops
from src.main.python.ddadevops.devops_image_build import DevopsImageBuild
from .domain.test_helper import devops_config
def test_devops_docker_build(tmp_path):
@ -11,15 +12,5 @@ def test_devops_docker_build(tmp_path):
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,
build_dir_name=build_dir
)
image = Image(dockerhub_user="user", dockerhub_password="password", devops=devops)
docker_build = DevopsImageBuild(project, image=image)
# docker_build.initialize_build_dir()
# assert os.path.exists(f"{docker_build.build_path()}")
image_build = DevopsImageBuild(project, devops_config({}))
assert image_build