-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Build bmp container into sonic-buildimage (#18946)
Why I did it Build bmp container into sonic-buildimage, and added relevant daemon/file handling. Work item tracking Microsoft ADO (number only):27588893 How I did it Build bmp container into sonic-buildimage, and added relevant daemon/file handling. How to verify it Local build successfully and verified in lab DUT.
- Loading branch information
1 parent
9e888d4
commit f8a78c1
Showing
27 changed files
with
413 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
{% from "dockers/dockerfile-macros.j2" import install_debian_packages, install_python_wheels, copy_files %} | ||
FROM docker-config-engine-bookworm-{{DOCKER_USERNAME}}:{{DOCKER_USERTAG}} | ||
|
||
ARG docker_container_name | ||
ARG image_version | ||
|
||
## Make apt-get non-interactive | ||
ENV DEBIAN_FRONTEND=noninteractive | ||
|
||
# Pass the image_version to container | ||
ENV IMAGE_VERSION=$image_version | ||
|
||
RUN apt-get update | ||
|
||
{% if docker_sonic_bmp_debs.strip() -%} | ||
# Copy locally-built Debian package dependencies | ||
{{ copy_files("debs/", docker_sonic_bmp_debs.split(' '), "/debs/") }} | ||
|
||
# Install locally-built Debian packages and implicitly install their dependencies | ||
{{ install_debian_packages(docker_sonic_bmp_debs.split(' ')) }} | ||
{%- endif %} | ||
|
||
{% if docker_sonic_bmp_whls.strip() %} | ||
# Copy locally-built Python wheel dependencies | ||
{{ copy_files("python-wheels/", docker_sonic_bmp_whls.split(' '), "/python-wheels/") }} | ||
|
||
# Install locally-built Python wheel dependencies | ||
{{ install_python_wheels(docker_sonic_bmp_whls.split(' ')) }} | ||
{% endif %} | ||
|
||
RUN apt-get clean -y && \ | ||
apt-get autoclean - && \ | ||
apt-get autoremove -y && \ | ||
rm -rf /debs && \ | ||
mkdir -p /etc/bmp | ||
|
||
COPY ["bmp.sh", "/usr/bin/"] | ||
COPY ["supervisord.conf", "/etc/supervisor/conf.d/"] | ||
COPY ["files/supervisor-proc-exit-listener", "/usr/bin"] | ||
COPY ["critical_processes", "/etc/supervisor/"] | ||
|
||
RUN chmod +x /usr/bin/bmp.sh | ||
RUN touch /var/log/openbmpd.log | ||
|
||
RUN apt-get clean -y && \ | ||
apt-get autoclean -y && \ | ||
apt-get autoremove -y && \ | ||
rm -rf /debs | ||
|
||
ENTRYPOINT ["/usr/local/bin/supervisord"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
############################################################################### | ||
## Monit configuration for bmp container | ||
############################################################################### | ||
check program container_memory_bmp with path "/usr/bin/memory_checker bmp 419430400" | ||
if status == 3 for 10 times within 20 cycles then exec "/usr/bin/docker exec bmp supervisorctl restart openbmpd" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/usr/bin/env bash | ||
|
||
|
||
if [ "${RUNTIME_OWNER}" == "" ]; then | ||
RUNTIME_OWNER="kube" | ||
fi | ||
|
||
CTR_SCRIPT="/usr/share/sonic/scripts/container_startup.py" | ||
if test -f ${CTR_SCRIPT} | ||
then | ||
${CTR_SCRIPT} -f bmp -o ${RUNTIME_OWNER} -v ${IMAGE_VERSION} | ||
fi | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
group:sonic-bmp | ||
program:openbmpd | ||
program:bmpcfgd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
[supervisord] | ||
logfile_maxbytes=1MB | ||
logfile_backups=2 | ||
nodaemon=true | ||
|
||
[eventlistener:dependent-startup] | ||
command=python3 -m supervisord_dependent_startup | ||
autostart=true | ||
autorestart=unexpected | ||
startretries=0 | ||
exitcodes=0,3 | ||
events=PROCESS_STATE | ||
buffer_size=1024 | ||
|
||
[eventlistener:supervisor-proc-exit-listener] | ||
command=/usr/bin/supervisor-proc-exit-listener --container-name bmp | ||
events=PROCESS_STATE_EXITED,PROCESS_STATE_RUNNING | ||
autostart=true | ||
autorestart=false | ||
buffer_size=1024 | ||
|
||
[program:rsyslogd] | ||
command=/usr/sbin/rsyslogd -n -iNONE | ||
priority=1 | ||
autostart=false | ||
autorestart=true | ||
stdout_logfile=syslog | ||
stderr_logfile=syslog | ||
dependent_startup=true | ||
|
||
[program:bmp] | ||
command=/usr/bin/bmp.sh | ||
priority=2 | ||
autostart=false | ||
autorestart=false | ||
startsecs=0 | ||
stdout_logfile=syslog | ||
stderr_logfile=syslog | ||
dependent_startup=true | ||
dependent_startup_wait_for=rsyslogd:running | ||
|
||
[group:sonic-bmp] | ||
programs=openbmpd,bmpcfgd | ||
|
||
[program:bmpcfgd] | ||
command=python3 /usr/local/bin/bmpcfgd | ||
priority=3 | ||
autostart=false | ||
autorestart=false | ||
stdout_logfile=syslog | ||
stderr_logfile=syslog | ||
dependent_startup=true | ||
|
||
[program:openbmpd] | ||
command=/usr/bin/openbmpd -f -l /var/log/openbmpd.log -c /etc/bmp/openbmpd.conf | ||
priority=3 | ||
autostart=false | ||
autorestart=false | ||
stdout_logfile=syslog | ||
stderr_logfile=syslog | ||
dependent_startup=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[Unit] | ||
Description=BMP container | ||
Requires=database.service | ||
After=database.service | ||
Before=ntp-config.service | ||
BindsTo=sonic.target | ||
After=sonic.target | ||
StartLimitIntervalSec=1200 | ||
StartLimitBurst=3 | ||
|
||
[Service] | ||
User={{ sonicadmin_user }} | ||
ExecStartPre=/usr/local/bin/{{docker_container_name}}.sh start | ||
ExecStart=/usr/local/bin/{{docker_container_name}}.sh wait | ||
ExecStop=/usr/local/bin/{{docker_container_name}}.sh stop | ||
RestartSec=30 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
#!/bin/bash | ||
|
||
function debug() | ||
{ | ||
/usr/bin/logger $1 | ||
} | ||
|
||
function check_warm_boot() | ||
{ | ||
SYSTEM_WARM_START=`$SONIC_DB_CLI STATE_DB hget "WARM_RESTART_ENABLE_TABLE|system" enable` | ||
SERVICE_WARM_START=`$SONIC_DB_CLI STATE_DB hget "WARM_RESTART_ENABLE_TABLE|${SERVICE}" enable` | ||
if [[ x"$SYSTEM_WARM_START" == x"true" ]] || [[ x"$SERVICE_WARM_START" == x"true" ]]; then | ||
WARM_BOOT="true" | ||
else | ||
WARM_BOOT="false" | ||
fi | ||
} | ||
|
||
function check_fast_boot () | ||
{ | ||
SYSTEM_FAST_REBOOT=`sonic-db-cli STATE_DB hget "FAST_RESTART_ENABLE_TABLE|system" enable` | ||
if [[ x"${SYSTEM_FAST_REBOOT}" == x"true" ]]; then | ||
FAST_BOOT="true" | ||
else | ||
FAST_BOOT="false" | ||
fi | ||
} | ||
|
||
function check_redundant_type() | ||
{ | ||
DEVICE_SUBTYPE=`$SONIC_DB_CLI CONFIG_DB hget "DEVICE_METADATA|localhost" subtype` | ||
if [[ x"$DEVICE_SUBTYPE" == x"DualToR" ]]; then | ||
MUX_CONFIG=`show muxcable config` | ||
if [[ $MUX_CONFIG =~ .*active-active.* ]]; then | ||
ACTIVE_ACTIVE="true" | ||
else | ||
ACTIVE_ACTIVE="false" | ||
fi | ||
else | ||
ACTIVE_ACTIVE="false" | ||
fi | ||
CONFIG_KNOB=`$SONIC_DB_CLI CONFIG_DB hget "MUX_LINKMGR|SERVICE_MGMT" kill_radv` | ||
if [[ x"$CONFIG_KNOB" == x"False" ]]; then | ||
ACTIVE_ACTIVE='false' | ||
fi | ||
debug "DEVICE_SUBTYPE: ${DEVICE_SUBTYPE}, CONFIG_KNOB: ${CONFIG_KNOB}" | ||
} | ||
|
||
start() { | ||
debug "Starting ${SERVICE}$DEV service..." | ||
|
||
# start service docker | ||
/usr/bin/${SERVICE}.sh start $DEV | ||
debug "Started ${SERVICE}$DEV service..." | ||
} | ||
|
||
wait() { | ||
/usr/bin/${SERVICE}.sh wait $DEV | ||
} | ||
|
||
stop() { | ||
debug "Stopping ${SERVICE}$DEV service..." | ||
|
||
check_warm_boot | ||
check_fast_boot | ||
check_redundant_type | ||
debug "Warm boot flag: ${SERVICE}$DEV ${WARM_BOOT}." | ||
debug "Fast boot flag: ${SERVICE}$DEV ${FAST_BOOT}." | ||
|
||
# For WARM/FAST boot do not perform service stop | ||
if [[ x"$WARM_BOOT" != x"true" ]] && [[ x"$FAST_BOOT" != x"true" ]]; then | ||
if [[ x"$SERVICE" == x"radv" ]] && [[ x"$ACTIVE_ACTIVE" == x"true" ]]; then | ||
debug "Killing Docker ${SERVICE}${DEV} for active-active dualtor device..." | ||
/usr/bin/${SERVICE}.sh kill $DEV | ||
else | ||
/usr/bin/${SERVICE}.sh stop $DEV | ||
debug "Stopped ${SERVICE}$DEV service..." | ||
fi | ||
else | ||
debug "Killing Docker ${SERVICE}${DEV}..." | ||
/usr/bin/${SERVICE}.sh kill $DEV | ||
fi | ||
} | ||
|
||
DEV=$2 | ||
|
||
SCRIPT_NAME=$(basename -- "$0") | ||
SERVICE="${SCRIPT_NAME%.*}" | ||
NAMESPACE_PREFIX="asic" | ||
if [[ "$DEV" && "$DEV" != *"dpu"* ]]; then | ||
NET_NS="$NAMESPACE_PREFIX$DEV" #name of the network namespace | ||
SONIC_DB_CLI="sonic-db-cli -n $NET_NS" | ||
else | ||
SONIC_DB_CLI="sonic-db-cli" | ||
fi | ||
|
||
case "$1" in | ||
start|wait|stop) | ||
$1 | ||
;; | ||
*) | ||
echo "Usage: $0 {start|wait|stop}" | ||
exit 1 | ||
;; | ||
esac |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
DPATH := $($(DOCKER_BMP)_PATH) | ||
DEP_FILES := $(SONIC_COMMON_FILES_LIST) rules/docker-bmp.mk rules/docker-bmp.dep | ||
DEP_FILES += $(SONIC_COMMON_BASE_FILES_LIST) | ||
DEP_FILES += $(shell git ls-files $(DPATH)) | ||
|
||
$(DOCKER_BMP)_CACHE_MODE := GIT_CONTENT_SHA | ||
$(DOCKER_BMP)_DEP_FLAGS := $(SONIC_COMMON_FLAGS_LIST) | ||
$(DOCKER_BMP)_DEP_FILES := $(DEP_FILES) | ||
|
||
$(eval $(call add_dbg_docker,$(DOCKER_BMP),$(DOCKER_BMP_DBG))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# docker image for BMP agent | ||
|
||
DOCKER_BMP_STEM = docker-sonic-bmp | ||
DOCKER_BMP = $(DOCKER_BMP_STEM).gz | ||
DOCKER_BMP_DBG = $(DOCKER_BMP_STEM)-$(DBG_IMAGE_MARK).gz | ||
|
||
$(DOCKER_BMP)_PATH = $(DOCKERS_PATH)/$(DOCKER_BMP_STEM) | ||
|
||
$(DOCKER_BMP)_DEPENDS += $(LIBSWSSCOMMON) \ | ||
$(SONIC_BMPD) | ||
|
||
$(DOCKER_BMP)_INSTALL_PYTHON_WHEELS = $(SONIC_BMPCFGD) \ | ||
$(SONIC_UTILITIES_PY3) | ||
$(DOCKER_BMP)_INSTALL_DEBS = $(LIBSWSSCOMMON) \ | ||
$(SONIC_BMPD) \ | ||
$(PYTHON3_SWSSCOMMON) \ | ||
$(LIBYANG_PY3) | ||
|
||
$(DOCKER_BMP)_DBG_DEPENDS = $($(DOCKER_CONFIG_ENGINE_BOOKWORM)_DBG_DEPENDS) | ||
|
||
$(DOCKER_BMP)_LOAD_DOCKERS += $(DOCKER_CONFIG_ENGINE_BOOKWORM) | ||
|
||
$(DOCKER_BMP)_VERSION = 1.0.0 | ||
$(DOCKER_BMP)_PACKAGE_NAME = bmp | ||
|
||
$(DOCKER_BMP)_DBG_IMAGE_PACKAGES = $($(DOCKER_CONFIG_ENGINE_BOOKWORM)_DBG_IMAGE_PACKAGES) | ||
|
||
SONIC_DOCKER_IMAGES += $(DOCKER_BMP) | ||
SONIC_BOOKWORM_DOCKERS += $(DOCKER_BMP) | ||
ifeq ($(INCLUDE_SYSTEM_BMP), y) | ||
SONIC_INSTALL_DOCKER_IMAGES += $(DOCKER_BMP) | ||
endif | ||
|
||
SONIC_DOCKER_DBG_IMAGES += $(DOCKER_BMP_DBG) | ||
SONIC_BOOKWORM_DBG_DOCKERS += $(DOCKER_BMP_DBG) | ||
ifeq ($(INCLUDE_SYSTEM_BMP), y) | ||
SONIC_INSTALL_DOCKER_DBG_IMAGES += $(DOCKER_BMP_DBG) | ||
endif | ||
|
||
$(DOCKER_BMP)_CONTAINER_NAME = bmp | ||
$(DOCKER_BMP)_RUN_OPT += -t | ||
$(DOCKER_BMP)_RUN_OPT += -v /etc/sonic:/etc/sonic:ro | ||
$(DOCKER_BMP)_RUN_OPT += -v /etc/timezone:/etc/timezone:ro | ||
$(DOCKER_BMP)_RUN_OPT += -v /var/run/dbus:/var/run/dbus:rw | ||
|
||
$(DOCKER_BMP)_FILES += $(SUPERVISOR_PROC_EXIT_LISTENER_SCRIPT) | ||
$(DOCKER_BMP)_BASE_IMAGE_FILES += monit_bmp:/etc/monit/conf.d |
Oops, something went wrong.