diff --git a/Makefile b/Makefile index 2231e6d98231..54e853278518 100644 --- a/Makefile +++ b/Makefile @@ -12,6 +12,7 @@ ifeq ($(NOSTRETCH), 0) EXTRA_DOCKER_TARGETS=$(notdir $@) BLDENV=stretch make -f Makefile.work stretch endif BLDENV=buster make -f Makefile.work $@ + BLDENV=buster make -f Makefile.work docker-cleanup jessie: @echo "+++ Making $@ +++" @@ -29,7 +30,7 @@ init: @echo "+++ Making $@ +++" make -f Makefile.work $@ -clean configure reset showtag sonic-slave-build sonic-slave-bash : +clean configure reset docker-cleanup showtag sonic-slave-build sonic-slave-bash : @echo "+++ Making $@ +++" ifeq ($(NOJESSIE), 0) make -f Makefile.work $@ diff --git a/Makefile.work b/Makefile.work index 0d7f62af3917..9c66264fa792 100644 --- a/Makefile.work +++ b/Makefile.work @@ -75,6 +75,7 @@ $(shell rm -f .screen) MAKEFLAGS += -B CONFIGURED_ARCH := $(shell [ -f .arch ] && cat .arch || echo $(PLATFORM_ARCH)) +CONFIGURED_PLATFORM = $(if $(PLATFORM),$(PLATFORM),$(shell cat .platform 2>/dev/null)) ifeq ($(CONFIGURED_ARCH),) override CONFIGURED_ARCH = amd64 endif @@ -115,7 +116,8 @@ $(shell BUILD_SLAVE=y scripts/prepare_docker_buildinfo.sh $(SLAVE_BASE_IMAGE) $( # Add the versions in the tag, if the version change, need to rebuild the slave SLAVE_BASE_TAG = $(shell cat $(SLAVE_DIR)/Dockerfile $(SLAVE_DIR)/buildinfo/versions/versions-* | sha1sum | awk '{print substr($$1,0,11);}') -SLAVE_TAG = $(shell cat $(SLAVE_DIR)/Dockerfile.user $(SLAVE_DIR)/Dockerfile $(SLAVE_DIR)/buildinfo/versions/versions-* | sha1sum | awk '{print substr($$1,0,11);}') +SLAVE_TAG = $(shell (cat $(SLAVE_DIR)/Dockerfile.user $(SLAVE_DIR)/Dockerfile $(SLAVE_DIR)/buildinfo/versions/versions-* .git/HEAD && echo $(USER)/$(PWD)/$(CONFIGURED_PLATFORM)) \ + | sha1sum | awk '{print substr($$1,0,11);}') OVERLAY_MODULE_CHECK := \ lsmod | grep -q "^overlay " &>/dev/null || \ @@ -125,6 +127,14 @@ OVERLAY_MODULE_CHECK := \ BUILD_TIMESTAMP := $(shell date +%Y%m%d\.%H%M%S) +# Create separate Docker lockfiles for saving vs. loading an image. +ifeq ($(DOCKER_LOCKDIR),) +override DOCKER_LOCKDIR := /tmp/docklock +endif +DOCKER_LOCKFILE_SAVE := $(DOCKER_LOCKDIR)/docker_save.lock +$(shell mkdir -m 0777 -p $(DOCKER_LOCKDIR)) +$(shell [ -f $(DOCKER_LOCKFILE_SAVE) ] || (touch $(DOCKER_LOCKFILE_SAVE) && chmod 0777 $(DOCKER_LOCKFILE_SAVE))) + ifeq ($(DOCKER_BUILDER_MOUNT),) override DOCKER_BUILDER_MOUNT := "$(PWD):/sonic" endif @@ -135,6 +145,7 @@ endif DOCKER_RUN := docker run --rm=true --privileged --init \ -v $(DOCKER_BUILDER_MOUNT) \ + -v "$(DOCKER_LOCKDIR):$(DOCKER_LOCKDIR)" \ -w $(DOCKER_BUILDER_WORKDIR) \ -e "http_proxy=$(http_proxy)" \ -e "https_proxy=$(https_proxy)" \ @@ -153,6 +164,31 @@ ifneq ($(SONIC_DPKG_CACHE_SOURCE),) DOCKER_RUN += -v "$(SONIC_DPKG_CACHE_SOURCE):/dpkg_cache:rw" endif + +# User name and tag for "docker-*" images created by native dockerd mode. +ifeq ($(strip $(SONIC_CONFIG_USE_NATIVE_DOCKERD_FOR_BUILD)),y) +DOCKER_USERNAME = -$(USER_LC) +DOCKER_USERTAG = $(SLAVE_TAG) +else +DOCKER_USERNAME = +DOCKER_USERTAG = latest +endif + +# Define canned sequence to clean up Docker image cache. +# - These are the remnants from building the runtime Docker images using native (host) Docker daemon. +# - Image naming convention differs on a shared build system vs. non-shared. +# $(docker-image-cleanup) +ifeq ($(SONIC_CONFIG_USE_NATIVE_DOCKERD_FOR_BUILD),y) +define docker-image-cleanup + @for i in $(shell docker images --quiet --filter 'dangling=true') ; do (docker rmi -f $$i &> /dev/null || true) ; done + @for i in $(shell docker images --quiet docker-*$(DOCKER_USERNAME):$(DOCKER_USERTAG)) ; do (docker rmi -f $$i &> /dev/null || true) ; done +endef +else +define docker-image-cleanup + @: +endef +endif + ifeq ($(SONIC_CONFIG_USE_NATIVE_DOCKERD_FOR_BUILD), y) DOCKER_RUN += -v /var/run/docker.sock:/var/run/docker.sock endif @@ -219,6 +255,7 @@ SONIC_BUILD_INSTRUCTION := make \ BUILD_NUMBER=$(BUILD_NUMBER) \ BUILD_TIMESTAMP=$(BUILD_TIMESTAMP) \ SONIC_IMAGE_VERSION=$(SONIC_IMAGE_VERSION) \ + SLAVE_TAG=$(SLAVE_TAG) \ ENABLE_DHCP_GRAPH_SERVICE=$(ENABLE_DHCP_GRAPH_SERVICE) \ ENABLE_ZTP=$(ENABLE_ZTP) \ SHUTDOWN_BGP_ON_START=$(SHUTDOWN_BGP_ON_START) \ @@ -240,6 +277,11 @@ SONIC_BUILD_INSTRUCTION := make \ SONIC_DPKG_CACHE_SOURCE=$(SONIC_DPKG_CACHE_SOURCE) \ HTTP_PROXY=$(http_proxy) \ HTTPS_PROXY=$(https_proxy) \ + USER_LC=$(USER_LC) \ + DOCKER_USERTAG=$(DOCKER_USERTAG) \ + DOCKER_LOCKDIR=$(DOCKER_LOCKDIR) \ + DOCKER_LOCKFILE_SAVE=$(DOCKER_LOCKFILE_SAVE) \ + SONIC_CONFIG_USE_NATIVE_DOCKERD_FOR_BUILD=$(SONIC_CONFIG_USE_NATIVE_DOCKERD_FOR_BUILD) \ SONIC_INCLUDE_SYSTEM_TELEMETRY=$(INCLUDE_SYSTEM_TELEMETRY) \ SONIC_INCLUDE_RESTAPI=$(INCLUDE_RESTAPI) \ TELEMETRY_WRITABLE=$(TELEMETRY_WRITABLE) \ @@ -286,6 +328,9 @@ else @$(DOCKER_RUN) $(SLAVE_IMAGE):$(SLAVE_TAG) bash -c "$(SONIC_BUILD_INSTRUCTION) $@; scripts/collect_build_version_files.sh \$$?" endif +docker-cleanup: + $(docker-image-cleanup) + sonic-build-hooks: @pushd src/sonic-build-hooks; TRUSTED_GPG_URLS=$(TRUSTED_GPG_URLS) make all; popd @cp src/sonic-build-hooks/buildinfo/sonic-build-hooks* $(SLAVE_DIR)/buildinfo diff --git a/dockers/docker-config-engine-buster/Dockerfile.j2 b/dockers/docker-config-engine-buster/Dockerfile.j2 index 3022546a068c..24d756369caa 100644 --- a/dockers/docker-config-engine-buster/Dockerfile.j2 +++ b/dockers/docker-config-engine-buster/Dockerfile.j2 @@ -1,5 +1,5 @@ {% from "dockers/dockerfile-macros.j2" import install_debian_packages, install_python_wheels, copy_files %} -FROM docker-base-buster +FROM {{ docker_config_engine_buster_load_image }} ## Make apt-get non-interactive ENV DEBIAN_FRONTEND=noninteractive diff --git a/dockers/docker-config-engine-stretch/Dockerfile.j2 b/dockers/docker-config-engine-stretch/Dockerfile.j2 index 813f41bc296b..ea8f28d08e35 100644 --- a/dockers/docker-config-engine-stretch/Dockerfile.j2 +++ b/dockers/docker-config-engine-stretch/Dockerfile.j2 @@ -1,5 +1,5 @@ {% from "dockers/dockerfile-macros.j2" import install_debian_packages, install_python_wheels, copy_files %} -FROM docker-base-stretch +FROM {{ docker_config_engine_stretch_load_image }} ## Make apt-get non-interactive ENV DEBIAN_FRONTEND=noninteractive diff --git a/dockers/docker-config-engine/Dockerfile.j2 b/dockers/docker-config-engine/Dockerfile.j2 index 8790ba67d7f9..82ed3761da25 100644 --- a/dockers/docker-config-engine/Dockerfile.j2 +++ b/dockers/docker-config-engine/Dockerfile.j2 @@ -1,4 +1,4 @@ -FROM docker-base +FROM {{ docker_config_engine_load_image }} ## Make apt-get non-interactive ENV DEBIAN_FRONTEND=noninteractive diff --git a/dockers/docker-database/Dockerfile.j2 b/dockers/docker-database/Dockerfile.j2 index aef22e24379c..c9ea98ce9799 100644 --- a/dockers/docker-database/Dockerfile.j2 +++ b/dockers/docker-database/Dockerfile.j2 @@ -1,5 +1,5 @@ {% from "dockers/dockerfile-macros.j2" import install_debian_packages, install_python_wheels, copy_files %} -FROM docker-config-engine-buster +FROM {{ docker_database_load_image }} ARG docker_container_name RUN [ -f /etc/rsyslog.conf ] && sed -ri "s/%syslogtag%/$docker_container_name#%syslogtag%/;" /etc/rsyslog.conf diff --git a/dockers/docker-dhcp-relay/Dockerfile.j2 b/dockers/docker-dhcp-relay/Dockerfile.j2 index 1100aa510742..ab853be4720d 100644 --- a/dockers/docker-dhcp-relay/Dockerfile.j2 +++ b/dockers/docker-dhcp-relay/Dockerfile.j2 @@ -1,5 +1,5 @@ {% from "dockers/dockerfile-macros.j2" import install_debian_packages, install_python_wheels, copy_files %} -FROM docker-config-engine-buster +FROM {{ docker_dhcp_relay_load_image }} ARG docker_container_name ARG image_version diff --git a/dockers/docker-fpm-frr/Dockerfile.j2 b/dockers/docker-fpm-frr/Dockerfile.j2 index ab8b585899f9..5453e57ee71e 100644 --- a/dockers/docker-fpm-frr/Dockerfile.j2 +++ b/dockers/docker-fpm-frr/Dockerfile.j2 @@ -1,5 +1,5 @@ {% from "dockers/dockerfile-macros.j2" import install_debian_packages, install_python_wheels, copy_files %} -FROM docker-config-engine-buster +FROM {{ docker_fpm_frr_load_image }} ARG docker_container_name ARG frr_user_uid diff --git a/dockers/docker-fpm-gobgp/Dockerfile.j2 b/dockers/docker-fpm-gobgp/Dockerfile.j2 index 65b104e43b26..ccb953f94b09 100644 --- a/dockers/docker-fpm-gobgp/Dockerfile.j2 +++ b/dockers/docker-fpm-gobgp/Dockerfile.j2 @@ -1,4 +1,4 @@ -FROM docker-fpm-quagga +FROM {{ docker_fpm_gobgp_load_image }} ## Make apt-get non-interactive ENV DEBIAN_FRONTEND=noninteractive diff --git a/dockers/docker-fpm-quagga/Dockerfile.j2 b/dockers/docker-fpm-quagga/Dockerfile.j2 index ac382afbe5b2..8fb2554ad99f 100644 --- a/dockers/docker-fpm-quagga/Dockerfile.j2 +++ b/dockers/docker-fpm-quagga/Dockerfile.j2 @@ -1,4 +1,4 @@ -FROM docker-config-engine +FROM {{ docker_fpm_quagga_load_image }} ARG docker_container_name RUN [ -f /etc/rsyslog.conf ] && sed -ri "s/%syslogtag%/$docker_container_name#%syslogtag%/;" /etc/rsyslog.conf diff --git a/dockers/docker-iccpd/Dockerfile.j2 b/dockers/docker-iccpd/Dockerfile.j2 index 51cc306bdd55..00866ff521dd 100644 --- a/dockers/docker-iccpd/Dockerfile.j2 +++ b/dockers/docker-iccpd/Dockerfile.j2 @@ -1,5 +1,5 @@ {% from "dockers/dockerfile-macros.j2" import install_debian_packages, install_python_wheels, copy_files %} -FROM docker-config-engine-buster +FROM {{ docker_iccpd_load_image }} ARG docker_container_name RUN [ -f /etc/rsyslog.conf ] && sed -ri "s/%syslogtag%/$docker_container_name#%syslogtag%/;" /etc/rsyslog.conf diff --git a/dockers/docker-lldp/Dockerfile.j2 b/dockers/docker-lldp/Dockerfile.j2 index a1c7a1c1bee2..0ec7872e76b2 100644 --- a/dockers/docker-lldp/Dockerfile.j2 +++ b/dockers/docker-lldp/Dockerfile.j2 @@ -1,5 +1,5 @@ {% from "dockers/dockerfile-macros.j2" import install_debian_packages, install_python_wheels, copy_files %} -FROM docker-config-engine-buster +FROM {{ docker_lldp_load_image }} ARG docker_container_name ARG image_version diff --git a/dockers/docker-nat/Dockerfile.j2 b/dockers/docker-nat/Dockerfile.j2 index 36a178a68af2..ffd9b26cf0b4 100644 --- a/dockers/docker-nat/Dockerfile.j2 +++ b/dockers/docker-nat/Dockerfile.j2 @@ -1,5 +1,5 @@ {% from "dockers/dockerfile-macros.j2" import install_debian_packages, copy_files %} -FROM docker-config-engine-buster +FROM {{ docker_nat_load_image }} ARG docker_container_name RUN [ -f /etc/rsyslog.conf ] && sed -ri "s/%syslogtag%/$docker_container_name#%syslogtag%/;" /etc/rsyslog.conf diff --git a/dockers/docker-orchagent/Dockerfile.j2 b/dockers/docker-orchagent/Dockerfile.j2 index 17c0983c58b2..4f37057c372e 100755 --- a/dockers/docker-orchagent/Dockerfile.j2 +++ b/dockers/docker-orchagent/Dockerfile.j2 @@ -1,5 +1,5 @@ {% from "dockers/dockerfile-macros.j2" import install_debian_packages, install_python_wheels, copy_files %} -FROM docker-config-engine-buster +FROM {{ docker_orchagent_load_image }} ARG docker_container_name RUN [ -f /etc/rsyslog.conf ] && sed -ri "s/%syslogtag%/$docker_container_name#%syslogtag%/;" /etc/rsyslog.conf diff --git a/dockers/docker-platform-monitor/Dockerfile.j2 b/dockers/docker-platform-monitor/Dockerfile.j2 index 5d4d91d2d69f..12b94c997957 100755 --- a/dockers/docker-platform-monitor/Dockerfile.j2 +++ b/dockers/docker-platform-monitor/Dockerfile.j2 @@ -1,5 +1,5 @@ {% from "dockers/dockerfile-macros.j2" import install_debian_packages, install_python_wheels, copy_files %} -FROM docker-config-engine-buster +FROM {{ docker_platform_monitor_load_image }} ARG docker_container_name ARG image_version diff --git a/dockers/docker-ptf-saithrift/Dockerfile.j2 b/dockers/docker-ptf-saithrift/Dockerfile.j2 index 3076de4878b6..ac5b273d2d7a 100644 --- a/dockers/docker-ptf-saithrift/Dockerfile.j2 +++ b/dockers/docker-ptf-saithrift/Dockerfile.j2 @@ -1,4 +1,4 @@ -FROM docker-ptf +FROM {{ docker_ptf_saithrift_load_image }} ## Make apt-get non-interactive ENV DEBIAN_FRONTEND=noninteractive diff --git a/dockers/docker-router-advertiser/Dockerfile.j2 b/dockers/docker-router-advertiser/Dockerfile.j2 index 7d225cbd4e79..3b64b982ef2a 100644 --- a/dockers/docker-router-advertiser/Dockerfile.j2 +++ b/dockers/docker-router-advertiser/Dockerfile.j2 @@ -1,5 +1,5 @@ {% from "dockers/dockerfile-macros.j2" import install_debian_packages, install_python_wheels, copy_files %} -FROM docker-config-engine-buster +FROM {{ docker_router_advertiser_load_image }} ARG docker_container_name ARG image_version diff --git a/dockers/docker-sflow/Dockerfile.j2 b/dockers/docker-sflow/Dockerfile.j2 index 476ff3514ace..093ff2c324f0 100644 --- a/dockers/docker-sflow/Dockerfile.j2 +++ b/dockers/docker-sflow/Dockerfile.j2 @@ -1,5 +1,5 @@ {% from "dockers/dockerfile-macros.j2" import install_debian_packages, install_python_wheels, copy_files %} -FROM docker-config-engine-buster +FROM {{docker_sflow_load_image}} ARG docker_container_name RUN [ -f /etc/rsyslog.conf ] && sed -ri "s/%syslogtag%/$docker_container_name#%syslogtag%/;" /etc/rsyslog.conf diff --git a/dockers/docker-snmp/Dockerfile.j2 b/dockers/docker-snmp/Dockerfile.j2 index 528189c2014f..ca362c45f4ba 100644 --- a/dockers/docker-snmp/Dockerfile.j2 +++ b/dockers/docker-snmp/Dockerfile.j2 @@ -1,5 +1,5 @@ {% from "dockers/dockerfile-macros.j2" import install_debian_packages, install_python3_wheels, copy_files %} -FROM docker-config-engine-buster +FROM {{ docker_snmp_load_image }} ARG docker_container_name ARG image_version diff --git a/dockers/docker-sonic-mgmt-framework/Dockerfile.j2 b/dockers/docker-sonic-mgmt-framework/Dockerfile.j2 index 5ee8cae84466..f04272dfdb8b 100644 --- a/dockers/docker-sonic-mgmt-framework/Dockerfile.j2 +++ b/dockers/docker-sonic-mgmt-framework/Dockerfile.j2 @@ -1,4 +1,4 @@ -FROM docker-config-engine-buster +FROM {{ docker_sonic_mgmt_framework_load_image }} ARG docker_container_name RUN [ -f /etc/rsyslog.conf ] && sed -ri "s/%syslogtag%/$docker_container_name#%syslogtag%/;" /etc/rsyslog.conf diff --git a/dockers/docker-sonic-restapi/Dockerfile.j2 b/dockers/docker-sonic-restapi/Dockerfile.j2 index 837796e66d82..72f624d07533 100644 --- a/dockers/docker-sonic-restapi/Dockerfile.j2 +++ b/dockers/docker-sonic-restapi/Dockerfile.j2 @@ -1,5 +1,5 @@ {% from "dockers/dockerfile-macros.j2" import install_debian_packages, install_python_wheels, copy_files %} -FROM docker-config-engine-stretch +FROM {{ docker_sonic_restapi_load_image }} ARG docker_container_name RUN [ -f /etc/rsyslog.conf ] && sed -ri "s/%syslogtag%/$docker_container_name#%syslogtag%/;" /etc/rsyslog.conf diff --git a/dockers/docker-sonic-telemetry/Dockerfile.j2 b/dockers/docker-sonic-telemetry/Dockerfile.j2 index 88ff94318208..e70b46072cf6 100644 --- a/dockers/docker-sonic-telemetry/Dockerfile.j2 +++ b/dockers/docker-sonic-telemetry/Dockerfile.j2 @@ -1,5 +1,5 @@ {% from "dockers/dockerfile-macros.j2" import install_debian_packages, install_python_wheels, copy_files %} -FROM docker-config-engine-buster +FROM {{ docker_sonic_telemetry_load_image }} ARG docker_container_name ARG image_version diff --git a/dockers/docker-teamd/Dockerfile.j2 b/dockers/docker-teamd/Dockerfile.j2 index 7f4db2936857..b84441dbff4c 100644 --- a/dockers/docker-teamd/Dockerfile.j2 +++ b/dockers/docker-teamd/Dockerfile.j2 @@ -1,5 +1,5 @@ {% from "dockers/dockerfile-macros.j2" import install_debian_packages, install_python_wheels, copy_files %} -FROM docker-config-engine-buster +FROM {{ docker_teamd_load_image }} ARG docker_container_name RUN [ -f /etc/rsyslog.conf ] && sed -ri "s/%syslogtag%/$docker_container_name#%syslogtag%/;" /etc/rsyslog.conf diff --git a/platform/broadcom/docker-saiserver-brcm/Dockerfile.j2 b/platform/broadcom/docker-saiserver-brcm/Dockerfile.j2 index a4b4fedd39ad..74d9658fe7d8 100644 --- a/platform/broadcom/docker-saiserver-brcm/Dockerfile.j2 +++ b/platform/broadcom/docker-saiserver-brcm/Dockerfile.j2 @@ -1,4 +1,4 @@ -FROM docker-config-engine-buster +FROM {{ docker_saiserver_brcm_load_image }} ARG docker_container_name RUN [ -f /etc/rsyslog.conf ] && sed -ri "s/%syslogtag%/$docker_container_name#%syslogtag%/;" /etc/rsyslog.conf diff --git a/platform/broadcom/docker-syncd-brcm-rpc/Dockerfile.j2 b/platform/broadcom/docker-syncd-brcm-rpc/Dockerfile.j2 index f68fbb661d9c..86baaa1dd144 100644 --- a/platform/broadcom/docker-syncd-brcm-rpc/Dockerfile.j2 +++ b/platform/broadcom/docker-syncd-brcm-rpc/Dockerfile.j2 @@ -1,4 +1,4 @@ -FROM docker-syncd-brcm +FROM {{ docker_syncd_brcm_rpc_load_image }} ## Make apt-get non-interactive ENV DEBIAN_FRONTEND=noninteractive diff --git a/platform/broadcom/docker-syncd-brcm/Dockerfile.j2 b/platform/broadcom/docker-syncd-brcm/Dockerfile.j2 index cf597df680de..fd69bed52881 100755 --- a/platform/broadcom/docker-syncd-brcm/Dockerfile.j2 +++ b/platform/broadcom/docker-syncd-brcm/Dockerfile.j2 @@ -1,5 +1,5 @@ {% from "dockers/dockerfile-macros.j2" import install_debian_packages %} -FROM docker-config-engine-buster +FROM {{ docker_syncd_brcm_load_image }} ARG docker_container_name RUN [ -f /etc/rsyslog.conf ] && sed -ri "s/%syslogtag%/$docker_container_name#%syslogtag%/;" /etc/rsyslog.conf diff --git a/platform/vs/docker-gbsyncd-vs/Dockerfile.j2 b/platform/vs/docker-gbsyncd-vs/Dockerfile.j2 index d740dca663cb..6a025da94770 100644 --- a/platform/vs/docker-gbsyncd-vs/Dockerfile.j2 +++ b/platform/vs/docker-gbsyncd-vs/Dockerfile.j2 @@ -1,4 +1,5 @@ -FROM docker-config-engine-buster + {% from "dockers/dockerfile-macros.j2" import install_debian_packages, install_python_wheels, copy_files %} +FROM {{ docker_gbsyncd_vs_load_image }} ARG docker_container_name RUN [ -f /etc/rsyslog.conf ] && sed -ri "s/%syslogtag%/$docker_container_name#%syslogtag%/;" /etc/rsyslog.conf diff --git a/platform/vs/docker-sonic-vs/Dockerfile.j2 b/platform/vs/docker-sonic-vs/Dockerfile.j2 index 837e8fc3cb66..cfcd5f0c8ec6 100644 --- a/platform/vs/docker-sonic-vs/Dockerfile.j2 +++ b/platform/vs/docker-sonic-vs/Dockerfile.j2 @@ -1,4 +1,4 @@ -FROM docker-config-engine-buster +FROM {{ docker_sonic_vs_load_image }} ARG docker_container_name RUN [ -f /etc/rsyslog.conf ] && sed -ri "s/%syslogtag%/$docker_container_name#%syslogtag%/;" /etc/rsyslog.conf diff --git a/platform/vs/docker-syncd-vs/Dockerfile.j2 b/platform/vs/docker-syncd-vs/Dockerfile.j2 index 1ef1245e14fb..d5815a2de1dc 100644 --- a/platform/vs/docker-syncd-vs/Dockerfile.j2 +++ b/platform/vs/docker-syncd-vs/Dockerfile.j2 @@ -1,4 +1,4 @@ -FROM docker-config-engine-buster +FROM {{ docker_syncd_vs_load_image }} ARG docker_container_name RUN [ -f /etc/rsyslog.conf ] && sed -ri "s/%syslogtag%/$docker_container_name#%syslogtag%/;" /etc/rsyslog.conf diff --git a/rules/config b/rules/config index 39eb786f2ff0..1665ab6cdcf6 100644 --- a/rules/config +++ b/rules/config @@ -29,7 +29,10 @@ DEFAULT_BUILD_LOG_TIMESTAMP = none # SONIC_USE_DOCKER_BUILDKIT = y # SONIC_CONFIG_USE_NATIVE_DOCKERD_FOR_BUILD - use native dockerd for build. -# If set to y SONiC build container will use native dockerd instead of dind for faster build +# If set to y SONiC build container will use native dockerd instead of dind for faster build. +# Special handling of the docker image file names is needed to avoid conflicts with +# other SONiC build jobs on the same server. This requires changes to the Dockerfile.j2 FROM statement +# in the dockers/ and platform/ subdirs to use a variable reference instead of an explicit image name. # SONIC_CONFIG_USE_NATIVE_DOCKERD_FOR_BUILD = y # SONIC_CONFIG_ENABLE_COLORS - enable colored output in build system. diff --git a/rules/functions b/rules/functions index 5ccb111cec72..d6d49bfadb30 100644 --- a/rules/functions +++ b/rules/functions @@ -165,3 +165,7 @@ sudo mount -t overlay overlay -olowerdir=/var/lib/dpkg,upperdir=$$upperdir,workd export SONIC_DPKG_ADMINDIR=$$mergedir trap "sudo umount $$mergedir && rm -rf $$mergedir $$upperdir $$workdir" EXIT endef + +TO_LOWER = $(shell echo $(1) | tr '[:upper:]' '[:lower:]') +TO_UPPER = $(shell echo $(1) | tr '[:lower:]' '[:upper:]') + diff --git a/slave.mk b/slave.mk index 485649e8cf45..10fe9b47c4d5 100644 --- a/slave.mk +++ b/slave.mk @@ -182,6 +182,16 @@ ifeq ($(SONIC_BUILD_JOBS),) override SONIC_BUILD_JOBS := $(SONIC_CONFIG_BUILD_JOBS) endif +ifeq ($(strip $(SONIC_CONFIG_USE_NATIVE_DOCKERD_FOR_BUILD)),y) +DOCKER_IMAGE_REF = $*$(USER_LC):$(DOCKER_USERTAG) +DOCKER_DBG_IMAGE_REF = $*-$(DBG_IMAGE_MARK)$(USER_LC):$(DOCKER_USERTAG) +docker-load-image-get = $(if $(1),$(1)$(USER_LC):$(DOCKER_USERTAG)) +else +DOCKER_IMAGE_REF = $* +DOCKER_DBG_IMAGE_REF = $*-$(DBG_IMAGE_MARK) +docker-load-image-get = $(1) +endif + ifeq ($(VS_PREPARE_MEM),) override VS_PREPARE_MEM := $(DEFAULT_VS_PREPARE_MEM) endif @@ -278,6 +288,69 @@ endif export kernel_procure_method=$(KERNEL_PROCURE_METHOD) export vs_build_prepare_mem=$(VS_PREPARE_MEM) +############################################################################### +## Canned sequences +############################################################################### +## When multiple builds are triggered on the same build server that causes the docker image naming problem because +## all the build jobs are trying to create the same docker image with latest as tag. +## This happens only when sonic docker images are built using native host dockerd. +## +## docker-swss:latest <=SAVE/LOAD=> docker-swss-:latest + +# $(call docker-image-save,from,to) +# Sonic docker images are always created with username as extension. During the save operation, +# it removes the username extension from docker image and saved them as compressed tar file for SONiC image generation. +# The save operation is protected with lock for parallel build. +# +# $(1) => Docker name +# $(2) => Docker target name + +ifeq ($(strip $(SONIC_CONFIG_USE_NATIVE_DOCKERD_FOR_BUILD)),y) +define docker-image-save + @echo "Attempting docker image lock for $(1) save" $(LOG) + $(call MOD_LOCK,$(1),$(DOCKER_LOCKDIR),$(DOCKER_LOCKFILE_SUFFIX),$(DOCKER_LOCKFILE_TIMEOUT)) + @echo "Obtained docker image lock for $(1) save" $(LOG) + @echo "Tagging docker image $(1)$(USER_LC):$(DOCKER_USERTAG) as $(1):latest" $(LOG) + docker tag $(1)$(USER_LC):$(DOCKER_USERTAG) $(1):latest $(LOG) + @echo "Saving docker image $(1):latest" $(LOG) + docker save $(1):latest | gzip -c > $(2) + @echo "Removing docker image $(1):latest" $(LOG) + docker rmi -f $(1):latest $(LOG) + $(call MOD_UNLOCK,$(1)) + @echo "Released docker image lock for $(1) save" $(LOG) + @echo "Removing docker image $(1)$(USER_LC):$(DOCKER_USERTAG)" $(LOG) + docker rmi -f $(1)$(USER_LC):$(DOCKER_USERTAG) $(LOG) +endef + +# $(call docker-image-load,from) +# Sonic docker images are always created with username as extension. During the load operation, +# it loads the docker image from compressed tar file and tag them with username as extension. +# The load operation is protected with lock for parallel build. +# +# $(1) => Docker name +# $(2) => Docker target name +define docker-image-load + @echo "Attempting docker image lock for $(1) load" $(LOG) + $(call MOD_LOCK,$(1),$(DOCKER_LOCKDIR),$(DOCKER_LOCKFILE_SUFFIX),$(DOCKER_LOCKFILE_TIMEOUT)) + @echo "Obtained docker image lock for $(1) load" $(LOG) + @echo "Loading docker image $(TARGET_PATH)/$(1).gz" $(LOG) + docker load -i $(TARGET_PATH)/$(1).gz $(LOG) + @echo "Tagging docker image $(1):latest as $(1)$(USER_LC):$(DOCKER_USERTAG)" $(LOG) + docker tag $(1):latest $(1)$(USER_LC):$(DOCKER_USERTAG) $(LOG) + @echo "Removing docker image $(1):latest" $(LOG) + docker rmi -f $(1):latest $(LOG) + $(call MOD_UNLOCK,$(1)) + @echo "Released docker image lock for $(1) load" $(LOG) +endef +else +define docker-image-save + docker save $(1):latest | gzip -c > $(2) +endef +define docker-image-load + docker load -i $(TARGET_PATH)/$(1).gz $(LOG) +endef +endif + ############################################################################### ## Local targets ############################################################################### @@ -663,9 +736,9 @@ $(addprefix $(TARGET_PATH)/, $(SONIC_SIMPLE_DOCKER_IMAGES)) : $(TARGET_PATH)/%.g --build-arg docker_container_name=$($*.gz_CONTAINER_NAME) \ --label Tag=$(SONIC_IMAGE_VERSION) \ -f $(TARGET_DOCKERFILE)/Dockerfile.buildinfo \ - -t $* $($*.gz_PATH) $(LOG) - scripts/collect_docker_version_files.sh $* $(TARGET_PATH) - docker save $* | gzip -c > $@ + -t $(DOCKER_IMAGE_REF) $($*.gz_PATH) $(LOG) + scripts/collect_docker_version_files.sh $(DOCKER_IMAGE_REF) $(TARGET_PATH) + $(call docker-image-save,$*,$@) # Clean up if [ -f $($*.gz_PATH).patch/series ]; then pushd $($*.gz_PATH) && quilt pop -a -f; [ -d .pc ] && rm -rf .pc; popd; fi $(FOOTER) @@ -737,6 +810,7 @@ $(addprefix $(TARGET_PATH)/, $(DOCKER_IMAGES)) : $(TARGET_PATH)/%.gz : .platform $(eval export $(subst -,_,$(notdir $($*.gz_PATH)))_pydebs=$(shell printf "$(subst $(SPACE),\n,$(call expand,$($*.gz_PYTHON_DEBS)))\n" | awk '!a[$$0]++')) $(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)))_load_image=$(shell printf "$(call docker-load-image-get,$(subst $(SPACE),\n,$(patsubst %.gz,%,$(call expand,$($*.gz_LOAD_DOCKERS)))))\n" | awk '!a[$$0]++')) j2 $($*.gz_PATH)/Dockerfile.j2 > $($*.gz_PATH)/Dockerfile # Prepare docker build info PACKAGE_URL_PREFIX=$(PACKAGE_URL_PREFIX) \ @@ -755,9 +829,9 @@ $(addprefix $(TARGET_PATH)/, $(DOCKER_IMAGES)) : $(TARGET_PATH)/%.gz : .platform --build-arg frr_user_gid=$(FRR_USER_GID) \ --build-arg image_version=$(SONIC_IMAGE_VERSION) \ --label Tag=$(SONIC_IMAGE_VERSION) \ - -t $* $($*.gz_PATH) $(LOG) - scripts/collect_docker_version_files.sh $* $(TARGET_PATH) - docker save $* | gzip -c > $@ + -t $(DOCKER_IMAGE_REF) $($*.gz_PATH) $(LOG) + scripts/collect_docker_version_files.sh $(DOCKER_IMAGE_REF) $(TARGET_PATH) + $(call docker-image-save,$*,$@) # Clean up if [ -f $($*.gz_PATH).patch/series ]; then pushd $($*.gz_PATH) && quilt pop -a -f; [ -d .pc ] && rm -rf .pc; popd; fi @@ -769,7 +843,7 @@ $(addprefix $(TARGET_PATH)/, $(DOCKER_IMAGES)) : $(TARGET_PATH)/%.gz : .platform SONIC_TARGET_LIST += $(addprefix $(TARGET_PATH)/, $(DOCKER_IMAGES)) -# Targets for building docker images +# Targets for building docker debug images $(addprefix $(TARGET_PATH)/, $(DOCKER_DBG_IMAGES)) : $(TARGET_PATH)/%-$(DBG_IMAGE_MARK).gz : .platform docker-start \ $$(addprefix $$($$*.gz_DEBS_PATH)/,$$($$*.gz_DBG_DEPENDS)) \ $$(addsuffix -load,$$(addprefix $(TARGET_PATH)/,$$*.gz)) \ @@ -787,7 +861,7 @@ $(addprefix $(TARGET_PATH)/, $(DOCKER_DBG_IMAGES)) : $(TARGET_PATH)/%-$(DBG_IMAG # 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 + ./build_debug_docker_j2.sh $(DOCKER_IMAGE_REF) $(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 # Prepare docker build info PACKAGE_URL_PREFIX=$(PACKAGE_URL_PREFIX) \ @@ -802,10 +876,11 @@ $(addprefix $(TARGET_PATH)/, $(DOCKER_DBG_IMAGES)) : $(TARGET_PATH)/%-$(DBG_IMAG --build-arg docker_container_name=$($*.gz_CONTAINER_NAME) \ --label Tag=$(SONIC_IMAGE_VERSION) \ --file $($*.gz_PATH)/Dockerfile-dbg \ - -t $*-dbg $($*.gz_PATH) $(LOG) - scripts/collect_docker_version_files.sh $*-dbg $(TARGET_PATH) - docker save $*-dbg | gzip -c > $@ + -t $(DOCKER_DBG_IMAGE_REF) $($*.gz_PATH) $(LOG) + scripts/collect_docker_version_files.sh $(DOCKER_DBG_IMAGE_REF) $(TARGET_PATH) + $(call docker-image-save,$*-$(DBG_IMAGE_MARK),$@) # Clean up + docker rmi -f $(DOCKER_IMAGE_REF) &> /dev/null || true if [ -f $($*.gz_PATH).patch/series ]; then pushd $($*.gz_PATH) && quilt pop -a -f; [ -d .pc ] && rm -rf .pc; popd; fi # Save the target deb into DPKG cache @@ -822,7 +897,7 @@ DOCKER_LOAD_TARGETS = $(addsuffix -load,$(addprefix $(TARGET_PATH)/, \ $(DOCKER_LOAD_TARGETS) : $(TARGET_PATH)/%.gz-load : .platform docker-start $$(TARGET_PATH)/$$*.gz $(HEADER) - docker load -i $(TARGET_PATH)/$*.gz $(LOG) + $(call docker-image-load,$*) $(FOOTER) ###############################################################################