fix resource loading from pkg

This commit is contained in:
Michael Jerger 2023-05-19 14:34:39 +02:00
parent 72b5e19ffe
commit 651c166920
4 changed files with 13 additions and 10 deletions

View file

@ -28,7 +28,7 @@ use_plugin("python.distutils")
default_task = "publish" default_task = "publish"
name = "ddadevops" name = "ddadevops"
version = "4.0.0-dev21" version = "4.0.0-dev26"
summary = "tools to support builds combining gopass, terraform, dda-pallet, aws & hetzner-cloud" summary = "tools to support builds combining gopass, terraform, dda-pallet, aws & hetzner-cloud"
description = __doc__ description = __doc__
authors = [Author("meissa GmbH", "buero@meissa-gmbh.de")] authors = [Author("meissa GmbH", "buero@meissa-gmbh.de")]

View file

@ -17,30 +17,30 @@ class ImageBuildService:
) )
def __copy_build_resource_file_from_package__(self, resource_name, devops: Devops): def __copy_build_resource_file_from_package__(self, resource_name, devops: Devops):
data = self.resource_api.read_resource(f"src/main/resources/docker/{resource_name}") data = self.resource_api.read_resource(f"main/resources/docker/{resource_name}")
self.file_api.write_data_to_file( self.file_api.write_data_to_file(
f"{devops.build_path()}/{resource_name}", data f"{devops.build_path()}/{resource_name}", data
) )
def __copy_build_resources_from_package__(self, devops: Devops): def __copy_build_resources_from_package__(self, devops: Devops):
self.__copy_build_resource_file_from_package__( self.__copy_build_resource_file_from_package__(
"image/resources/install_functions.sh", devops.specialized_builds[BuildType.C4K] "image/resources/install_functions.sh", devops.specialized_builds[BuildType.IMAGE]
) )
def __copy_build_resources_from_dir__(self, devops: Devops): def __copy_build_resources_from_dir__(self, devops: Devops):
image = devops.specialized_builds[BuildType.C4K] image = devops.specialized_builds[BuildType.IMAGE]
self.file_api.cp_force( self.file_api.cp_force(
image.build_commons_path(), devops.build_path() image.build_commons_path(), devops.build_path()
) )
def initialize_build_dir(self, devops: Devops): def initialize_build_dir(self, devops: Devops):
image = devops.specialized_builds[BuildType.C4K] image = devops.specialized_builds[BuildType.IMAGE]
build_path = devops.build_path() build_path = devops.build_path()
self.file_api.clean_dir(f"{build_path}/image/resources") self.file_api.clean_dir(f"{build_path}/image/resources")
if image.image_use_package_common_files: if image.image_use_package_common_files:
self.__copy_build_resources_from_package__(image) self.__copy_build_resources_from_package__(devops)
else: else:
self.__copy_build_resources_from_dir__(image) self.__copy_build_resources_from_dir__(devops)
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)
@ -51,13 +51,13 @@ class ImageBuildService:
self.image_api.drun(devops.name) self.image_api.drun(devops.name)
def dockerhub_login(self, devops: Devops): def dockerhub_login(self, devops: Devops):
image = devops.specialized_builds[BuildType.C4K] image = devops.specialized_builds[BuildType.IMAGE]
self.image_api.dockerhub_login( self.image_api.dockerhub_login(
image.image_dockerhub_user, image.image_dockerhub_password image.image_dockerhub_user, image.image_dockerhub_password
) )
def dockerhub_publish(self, devops: Devops): def dockerhub_publish(self, devops: Devops):
image = devops.specialized_builds[BuildType.C4K] image = devops.specialized_builds[BuildType.IMAGE]
if image.image_tag is None or image.image_tag == "": if image.image_tag is None or image.image_tag == "":
raise ValueError(f"image_tag must not be empty.") raise ValueError(f"image_tag must not be empty.")
self.image_api.dockerhub_publish( self.image_api.dockerhub_publish(

View file

@ -25,6 +25,9 @@ class Image(Validateable):
result = [] result = []
result += self.__validate_is_not_empty__("image_dockerhub_user") result += self.__validate_is_not_empty__("image_dockerhub_user")
result += self.__validate_is_not_empty__("image_dockerhub_password") result += self.__validate_is_not_empty__("image_dockerhub_password")
if not self.image_use_package_common_files:
result += self.__validate_is_not_empty__("image_build_commons_path")
result += self.__validate_is_not_empty__("image_build_commons_dir_name")
return result return result
def build_commons_path(self): def build_commons_path(self):

View file

@ -9,7 +9,7 @@ from ..domain import Devops, Image, C4k, Release, BuildFile
class ResourceApi: class ResourceApi:
def read_resource(self, path: str) -> bytes: def read_resource(self, path: str) -> bytes:
return resource_string(__name__, path) return resource_string('src', path)
class FileApi: class FileApi: