Skip to content

Commit 76b7cb8

Browse files
authored
[dhcp_server] Add dhcp_server container (#14031)
Why I did it Add dhcp_server ipv4 feature to SONiC. HLD: sonic-net/SONiC#1282 How I did it To be clarify: This container is disabled by INCLUDE_DHCP_SERVER = n for now, which would cause container not build. Add INCLUDE_DHCP_SERVER to indicate whether to build dhcp_server container Add docker file for dhcp_server, build and install kea-dhcp4 inside container Add template file for dhcp_server container services. Add entry for dhcp_server to FEATURE table in config_db. How to verify it Build image with INCLUDE_DHCP_SERVER = y to verify: Image can be install successfully without crush. By config feature state dhcp_server enabled to enable dhcp_server.
1 parent b13b41f commit 76b7cb8

File tree

15 files changed

+263
-0
lines changed

15 files changed

+263
-0
lines changed

Makefile.work

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,7 @@ SONIC_BUILD_INSTRUCTION := $(MAKE) \
537537
SONIC_CONFIG_USE_NATIVE_DOCKERD_FOR_BUILD=$(SONIC_CONFIG_USE_NATIVE_DOCKERD_FOR_BUILD) \
538538
SONIC_INCLUDE_SYSTEM_TELEMETRY=$(INCLUDE_SYSTEM_TELEMETRY) \
539539
INCLUDE_DHCP_RELAY=$(INCLUDE_DHCP_RELAY) \
540+
INCLUDE_DHCP_SERVER=$(INCLUDE_DHCP_SERVER) \
540541
INCLUDE_MACSEC=$(INCLUDE_MACSEC) \
541542
SONIC_INCLUDE_RESTAPI=$(INCLUDE_RESTAPI) \
542543
SONIC_INCLUDE_MUX=$(INCLUDE_MUX) \
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
{% from "dockers/dockerfile-macros.j2" import install_debian_packages, install_python_wheels, copy_files %}
2+
FROM docker-config-engine-bullseye-{{DOCKER_USERNAME}}:{{DOCKER_USERTAG}}
3+
4+
ARG docker_container_name
5+
ARG image_version
6+
7+
## Make apt-get non-interactive
8+
ENV DEBIAN_FRONTEND=noninteractive
9+
10+
# Pass the image_version to container
11+
ENV IMAGE_VERSION=$image_version
12+
13+
RUN apt-get update && \
14+
apt-get install -f -y \
15+
tcpdump \
16+
# For kea build environment
17+
automake \
18+
libtool \
19+
pkg-config \
20+
build-essential \
21+
ccache \
22+
# For kea dependancies
23+
libboost-dev \
24+
libboost-system-dev \
25+
liblog4cplus-dev \
26+
libssl-dev
27+
28+
# Install kea from source
29+
RUN apt-get install -f -y devscripts
30+
RUN mkdir kea && cd kea && dget -u http://deb.debian.org/debian/pool/main/i/isc-kea/isc-kea_2.2.0-6.dsc
31+
RUN cd /kea/isc-kea-2.2.0 && autoreconf --install && ./configure --disable-FEATURE \
32+
--enable-static=no --disable-install-configurations --enable-pgsql-ssl=no --with-PACKAGE=no \
33+
&& make -j$(nproc) && make install
34+
# Create run folder for kea
35+
RUN mkdir -p /run/kea
36+
# Create config folder for kea
37+
RUN mkdir -p /etc/kea
38+
# Remove stuff we don't need to reduce image size
39+
RUN cd /usr/local/lib && rm -v *.la && rm -v kea/hooks/*.la
40+
# Strip debug symbols to reduce file size of binaries
41+
Run find /usr/local/sbin/ /usr/local/lib/ -type f -exec strip --strip-unneeded {} \;
42+
# Remove source code
43+
RUN rm -rf /kea
44+
RUN echo "/usr/local/lib/kea/hooks" > /etc/ld.so.conf.d/kea.conf && \
45+
ldconfig
46+
# Remove sbin we don't need
47+
RUN cd /usr/local/sbin && rm -f kea-admin kea-ctrl-agent kea-dhcp-ddns kea-dhcp6 keactrl
48+
# Remove hook lib we don't need
49+
RUN cd /usr/local/lib/kea/hooks && rm -f libdhcp_bootp.so libdhcp_flex_option.so libdhcp_stat_cmds.so
50+
# RUN pip3 install psutil
51+
52+
{% if docker_dhcp_server_debs.strip() -%}
53+
# Copy locally-built Debian package dependencies
54+
{{ copy_files("debs/", docker_dhcp_server_debs.split(' '), "/debs/") }}
55+
56+
# Install locally-built Debian packages and implicitly install their dependencies
57+
{{ install_debian_packages(docker_dhcp_server_debs.split(' ')) }}
58+
{%- endif %}
59+
60+
# Remove build stuff we don't need
61+
RUN apt-get remove -y devscripts \
62+
automake \
63+
libtool \
64+
pkg-config \
65+
build-essential \
66+
ccache
67+
68+
RUN apt-get clean -y && \
69+
apt-get autoclean -y && \
70+
apt-get autoremove -y && \
71+
rm -rf /debs
72+
73+
COPY ["docker_init.sh", "/usr/bin/"]
74+
COPY ["supervisord.conf", "/etc/supervisor/conf.d/"]
75+
COPY ["files/supervisor-proc-exit-listener", "/usr/bin"]
76+
COPY ["critical_processes", "/etc/supervisor/"]
77+
COPY ["cli", "/cli/"]
78+
79+
ENTRYPOINT ["/usr/bin/docker_init.sh"]
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import click
2+
import utilities_common.cli as clicommon
3+
4+
5+
@click.group(cls=clicommon.AliasedGroup, name="dhcp_server")
6+
def dhcp_server():
7+
pass
8+
9+
10+
def register(cli):
11+
# cli.add_command(dhcp_server)
12+
pass
13+
14+
15+
if __name__ == '__main__':
16+
dhcp_server()
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import click
2+
import utilities_common.cli as clicommon
3+
4+
5+
@click.group(cls=clicommon.AbbreviationGroup, name="dhcp_server")
6+
def dhcp_server():
7+
"""config DHCP Server information"""
8+
pass
9+
10+
11+
def register(cli):
12+
# cli.add_command(dhcp_server)
13+
pass
14+
15+
16+
if __name__ == '__main__':
17+
dhcp_server()
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import click
2+
import utilities_common.cli as clicommon
3+
4+
5+
@click.group(cls=clicommon.AliasedGroup, name="dhcp_server")
6+
def dhcp_server():
7+
"""show DHCP Server information"""
8+
pass
9+
10+
11+
def register(cli):
12+
# cli.add_command(dhcp_server)
13+
pass

dockers/docker-dhcp-server/critical_processes

Whitespace-only changes.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env bash
2+
3+
# The docker container should start this script as PID 1, so now that supervisord is
4+
# properly configured, we exec /usr/local/bin/supervisord so that it runs as PID 1 for the
5+
# duration of the container's lifetime
6+
exec /usr/local/bin/supervisord
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
[supervisord]
2+
logfile_maxbytes=1MB
3+
logfile_backups=2
4+
nodaemon=true
5+
6+
[eventlistener:dependent-startup]
7+
command=python3 -m supervisord_dependent_startup
8+
autostart=true
9+
autorestart=unexpected
10+
startretries=0
11+
exitcodes=0,3
12+
events=PROCESS_STATE
13+
buffer_size=1024
14+
15+
[eventlistener:supervisor-proc-exit-listener]
16+
command=/usr/bin/supervisor-proc-exit-listener --container-name dhcp_server
17+
events=PROCESS_STATE_EXITED,PROCESS_STATE_RUNNING
18+
autostart=true
19+
autorestart=unexpected
20+
buffer_size=1024
21+
22+
[program:rsyslogd]
23+
command=/usr/sbin/rsyslogd -n -iNONE
24+
priority=1
25+
autostart=false
26+
autorestart=false
27+
stdout_logfile=syslog
28+
stderr_logfile=syslog
29+
dependent_startup=true
30+
31+
[program:start]
32+
command=/usr/bin/start.sh
33+
priority=2
34+
autostart=false
35+
autorestart=false
36+
startsecs=0
37+
stdout_logfile=syslog
38+
stderr_logfile=syslog
39+
dependent_startup=true
40+
dependent_startup_wait_for=rsyslogd:running
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[Unit]
2+
Description=DHCP server container
3+
Requires=swss.service
4+
After=swss.service
5+
After=syncd.service
6+
BindsTo=sonic.target
7+
After=sonic.target
8+
StartLimitIntervalSec=1200
9+
StartLimitBurst=3
10+
11+
[Service]
12+
User={{ sonicadmin_user }}
13+
ExecStartPre=/usr/bin/{{ docker_container_name }}.sh start
14+
ExecStart=/usr/bin/{{ docker_container_name }}.sh wait
15+
ExecStop=/usr/bin/{{ docker_container_name }}.sh stop
16+
Restart=always
17+
RestartSec=30
18+
19+
[Install]
20+
WantedBy=sonic.target

files/build_templates/docker_image_ctl.j2

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,9 @@ start() {
540540
# TODO: Mellanox will remove the --tmpfs exception after SDK socket path changed in new SDK version
541541
{%- endif %}
542542
docker create {{docker_image_run_opt}} \
543+
{%- if docker_container_name != "dhcp_server" %}
543544
--net=$NET \
545+
{%- endif %}
544546
-e RUNTIME_OWNER=local \
545547
--uts=host \{# W/A: this should be set per-docker, for those dockers which really need host's UTS namespace #}
546548
{%- if install_debug_image == "y" %}

0 commit comments

Comments
 (0)