Skip to content

Commit

Permalink
BCI images added for KEA DHCP
Browse files Browse the repository at this point in the history
  • Loading branch information
rcmadhankumar committed Oct 23, 2024
1 parent fe14e57 commit 00623d3
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 3 deletions.
21 changes: 19 additions & 2 deletions src/bci_build/package/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1517,6 +1533,7 @@ def generate_disk_size_constraints(size_gb: int) -> str:
*TOMCAT_CONTAINERS,
*GCC_CONTAINERS,
*SPACK_CONTAINERS,
*KEA_DHCP_CONTAINERS,
)
}

Expand Down
36 changes: 36 additions & 0 deletions src/bci_build/package/keadhcp.py
Original file line number Diff line number Diff line change
@@ -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],
)
)
36 changes: 36 additions & 0 deletions src/bci_build/package/keadhcp/README.md.j2
Original file line number Diff line number Diff line change
@@ -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' %}
8 changes: 7 additions & 1 deletion src/bci_build/package/package_versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
9 changes: 9 additions & 0 deletions tests/test_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 00623d3

Please sign in to comment.