From 00623d3840d23f62e3fbdf9be0fdcab11271dc55 Mon Sep 17 00:00:00 2001 From: rcmadhankumar Date: Wed, 16 Oct 2024 14:31:49 +0530 Subject: [PATCH] BCI images added for KEA DHCP --- src/bci_build/package/__init__.py | 21 ++++++++++-- src/bci_build/package/keadhcp.py | 36 +++++++++++++++++++++ src/bci_build/package/keadhcp/README.md.j2 | 36 +++++++++++++++++++++ src/bci_build/package/package_versions.json | 8 ++++- tests/test_package.py | 9 ++++++ 5 files changed, 107 insertions(+), 3 deletions(-) create mode 100644 src/bci_build/package/keadhcp.py create mode 100644 src/bci_build/package/keadhcp/README.md.j2 diff --git a/src/bci_build/package/__init__.py b/src/bci_build/package/__init__.py index f33750fb3..c3adf7b54 100644 --- a/src/bci_build/package/__init__.py +++ b/src/bci_build/package/__init__.py @@ -202,6 +202,9 @@ class BaseContainerImage(abc.ABC): #: An optional list of tcp port exposes, it is omitted if empty or ``None`` exposes_tcp: list[int] | None = None + #: An optional list of udp port exposes, it is omitted if empty or ``None`` + exposes_udp: list[int] | None = None + #: Extra environment variables to be set in the container env: dict[str, str | int] | dict[str, str] | dict[str, int] = field( default_factory=dict @@ -727,6 +730,13 @@ def _dockerfile_volume_expose( entries: list[int] | None, ) -> str: ... + @overload + def _dockerfile_volume_expose( + self, + instruction: Literal["EXPOSEUDP"], + entries: list[int] | None, + ) -> str: ... + @overload def _dockerfile_volume_expose( self, @@ -736,12 +746,15 @@ def _dockerfile_volume_expose( def _dockerfile_volume_expose( self, - instruction: Literal["EXPOSE", "VOLUME"], + instruction: Literal["EXPOSE", "EXPOSEUDP", "VOLUME"], entries: list[int] | list[str] | None, ): if not entries: return "" + if instruction == "EXPOSEUDP": + return "\n" + "EXPOSE " + " ".join(str(e) + "/udp" for e in entries) + return "\n" + f"{instruction} " + " ".join(str(e) for e in entries) @property @@ -750,7 +763,9 @@ def volume_dockerfile(self) -> str: @property def expose_dockerfile(self) -> str: - return self._dockerfile_volume_expose("EXPOSE", self.exposes_tcp) + return self._dockerfile_volume_expose( + "EXPOSE", self.exposes_tcp + ) + self._dockerfile_volume_expose("EXPOSEUDP", self.exposes_udp) @property def kiwi_packages(self) -> str: @@ -1457,6 +1472,7 @@ def generate_disk_size_constraints(size_gb: int) -> str: from .basecontainers import MINIMAL_CONTAINERS # noqa: E402 from .gcc import GCC_CONTAINERS # noqa: E402 from .golang import GOLANG_CONTAINERS # noqa: E402 +from .keadhcp import KEA_DHCP_CONTAINERS # noqa: E402 from .kiwi import KIWI_CONTAINERS # noqa: E402 from .mariadb import MARIADB_CLIENT_CONTAINERS # noqa: E402 from .mariadb import MARIADB_CONTAINERS # noqa: E402 @@ -1517,6 +1533,7 @@ def generate_disk_size_constraints(size_gb: int) -> str: *TOMCAT_CONTAINERS, *GCC_CONTAINERS, *SPACK_CONTAINERS, + *KEA_DHCP_CONTAINERS, ) } diff --git a/src/bci_build/package/keadhcp.py b/src/bci_build/package/keadhcp.py new file mode 100644 index 000000000..0232222da --- /dev/null +++ b/src/bci_build/package/keadhcp.py @@ -0,0 +1,36 @@ +"""KEA DHCP Server BCI container""" + +from bci_build.os_version import ALL_NONBASE_OS_VERSIONS +from bci_build.os_version import CAN_BE_LATEST_OS_VERSION +from bci_build.package import ApplicationStackContainer +from bci_build.package.versions import get_pkg_version + +_BASE_PODMAN_KEA_CMD = "podman run --replace -it --privileged --network=host" +_KEA_DHCP4_CONFIG_PATH = "/etc/kea/kea-dhcp4.conf" +_KEA_DHCP6_CONFIG_PATH = "/etc/kea/kea-dhcp6.conf" + +KEA_DHCP_CONTAINERS = [] + +for os_version in ALL_NONBASE_OS_VERSIONS: + KEA_DHCP_CONTAINERS.append( + ApplicationStackContainer( + name="keadhcp", + os_version=os_version, + version=get_pkg_version("kea", os_version), + license="MPL-2.0", + is_latest=os_version in CAN_BE_LATEST_OS_VERSION, + pretty_name="Kea DHCP Server", + package_list=["kea", "util-linux"], + custom_end=""" +RUN mkdir -p /var/run/kea +""", + extra_labels={ + "run": f"{_BASE_PODMAN_KEA_CMD} --name kea-dhcp4 -v /etc/kea:/etc/kea IMAGE kea-dhcp4 -c {_KEA_DHCP4_CONFIG_PATH}", + "runcwd": f"{_BASE_PODMAN_KEA_CMD} --name kea-dhcp4 -v .:/etc/kea IMAGE kea-dhcp4 -c {_KEA_DHCP4_CONFIG_PATH}", + "run_dhcp6": f"{_BASE_PODMAN_KEA_CMD} --name kea-dhcp6 -v /etc/kea:/etc/kea IMAGE kea-dhcp6 -c {_KEA_DHCP6_CONFIG_PATH}", + "runcwd_dhcp6": f"{_BASE_PODMAN_KEA_CMD} --name kea-dhcp6 -v .:/etc/kea IMAGE kea-dhcp6 -c {_KEA_DHCP6_CONFIG_PATH}", + }, + exposes_tcp=[67], + exposes_udp=[67], + ) + ) diff --git a/src/bci_build/package/keadhcp/README.md.j2 b/src/bci_build/package/keadhcp/README.md.j2 new file mode 100644 index 000000000..436762e82 --- /dev/null +++ b/src/bci_build/package/keadhcp/README.md.j2 @@ -0,0 +1,36 @@ +# {{ image.pretty_name }} container image + +{% include 'badges.j2' %} + + {{ image.description }} + +## How to use this container image + +The container image expects dhcp configuration file in the path /etc/kea. +To run dhcp4 for the configuration provided in the directory /etc/kea + +```ShellSession +podman container runlabel run \ + {{ image.pretty_reference }} +``` +To run dhcp6 for the configuration provided in the directory /etc/kea + +```ShellSession +podman container runlabel run_dhcp6 \ + {{ image.pretty_reference }} +``` + +Dhcp configuration file can also be provided in the current directory. +To run dhcp4 for the configuration provided in the current directory + +```ShellSession +podman container runlabel runcwd \ + {{ image.pretty_reference }} +``` +To run dhcp6 for the configuration provided in the current directory + +```ShellSession +podman container runlabel runcwd_dhcp6 \ + {{ image.pretty_reference }} +``` +{% include 'licensing_and_eula.j2' %} diff --git a/src/bci_build/package/package_versions.json b/src/bci_build/package/package_versions.json index 705788d4f..df1a0c429 100644 --- a/src/bci_build/package/package_versions.json +++ b/src/bci_build/package/package_versions.json @@ -44,5 +44,11 @@ "6": "0.21.2", "7": "0.21.2", "Tumbleweed": "0.22.1" + }, + "kea":{ + "6": "2.6.1", + "7": "2.6.1", + "Tumbleweed": "2.6.1", + "version_format": "minor" } -} \ No newline at end of file +} diff --git a/tests/test_package.py b/tests/test_package.py index e8671b0b1..0deee2105 100644 --- a/tests/test_package.py +++ b/tests/test_package.py @@ -119,6 +119,15 @@ def test_expose_dockerfile(bci: BCI_FIXTURE_RET_T): assert cls(**kwargs, exposes_tcp=[80, 443]).expose_dockerfile == "\nEXPOSE 80 443" +def test_expose_udp_dockerfile(bci: BCI_FIXTURE_RET_T): + cls, kwargs = bci + + assert ( + cls(**kwargs, exposes_udp=[67, 68]).expose_dockerfile + == "\nEXPOSE 67/udp 68/udp" + ) + + def test_no_volume_dockerfile(bci: BCI_FIXTURE_RET_T): cls, kwargs = bci