Skip to content

Commit a79fcb4

Browse files
authored
[build]: add option to pull sonic-slave docker from registry (#6300)
- add config option ENABLE_DOCKER_BASE_PULL to pull sonic-slave docker from registry - use REGISTRY_PORT, REGISTRY_SERVER to specify docker registry Signed-off-by: Guohan Lu <[email protected]>
1 parent d40c9a1 commit a79fcb4

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

Makefile.work

+19-4
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ endif
9191

9292
include rules/config
9393

94+
ifeq ($(ENABLE_DOCKER_BASE_PULL),)
95+
override ENABLE_DOCKER_BASE_PULL = n
96+
endif
97+
9498
ifeq ($(CONFIGURED_ARCH),amd64)
9599
SLAVE_BASE_IMAGE = $(SLAVE_DIR)
96100
else
@@ -194,6 +198,9 @@ DOCKER_BASE_BUILD = docker build --no-cache \
194198
--build-arg https_proxy=$(https_proxy) \
195199
$(SLAVE_DIR)
196200

201+
DOCKER_BASE_PULL = docker pull \
202+
$(REGISTRY_SERVER):$(REGISTRY_PORT)/$(SLAVE_BASE_IMAGE):$(SLAVE_BASE_TAG)
203+
197204
DOCKER_BUILD = docker build --no-cache \
198205
--build-arg user=$(USER) \
199206
--build-arg uid=$(shell id -u) \
@@ -258,9 +265,13 @@ endif
258265
@pushd src/sonic-build-hooks; TRUSTED_GPG_URLS=$(TRUSTED_GPG_URLS) make all; popd
259266
@cp src/sonic-build-hooks/buildinfo/sonic-build-hooks* $(SLAVE_DIR)/buildinfo
260267
@docker inspect --type image $(SLAVE_BASE_IMAGE):$(SLAVE_BASE_TAG) &> /dev/null || \
268+
{ [ $(ENABLE_DOCKER_BASE_PULL) == y ] && { echo Image $(SLAVE_BASE_IMAGE):$(SLAVE_BASE_TAG) not found. Pulling...; } && \
269+
$(DOCKER_BASE_PULL) && \
270+
{ docker tag $(REGISTRY_SERVER):$(REGISTRY_PORT)/$(SLAVE_BASE_IMAGE):$(SLAVE_BASE_TAG) $(SLAVE_BASE_IMAGE):$(SLAVE_BASE_TAG)
271+
scripts/collect_docker_version_files.sh $(SLAVE_BASE_IMAGE):$(SLAVE_BASE_TAG) target ; } } || \
261272
{ echo Image $(SLAVE_BASE_IMAGE):$(SLAVE_BASE_TAG) not found. Building... ; \
262-
$(DOCKER_BASE_BUILD) ; \
263-
scripts/collect_docker_version_files.sh $(SLAVE_BASE_IMAGE):$(SLAVE_BASE_TAG) target ; }
273+
$(DOCKER_BASE_BUILD) ; \
274+
scripts/collect_docker_version_files.sh $(SLAVE_BASE_IMAGE):$(SLAVE_BASE_TAG) target ; }
264275
@docker inspect --type image $(SLAVE_IMAGE):$(SLAVE_TAG) &> /dev/null || \
265276
{ echo Image $(SLAVE_IMAGE):$(SLAVE_TAG) not found. Building... ; \
266277
$(DOCKER_BUILD) ; }
@@ -282,9 +293,13 @@ sonic-slave-base-build : sonic-build-hooks
282293
@$(OVERLAY_MODULE_CHECK)
283294
@echo Checking sonic-slave-base image: $(SLAVE_BASE_IMAGE):$(SLAVE_BASE_TAG)
284295
@docker inspect --type image $(SLAVE_BASE_IMAGE):$(SLAVE_BASE_TAG) &> /dev/null || \
296+
{ [ $(ENABLE_DOCKER_BASE_PULL) == y ] && { echo Image $(SLAVE_BASE_IMAGE):$(SLAVE_BASE_TAG) not found. Pulling...; } && \
297+
$(DOCKER_BASE_PULL) && \
298+
{ docker tag $(REGISTRY_SERVER):$(REGISTRY_PORT)/$(SLAVE_BASE_IMAGE):$(SLAVE_BASE_TAG) $(SLAVE_BASE_IMAGE):$(SLAVE_BASE_TAG)
299+
scripts/collect_docker_version_files.sh $(SLAVE_BASE_IMAGE):$(SLAVE_BASE_TAG) target ; } } || \
285300
{ echo Image $(SLAVE_BASE_IMAGE):$(SLAVE_BASE_TAG) not found. Building... ; \
286-
$(DOCKER_BASE_BUILD) ; \
287-
scripts/collect_docker_version_files.sh $(SLAVE_BASE_IMAGE):$(SLAVE_BASE_TAG) target ; }
301+
$(DOCKER_BASE_BUILD) ; \
302+
scripts/collect_docker_version_files.sh $(SLAVE_BASE_IMAGE):$(SLAVE_BASE_TAG) target ; }
288303

289304
sonic-slave-build : sonic-slave-base-build
290305
@echo Checking sonic-slave image: $(SLAVE_IMAGE):$(SLAVE_TAG)

rules/config

+7
Original file line numberDiff line numberDiff line change
@@ -179,3 +179,10 @@ TRUSTED_GPG_URLS = https://packages.trafficmanager.net/debian/public_key.gpg,htt
179179
# git : git repositories, donloaded by git clone
180180
# docker: docker base images
181181
SONIC_VERSION_CONTROL_COMPONENTS ?= none
182+
183+
# SONiC docker registry
184+
#
185+
# Uncomment below line to enable pulling sonic-slave docker from registry
186+
# ENABLE_DOCKER_BASE_PULL = y
187+
REGISTRY_PORT=443
188+
REGISTRY_SERVER=sonicdev-microsoft.azurecr.io

0 commit comments

Comments
 (0)