-
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.
[PINS] Build P4RT container for PINS (#9083)
- Add INCLUDE_PINS to config to enable/disable container - Add Docker files and supporting resources - Add sonic-pins submodule and associated make files Submission containing materials of a third party: Copyright Google LLC; Licensed under Apache 2.0 #### Why I did it Adds P4RT container to SONiC for PINS The P4RT app is covered by this HLD: https://github.com/pins/SONiC/blob/master/doc/pins/p4rt_app_hld.md #### How I did it Followed the pattern and templates used for other SONiC applications #### How to verify it Build SONiC with INCLUDE_P4RT set to "y". Verify that the resulting build has a container called "p4rt" running. You can verify that the service is up by running the following command on the SONiC switch: ```bash sudo netstat -lpnt | grep p4rt ``` You should see the service listening on TCP port 9559. #### Which release branch to backport (provide reason below if selected) None #### Description for the changelog Build P4RT container for PINS
- Loading branch information
Showing
20 changed files
with
288 additions
and
0 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,31 @@ | ||
{% from "dockers/dockerfile-macros.j2" import install_debian_packages, install_python_wheels, copy_files %} | ||
FROM docker-config-engine-buster | ||
|
||
ARG docker_container_name | ||
ARG git_commit | ||
RUN [ -f /etc/rsyslog.conf ] && sed -ri "s/%syslogtag%/$docker_container_name#%syslogtag%/;" /etc/rsyslog.conf | ||
|
||
## Make apt-get non-interactive | ||
ENV DEBIAN_FRONTEND=noninteractive | ||
|
||
RUN apt-get update | ||
|
||
{% if docker_sonic_p4rt_debs.strip() -%} | ||
# Copy locally-built Debian package dependencies | ||
{{ copy_files("debs/", docker_sonic_p4rt_debs.split(' '), "/debs/") }} | ||
|
||
# Install locally-built Debian packages and implicitly install their dependencies | ||
{{ install_debian_packages(docker_sonic_p4rt_debs.split(' ')) }} | ||
{%- endif %} | ||
|
||
RUN apt-get clean -y && \ | ||
apt-get autoclean -y && \ | ||
apt-get autoremove -y && \ | ||
rm -rf /debs | ||
|
||
COPY ["start.sh", "p4rt.sh", "/usr/bin/"] | ||
COPY ["supervisord.conf", "/etc/supervisor/conf.d/"] | ||
COPY ["files/supervisor-proc-exit-listener", "/usr/bin"] | ||
COPY ["critical_processes", "/etc/supervisor"] | ||
|
||
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 @@ | ||
program:p4rt |
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 @@ | ||
#!/usr/bin/env bash | ||
|
||
P4RT_ARGS=" --alsologtostderr --logbuflevel=-1" | ||
|
||
exec /usr/local/bin/p4rt ${P4RT_ARGS} |
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,4 @@ | ||
#!/usr/bin/env bash | ||
|
||
mkdir -p /var/sonic | ||
echo "# Config files managed by sonic-config-engine" > /var/sonic/config_status |
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,49 @@ | ||
[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=50 | ||
|
||
[eventlistener:supervisor-proc-exit-listener] | ||
command=/usr/bin/supervisor-proc-exit-listener --container-name p4rt | ||
events=PROCESS_STATE_EXITED | ||
autostart=true | ||
autorestart=unexpected | ||
|
||
[program:rsyslogd] | ||
command=/usr/sbin/rsyslogd -n -iNONE | ||
priority=1 | ||
autostart=false | ||
autorestart=unexpected | ||
stdout_logfile=syslog | ||
stderr_logfile=syslog | ||
dependent_startup=true | ||
|
||
[program:start] | ||
command=/usr/bin/start.sh | ||
priority=2 | ||
autostart=true | ||
autorestart=false | ||
startsecs=0 | ||
stdout_logfile=syslog | ||
stderr_logfile=syslog | ||
dependent_startup=true | ||
dependent_startup_wait_for=rsyslogd:running | ||
|
||
[program:p4rt] | ||
command=/usr/bin/p4rt.sh | ||
priority=3 | ||
autostart=false | ||
autorestart=false | ||
stdout_logfile=syslog | ||
stderr_logfile=syslog | ||
dependent_startup=true | ||
dependent_startup_wait_for=start:exited |
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,20 @@ | ||
[Unit] | ||
Description=P4RT App container | ||
Requires=database.service | ||
After=database.service swss.service | ||
BindsTo=sonic.target | ||
After=sonic.target | ||
Before=ntp-config.service | ||
StartLimitIntervalSec=1200 | ||
StartLimitBurst=3 | ||
|
||
[Service] | ||
User={{ sonicadmin_user }} | ||
ExecStartPre=/usr/bin/{{docker_container_name}}.sh start | ||
ExecStart=/usr/bin/{{docker_container_name}}.sh wait | ||
ExecStop=/usr/bin/{{docker_container_name}}.sh stop | ||
Restart=always | ||
RestartSec=30 | ||
|
||
[Install] | ||
WantedBy=sonic.target |
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_P4RT)_PATH) | ||
DEP_FILES := $(SONIC_COMMON_FILES_LIST) rules/docker-p4rt.mk rules/docker-p4rt.dep | ||
DEP_FILES += $(SONIC_COMMON_BASE_FILES_LIST) | ||
DEP_FILES += $(shell git ls-files $(DPATH)) | ||
|
||
$(DOCKER_P4RT)_CACHE_MODE := GIT_CONTENT_SHA | ||
$(DOCKER_P4RT)_DEP_FLAGS := $(SONIC_COMMON_FLAGS_LIST) | ||
$(DOCKER_P4RT)_DEP_FILES := $(DEP_FILES) | ||
|
||
$(eval $(call add_dbg_docker,$(DOCKER_P4RT),$(DOCKER_P4RT_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,35 @@ | ||
# docker image for p4rt | ||
|
||
DOCKER_P4RT_STEM = docker-sonic-p4rt | ||
DOCKER_P4RT = $(DOCKER_P4RT_STEM).gz | ||
DOCKER_P4RT_DBG = $(DOCKER_P4RT_STEM)-$(DBG_IMAGE_MARK).gz | ||
|
||
$(DOCKER_P4RT)_PATH = $(DOCKERS_PATH)/$(DOCKER_P4RT_STEM) | ||
|
||
$(DOCKER_P4RT)_DEPENDS += $(SONIC_P4RT) | ||
$(DOCKER_P4RT)_DBG_DEPENDS = $($(DOCKER_CONFIG_ENGINE_BUSTER)_DBG_DEPENDS) | ||
$(DOCKER_P4RT)_DBG_DEPENDS += $(SONIC_P4RT_DBG) $(LIBSWSSCOMMON_DBG) | ||
$(DOCKER_P4RT)_DBG_DEPENDS += $(LIBSAIREDIS_DBG) | ||
$(DOCKER_P4RT)_DBG_IMAGE_PACKAGES = $($(DOCKER_CONFIG_ENGINE_BUSTER)_DBG_IMAGE_PACKAGES) | ||
|
||
$(DOCKER_P4RT)_LOAD_DOCKERS += $(DOCKER_CONFIG_ENGINE_BUSTER) | ||
|
||
$(DOCKER_P4RT)_VERSION = 1.0.0 | ||
$(DOCKER_P4RT)_PACKAGE_NAME = p4rt | ||
$(DOCKER_P4RT)_WARM_SHUTDOWN_BEFORE = swss | ||
$(DOCKER_P4RT)_FAST_SHUTDOWN_BEFORE = swss | ||
|
||
SONIC_DOCKER_IMAGES += $(DOCKER_P4RT) | ||
SONIC_DOCKER_DBG_IMAGES += $(DOCKER_P4RT_DBG) | ||
|
||
ifeq ($(INCLUDE_P4RT), y) | ||
SONIC_INSTALL_DOCKER_IMAGES += $(DOCKER_P4RT) | ||
SONIC_INSTALL_DOCKER_DBG_IMAGES += $(DOCKER_P4RT_DBG) | ||
endif | ||
|
||
$(DOCKER_P4RT)_CONTAINER_NAME = p4rt | ||
$(DOCKER_P4RT)_RUN_OPT += --privileged -t | ||
$(DOCKER_P4RT)_RUN_OPT += -v /etc/sonic:/etc/sonic:ro | ||
$(DOCKER_P4RT)_GIT_COMMIT = $(shell cd "$($(SONIC_P4RT)_SRC_PATH)" && git log -n 1 --format=format:"%H %s" || echo "Unable to fetch git log for p4rt") | ||
|
||
$(DOCKER_P4RT)_FILES += $(SUPERVISOR_PROC_EXIT_LISTENER_SCRIPT) |
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,12 @@ | ||
SPATH := $($(SONIC_P4RT)_SRC_PATH) | ||
DEP_FILES := $(SONIC_COMMON_FILES_LIST) rules/p4rt.mk rules/p4rt.dep | ||
DEP_FILES += $(SONIC_COMMON_BASE_FILES_LIST) $(SPATH)/Makefile | ||
SMDEP_PATH := $(SPATH)/sonic-pins | ||
DEP_FILES += $(shell cd $(SPATH) && git ls-files | grep -v ^sonic-pins) | ||
SMDEP_FILES := $(addprefix $(SMDEP_PATH)/,$(shell cd $(SMDEP_PATH) && git ls-files)) | ||
|
||
$(SONIC_P4RT)_CACHE_MODE := GIT_CONTENT_SHA | ||
$(SONIC_P4RT)_DEP_FLAGS := $(SONIC_COMMON_FLAGS_LIST) | ||
$(SONIC_P4RT)_DEP_FILES := $(DEP_FILES) | ||
$(SONIC_P4RT)_SMDEP_FILES := $(SMDEP_FILES) | ||
$(SONIC_P4RT)_SMDEP_PATHS := $(SMDEP_PATH) |
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,20 @@ | ||
# SONiC P4RT package | ||
|
||
SONIC_P4RT_VERSION = 0.0.1 | ||
|
||
SONIC_P4RT = sonic-p4rt_$(SONIC_P4RT_VERSION)_$(CONFIGURED_ARCH).deb | ||
$(SONIC_P4RT)_SRC_PATH = $(SRC_PATH)/sonic-p4rt | ||
$(SONIC_P4RT)_DEPENDS += $(LIBSWSSCOMMON_DEV) | ||
$(SONIC_P4RT)_RDEPENDS += $(LIBSWSSCOMMON) | ||
SONIC_MAKE_DEBS += $(SONIC_P4RT) | ||
|
||
SONIC_P4RT_DBG = sonic-p4rt-dbgsym_$(SONIC_P4RT_VERSION)_$(CONFIGURED_ARCH).deb | ||
$(SONIC_P4RT_DBG)_DEPENDS += $(SONIC_P4RT) | ||
$(SONIC_P4RT_DBG)_RDEPENDS += $(SONIC_P4RT) | ||
$(eval $(call add_derived_package,$(SONIC_P4RT),$(SONIC_P4RT_DBG))) | ||
|
||
export SONIC_P4RT SONIC_P4RT_DBG SONIC_P4RT_VERSION | ||
|
||
# The .c, .cpp, .h & .hpp files under src/{$DBG_SRC_ARCHIVE list} | ||
# are archived into debug one image to facilitate debugging. | ||
DBG_SRC_ARCHIVE += sonic-p4rt |
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
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,46 @@ | ||
.ONESHELL: | ||
SHELL = /bin/bash | ||
.SHELLFLAGS += -e | ||
|
||
BAZEL_TARGET_PATH = p4rt_app | ||
BAZEL_BUILD_TARGETS = //p4rt_app:p4rt_deb //p4rt_app:p4rt_dbg_deb | ||
|
||
# Enable debug symbols for remote debugging (generate a .dwp). | ||
BAZEL_BUILD_OPTS += --fission=yes --features=per_object_debug_info | ||
|
||
# Override sonic_swss_common to use the version specific to this buildimage. | ||
BAZEL_BUILD_OPTS += --override_repository=sonic_swss_common=/sonic/src/sonic-swss-common | ||
|
||
# Build optimized, stripped binaries. | ||
BAZEL_BUILD_OPTS += -c opt | ||
|
||
# Use a host directory to store Bazel cache, if mounted. This will speed up | ||
# incremental rebuilds on the same system for developers that makes changes | ||
# to sonic-pins code. | ||
# | ||
# To build with Bazel cache, add DOCKER_BUILDER_USER_MOUNT: | ||
# DOCKER_BUILDER_USER_MOUNT=<directory on host system>:$BAZEL_CACHE:rw | ||
# | ||
# For example: | ||
# DOCKER_BUILDER_USER_MOUNT=/tmp/bazel_cache:/bazel:rw make target/... | ||
# | ||
BAZEL_CACHE ?= /bazel | ||
BAZEL_OPTS += $(shell test -d $(BAZEL_CACHE) && echo --output_user_root=$(BAZEL_CACHE)/cache) | ||
|
||
MAIN_TARGET = $(SONIC_P4RT) | ||
DERIVED_TARGETS = $(SONIC_P4RT_DBG) | ||
|
||
$(addprefix $(DEST)/, $(MAIN_TARGET)): $(DEST)/% : | ||
function cleanup { | ||
# Note: make seems to hang if Bazel is still running | ||
cd $(CURDIR)/sonic-pins && bazel $(BAZEL_OPTS) shutdown | ||
} | ||
trap cleanup EXIT | ||
pushd ./sonic-pins | ||
bazel $(BAZEL_OPTS) build $(BAZEL_BUILD_OPTS) $(BAZEL_BUILD_TARGETS) | ||
bazel $(BAZEL_OPTS) test $(BAZEL_BUILD_OPTS) //$(BAZEL_TARGET_PATH)/... | ||
cd ./bazel-bin/$(BAZEL_TARGET_PATH) | ||
mv $* $(DERIVED_TARGETS) $(DEST)/ | ||
popd | ||
|
||
$(addprefix $(DEST)/, $(DERIVED_TARGETS)): $(DEST)/% : $(DEST)/$(MAIN_TARGET) |
Submodule sonic-pins
added at
36322d