Skip to content

Commit

Permalink
feat: redone kea containers for better docker support
Browse files Browse the repository at this point in the history
  • Loading branch information
mglants committed May 13, 2024
1 parent c3ddf75 commit 9de9e71
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 17 deletions.
2 changes: 1 addition & 1 deletion apps/kea-dhcp-sidecar/ci/latest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python

def get_latest(channel):
return "v0.0.1"
return "v0.0.2"

if __name__ == "__main__":
import sys
Expand Down
4 changes: 2 additions & 2 deletions apps/kea-dhcp-sidecar/generate_config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ generate_config() {
PEER_ENTRIES="${PEER_ENTRIES%,}"

# Generate the JSON object with the list of peers
echo "\"peers\": [$PEER_ENTRIES]" > /etc/kea/peers.json
echo "\"peers\": [$PEER_ENTRIES]" > /config/kea/peers.json
# Reload kea-configuration
curl -X POST -H "Content-Type: application/json" -d '{ "command": "config-reload", "service": [ "dhcp4","dhcp6" ] }' http://127.0.0.1:8000/
}
echo "First initialization"
cp /etc/kea/ha-init.json /etc/kea/ha.json
cp /config/kea/ha-init.json /config/kea/ha.json
generate_config
curl -X POST -H "Content-Type: application/json" -d '{ "command": "libreload", "service": [ "dhcp4","dhcp6" ] }' http://127.0.0.1:8000/
curl -X POST -H "Content-Type: application/json" -d '{ "command": "config-reload", "service": [ "dhcp4","dhcp6" ] }' http://127.0.0.1:8000/
Expand Down
21 changes: 15 additions & 6 deletions apps/kea-dhcp/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ RUN cd /tmp/build \
&& autoreconf -if \
&& ./configure \
--prefix=/usr/local \
--sysconfdir=/etc \
--sysconfdir=/config \
--localstatedir=/data \
--runstatedir=/run \
--disable-rpath \
--disable-static \
--with-boost-include \
Expand All @@ -35,10 +37,14 @@ RUN ldconfig /
# Delete unnecessary directory
RUN rm -rf /tmp/root/var/run /tmp/root/usr/local/share/man/* /tmp/root/usr/local/include /tmp/root/usr/include \
/tmp/root/usr/share/kea /tmp/root/usr/share/doc/kea /tmp/root/usr/local/lib/kea/hooks/*.la \
/tmp/root/usr/local/lib/*.la /tmp/root/usr/local/include/*



/tmp/root/usr/local/lib/*.la /tmp/root/usr/local/include/* /tmp/root/data/log/
# Patch config files for patching sockets and logs
COPY ./patches /patches
RUN cd /tmp/root/config/kea && \
patch < /patches/kea-ctrl-agent.patch && \
patch < /patches/kea-dhcp-ddns.patch && \
patch < /patches/kea-dhcp4.patch && \
patch < /patches/kea-dhcp6.patch
# Intermediate container with runtime dependencies
FROM docker.io/python:alpine3.19 as exporter
RUN mkdir /install
Expand Down Expand Up @@ -69,14 +75,17 @@ LABEL org.opencontainers.image.source="https://github.com/isc-projects/kea"
LABEL org.opencontainers.image.documentation="https://kea.readthedocs.io/"
LABEL org.opencontainers.image.vendor="isc-projects"

#Logging
RUN mkdir /var/log/kea
ENV KEA_LOGGER_DESTINATION stdout
ENV KEA_LOCKFILE_DIR /run/kea
# publish port TCP and UDP
EXPOSE 67/UDP 547/TCP 547/UDP 8080 9547

# service running
STOPSIGNAL SIGTERM

# select entrypoint
WORKDIR /etc/kea
COPY ./entrypoint.sh /usr/local/bin/
ENTRYPOINT ["/sbin/tini", "--"]
CMD ["/usr/local/bin/entrypoint.sh"]
Expand Down
16 changes: 8 additions & 8 deletions apps/kea-dhcp/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -e -u

RUNPATH="/usr/local/var/run/kea"
RUNPATH="/run/kea"

if [ -e "${RUNPATH}/kea-dhcp4.kea-dhcp4.pid" ]; then
rm -f "${RUNPATH}/kea-dhcp4.kea-dhcp4.pid"
Expand All @@ -14,14 +14,14 @@ if [ -e "${RUNPATH}/kea-ctrl-agent.kea-ctrl-agent.pid" ]; then
rm -f "${RUNPATH}/kea-ctrl-agent.kea-ctrl-agent.pid"
fi

keactrl start -c /etc/kea/keactrl.conf
keactrl start -c /config/kea/keactrl.conf
sleep 10
set +e +u
if [[ -e /tmp/kea4-ctrl-socket ]] && [[ -e /tmp/kea6-ctrl-socket ]];then
python3 /usr/local/bin/kea-exporter /tmp/kea4-ctrl-socket /tmp/kea6-ctrl-socket
elif [[ -e /tmp/kea4-ctrl-socket ]];then
python3 /usr/local/bin/kea-exporter /tmp/kea4-ctrl-socket
elif [[ -e /tmp/kea6-ctrl-socket ]];then
python3 /usr/local/bin/kea-exporter /tmp/kea6-ctrl-socket
if [[ -e /run/kea/kea-dhcp4-ctrl.sock ]] && [[ -e /run/kea/kea-dhcp6-ctrl.sock ]];then
python3 /usr/local/bin/kea-exporter /run/kea/kea-dhcp4-ctrl.sock /run/kea/kea-dhcp6-ctrl.sock
elif [[ -e /run/kea/kea-dhcp4-ctrl.sock ]];then
python3 /usr/local/bin/kea-exporter /run/kea/kea-dhcp4-ctrl.sock
elif [[ -e /run/kea/kea-dhcp6-ctrl.sock ]];then
python3 /usr/local/bin/kea-exporter /run/kea/kea-dhcp6-ctrl.sock
fi
tail -f /dev/null
30 changes: 30 additions & 0 deletions apps/kea-dhcp/patches/kea-ctrl-agent.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
--- kea-ctrl-agent.conf 2024-05-13 04:17:12
+++ kea-ctrl-agent-new.conf 2024-05-13 04:15:11
@@ -32,15 +32,15 @@
"control-sockets": {
"dhcp4": {
"socket-type": "unix",
- "socket-name": "/tmp/kea4-ctrl-socket"
+ "socket-name": "/run/kea/kea-dhcp4-ctrl.sock"
},
"dhcp6": {
"socket-type": "unix",
- "socket-name": "/tmp/kea6-ctrl-socket"
+ "socket-name": "/run/kea/kea-dhcp6-ctrl.sock"
},
"d2": {
"socket-type": "unix",
- "socket-name": "/tmp/kea-ddns-ctrl-socket"
+ "socket-name": "/run/kea/kea-dhcp-ddns-ctrl.sock"
}
},

@@ -73,7 +73,7 @@
// - syslog (logs to syslog)
// - syslog:name (logs to syslog using specified name)
// Any other value is considered a name of the file
- "output": "/data/log/kea-ctrl-agent.log"
+ "output": "stdout"

// Shorter log pattern suitable for use with systemd,
// avoids redundant information
20 changes: 20 additions & 0 deletions apps/kea-dhcp/patches/kea-dhcp-ddns.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
--- kea-dhcp-ddns.conf 2024-05-13 04:15:43
+++ kea-dhcp-ddns-new.conf 2024-05-13 04:15:38
@@ -23,7 +23,7 @@
"port": 53001,
"control-socket": {
"socket-type": "unix",
- "socket-name": "/tmp/kea-ddns-ctrl-socket"
+ "socket-name": "/run/kea/kea-dhcp-ddns-ctrl.sock"
},
"tsig-keys": [],
"forward-ddns" : {},
@@ -44,7 +44,7 @@
// - syslog (logs to syslog)
// - syslog:name (logs to syslog using specified name)
// Any other value is considered a name of the file
- "output": "/data/log/kea-ddns.log"
+ "output": "stdout"

// Shorter log pattern suitable for use with systemd,
// avoids redundant information
20 changes: 20 additions & 0 deletions apps/kea-dhcp/patches/kea-dhcp4.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
--- kea-dhcp4.conf 2024-05-13 04:15:59
+++ kea-dhcp4-new.conf 2024-05-13 04:15:50
@@ -49,7 +49,7 @@
// more. For detailed description, see Sections 8.8, 16 and 15.
"control-socket": {
"socket-type": "unix",
- "socket-name": "/tmp/kea4-ctrl-socket"
+ "socket-name": "/run/kea/kea-dhcp4-ctrl.sock"
},

// Use Memfile lease database backend to store leases in a CSV file.
@@ -436,7 +436,7 @@
// - syslog (logs to syslog)
// - syslog:name (logs to syslog using specified name)
// Any other value is considered a name of the file
- "output": "/data/log/kea-dhcp4.log"
+ "output": "stdout"

// Shorter log pattern suitable for use with systemd,
// avoids redundant information
20 changes: 20 additions & 0 deletions apps/kea-dhcp/patches/kea-dhcp6.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
--- kea-dhcp6.conf 2024-05-13 04:16:09
+++ kea-dhcp6-new.conf 2024-05-13 04:16:10
@@ -43,7 +43,7 @@
// description, see Sections 9.12, 16 and 15.
"control-socket": {
"socket-type": "unix",
- "socket-name": "/tmp/kea6-ctrl-socket"
+ "socket-name": "/run/kea/kea-dhcp6-ctrl.sock"
},

// Use Memfile lease database backend to store leases in a CSV file.
@@ -395,7 +395,7 @@
// - syslog (logs to syslog)
// - syslog:name (logs to syslog using specified name)
// Any other value is considered a name of the file
- "output": "/data/log/kea-dhcp6.log"
+ "output": "stdout"

// Shorter log pattern suitable for use with systemd,
// avoids redundant information

0 comments on commit 9de9e71

Please sign in to comment.