From 53653161640a23e503efc2849b3567d4f5a8d273 Mon Sep 17 00:00:00 2001 From: Liu Shilong Date: Wed, 22 Jun 2022 17:33:20 +0800 Subject: [PATCH] [ci] Set default ACR in UpgrateVersion/PR/official pipeline. (#11002) * [ci] Set default ACR in UpgrateVersion/PR/official pipeline. (#10341) Why I did it docker hub will limit the pull rate. Use ACR instead to pull debian related docker image. How I did it Set DEFAULT_CONTAINER_REGISTRY in pipeline. * Add a config variable to override default container registry instead of dockerhub. (#10166) * Add variable to reset default docker registry * fix bug in docker version control --- .azure-pipelines/official-build.yml | 11 +++++++++++ Makefile.work | 7 ++++++- azure-pipelines.yml | 8 ++++++++ dockers/docker-base-stretch/Dockerfile.j2 | 7 ++++--- dockers/docker-base/Dockerfile.j2 | 7 ++++--- dockers/docker-ptf/Dockerfile.j2 | 7 ++++--- dockers/docker-sonic-mgmt/Dockerfile.j2 | 3 ++- rules/config | 3 +++ slave.mk | 2 ++ sonic-slave-jessie/Dockerfile.j2 | 7 ++++--- sonic-slave-stretch/Dockerfile.j2 | 7 ++++--- 11 files changed, 52 insertions(+), 17 deletions(-) diff --git a/.azure-pipelines/official-build.yml b/.azure-pipelines/official-build.yml index 2b8e0fa2a0f2..faf47d7a2ba9 100644 --- a/.azure-pipelines/official-build.yml +++ b/.azure-pipelines/official-build.yml @@ -18,9 +18,20 @@ schedules: - 201911 - 201811 +resources: + repositories: + - repository: buildimage + type: github + name: Azure/sonic-buildimage + ref: master + endpoint: build + trigger: none pr: none +variables: +- template: .azure-pipelines/template-variables.yml@buildimage + stages: - stage: Build pool: sonicbld diff --git a/Makefile.work b/Makefile.work index 35f5a7b10e97..bca8d77eaaf8 100644 --- a/Makefile.work +++ b/Makefile.work @@ -79,7 +79,7 @@ SLAVE_DIR = sonic-slave-stretch else SLAVE_DIR = sonic-slave-jessie endif -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_BASE_TAG = $(shell CONFIGURED_ARCH=$(CONFIGURED_ARCH) DEFAULT_CONTAINER_REGISTRY=$(DEFAULT_CONTAINER_REGISTRY) 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) SLAVE_IMAGE = $(SLAVE_BASE_IMAGE)-$(USER_LC) @@ -109,6 +109,10 @@ DOCKER_RUN := docker run --rm=true --privileged \ include rules/config +ifneq ($(DEFAULT_CONTAINER_REGISTRY),) +override DEFAULT_CONTAINER_REGISTRY := $(DEFAULT_CONTAINER_REGISTRY)/ +endif + ifeq ($(SONIC_CONFIG_USE_NATIVE_DOCKERD_FOR_BUILD), y) DOCKER_RUN += -v /var/run/docker.sock:/var/run/docker.sock endif @@ -187,6 +191,7 @@ SONIC_BUILD_INSTRUCTION := make \ SONIC_INCLUDE_ACMS=$(INCLUDE_ACMS)\ SONIC_INCLUDE_VNET_MONITOR=$(INCLUDE_VNET_MONITOR) \ EXTRA_JESSIE_TARGETS=$(EXTRA_JESSIE_TARGETS) \ + DEFAULT_CONTAINER_REGISTRY=$(DEFAULT_CONTAINER_REGISTRY) \ $(SONIC_OVERRIDE_BUILD_VARS) .PHONY: sonic-slave-build sonic-slave-bash init reset diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 5756e8ac1417..d5c1190c2baa 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -30,6 +30,14 @@ resources: type: github name: Azure/sonic-mgmt endpoint: build + - repository: buildimage + type: github + name: Azure/sonic-buildimage + endpoint: build + ref: master + +variables: +- template: .azure-pipelines/template-variables.yml@buildimage stages: - stage: Build diff --git a/dockers/docker-base-stretch/Dockerfile.j2 b/dockers/docker-base-stretch/Dockerfile.j2 index 960f3f96e037..19af55acc400 100644 --- a/dockers/docker-base-stretch/Dockerfile.j2 +++ b/dockers/docker-base-stretch/Dockerfile.j2 @@ -1,10 +1,11 @@ +{% set prefix = DEFAULT_CONTAINER_REGISTRY %} {% from "dockers/dockerfile-macros.j2" import install_debian_packages, install_python_wheels, copy_files %} {% if CONFIGURED_ARCH == "armhf" %} -FROM multiarch/debian-debootstrap:armhf-stretch +FROM {{ prefix }}multiarch/debian-debootstrap:armhf-stretch {% elif CONFIGURED_ARCH == "arm64" %} -FROM multiarch/debian-debootstrap:arm64-stretch +FROM {{ prefix }}multiarch/debian-debootstrap:arm64-stretch {% else %} -FROM debian:stretch +FROM {{ prefix }}debian:stretch {% endif %} # Clean documentation in FROM image diff --git a/dockers/docker-base/Dockerfile.j2 b/dockers/docker-base/Dockerfile.j2 index e45235a1e139..3407361dccaf 100644 --- a/dockers/docker-base/Dockerfile.j2 +++ b/dockers/docker-base/Dockerfile.j2 @@ -1,9 +1,10 @@ +{% set prefix = DEFAULT_CONTAINER_REGISTRY %} {% if CONFIGURED_ARCH == "armhf" %} -FROM multiarch/debian-debootstrap:armhf-jessie +FROM {{ prefix }}multiarch/debian-debootstrap:armhf-jessie {% elif CONFIGURED_ARCH == "arm64" %} -FROM multiarch/debian-debootstrap:arm64-jessie +FROM {{ prefix }}multiarch/debian-debootstrap:arm64-jessie {% else %} -FROM debian:jessie +FROM {{ prefix }}/debian:jessie {% endif %} ## Remove retired jessie-updates repo diff --git a/dockers/docker-ptf/Dockerfile.j2 b/dockers/docker-ptf/Dockerfile.j2 index 1698def79f88..b3f4a9d38dec 100644 --- a/dockers/docker-ptf/Dockerfile.j2 +++ b/dockers/docker-ptf/Dockerfile.j2 @@ -1,9 +1,10 @@ +{% set prefix = DEFAULT_CONTAINER_REGISTRY %} {% if CONFIGURED_ARCH == "armhf" %} -FROM multiarch/debian-debootstrap:armhf-stretch +FROM {{ prefix }}multiarch/debian-debootstrap:armhf-stretch {% elif CONFIGURED_ARCH == "arm64" %} -FROM multiarch/debian-debootstrap:arm64-stretch +FROM {{ prefix }}multiarch/debian-debootstrap:arm64-stretch {% else %} -FROM debian:stretch +FROM {{ prefix }}debian:stretch {% endif %} MAINTAINER Pavel Shirshov diff --git a/dockers/docker-sonic-mgmt/Dockerfile.j2 b/dockers/docker-sonic-mgmt/Dockerfile.j2 index 67142242293c..401ab1ee8f86 100644 --- a/dockers/docker-sonic-mgmt/Dockerfile.j2 +++ b/dockers/docker-sonic-mgmt/Dockerfile.j2 @@ -1,4 +1,5 @@ -FROM ubuntu:16.04 +{% set prefix = DEFAULT_CONTAINER_REGISTRY %} +FROM {{ prefix }}ubuntu:16.04 ENV DEBIAN_FRONTEND=noninteractive diff --git a/rules/config b/rules/config index f74ab69b194b..6b9c81a46ed6 100644 --- a/rules/config +++ b/rules/config @@ -129,3 +129,6 @@ INCLUDE_ACMS = y # INCLUDE_VNET_MONITOR - build docker-vnet-monitor for vnetping utility on the device INCLUDE_VNET_MONITOR = n +# reset default container registry from dockerhub to other +DEFAULT_CONTAINER_REGISTRY ?= + diff --git a/slave.mk b/slave.mk index aad06e3764b7..a11d611abc2c 100644 --- a/slave.mk +++ b/slave.mk @@ -85,6 +85,7 @@ list : ############################################################################### include $(RULES_PATH)/config +export DEFAULT_CONTAINER_REGISTRY ifeq ($(SONIC_ENABLE_PFCWD_ON_START),y) ENABLE_PFCWD_ON_START = y @@ -223,6 +224,7 @@ $(info "INCLUDE_RESTAPI" : "$(INCLUDE_RESTAPI)") $(info "INCLUDE_SFLOW" : "$(INCLUDE_SFLOW)") $(info "INCLUDE_NAT" : "$(INCLUDE_NAT)") $(info "INCLUDE_KUBERNETES" : "$(INCLUDE_KUBERNETES)") +$(info "DEFAULT_CONTAINER_REGISTRY" : "$(DEFAULT_CONTAINER_REGISTRY)") $(info ) ifeq ($(SONIC_USE_DOCKER_BUILDKIT),y) diff --git a/sonic-slave-jessie/Dockerfile.j2 b/sonic-slave-jessie/Dockerfile.j2 index ab1604496b4d..41b14010b288 100644 --- a/sonic-slave-jessie/Dockerfile.j2 +++ b/sonic-slave-jessie/Dockerfile.j2 @@ -1,9 +1,10 @@ +{% set prefix = DEFAULT_CONTAINER_REGISTRY %} {%- if CONFIGURED_ARCH == "armhf" -%} -FROM multiarch/debian-debootstrap:armhf-jessie +FROM {{ prefix }}multiarch/debian-debootstrap:armhf-jessie {%- elif CONFIGURED_ARCH == "arm64" -%} -FROM multiarch/debian-debootstrap:arm64-jessie +FROM {{ prefix }}multiarch/debian-debootstrap:arm64-jessie {%- else -%} -FROM debian:jessie +FROM {{ prefix }}debian:jessie {%- endif %} MAINTAINER johnar@microsoft.com diff --git a/sonic-slave-stretch/Dockerfile.j2 b/sonic-slave-stretch/Dockerfile.j2 index b3d555fbdcf7..a39f21be63aa 100644 --- a/sonic-slave-stretch/Dockerfile.j2 +++ b/sonic-slave-stretch/Dockerfile.j2 @@ -1,9 +1,10 @@ +{% set prefix = DEFAULT_CONTAINER_REGISTRY %} {%- if CONFIGURED_ARCH == "armhf" %} -FROM multiarch/debian-debootstrap:armhf-stretch +FROM {{ prefix }}multiarch/debian-debootstrap:armhf-stretch {%- elif CONFIGURED_ARCH == "arm64" %} -FROM multiarch/debian-debootstrap:arm64-stretch +FROM {{ prefix }}multiarch/debian-debootstrap:arm64-stretch {%- else -%} -FROM debian:stretch +FROM {{ prefix }}debian:stretch {%- endif %} MAINTAINER gulv@microsoft.com