2018-08-16 17:54:31 -05:00
|
|
|
###############################################################################
|
|
|
|
## Wrapper for starting make inside sonic-slave container
|
|
|
|
#
|
|
|
|
# Supported parameters:
|
|
|
|
#
|
|
|
|
# * PLATFORM: Specific platform we wish to build images for.
|
|
|
|
# * BUILD_NUMBER: Desired version-number to pass to the building-system.
|
|
|
|
# * ENABLE_DHCP_GRAPH_SERVICE: Enables get-graph service to fetch minigraph files
|
|
|
|
# through http.
|
|
|
|
# * SHUTDOWN_BGP_ON_START: Sets admin-down state for all bgp peerings after restart.
|
|
|
|
# * ENABLE_PFCWD_ON_START: Enable PFC Watchdog (PFCWD) on server-facing ports
|
|
|
|
# * by default for TOR switch.
|
2018-10-21 19:20:27 -05:00
|
|
|
# * ENABLE_SYNCD_RPC: Enables rpc-based syncd builds.
|
|
|
|
# * INSTALL_DEBUG_TOOLS: Install debug tools and debug symbol packeages.
|
2018-08-16 17:54:31 -05:00
|
|
|
# * USERNAME: Desired username -- default at rules/config
|
|
|
|
# * PASSWORD: Desired password -- default at rules/config
|
2018-09-12 02:23:00 -05:00
|
|
|
# * KEEP_SLAVE_ON: Keeps slave container up and active after building process concludes.
|
|
|
|
# * Note that rm=true is still set, so once user quits from the docker
|
|
|
|
# * session, the docker will be removed.
|
|
|
|
# * Please note that with current Stretch build structure,
|
|
|
|
# * user of KEEP_SLAVE_ON feature will have to be conscious
|
|
|
|
# * about which docker to stay inside after build is done.
|
|
|
|
# * - If user desires to stay inside Jessie docker, please issue
|
2019-05-27 17:50:51 -05:00
|
|
|
# * make KEEP_SLAVE_ON=yes jessie
|
|
|
|
# * - If user desires to stay inside Stretch docker, please issue
|
|
|
|
# * make NOJESSIE=1 KEEP_SLAVE_ON=yes <any target>
|
2018-08-16 17:54:31 -05:00
|
|
|
# * SOURCE_FOLDER: host path to be mount as /var/$(USER)/src, only effective when KEEP_SLAVE_ON=yes
|
|
|
|
# * SONIC_BUILD_JOBS: Specifying number of concurrent build job(s) to run
|
2019-03-29 17:25:17 -05:00
|
|
|
# * VS_PREPARE_MEM: Prepare memory in VS build (drop cache and compact).
|
|
|
|
# * Default: yes
|
|
|
|
# * Values: yes, no
|
2018-08-16 17:54:31 -05:00
|
|
|
# * KERNEL_PROCURE_METHOD: Specifying method of obtaining kernel Debian package: download or build
|
|
|
|
#
|
|
|
|
###############################################################################
|
|
|
|
|
|
|
|
SHELL = /bin/bash
|
|
|
|
|
|
|
|
USER := $(shell id -un)
|
|
|
|
PWD := $(shell pwd)
|
|
|
|
|
|
|
|
ifeq ($(USER), root)
|
|
|
|
$(error Add your user account to docker group and use your user account to make. root or sudo are not supported!)
|
|
|
|
endif
|
|
|
|
|
2019-07-26 15:13:33 -05:00
|
|
|
# Check for j2cli availability
|
|
|
|
J2_VER := $(shell j2 --version 2>&1 | grep j2cli | awk '{printf $$2}')
|
|
|
|
ifeq ($(J2_VER),)
|
|
|
|
$(error Install j2cli)
|
|
|
|
endif
|
|
|
|
|
2019-07-13 14:43:45 -05:00
|
|
|
# Check for minimum Docker version on build host
|
|
|
|
# Note: Using the greater of CE (17.05.0) and EE (17.06.1) versions that support ARG before FROM
|
|
|
|
docker_min := 17.06.1
|
|
|
|
docker_min_ver := $(shell echo "$(docker_min)" | awk -F. '{printf("%d%03d%03d\n",$$1,$$2,$$3);}' 2>/dev/null)
|
2019-07-23 09:01:21 -05:00
|
|
|
docker_ver := $(shell docker info 2>/dev/null | grep -i "server version" | rev | cut -d' ' -f1 | rev | awk -F. '{printf("%d%03d%03d\n",$$1,$$2,$$3);}' 2>/dev/null)
|
2019-07-31 17:26:00 -05:00
|
|
|
docker_is_valid := $(shell if [[ "$(docker_ver)" -lt $(docker_min_ver) ]] ; then echo "0"; else echo "1"; fi)
|
2019-07-13 14:43:45 -05:00
|
|
|
ifeq (0,$(docker_is_valid))
|
|
|
|
$(error SONiC requires Docker version $(docker_min) or later)
|
|
|
|
endif
|
|
|
|
|
2018-08-16 17:54:31 -05:00
|
|
|
# Remove lock file in case previous run was forcefully stopped
|
|
|
|
$(shell rm -f .screen)
|
|
|
|
|
|
|
|
MAKEFLAGS += -B
|
|
|
|
|
2019-07-26 00:06:41 -05:00
|
|
|
CONFIGURED_ARCH := $(shell [ -f .arch ] && cat .arch || echo $(PLATFORM_ARCH))
|
2019-07-26 15:13:33 -05:00
|
|
|
ifeq ($(CONFIGURED_ARCH),)
|
|
|
|
override CONFIGURED_ARCH = amd64
|
|
|
|
endif
|
2019-07-26 00:06:41 -05:00
|
|
|
ifeq ($(PLATFORM_ARCH),)
|
|
|
|
override PLATFORM_ARCH = $(CONFIGURED_ARCH)
|
|
|
|
endif
|
|
|
|
|
2018-08-16 17:54:31 -05:00
|
|
|
ifeq ($(BLDENV), stretch)
|
|
|
|
SLAVE_DIR = sonic-slave-stretch
|
|
|
|
else
|
|
|
|
SLAVE_DIR = sonic-slave
|
|
|
|
endif
|
2019-07-26 15:13:33 -05:00
|
|
|
SLAVE_BASE_TAG = $(shell CONFIGURED_ARCH=$(CONFIGURED_ARCH) j2 $(SLAVE_DIR)/Dockerfile.j2 > $(SLAVE_DIR)/Dockerfile && sha1sum $(SLAVE_DIR)/Dockerfile | awk '{print substr($$1,0,11);}')
|
|
|
|
SLAVE_TAG = $(shell cat $(SLAVE_DIR)/Dockerfile.user $(SLAVE_DIR)/Dockerfile | sha1sum | awk '{print substr($$1,0,11);}')
|
|
|
|
SLAVE_BASE_IMAGE = $(SLAVE_DIR)-base
|
|
|
|
SLAVE_IMAGE = $(SLAVE_BASE_IMAGE)-$(USER)
|
2018-08-16 17:54:31 -05:00
|
|
|
|
2019-06-20 11:20:34 -05:00
|
|
|
OVERLAY_MODULE_CHECK := \
|
|
|
|
lsmod | grep -q "^overlay " &>/dev/null || \
|
|
|
|
zgrep -q 'CONFIG_OVERLAY_FS=y' /proc/config.gz &>/dev/null || \
|
|
|
|
grep -q 'CONFIG_OVERLAY_FS=y' /boot/config-$(shell uname -r) &>/dev/null || \
|
|
|
|
(echo "ERROR: Module 'overlay' not loaded. Try running 'sudo modprobe overlay'."; exit 1)
|
2018-09-05 00:32:46 -05:00
|
|
|
|
2018-10-04 23:20:01 -05:00
|
|
|
BUILD_TIMESTAMP := $(shell date +%Y%m%d\.%H%M%S)
|
|
|
|
|
2018-11-05 12:44:06 -06:00
|
|
|
ifeq ($(DOCKER_BUILDER_MOUNT),)
|
|
|
|
override DOCKER_BUILDER_MOUNT := "$(PWD):/sonic"
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifeq ($(DOCKER_BUILDER_WORKDIR),)
|
|
|
|
override DOCKER_BUILDER_WORKDIR := "/sonic"
|
|
|
|
endif
|
|
|
|
|
2018-08-16 17:54:31 -05:00
|
|
|
DOCKER_RUN := docker run --rm=true --privileged \
|
2018-11-05 12:44:06 -06:00
|
|
|
-v $(DOCKER_BUILDER_MOUNT) \
|
|
|
|
-w $(DOCKER_BUILDER_WORKDIR) \
|
2018-08-16 17:54:31 -05:00
|
|
|
-e "http_proxy=$(http_proxy)" \
|
|
|
|
-e "https_proxy=$(https_proxy)" \
|
|
|
|
-i$(if $(TERM),t,)
|
|
|
|
|
2018-11-01 20:00:00 -05:00
|
|
|
include rules/config
|
|
|
|
|
|
|
|
ifeq ($(SONIC_CONFIG_USE_NATIVE_DOCKERD_FOR_BUILD), y)
|
|
|
|
DOCKER_RUN += -v /var/run/docker.sock:/var/run/docker.sock
|
|
|
|
endif
|
2019-07-26 00:06:41 -05:00
|
|
|
ifneq (,$(filter $(CONFIGURED_ARCH), armhf arm64))
|
|
|
|
# Multiarch docker cannot start dockerd service due to iptables cannot run over different arch kernel
|
|
|
|
SONIC_SERVICE_DOCKERD_FOR_MULTIARCH=y
|
|
|
|
SONIC_NATIVE_DOCKERD_FOR_MUTLIARCH := dockerd --experimental=true --storage-driver=vfs \
|
|
|
|
--data-root=/var/lib/march/docker/ --exec-root=/var/run/march/docker/ \
|
|
|
|
-H unix:///var/run/march/docker.sock -p /var/run/march/docker.pid
|
|
|
|
DOCKER_RUN += -v /var/run/march/docker.sock:/var/run/docker.sock
|
|
|
|
DOCKER_RUN += -v /var/run/march/docker.pid:/var/run/docker.pid
|
|
|
|
DOCKER_RUN += -v /var/run/march/docker:/var/run/docker
|
|
|
|
DOCKER_RUN += -v /var/lib/march/docker:/var/lib/docker
|
|
|
|
SONIC_USERFACL_DOCKERD_FOR_MUTLIARCH := setfacl -m user:$(USER):rw /var/run/march/docker.sock
|
|
|
|
|
|
|
|
#Override Native config to prevent docker service
|
|
|
|
SONIC_CONFIG_USE_NATIVE_DOCKERD_FOR_BUILD=y
|
|
|
|
|
|
|
|
DOCKER_MULTIARCH_CHECK := docker inspect --type image multiarch/qemu-user-static:register &> /dev/null || (echo "multiarch docker not found ..."; docker run --rm --privileged multiarch/qemu-user-static:register --reset --credential yes)
|
|
|
|
|
2019-10-24 15:50:45 -05:00
|
|
|
DOCKER_SERVICE_SAFE_KILLER := (MARCH_PID=`ps -eo pid,cmd | grep "[0-9] dockerd.*march" | awk '{print $$1}'`; echo "Killing march docker $$MARCH_PID"; [ -z "$$MARCH_PID" ] || sudo kill -9 "$$MARCH_PID";)
|
|
|
|
DOCKER_SERVICE_MULTIARCH_CHECK := ($(DOCKER_SERVICE_SAFE_KILLER); sudo rm -fr /var/run/march/; (echo "Starting docker march service..."; sudo $(SONIC_NATIVE_DOCKERD_FOR_MUTLIARCH) &) &>/dev/null ; sleep 2; sudo $(SONIC_USERFACL_DOCKERD_FOR_MUTLIARCH);)
|
2019-07-26 00:06:41 -05:00
|
|
|
|
|
|
|
# Docker service to load the compiled dockers-*.gz
|
|
|
|
SONIC_NATIVE_DOCKERD_FOR_DOCKERFS := rm -fr $(PWD)/dockerfs/; mkdir -p $(PWD)/dockerfs/; sudo dockerd --storage-driver=overlay2 --iptables=false \
|
|
|
|
--data-root $(PWD)/dockerfs/var/lib/docker/ --exec-root=$(PWD)/dockerfs/var/run/docker/ \
|
|
|
|
-H unix://$(PWD)/dockerfs/var/run/docker.sock -p $(PWD)/dockerfs/var/run/docker.pid &
|
|
|
|
SONIC_USERFACL_DOCKERD_FOR_DOCKERFS := setfacl -m user:$(USER):rw $(PWD)/dockerfs/var/run/docker.sock
|
|
|
|
DOCKER_SERVICE_DOCKERFS_CHECK := (sudo docker -H unix://$(PWD)/dockerfs/var/run/docker.sock info &> /dev/null && sudo kill -9 `sudo cat $(PWD)/dockerfs/var/run/docker.pid` && false) || (echo "Starting docker build service..."; (sudo $(SONIC_NATIVE_DOCKERD_FOR_DOCKERFS) ) &>/dev/null ; sleep 1; sudo $(SONIC_USERFACL_DOCKERD_FOR_DOCKERFS);)
|
|
|
|
|
|
|
|
endif
|
2018-11-01 20:00:00 -05:00
|
|
|
|
2018-08-16 17:54:31 -05:00
|
|
|
DOCKER_BASE_BUILD = docker build --no-cache \
|
2019-07-13 14:43:45 -05:00
|
|
|
-t $(SLAVE_BASE_IMAGE):$(SLAVE_BASE_TAG) \
|
2018-08-16 17:54:31 -05:00
|
|
|
--build-arg http_proxy=$(http_proxy) \
|
|
|
|
--build-arg https_proxy=$(https_proxy) \
|
2019-07-13 14:43:45 -05:00
|
|
|
$(SLAVE_DIR)
|
2018-08-16 17:54:31 -05:00
|
|
|
|
|
|
|
DOCKER_BUILD = docker build --no-cache \
|
|
|
|
--build-arg user=$(USER) \
|
|
|
|
--build-arg uid=$(shell id -u) \
|
|
|
|
--build-arg guid=$(shell id -g) \
|
|
|
|
--build-arg hostname=$(shell echo $$HOSTNAME) \
|
2019-07-13 14:43:45 -05:00
|
|
|
--build-arg slave_base_tag_ref=$(SLAVE_BASE_TAG) \
|
|
|
|
-t $(SLAVE_IMAGE):$(SLAVE_TAG) \
|
2018-08-16 17:54:31 -05:00
|
|
|
-f $(SLAVE_DIR)/Dockerfile.user \
|
2019-07-13 14:43:45 -05:00
|
|
|
$(SLAVE_DIR)
|
2018-08-16 17:54:31 -05:00
|
|
|
|
|
|
|
SONIC_BUILD_INSTRUCTION := make \
|
|
|
|
-f slave.mk \
|
2019-02-05 00:06:37 -06:00
|
|
|
BLDENV=$(BLDENV) \
|
2018-08-16 17:54:31 -05:00
|
|
|
PLATFORM=$(PLATFORM) \
|
2019-07-26 00:06:41 -05:00
|
|
|
PLATFORM_ARCH=$(PLATFORM_ARCH) \
|
2018-08-16 17:54:31 -05:00
|
|
|
BUILD_NUMBER=$(BUILD_NUMBER) \
|
2018-10-04 23:20:01 -05:00
|
|
|
BUILD_TIMESTAMP=$(BUILD_TIMESTAMP) \
|
2018-08-16 17:54:31 -05:00
|
|
|
ENABLE_DHCP_GRAPH_SERVICE=$(ENABLE_DHCP_GRAPH_SERVICE) \
|
|
|
|
SHUTDOWN_BGP_ON_START=$(SHUTDOWN_BGP_ON_START) \
|
|
|
|
SONIC_ENABLE_PFCWD_ON_START=$(ENABLE_PFCWD_ON_START) \
|
2018-10-15 15:49:35 -05:00
|
|
|
SONIC_ENABLE_SYNCD_RPC=$(ENABLE_SYNCD_RPC) \
|
2018-10-21 19:20:27 -05:00
|
|
|
SONIC_INSTALL_DEBUG_TOOLS=$(INSTALL_DEBUG_TOOLS) \
|
2018-08-16 17:54:31 -05:00
|
|
|
PASSWORD=$(PASSWORD) \
|
|
|
|
USERNAME=$(USERNAME) \
|
|
|
|
SONIC_BUILD_JOBS=$(SONIC_BUILD_JOBS) \
|
2019-06-20 11:19:33 -05:00
|
|
|
SONIC_USE_DOCKER_BUILDKIT=$(SONIC_USE_DOCKER_BUILDKIT) \
|
2019-03-29 17:25:17 -05:00
|
|
|
VS_PREPARE_MEM=$(VS_PREPARE_MEM) \
|
2018-08-16 17:54:31 -05:00
|
|
|
KERNEL_PROCURE_METHOD=$(KERNEL_PROCURE_METHOD) \
|
|
|
|
HTTP_PROXY=$(http_proxy) \
|
|
|
|
HTTPS_PROXY=$(https_proxy) \
|
2019-03-27 20:32:25 -05:00
|
|
|
SONIC_ENABLE_SYSTEM_TELEMETRY=$(ENABLE_SYSTEM_TELEMETRY) \
|
2020-01-14 19:13:45 -06:00
|
|
|
SONIC_ENABLE_RESTAPI=$(ENABLE_RESTAPI) \
|
2019-05-27 17:50:51 -05:00
|
|
|
EXTRA_JESSIE_TARGETS=$(EXTRA_JESSIE_TARGETS) \
|
2019-03-27 20:32:25 -05:00
|
|
|
$(SONIC_OVERRIDE_BUILD_VARS)
|
2018-08-16 17:54:31 -05:00
|
|
|
|
|
|
|
.PHONY: sonic-slave-build sonic-slave-bash init reset
|
|
|
|
|
|
|
|
.DEFAULT_GOAL := all
|
|
|
|
|
|
|
|
%::
|
2019-07-26 00:06:41 -05:00
|
|
|
ifneq (,$(filter $(CONFIGURED_ARCH), armhf arm64))
|
|
|
|
@$(DOCKER_MULTIARCH_CHECK)
|
2019-10-10 17:11:26 -05:00
|
|
|
ifneq ($(BLDENV), )
|
2019-07-26 00:06:41 -05:00
|
|
|
@$(DOCKER_SERVICE_MULTIARCH_CHECK)
|
|
|
|
@$(DOCKER_SERVICE_DOCKERFS_CHECK)
|
2019-10-10 17:11:26 -05:00
|
|
|
endif
|
2019-07-26 00:06:41 -05:00
|
|
|
endif
|
2018-09-05 00:32:46 -05:00
|
|
|
@$(OVERLAY_MODULE_CHECK)
|
2019-07-26 00:06:41 -05:00
|
|
|
|
2018-08-16 17:54:31 -05:00
|
|
|
@docker inspect --type image $(SLAVE_BASE_IMAGE):$(SLAVE_BASE_TAG) &> /dev/null || \
|
|
|
|
{ echo Image $(SLAVE_BASE_IMAGE):$(SLAVE_BASE_TAG) not found. Building... ; \
|
|
|
|
$(DOCKER_BASE_BUILD) ; }
|
|
|
|
@docker inspect --type image $(SLAVE_IMAGE):$(SLAVE_TAG) &> /dev/null || \
|
|
|
|
{ echo Image $(SLAVE_IMAGE):$(SLAVE_TAG) not found. Building... ; \
|
|
|
|
$(DOCKER_BUILD) ; }
|
|
|
|
ifeq "$(KEEP_SLAVE_ON)" "yes"
|
|
|
|
ifdef SOURCE_FOLDER
|
|
|
|
@$(DOCKER_RUN) -v $(SOURCE_FOLDER):/var/$(USER)/src $(SLAVE_IMAGE):$(SLAVE_TAG) bash -c "$(SONIC_BUILD_INSTRUCTION) $@; /bin/bash"
|
|
|
|
else
|
|
|
|
@$(DOCKER_RUN) $(SLAVE_IMAGE):$(SLAVE_TAG) bash -c "$(SONIC_BUILD_INSTRUCTION) $@; /bin/bash"
|
|
|
|
endif
|
|
|
|
else
|
|
|
|
@$(DOCKER_RUN) $(SLAVE_IMAGE):$(SLAVE_TAG) $(SONIC_BUILD_INSTRUCTION) $@
|
|
|
|
endif
|
|
|
|
|
|
|
|
sonic-slave-build :
|
|
|
|
$(DOCKER_BASE_BUILD)
|
|
|
|
$(DOCKER_BUILD)
|
|
|
|
|
|
|
|
sonic-slave-bash :
|
2018-09-05 00:32:46 -05:00
|
|
|
@$(OVERLAY_MODULE_CHECK)
|
2018-08-16 17:54:31 -05:00
|
|
|
@docker inspect --type image $(SLAVE_BASE_IMAGE):$(SLAVE_BASE_TAG) &> /dev/null || \
|
|
|
|
{ echo Image $(SLAVE_BASE_IMAGE):$(SLAVE_BASE_TAG) not found. Building... ; \
|
|
|
|
$(DOCKER_BASE_BUILD) ; }
|
|
|
|
@docker inspect --type image $(SLAVE_IMAGE):$(SLAVE_TAG) &> /dev/null || \
|
|
|
|
{ echo Image $(SLAVE_IMAGE):$(SLAVE_TAG) not found. Building... ; \
|
|
|
|
$(DOCKER_BUILD) ; }
|
|
|
|
@$(DOCKER_RUN) -t $(SLAVE_IMAGE):$(SLAVE_TAG) bash
|
|
|
|
|
|
|
|
showtag:
|
|
|
|
@echo $(SLAVE_IMAGE):$(SLAVE_TAG)
|
|
|
|
@echo $(SLAVE_BASE_IMAGE):$(SLAVE_BASE_TAG)
|
|
|
|
|
|
|
|
init :
|
|
|
|
@git submodule update --init --recursive
|
|
|
|
@git submodule foreach --recursive '[ -f .git ] && echo "gitdir: $$(realpath --relative-to=. $$(cut -d" " -f2 .git))" > .git'
|
|
|
|
|
2019-08-28 11:33:03 -05:00
|
|
|
.ONESHELL : reset
|
2018-08-16 17:54:31 -05:00
|
|
|
reset :
|
|
|
|
@echo && echo -n "Warning! All local changes will be lost. Proceed? [y/N]: "
|
2019-08-28 11:33:03 -05:00
|
|
|
@read ans && (
|
|
|
|
if [ $$ans == y ]; then
|
|
|
|
echo "Resetting local repository. Please wait...";
|
|
|
|
$(DOCKER_RUN) $(SLAVE_IMAGE):$(SLAVE_TAG) sudo rm -rf fsroot;
|
|
|
|
if [[ "$(CONFIGURED_ARCH)" == "armhf" || "$(CONFIGURED_ARCH)" == "arm64" ]]; then
|
|
|
|
echo "Stopping march $(CONFIGURED_ARCH) docker"
|
|
|
|
sudo kill -9 `sudo cat /var/run/march/docker.pid` || true
|
|
|
|
sudo rm -f /var/run/march/docker.pid || true
|
|
|
|
fi
|
|
|
|
git clean -xfdf;
|
|
|
|
git reset --hard;
|
|
|
|
git submodule foreach --recursive git clean -xfdf;
|
|
|
|
git submodule foreach --recursive git reset --hard;
|
|
|
|
git submodule update --init --recursive;
|
|
|
|
echo "Reset complete!";
|
|
|
|
else
|
|
|
|
echo "Reset aborted";
|
|
|
|
fi )
|