From 12cfb2b8f4faa442353f0b31600c6d2cd0460ba6 Mon Sep 17 00:00:00 2001 From: Shilong Liu Date: Sat, 2 Apr 2022 07:48:44 +0800 Subject: [PATCH] [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. --- .azure-pipelines/azure-pipelines-UpgrateVersion.yml | 7 +++++-- .azure-pipelines/docker-sonic-slave-template.yml | 5 ++++- .azure-pipelines/official-build.yml | 11 +++++++++++ .azure-pipelines/template-clean-sonic-slave.yml | 4 +++- .azure-pipelines/template-variables.yml | 2 ++ azure-pipelines.yml | 9 +++++++++ 6 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 .azure-pipelines/template-variables.yml diff --git a/.azure-pipelines/azure-pipelines-UpgrateVersion.yml b/.azure-pipelines/azure-pipelines-UpgrateVersion.yml index 03593c551c..6e11e3826e 100644 --- a/.azure-pipelines/azure-pipelines-UpgrateVersion.yml +++ b/.azure-pipelines/azure-pipelines-UpgrateVersion.yml @@ -45,8 +45,11 @@ parameters: stages: - stage: Build variables: - CACHE_MODE: none - VERSION_CONTROL_OPTIONS: 'SONIC_VERSION_CONTROL_COMPONENTS=' + - name: CACHE_MODE + value: none + - name: VERSION_CONTROL_OPTIONS + value: 'SONIC_VERSION_CONTROL_COMPONENTS=' + - template: .azure-pipelines/template-variables.yml@buildimage jobs: - template: azure-pipelines-build.yml parameters: diff --git a/.azure-pipelines/docker-sonic-slave-template.yml b/.azure-pipelines/docker-sonic-slave-template.yml index 6b4b90f371..2a9421dda3 100644 --- a/.azure-pipelines/docker-sonic-slave-template.yml +++ b/.azure-pipelines/docker-sonic-slave-template.yml @@ -37,7 +37,10 @@ jobs: pool: ${{ parameters.pool }} steps: - template: cleanup.yml - - template: .azure-pipelines/template-clean-sonic-slave.yml@buildimage + - ${{ if eq(variables['Build.Reason'], 'PullRequest') }}: + - template: template-clean-sonic-slave.yml + - ${{ else }}: + - template: .azure-pipelines/template-variables.yml@buildimage - checkout: self clean: true submodules: recursive diff --git a/.azure-pipelines/official-build.yml b/.azure-pipelines/official-build.yml index f43c6521fc..fb986cf670 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/.azure-pipelines/template-clean-sonic-slave.yml b/.azure-pipelines/template-clean-sonic-slave.yml index c67f63fff4..ddb8c8e48f 100644 --- a/.azure-pipelines/template-clean-sonic-slave.yml +++ b/.azure-pipelines/template-clean-sonic-slave.yml @@ -1,8 +1,10 @@ steps: - script: | - containers=$(docker container ls -a | grep "sonic-slave" | awk '{ print $1 }') + set -x + containers=$(docker container ls -aq) [ -n "$containers" ] && docker container rm -f $containers docker images | grep "^" | awk '{print$3}' | xargs -i docker rmi {} images=$(docker images 'sonic-slave-*' -a -q) [ -n "$images" ] && docker rmi -f $images + exit 0 displayName: 'Cleanup sonic slave' diff --git a/.azure-pipelines/template-variables.yml b/.azure-pipelines/template-variables.yml new file mode 100644 index 0000000000..f28768e39e --- /dev/null +++ b/.azure-pipelines/template-variables.yml @@ -0,0 +1,2 @@ +variables: + DEFAULT_CONTAINER_REGISTRY: 'publicmirror.azurecr.io' diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 557ce3beff..27836a49b1 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -30,9 +30,18 @@ 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/azure-pipelines-repd-build-variables.yml +- ${{ if eq(variables['Build.Reason'], 'PullRequest') }}: + - template: .azure-pipelines/template-variables.yml +- ${{ else }}: + - template: .azure-pipelines/template-variables.yml@buildimage - name: CACHE_MODE value: rcache