[build]: Updated Makefile infrastructure to build debug images. (#2753)
* Updated Makefile infrastructure to build debug images. As a sample, platform/broadcom/docker-orchagent-brcm.mk is updated to add a docker-orchagent-brcm-dbg.gz target. Now "BLDENV=stretch make target/docker-orchagent-brcm-dbg.gz" will build the debug image. This debug image can be used in any linux box to inspect core file. If your module's external dependency can be suitably mocked, you my even manually run it inside. "docker run -it --entrypoint=/bin/bash e47a8fb8ed38" You may map the core file path to this docker run. * Dropped the regular binary using DBG_PACKAGES and a small name change to help readability. * Tweaked the changes to retain the existing behavior w.r.t INSTALL_DEBUG_TOOLS=y. When this change ('building debug docker image transparently') is extended to all dockers, this flag would become redundant. Yet, there can be some test based use cases that rely on this flag. Until after all the dockers gets their debug images by default and we switch all use cases of this flag to use the newly built debug images, we need to maintain the existing behavior.
This commit is contained in:
parent
83a76916f7
commit
c846fb9ead
44
build_debug_docker_j2.sh
Executable file
44
build_debug_docker_j2.sh
Executable file
@ -0,0 +1,44 @@
|
||||
#! /bin/bash
|
||||
|
||||
echo "
|
||||
FROM $1
|
||||
|
||||
ARG docker_container_name
|
||||
|
||||
## Make apt-get non-interactive
|
||||
ENV DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
{% if $2 is defined %}
|
||||
{% if $2|length %}
|
||||
|
||||
COPY \
|
||||
{% for deb in $2.split(' ') -%}
|
||||
debs/{{ deb }}{{' '}}
|
||||
{%- endfor -%}
|
||||
debs/
|
||||
|
||||
RUN dpkg -i \
|
||||
{% for deb in $2.split(' ') -%}
|
||||
debs/{{ deb }}{{' '}}
|
||||
{%- endfor %}
|
||||
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
{% if $3 is defined %}
|
||||
{% if $3|length %}
|
||||
|
||||
RUN apt-get install -f -y \
|
||||
{% for dbg in $3.split(' ') -%}
|
||||
{{ dbg }}{{' '}}
|
||||
{%- endfor %}
|
||||
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
|
||||
## Clean up
|
||||
RUN apt-get clean -y; apt-get autoclean -y; apt-get autoremove -y
|
||||
RUN rm -rf /debs
|
||||
|
||||
"
|
@ -1,18 +1,30 @@
|
||||
# docker image for orchagent
|
||||
|
||||
DOCKER_ORCHAGENT_BRCM = docker-orchagent-brcm.gz
|
||||
DOCKER_ORCHAGENT_BRCM_STEM = docker-orchagent-brcm
|
||||
DOCKER_ORCHAGENT_BRCM = $(DOCKER_ORCHAGENT_BRCM_STEM).gz
|
||||
DOCKER_ORCHAGENT_BRCM_DBG = $(DOCKER_ORCHAGENT_BRCM_STEM)$(DBG_IMAGE_MARK).gz
|
||||
|
||||
$(DOCKER_ORCHAGENT_BRCM)_PATH = $(DOCKERS_PATH)/docker-orchagent
|
||||
$(DOCKER_ORCHAGENT_BRCM)_DEPENDS += $(SWSS) $(REDIS_TOOLS)
|
||||
ifeq ($(INSTALL_DEBUG_TOOLS), y)
|
||||
$(DOCKER_ORCHAGENT_BRCM)_DEPENDS += $(SWSS_DBG) \
|
||||
$(DOCKER_ORCHAGENT_BRCM)_DBG_DEPENDS = $(SWSS_DBG) \
|
||||
$(LIBSWSSCOMMON_DBG) \
|
||||
$(LIBSAIREDIS_DBG)
|
||||
ifeq ($(INSTALL_DEBUG_TOOLS), y)
|
||||
$(DOCKER_ORCHAGENT_BRCM)_DEPENDS += $($(DOCKER_ORCHAGENT_BRCM)_DBG_DEPENDS)
|
||||
endif
|
||||
$(DOCKER_ORCHAGENT_BRCM)_DBG_DEPENDS += $($(DOCKER_CONFIG_ENGINE_STRETCH)_DBG_DEPENDS)
|
||||
|
||||
$(DOCKER_ORCHAGENT_BRCM)_LOAD_DOCKERS += $(DOCKER_CONFIG_ENGINE_STRETCH)
|
||||
$(DOCKER_ORCHAGENT_BRCM)_DBG_IMAGE_PACKAGES = $($(DOCKER_CONFIG_ENGINE_STRETCH)_DBG_IMAGE_PACKAGES)
|
||||
|
||||
SONIC_DOCKER_IMAGES += $(DOCKER_ORCHAGENT_BRCM)
|
||||
SONIC_STRETCH_DOCKERS += $(DOCKER_ORCHAGENT_BRCM)
|
||||
SONIC_INSTALL_DOCKER_IMAGES += $(DOCKER_ORCHAGENT_BRCM)
|
||||
|
||||
SONIC_DOCKER_DBG_IMAGES += $(DOCKER_ORCHAGENT_BRCM_DBG)
|
||||
SONIC_STRETCH_DBG_DOCKERS += $(DOCKER_ORCHAGENT_BRCM_DBG)
|
||||
SONIC_INSTALL_DOCKER_DBG_IMAGES += $(DOCKER_ORCHAGENT_BRCM_DBG)
|
||||
|
||||
$(DOCKER_ORCHAGENT_BRCM)_CONTAINER_NAME = swss
|
||||
$(DOCKER_ORCHAGENT_BRCM)_RUN_OPT += --net=host --privileged -t
|
||||
$(DOCKER_ORCHAGENT_BRCM)_RUN_OPT += -v /etc/network/interfaces:/etc/network/interfaces:ro
|
||||
|
@ -5,14 +5,15 @@ $(DOCKER_BASE_STRETCH)_PATH = $(DOCKERS_PATH)/docker-base-stretch
|
||||
$(DOCKER_BASE_STRETCH)_DEPENDS += $(SUPERVISOR)
|
||||
$(DOCKER_BASE_STRETCH)_DEPENDS += $(SOCAT)
|
||||
|
||||
ifeq ($(INSTALL_DEBUG_TOOLS),y)
|
||||
GDB = gdb
|
||||
GDBSERVER = gdbserver
|
||||
VIM = vim
|
||||
OPENSSH = openssh-client
|
||||
SSHPASS = sshpass
|
||||
STRACE = strace
|
||||
$(DOCKER_BASE_STRETCH)_DBG_PACKAGES += $(GDB) $(GDBSERVER) $(VIM) $(OPENSSH) $(SSHPASS) $(STRACE)
|
||||
$(DOCKER_BASE_STRETCH)_DBG_IMAGE_PACKAGES += $(GDB) $(GDBSERVER) $(VIM) $(OPENSSH) $(SSHPASS) $(STRACE)
|
||||
ifeq ($(INSTALL_DEBUG_TOOLS),y)
|
||||
$(DOCKER_BASE_STRETCH)_DBG_PACKAGES += $($(DOCKER_BASE_STRETCH)_DBG_IMAGE_PACKAGES)
|
||||
endif
|
||||
|
||||
SONIC_STRETCH_DOCKERS += $(DOCKER_BASE_STRETCH)
|
||||
|
@ -5,4 +5,8 @@ $(DOCKER_CONFIG_ENGINE_STRETCH)_PATH = $(DOCKERS_PATH)/docker-config-engine-stre
|
||||
$(DOCKER_CONFIG_ENGINE_STRETCH)_PYTHON_WHEELS += $(SWSSSDK_PY2)
|
||||
$(DOCKER_CONFIG_ENGINE_STRETCH)_PYTHON_WHEELS += $(SONIC_CONFIG_ENGINE)
|
||||
$(DOCKER_CONFIG_ENGINE_STRETCH)_LOAD_DOCKERS += $(DOCKER_BASE_STRETCH)
|
||||
|
||||
$(DOCKER_CONFIG_ENGINE_STRETCH)_DBG_DEPENDS = $($(DOCKER_BASE_STRETCH)_DBG_DEPENDS)
|
||||
$(DOCKER_CONFIG_ENGINE_STRETCH)_DBG_IMAGE_PACKAGES = $($(DOCKER_BASE_STRETCH)_DBG_IMAGE_PACKAGES)
|
||||
|
||||
SONIC_STRETCH_DOCKERS += $(DOCKER_CONFIG_ENGINE_STRETCH)
|
||||
|
36
slave.mk
36
slave.mk
@ -36,6 +36,7 @@ PYTHON_WHEELS_PATH = $(TARGET_PATH)/python-wheels
|
||||
PROJECT_ROOT = $(shell pwd)
|
||||
STRETCH_DEBS_PATH = $(TARGET_PATH)/debs/stretch
|
||||
STRETCH_FILES_PATH = $(TARGET_PATH)/files/stretch
|
||||
DBG_IMAGE_MARK = -dbg
|
||||
|
||||
CONFIGURED_PLATFORM := $(shell [ -f .platform ] && cat .platform || echo generic)
|
||||
PLATFORM_PATH = platform/$(CONFIGURED_PLATFORM)
|
||||
@ -475,9 +476,12 @@ SONIC_TARGET_LIST += $(addprefix $(TARGET_PATH)/, $(SONIC_SIMPLE_DOCKER_IMAGES))
|
||||
DOCKER_IMAGES_FOR_INSTALLERS := $(sort $(foreach installer,$(SONIC_INSTALLERS),$($(installer)_DOCKERS)))
|
||||
ifeq ($(BLDENV),stretch)
|
||||
DOCKER_IMAGES := $(SONIC_STRETCH_DOCKERS)
|
||||
DOCKER_DBG_IMAGES := $(SONIC_STRETCH_DBG_DOCKERS)
|
||||
SONIC_STRETCH_DOCKERS_FOR_INSTALLERS = $(filter $(SONIC_STRETCH_DOCKERS),$(DOCKER_IMAGES_FOR_INSTALLERS))
|
||||
SONIC_STRETCH_DBG_DOCKERS_FOR_INSTALLERS = $(filter $(SONIC_STRETCH_DBG_DOCKERS), $(patsubst %.gz,%$(DBG_IMAGE_MARK).gz, $(SONIC_STRETCH_DOCKERS_FOR_INSTALLERS)))
|
||||
else
|
||||
DOCKER_IMAGES := $(filter-out $(SONIC_STRETCH_DOCKERS), $(SONIC_DOCKER_IMAGES))
|
||||
DOCKER_DBG_IMAGES := $(filter-out $(SONIC_STRETCH_DBG_DOCKERS), $(SONIC_DOCKER_DBG_IMAGES))
|
||||
endif
|
||||
|
||||
# Targets for building docker images
|
||||
@ -524,9 +528,37 @@ $(addprefix $(TARGET_PATH)/, $(DOCKER_IMAGES)) : $(TARGET_PATH)/%.gz : .platform
|
||||
|
||||
SONIC_TARGET_LIST += $(addprefix $(TARGET_PATH)/, $(DOCKER_IMAGES))
|
||||
|
||||
# Targets for building docker images
|
||||
$(addprefix $(TARGET_PATH)/, $(DOCKER_DBG_IMAGES)) : $(TARGET_PATH)/%$(DBG_IMAGE_MARK).gz : .platform docker-start \
|
||||
$$(addprefix $(DEBS_PATH)/,$$($$*.gz_DBG_DEPENDS)) \
|
||||
$$(addsuffix -load,$$(addprefix $(TARGET_PATH)/,$$*.gz))
|
||||
$(HEADER)
|
||||
mkdir -p $($*.gz_PATH)/debs $(LOG)
|
||||
sudo mount --bind $(DEBS_PATH) $($*.gz_PATH)/debs $(LOG)
|
||||
# Export variables for j2. Use path for unique variable names, e.g. docker_orchagent_debs
|
||||
$(eval export $(subst -,_,$(notdir $($*.gz_PATH)))_dbg_debs=$(shell printf "$(subst $(SPACE),\n,$(call expand,$($*.gz_DBG_DEPENDS),RDEPENDS))\n" | awk '!a[$$0]++'))
|
||||
$(eval export $(subst -,_,$(notdir $($*.gz_PATH)))_image_dbgs=$(shell printf "$(subst $(SPACE),\n,$(call expand,$($*.gz_DBG_IMAGE_PACKAGES)))\n" | awk '!a[$$0]++'))
|
||||
./build_debug_docker_j2.sh $* $(subst -,_,$(notdir $($*.gz_PATH)))_dbg_debs $(subst -,_,$(notdir $($*.gz_PATH)))_image_dbgs > $($*.gz_PATH)/Dockerfile-dbg.j2
|
||||
j2 $($*.gz_PATH)/Dockerfile-dbg.j2 > $($*.gz_PATH)/Dockerfile-dbg
|
||||
docker info $(LOG)
|
||||
docker build --squash --no-cache \
|
||||
--build-arg http_proxy=$(HTTP_PROXY) \
|
||||
--build-arg https_proxy=$(HTTPS_PROXY) \
|
||||
--build-arg docker_container_name=$($*.gz_CONTAINER_NAME) \
|
||||
--label Tag=$(SONIC_GET_VERSION) \
|
||||
--file $($*.gz_PATH)/Dockerfile-dbg \
|
||||
-t $*-dbg $($*.gz_PATH) $(LOG)
|
||||
docker save $*-dbg | gzip -c > $@
|
||||
# Clean up
|
||||
if [ -f $($*.gz_PATH).patch/series ]; then pushd $($*.gz_PATH) && quilt pop -a -f; popd; fi
|
||||
$(FOOTER)
|
||||
|
||||
SONIC_TARGET_LIST += $(addprefix $(TARGET_PATH)/, $(DOCKER_DBG_IMAGES))
|
||||
|
||||
DOCKER_LOAD_TARGETS = $(addsuffix -load,$(addprefix $(TARGET_PATH)/, \
|
||||
$(SONIC_SIMPLE_DOCKER_IMAGES) \
|
||||
$(DOCKER_IMAGES)))
|
||||
|
||||
$(DOCKER_LOAD_TARGETS) : $(TARGET_PATH)/%.gz-load : .platform docker-start $$(TARGET_PATH)/$$*.gz
|
||||
$(HEADER)
|
||||
docker load -i $(TARGET_PATH)/$*.gz $(LOG)
|
||||
@ -660,6 +692,7 @@ $(SONIC_CLEAN_FILES) : $(FILES_PATH)/%-clean : .platform
|
||||
|
||||
SONIC_CLEAN_TARGETS += $(addsuffix -clean,$(addprefix $(TARGET_PATH)/, \
|
||||
$(SONIC_DOCKER_IMAGES) \
|
||||
$(SONIC_DOCKER_DBG_IMAGES) \
|
||||
$(SONIC_SIMPLE_DOCKER_IMAGES) \
|
||||
$(SONIC_INSTALLERS)))
|
||||
$(SONIC_CLEAN_TARGETS) : $(TARGET_PATH)/%-clean : .platform
|
||||
@ -683,7 +716,8 @@ all : .platform $$(addprefix $(TARGET_PATH)/,$$(SONIC_ALL))
|
||||
|
||||
stretch : $$(addprefix $(DEBS_PATH)/,$$(SONIC_STRETCH_DEBS)) \
|
||||
$$(addprefix $(FILES_PATH)/,$$(SONIC_STRETCH_FILES)) \
|
||||
$$(addprefix $(TARGET_PATH)/,$$(SONIC_STRETCH_DOCKERS_FOR_INSTALLERS))
|
||||
$$(addprefix $(TARGET_PATH)/,$$(SONIC_STRETCH_DOCKERS_FOR_INSTALLERS)) \
|
||||
$$(addprefix $(TARGET_PATH)/,$$(SONIC_STRETCH_DBG_DOCKERS_FOR_INSTALLERS))
|
||||
|
||||
|
||||
###############################################################################
|
||||
|
Loading…
Reference in New Issue
Block a user