From c1f7e32dda27315d45aab3b582fbd72cc804e36e Mon Sep 17 00:00:00 2001 From: Stepan Blyschak Date: Wed, 12 May 2021 15:54:20 +0300 Subject: [PATCH 1/3] [sonic-app-ext] support app extensions installation during build Signed-off-by: Stepan Blyschak --- .../build_templates/sonic_debian_extension.j2 | 22 +++++++++++++++++++ files/scripts/swss.sh | 11 +++++++++- rules/sonic-packages.mk | 9 ++++++++ slave.mk | 18 +++++++++++++-- 4 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 rules/sonic-packages.mk diff --git a/files/build_templates/sonic_debian_extension.j2 b/files/build_templates/sonic_debian_extension.j2 index 274019215bec..ee13fc5c11d4 100644 --- a/files/build_templates/sonic_debian_extension.j2 +++ b/files/build_templates/sonic_debian_extension.j2 @@ -654,6 +654,28 @@ sudo https_proxy=$https_proxy LANG=C chroot $FILESYSTEM_ROOT docker pull k8s.gcr echo "docker images pull complete" {% endif %} +{% macro get_install_options(set_owner, enabled) -%} +{% set args = ["-y", "-v", "DEBUG"] -%} +{% if set_owner -%} +{% set args = args + ["--set-owner", set_owner] -%} +{% endif -%} +{% if enabled == "y" -%} +{% set args = args + ["--enable"] -%} +{% endif -%} +{{ args | join(' ') }} +{% endmacro -%} + +{% for package in sonic_packages.strip().split() -%} +{% set name, repo, version, set_owner, enabled = package.split('|') -%} +sudo LANG=C chroot $FILESYSTEM_ROOT sonic-package-manager repository add {{ name }} {{ repo }} +sudo LANG=C chroot $FILESYSTEM_ROOT sonic-package-manager install {{ name }}=={{ version }} {{ get_install_options(set_owner, enabled) }} +{% endfor -%} + +{% for package in sonic_local_packages.strip().split() -%} +{% set name, path, set_owner, enabled = package.split('|') -%} +sudo LANG=C chroot $FILESYSTEM_ROOT sonic-package-manager install --from-tarball {{ path }} {{ get_install_options(set_owner, enabled) }} +{% endfor -%} + sudo umount $FILESYSTEM_ROOT/target sudo rm -r $FILESYSTEM_ROOT/target if [ $MULTIARCH_QEMU_ENVIRON == y ]; then diff --git a/files/scripts/swss.sh b/files/scripts/swss.sh index 97e50cb975e7..8c280b38d8ea 100755 --- a/files/scripts/swss.sh +++ b/files/scripts/swss.sh @@ -1,8 +1,17 @@ #!/bin/bash -DEPENDENT="radv dhcp_relay" +DEPENDENT="radv" MULTI_INST_DEPENDENT="teamd" +# Update dependent list based on other packages requirements +if [[ -f /etc/sonic/${SERVICE}_dependent ]]; then + DEPENDENT="${DEPENDENT} $(cat /etc/sonic/${SERVICE}_dependent)" +fi + +if [[ -f /etc/sonic/${SERVICE}_multi_inst_dependent ]]; then + MULTI_INST_DEPENDENT="${MULTI_INST_DEPENDENT} cat /etc/sonic/${SERVICE}_multi_inst_dependent" +fi + function debug() { /usr/bin/logger $1 diff --git a/rules/sonic-packages.mk b/rules/sonic-packages.mk new file mode 100644 index 000000000000..47e02001f93b --- /dev/null +++ b/rules/sonic-packages.mk @@ -0,0 +1,9 @@ +# rules to define remote packages that need to be installed +# during SONiC image build + +## Example: +## PACKAGE = my-package +## $(PACKAGE)_REPOSITORY = myrepo/mypackage +## $(PACKAGE)_VERSION = 1.0.0 +## SONIC_PACKAGES += $(PACKAGE) + diff --git a/slave.mk b/slave.mk index 9cce5392cc2c..b249c33edbb7 100644 --- a/slave.mk +++ b/slave.mk @@ -722,6 +722,9 @@ $(addprefix $(TARGET_PATH)/, $(DOCKER_IMAGES)) : $(TARGET_PATH)/%.gz : .platform $$(addprefix $(PYTHON_WHEELS_PATH)/,$$($$*.gz_PYTHON_WHEELS)) \ $$(addsuffix -load,$$(addprefix $(TARGET_PATH)/,$$($$*.gz_LOAD_DOCKERS))) \ $$($$*.gz_PATH)/Dockerfile.j2 \ + $(addprefix $(PYTHON_WHEELS_PATH)/,$(SONIC_UTILITIES_PY3)-install) \ + $(addprefix $(PYTHON_WHEELS_PATH)/,$(SONIC_UTILITIES_PY3)-install) \ + $(addprefix $(DEBS_PATH)/,$(PYTHON3_SWSSCOMMON)-install) \ $(call dpkg_depend,$(TARGET_PATH)/%.gz.dep) $(HEADER) @@ -747,6 +750,7 @@ $(addprefix $(TARGET_PATH)/, $(DOCKER_IMAGES)) : $(TARGET_PATH)/%.gz : .platform $(eval export $(subst -,_,$(notdir $($*.gz_PATH)))_whls=$(shell printf "$(subst $(SPACE),\n,$(call expand,$($*.gz_PYTHON_WHEELS)))\n" | awk '!a[$$0]++')) $(eval export $(subst -,_,$(notdir $($*.gz_PATH)))_dbgs=$(shell printf "$(subst $(SPACE),\n,$(call expand,$($*.gz_DBG_PACKAGES)))\n" | awk '!a[$$0]++')) $(eval export $(subst -,_,$(notdir $($*.gz_PATH)))_pkgs=$(shell printf "$(subst $(SPACE),\n,$(call expand,$($*.gz_APT_PACKAGES)))\n" | awk '!a[$$0]++')) + if [ -d $($*.gz_PATH)/cli-plugin-tests/ ]; then pushd $($*.gz_PATH)/cli-plugin-tests; pytest-$($(SONIC_UTILITIES_PY3)_PYTHON_VERSION) -v $(LOG); popd; fi j2 $($*.gz_PATH)/Dockerfile.j2 > $($*.gz_PATH)/Dockerfile $(call generate_manifest,$*) # Prepare docker build info @@ -873,6 +877,7 @@ $(addprefix $(TARGET_PATH)/, $(SONIC_INSTALLERS)) : $(TARGET_PATH)/% : \ $(SONIC_UTILITIES_DATA) \ $(SONIC_HOST_SERVICES_DATA)) \ $$(addprefix $(TARGET_PATH)/,$$($$*_DOCKERS)) \ + $$(addprefix $(TARGET_PATH)/,$$(SONIC_PACKAGES_LOCAL)) \ $$(addprefix $(FILES_PATH)/,$$($$*_FILES)) \ $(if $(findstring y,$(ENABLE_ZTP)),$(addprefix $(IMAGE_DISTRO_DEBS_PATH)/,$(SONIC_ZTP))) \ $(addprefix $(PYTHON_WHEELS_PATH)/,$(SONIC_UTILITIES_PY3)) \ @@ -923,8 +928,17 @@ $(addprefix $(TARGET_PATH)/, $(SONIC_INSTALLERS)) : $(TARGET_PATH)/% : \ export lazy_installer_debs="$(foreach deb, $($*_LAZY_INSTALLS),$(foreach device, $($(deb)_PLATFORM),$(addprefix $(device)@, $(IMAGE_DISTRO_DEBS_PATH)/$(deb))))" export installer_images="$(foreach docker, $($*_DOCKERS),\ $(addprefix $($(docker)_PACKAGE_NAME)|,\ - $(addprefix $($(docker)_PATH)|,\ - $(addprefix $(TARGET_PATH)/,$(addsuffix :$($(docker)_VERSION),$(docker))))))" + $(addprefix $($(docker)_PATH)|,\ + $(addprefix $(TARGET_PATH)/,$(addsuffix :$($(docker)_VERSION),$(docker))))))" + export sonic_packages="$(foreach package, $(SONIC_PACKAGES),\ + $(addsuffix |$($(package)_DEFAULT_FEATURE_STATE_ENABLED),\ + $(addsuffix |$($(package)_DEFAULT_FEATURE_OWNER),\ + $(addsuffix |$($(package)_VERSION),\ + $(addsuffix |$($(package)_REPOSITORY), $(package))))))" + export sonic_local_packages="$(foreach package, $(SONIC_PACKAGES_LOCAL),\ + $(addsuffix |$($(package)_DEFAULT_FEATURE_STATE_ENABLED),\ + $(addsuffix |$($(package)_DEFAULT_FEATURE_OWNER),\ + $(addsuffix |$(addprefix $(TARGET_PATH)/, $(package)), $(package)))))" export sonic_py_common_py2_wheel_path="$(addprefix $(PYTHON_WHEELS_PATH)/,$(SONIC_PY_COMMON_PY2))" export sonic_py_common_py3_wheel_path="$(addprefix $(PYTHON_WHEELS_PATH)/,$(SONIC_PY_COMMON_PY3))" export config_engine_py2_wheel_path="$(addprefix $(PYTHON_WHEELS_PATH)/,$(SONIC_CONFIG_ENGINE_PY2))" From abe88c0de021d74d4b8073f698c742222f0bd2a4 Mon Sep 17 00:00:00 2001 From: Stepan Blyschak Date: Mon, 31 May 2021 06:32:27 +0000 Subject: [PATCH 2/3] bring back dhcp_relay Signed-off-by: Stepan Blyschak --- files/scripts/swss.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/scripts/swss.sh b/files/scripts/swss.sh index 752e52317d7b..730d75bea2c1 100755 --- a/files/scripts/swss.sh +++ b/files/scripts/swss.sh @@ -1,6 +1,6 @@ #!/bin/bash -DEPENDENT="radv" +DEPENDENT="radv dhcp_relay" MULTI_INST_DEPENDENT="teamd" # Update dependent list based on other packages requirements From 9807d93e902480a83b8112e16a3be946721f0fee Mon Sep 17 00:00:00 2001 From: Stepan Blyschak Date: Fri, 11 Jun 2021 17:53:41 +0000 Subject: [PATCH 3/3] introduce _INSTALL_PYTHON_WHEELS and _INSTALL_DEBS to not install sonic-utilities for dockers that dont need it Signed-off-by: Stepan Blyschak --- slave.mk | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/slave.mk b/slave.mk index 6deebe8511b2..aa86571abff7 100644 --- a/slave.mk +++ b/slave.mk @@ -721,10 +721,9 @@ $(addprefix $(TARGET_PATH)/, $(DOCKER_IMAGES)) : $(TARGET_PATH)/%.gz : .platform $$(addprefix $(PYTHON_DEBS_PATH)/,$$($$*.gz_PYTHON_DEBS)) \ $$(addprefix $(PYTHON_WHEELS_PATH)/,$$($$*.gz_PYTHON_WHEELS)) \ $$(addsuffix -load,$$(addprefix $(TARGET_PATH)/,$$($$*.gz_LOAD_DOCKERS))) \ + $$(addsuffix -install,$$(addprefix $(PYTHON_WHEELS_PATH)/,$$($$*.gz_INSTALL_PYTHON_WHEELS))) \ + $$(addsuffix -install,$$(addprefix $(DEBS_PATH)/,$$($$*.gz_INSTALL_DEBS))) \ $$($$*.gz_PATH)/Dockerfile.j2 \ - $(addprefix $(PYTHON_WHEELS_PATH)/,$(SONIC_UTILITIES_PY3)-install) \ - $(addprefix $(PYTHON_WHEELS_PATH)/,$(SONIC_UTILITIES_PY3)-install) \ - $(addprefix $(DEBS_PATH)/,$(PYTHON3_SWSSCOMMON)-install) \ $(call dpkg_depend,$(TARGET_PATH)/%.gz.dep) $(HEADER)