unify image prefixes
This commit is contained in:
parent
72339f62cf
commit
26b76a045a
5 changed files with 117 additions and 91 deletions
|
@ -1,4 +1,4 @@
|
||||||
from src.main.python.ddadevops.domain import Image, Devops
|
from src.main.python.ddadevops.domain import Image, Devops, BuildType
|
||||||
from src.main.python.ddadevops.infrastructure import FileApi, ResourceApi, ImageApi
|
from src.main.python.ddadevops.infrastructure import FileApi, ResourceApi, ImageApi
|
||||||
|
|
||||||
|
|
||||||
|
@ -8,27 +8,27 @@ class ImageBuildService:
|
||||||
self.resource_api = ResourceApi()
|
self.resource_api = ResourceApi()
|
||||||
self.image_api = ImageApi()
|
self.image_api = ImageApi()
|
||||||
|
|
||||||
def __copy_build_resource_file_from_package__(self, resource_name, image: Image):
|
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"src/main/resources/docker/{resource_name}")
|
||||||
self.file_api.write_data_to_file(
|
self.file_api.write_data_to_file(
|
||||||
f"{image.devops.build_path()}/{resource_name}", data
|
f"{devops.build_path()}/{resource_name}", data
|
||||||
)
|
)
|
||||||
|
|
||||||
def __copy_build_resources_from_package__(self, image: Image):
|
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", image
|
"image/resources/install_functions.sh", devops.specialized_builds[BuildType.C4K]
|
||||||
)
|
)
|
||||||
|
|
||||||
def __copy_build_resources_from_dir__(self, image: Image):
|
def __copy_build_resources_from_dir__(self, devops: Devops):
|
||||||
self.file_api.cp_force(
|
self.file_api.cp_force(
|
||||||
image.docker_build_commons_path(), image.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_build
|
image = devops.specialized_builds[BuildType.C4K]
|
||||||
build_path = image.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.use_package_common_files:
|
if image.image_use_package_common_files:
|
||||||
self.__copy_build_resources_from_package__(image)
|
self.__copy_build_resources_from_package__(image)
|
||||||
else:
|
else:
|
||||||
self.__copy_build_resources_from_dir__(image)
|
self.__copy_build_resources_from_dir__(image)
|
||||||
|
@ -36,25 +36,24 @@ class ImageBuildService:
|
||||||
self.file_api.cp_recursive("test", build_path)
|
self.file_api.cp_recursive("test", build_path)
|
||||||
|
|
||||||
def image(self, devops: Devops):
|
def image(self, devops: Devops):
|
||||||
image = devops.specialized_build
|
self.image_api.image(devops.name, devops.build_path())
|
||||||
self.image_api.image(image.devops.name, image.devops.build_path())
|
|
||||||
|
|
||||||
def drun(self, devops: Devops):
|
def drun(self, devops: Devops):
|
||||||
image = devops.specialized_build
|
self.image_api.drun(devops.name)
|
||||||
self.image_api.drun(image.devops.name)
|
|
||||||
|
|
||||||
def dockerhub_login(self, devops: Devops):
|
def dockerhub_login(self, devops: Devops):
|
||||||
image = devops.specialized_build
|
image = devops.specialized_builds[BuildType.C4K]
|
||||||
self.image_api.dockerhub_login(
|
self.image_api.dockerhub_login(
|
||||||
image.dockerhub_user, 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_build
|
image = devops.specialized_builds[BuildType.C4K]
|
||||||
|
if image.image_tag is None or image.image_tag == "":
|
||||||
|
raise ValueError(f"image_tag must not be empty.")
|
||||||
self.image_api.dockerhub_publish(
|
self.image_api.dockerhub_publish(
|
||||||
image.devops.name, image.dockerhub_user, image.docker_publish_tag
|
devops.name, image.image_dockerhub_user, image.image_tag
|
||||||
)
|
)
|
||||||
|
|
||||||
def test(self, devops: Devops):
|
def test(self, devops: Devops):
|
||||||
image = devops.specialized_build
|
self.image_api.test(devops.name, devops.build_path())
|
||||||
self.image_api.test(image.devops.name, image.devops.build_path())
|
|
||||||
|
|
|
@ -2,7 +2,6 @@ from typing import Optional, List
|
||||||
from .common import (
|
from .common import (
|
||||||
filter_none,
|
filter_none,
|
||||||
Validateable,
|
Validateable,
|
||||||
Devops,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -11,23 +10,26 @@ class Image(Validateable):
|
||||||
self,
|
self,
|
||||||
input: dict,
|
input: dict,
|
||||||
):
|
):
|
||||||
self.dockerhub_user = input.get("image_dockerhub_user")
|
self.image_dockerhub_user = input.get("image_dockerhub_user")
|
||||||
self.dockerhub_password = input.get("image_dockerhub_password")
|
self.image_dockerhub_password = input.get("image_dockerhub_password")
|
||||||
# TODO: rename to image_tag
|
self.image_tag = input.get("image_tag")
|
||||||
self.docker_publish_tag = input.get("image_tag")
|
self.image_build_commons_path = input.get("image_build_commons_path")
|
||||||
self.build_commons_path = input.get("image_build_commons_path")
|
self.image_use_package_common_files = input.get(
|
||||||
self.use_package_common_files = input.get("image_use_package_common_files", True)
|
"image_use_package_common_files", True
|
||||||
# TODO: rename to image_build_commons_dir_name
|
)
|
||||||
self.docker_build_commons_dir_name = input.get(
|
self.image_build_commons_dir_name = input.get(
|
||||||
"image_build_commons_dir_name", "docker"
|
"image_build_commons_dir_name", "docker"
|
||||||
)
|
)
|
||||||
|
|
||||||
def validate(self) -> List[str]:
|
def validate(self) -> List[str]:
|
||||||
result = []
|
result = []
|
||||||
result += self.__validate_is_not_empty__("dockerhub_user")
|
result += self.__validate_is_not_empty__("image_dockerhub_user")
|
||||||
result += self.__validate_is_not_empty__("dockerhub_password")
|
result += self.__validate_is_not_empty__("image_dockerhub_password")
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def docker_build_commons_path(self):
|
def build_commons_path(self):
|
||||||
commons_path = [self.build_commons_path, self.docker_build_commons_dir_name]
|
commons_path = [
|
||||||
|
self.image_build_commons_path,
|
||||||
|
self.image_build_commons_dir_name,
|
||||||
|
]
|
||||||
return "/".join(filter_none(commons_path)) + "/"
|
return "/".join(filter_none(commons_path)) + "/"
|
||||||
|
|
|
@ -66,61 +66,3 @@ def test_should_validate_DnsRecord():
|
||||||
|
|
||||||
sut = DnsRecord("name", ipv6="1::")
|
sut = DnsRecord("name", ipv6="1::")
|
||||||
assert sut.is_valid()
|
assert sut.is_valid()
|
||||||
|
|
||||||
def test_version(tmp_path: Path):
|
|
||||||
version = Version(tmp_path, [1, 2, 3])
|
|
||||||
version.increment(ReleaseType.SNAPSHOT)
|
|
||||||
assert version.get_version_string() == "1.2.3-SNAPSHOT"
|
|
||||||
assert version.version_list == [1, 2, 3]
|
|
||||||
assert version.is_snapshot
|
|
||||||
|
|
||||||
version = Version(tmp_path, [1, 2, 3])
|
|
||||||
version.increment(ReleaseType.BUMP)
|
|
||||||
assert version.get_version_string() == "1.2.4-SNAPSHOT"
|
|
||||||
assert version.version_list == [1, 2, 4]
|
|
||||||
assert version.is_snapshot
|
|
||||||
|
|
||||||
version = Version(tmp_path, [1, 2, 3])
|
|
||||||
version.increment(ReleaseType.PATCH)
|
|
||||||
assert version.get_version_string() == "1.2.4"
|
|
||||||
assert version.version_list == [1, 2, 4]
|
|
||||||
assert not version.is_snapshot
|
|
||||||
|
|
||||||
version = Version(tmp_path, [1, 2, 3])
|
|
||||||
version.increment(ReleaseType.MINOR)
|
|
||||||
assert version.get_version_string() == "1.3.0"
|
|
||||||
assert version.version_list == [1, 3, 0]
|
|
||||||
assert not version.is_snapshot
|
|
||||||
|
|
||||||
version = Version(tmp_path, [1, 2, 3])
|
|
||||||
version.increment(ReleaseType.MAJOR)
|
|
||||||
assert version.get_version_string() == "2.0.0"
|
|
||||||
assert version.version_list == [2, 0, 0]
|
|
||||||
assert not version.is_snapshot
|
|
||||||
|
|
||||||
|
|
||||||
def test_release_context(tmp_path):
|
|
||||||
version = Version(tmp_path, [1, 2, 3])
|
|
||||||
release = ReleaseContext(ReleaseType.MINOR, version, "main")
|
|
||||||
|
|
||||||
release_version = release.release_version()
|
|
||||||
assert release_version.get_version_string() in "1.3.0"
|
|
||||||
|
|
||||||
bump_version = release.bump_version()
|
|
||||||
assert bump_version.get_version_string() in "1.3.1-SNAPSHOT"
|
|
||||||
|
|
||||||
|
|
||||||
def test_release(tmp_path):
|
|
||||||
devops = build_devops({})
|
|
||||||
sut = Release(devops, "main", "config_file.json")
|
|
||||||
assert not sut.is_valid()
|
|
||||||
|
|
||||||
sut.set_release_context(
|
|
||||||
ReleaseContext(ReleaseType.MINOR, Version("id", [1, 2, 3]), "main")
|
|
||||||
)
|
|
||||||
assert sut.is_valid()
|
|
||||||
|
|
||||||
|
|
||||||
def test_devops_build_commons_path():
|
|
||||||
sut = build_devops({})
|
|
||||||
assert "docker/" == sut.specialized_builds[BuildType.IMAGE].docker_build_commons_path()
|
|
||||||
|
|
14
src/test/python/domain/test_image.py
Normal file
14
src/test/python/domain/test_image.py
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
from pybuilder.core import Project
|
||||||
|
from pathlib import Path
|
||||||
|
from src.main.python.ddadevops.domain.common import (
|
||||||
|
BuildType,
|
||||||
|
)
|
||||||
|
from .test_helper import build_devops
|
||||||
|
|
||||||
|
|
||||||
|
def test_devops_build_commons_path():
|
||||||
|
sut = build_devops({})
|
||||||
|
image = sut.specialized_builds[BuildType.IMAGE]
|
||||||
|
assert image is not None
|
||||||
|
assert image.is_valid()
|
||||||
|
assert "docker/" == image.build_commons_path()
|
69
src/test/python/domain/test_release.py
Normal file
69
src/test/python/domain/test_release.py
Normal file
|
@ -0,0 +1,69 @@
|
||||||
|
from pybuilder.core import Project
|
||||||
|
from pathlib import Path
|
||||||
|
from src.main.python.ddadevops.domain.common import (
|
||||||
|
Validateable,
|
||||||
|
DnsRecord,
|
||||||
|
Devops,
|
||||||
|
BuildType,
|
||||||
|
)
|
||||||
|
from src.main.python.ddadevops.domain import (
|
||||||
|
Version,
|
||||||
|
ReleaseType,
|
||||||
|
Release,
|
||||||
|
ReleaseContext,
|
||||||
|
)
|
||||||
|
from src.main.python.ddadevops.domain.image import Image
|
||||||
|
from .test_helper import build_devops
|
||||||
|
|
||||||
|
def test_version(tmp_path: Path):
|
||||||
|
version = Version(tmp_path, [1, 2, 3])
|
||||||
|
version.increment(ReleaseType.SNAPSHOT)
|
||||||
|
assert version.get_version_string() == "1.2.3-SNAPSHOT"
|
||||||
|
assert version.version_list == [1, 2, 3]
|
||||||
|
assert version.is_snapshot
|
||||||
|
|
||||||
|
version = Version(tmp_path, [1, 2, 3])
|
||||||
|
version.increment(ReleaseType.BUMP)
|
||||||
|
assert version.get_version_string() == "1.2.4-SNAPSHOT"
|
||||||
|
assert version.version_list == [1, 2, 4]
|
||||||
|
assert version.is_snapshot
|
||||||
|
|
||||||
|
version = Version(tmp_path, [1, 2, 3])
|
||||||
|
version.increment(ReleaseType.PATCH)
|
||||||
|
assert version.get_version_string() == "1.2.4"
|
||||||
|
assert version.version_list == [1, 2, 4]
|
||||||
|
assert not version.is_snapshot
|
||||||
|
|
||||||
|
version = Version(tmp_path, [1, 2, 3])
|
||||||
|
version.increment(ReleaseType.MINOR)
|
||||||
|
assert version.get_version_string() == "1.3.0"
|
||||||
|
assert version.version_list == [1, 3, 0]
|
||||||
|
assert not version.is_snapshot
|
||||||
|
|
||||||
|
version = Version(tmp_path, [1, 2, 3])
|
||||||
|
version.increment(ReleaseType.MAJOR)
|
||||||
|
assert version.get_version_string() == "2.0.0"
|
||||||
|
assert version.version_list == [2, 0, 0]
|
||||||
|
assert not version.is_snapshot
|
||||||
|
|
||||||
|
|
||||||
|
def test_release_context(tmp_path):
|
||||||
|
version = Version(tmp_path, [1, 2, 3])
|
||||||
|
release = ReleaseContext(ReleaseType.MINOR, version, "main")
|
||||||
|
|
||||||
|
release_version = release.release_version()
|
||||||
|
assert release_version.get_version_string() in "1.3.0"
|
||||||
|
|
||||||
|
bump_version = release.bump_version()
|
||||||
|
assert bump_version.get_version_string() in "1.3.1-SNAPSHOT"
|
||||||
|
|
||||||
|
|
||||||
|
def test_release(tmp_path):
|
||||||
|
devops = build_devops({})
|
||||||
|
sut = Release(devops, "main", "config_file.json")
|
||||||
|
assert not sut.is_valid()
|
||||||
|
|
||||||
|
sut.set_release_context(
|
||||||
|
ReleaseContext(ReleaseType.MINOR, Version("id", [1, 2, 3]), "main")
|
||||||
|
)
|
||||||
|
assert sut.is_valid()
|
Loading…
Reference in a new issue