2016-12-05 13:12:19 -06:00
|
|
|
###############################################################################
|
|
|
|
## Wrapper for starting make inside sonic-slave container
|
2017-09-22 02:57:23 -05:00
|
|
|
#
|
|
|
|
# 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.
|
2018-03-06 01:55:37 -06:00
|
|
|
# * ENABLE_PFCWD_ON_START: Enable PFC Watchdog (PFCWD) on server-facing ports
|
|
|
|
# * by default for TOR switch.
|
2017-09-22 02:57:23 -05:00
|
|
|
# * SONIC_ENABLE_SYNCD_RPC: Enables rpc-based syncd builds.
|
|
|
|
# * USERNAME: Desired username -- default at rules/config
|
|
|
|
# * PASSWORD: Desired password -- default at rules/config
|
|
|
|
# * KEEP_SLAVE_ON: Keeps slave container up after building-process concludes.
|
2018-03-24 04:36:48 -05:00
|
|
|
# * SOURCE_FOLDER: host path to be mount as /var/$(USER)/src, only effective when KEEP_SLAVE_ON=yes
|
2018-07-25 10:14:18 -05:00
|
|
|
# * SONIC_BUILD_JOBS: Specifying number of concurrent build job(s) to run
|
|
|
|
# * KERNEL_PROCURE_METHOD: Specifying method of obtaining kernel Debian package: download or build
|
2017-09-22 02:57:23 -05:00
|
|
|
#
|
2016-12-05 13:12:19 -06:00
|
|
|
###############################################################################
|
2016-08-04 12:39:33 -05:00
|
|
|
|
2016-12-05 13:12:19 -06:00
|
|
|
SHELL = /bin/bash
|
2016-08-04 12:39:33 -05:00
|
|
|
|
2016-12-05 13:12:19 -06:00
|
|
|
USER := $(shell id -un)
|
|
|
|
PWD := $(shell pwd)
|
2016-10-31 23:50:59 -05:00
|
|
|
|
2017-07-26 23:52:12 -05:00
|
|
|
# Remove lock file in case previous run was forcefully stopped
|
|
|
|
$(shell rm -f .screen)
|
|
|
|
|
2016-12-05 13:12:19 -06:00
|
|
|
MAKEFLAGS += -B
|
2016-08-04 12:39:33 -05:00
|
|
|
|
2017-09-23 02:29:48 -05:00
|
|
|
ifeq ($(BLDENV), stretch)
|
|
|
|
SLAVE_BASE_TAG = $(shell sha1sum sonic-slave-stretch/Dockerfile | awk '{print substr($$1,0,11);}')
|
2017-09-26 03:25:17 -05:00
|
|
|
SLAVE_TAG = $(shell cat sonic-slave-stretch/Dockerfile.user sonic-slave-stretch/Dockerfile | sha1sum | awk '{print substr($$1,0,11);}')
|
2017-09-23 02:29:48 -05:00
|
|
|
SLAVE_BASE_IMAGE = sonic-slave-stretch-base
|
|
|
|
SLAVE_IMAGE = sonic-slave-stretch-$(USER)
|
|
|
|
SLAVE_DIR = sonic-slave-stretch
|
|
|
|
else
|
2017-11-03 16:36:26 -05:00
|
|
|
SLAVE_BASE_TAG = $(shell sha1sum sonic-slave/Dockerfile | awk '{print substr($$1,0,11);}')
|
|
|
|
SLAVE_TAG = $(shell cat sonic-slave/Dockerfile.user sonic-slave/Dockerfile | sha1sum | awk '{print substr($$1,0,11);}')
|
2017-08-08 02:21:54 -05:00
|
|
|
SLAVE_BASE_IMAGE = sonic-slave-base
|
2017-03-01 13:00:59 -06:00
|
|
|
SLAVE_IMAGE = sonic-slave-$(USER)
|
2017-09-23 02:29:48 -05:00
|
|
|
SLAVE_DIR = sonic-slave
|
|
|
|
endif
|
2017-03-01 13:00:59 -06:00
|
|
|
|
2017-09-13 02:02:53 -05:00
|
|
|
INSMOD_OVERLAY := sudo modprobe overlay
|
2016-12-05 13:12:19 -06:00
|
|
|
DOCKER_RUN := docker run --rm=true --privileged \
|
|
|
|
-v $(PWD):/sonic \
|
2017-07-24 04:29:36 -05:00
|
|
|
-w /sonic \
|
2017-12-24 01:34:15 -06:00
|
|
|
-e "http_proxy=$(http_proxy)" \
|
|
|
|
-e "https_proxy=$(https_proxy)" \
|
2017-07-24 02:52:51 -05:00
|
|
|
-i$(if $(TERM),t,)
|
2016-08-04 12:39:33 -05:00
|
|
|
|
2017-08-08 02:21:54 -05:00
|
|
|
DOCKER_BASE_BUILD = docker build --no-cache \
|
|
|
|
-t $(SLAVE_BASE_IMAGE) \
|
2017-12-24 01:34:15 -06:00
|
|
|
--build-arg http_proxy=$(http_proxy) \
|
|
|
|
--build-arg https_proxy=$(https_proxy) \
|
2017-09-23 02:29:48 -05:00
|
|
|
$(SLAVE_DIR) && \
|
2017-08-08 02:21:54 -05:00
|
|
|
docker tag $(SLAVE_BASE_IMAGE):latest $(SLAVE_BASE_IMAGE):$(SLAVE_BASE_TAG)
|
|
|
|
|
2017-03-01 16:25:44 -06:00
|
|
|
DOCKER_BUILD = docker build --no-cache \
|
2016-12-05 13:12:19 -06:00
|
|
|
--build-arg user=$(USER) \
|
|
|
|
--build-arg uid=$(shell id -u) \
|
|
|
|
--build-arg guid=$(shell id -g) \
|
2017-04-05 18:14:41 -05:00
|
|
|
--build-arg hostname=$(shell echo $$HOSTNAME) \
|
2017-03-01 13:00:59 -06:00
|
|
|
-t $(SLAVE_IMAGE) \
|
2017-09-23 02:29:48 -05:00
|
|
|
-f $(SLAVE_DIR)/Dockerfile.user \
|
|
|
|
$(SLAVE_DIR) && \
|
2017-03-01 13:00:59 -06:00
|
|
|
docker tag $(SLAVE_IMAGE):latest $(SLAVE_IMAGE):$(SLAVE_TAG)
|
2016-11-23 18:18:35 -06:00
|
|
|
|
2017-09-22 02:57:23 -05:00
|
|
|
SONIC_BUILD_INSTRUCTION := make \
|
|
|
|
-f slave.mk \
|
|
|
|
PLATFORM=$(PLATFORM) \
|
|
|
|
BUILD_NUMBER=$(BUILD_NUMBER) \
|
|
|
|
ENABLE_DHCP_GRAPH_SERVICE=$(ENABLE_DHCP_GRAPH_SERVICE) \
|
|
|
|
SHUTDOWN_BGP_ON_START=$(SHUTDOWN_BGP_ON_START) \
|
2018-03-06 01:55:37 -06:00
|
|
|
SONIC_ENABLE_PFCWD_ON_START=$(ENABLE_PFCWD_ON_START) \
|
2017-10-11 19:46:26 -05:00
|
|
|
ENABLE_SYNCD_RPC=$(ENABLE_SYNCD_RPC) \
|
2017-09-22 02:57:23 -05:00
|
|
|
PASSWORD=$(PASSWORD) \
|
2017-12-20 17:25:30 -06:00
|
|
|
USERNAME=$(USERNAME) \
|
2017-12-24 01:34:15 -06:00
|
|
|
SONIC_BUILD_JOBS=$(SONIC_BUILD_JOBS) \
|
2018-07-25 10:14:18 -05:00
|
|
|
KERNEL_PROCURE_METHOD=$(KERNEL_PROCURE_METHOD) \
|
2017-12-24 01:34:15 -06:00
|
|
|
HTTP_PROXY=$(http_proxy) \
|
2018-03-27 15:39:04 -05:00
|
|
|
HTTPS_PROXY=$(https_proxy) \
|
2018-04-18 02:31:12 -05:00
|
|
|
SONIC_ENABLE_SYSTEM_TELEMETRY=$(ENABLE_SYSTEM_TELEMETRY)
|
2017-09-22 02:57:23 -05:00
|
|
|
|
2017-12-21 13:15:06 -06:00
|
|
|
.PHONY: sonic-slave-build sonic-slave-bash init reset
|
2016-09-27 13:42:35 -05:00
|
|
|
|
2016-12-05 13:12:19 -06:00
|
|
|
.DEFAULT_GOAL := all
|
2016-10-31 23:50:59 -05:00
|
|
|
|
2016-12-05 13:12:19 -06:00
|
|
|
%::
|
2017-08-08 02:21:54 -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) ; }
|
2017-03-01 13:00:59 -06:00
|
|
|
@docker inspect --type image $(SLAVE_IMAGE):$(SLAVE_TAG) &> /dev/null || \
|
|
|
|
{ echo Image $(SLAVE_IMAGE):$(SLAVE_TAG) not found. Building... ; \
|
|
|
|
$(DOCKER_BUILD) ; }
|
2017-09-13 02:02:53 -05:00
|
|
|
@$(INSMOD_OVERLAY)
|
2017-09-22 02:57:23 -05:00
|
|
|
ifeq "$(KEEP_SLAVE_ON)" "yes"
|
2017-11-16 10:15:14 -06:00
|
|
|
ifdef SOURCE_FOLDER
|
2018-03-24 04:36:48 -05:00
|
|
|
@$(DOCKER_RUN) -v $(SOURCE_FOLDER):/var/$(USER)/src $(SLAVE_IMAGE):$(SLAVE_TAG) bash -c "$(SONIC_BUILD_INSTRUCTION) $@; /bin/bash"
|
2017-11-16 10:15:14 -06:00
|
|
|
else
|
|
|
|
@$(DOCKER_RUN) $(SLAVE_IMAGE):$(SLAVE_TAG) bash -c "$(SONIC_BUILD_INSTRUCTION) $@; /bin/bash"
|
|
|
|
endif
|
2017-09-22 02:57:23 -05:00
|
|
|
else
|
|
|
|
@$(DOCKER_RUN) $(SLAVE_IMAGE):$(SLAVE_TAG) $(SONIC_BUILD_INSTRUCTION) $@
|
|
|
|
endif
|
2016-08-04 12:39:33 -05:00
|
|
|
|
2016-12-05 13:12:19 -06:00
|
|
|
sonic-slave-build :
|
2017-08-08 02:21:54 -05:00
|
|
|
$(DOCKER_BASE_BUILD)
|
|
|
|
$(DOCKER_BUILD)
|
2016-10-31 23:50:59 -05:00
|
|
|
|
2016-12-05 13:12:19 -06:00
|
|
|
sonic-slave-bash :
|
2017-08-08 02:21:54 -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) ; }
|
2017-03-01 13:00:59 -06:00
|
|
|
@docker inspect --type image $(SLAVE_IMAGE):$(SLAVE_TAG) &> /dev/null || \
|
|
|
|
{ echo Image $(SLAVE_IMAGE):$(SLAVE_TAG) not found. Building... ; \
|
|
|
|
$(DOCKER_BUILD) ; }
|
2017-09-13 02:02:53 -05:00
|
|
|
@$(INSMOD_OVERLAY)
|
2017-03-01 13:00:59 -06:00
|
|
|
@$(DOCKER_RUN) -t $(SLAVE_IMAGE):$(SLAVE_TAG) bash
|
2017-10-24 21:49:37 -05:00
|
|
|
|
2018-07-01 11:46:42 -05:00
|
|
|
showtag:
|
|
|
|
@echo $(SLAVE_IMAGE):$(SLAVE_TAG)
|
|
|
|
@echo $(SLAVE_BASE_IMAGE):$(SLAVE_BASE_TAG)
|
|
|
|
|
2017-10-24 21:49:37 -05:00
|
|
|
init :
|
2017-12-21 13:15:06 -06:00
|
|
|
@git submodule update --init --recursive
|
|
|
|
@git submodule foreach --recursive '[ -f .git ] && echo "gitdir: $$(realpath --relative-to=. $$(cut -d" " -f2 .git))" > .git'
|
|
|
|
|
|
|
|
reset :
|
|
|
|
@echo && echo -n "Warning! All local changes will be lost. Proceed? [y/N]: "
|
|
|
|
@read ans && \
|
|
|
|
if [ $$ans == y ]; then \
|
|
|
|
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;\
|
|
|
|
else \
|
|
|
|
echo "Reset aborted"; \
|
|
|
|
fi
|