From 1685e6ef4db0cc0fd145ae411efafb8ae9f291e2 Mon Sep 17 00:00:00 2001 From: shilongliu Date: Wed, 31 Aug 2022 14:07:32 +0800 Subject: [PATCH 1/6] [ci] Update docker sonic slave pipeline to build slave base docker --- .azure-pipelines/docker-sonic-slave-arm64.yml | 52 --------- .azure-pipelines/docker-sonic-slave-armhf.yml | 52 --------- .../docker-sonic-slave-template.yml | 107 +++++++----------- .azure-pipelines/docker-sonic-slave.yml | 40 ++++--- 4 files changed, 60 insertions(+), 191 deletions(-) delete mode 100644 .azure-pipelines/docker-sonic-slave-arm64.yml delete mode 100644 .azure-pipelines/docker-sonic-slave-armhf.yml diff --git a/.azure-pipelines/docker-sonic-slave-arm64.yml b/.azure-pipelines/docker-sonic-slave-arm64.yml deleted file mode 100644 index 6350d8fd3b5..00000000000 --- a/.azure-pipelines/docker-sonic-slave-arm64.yml +++ /dev/null @@ -1,52 +0,0 @@ -# Starter pipeline -# Start with a minimal pipeline that you can customize to build and deploy your code. -# Add steps that build, run tests, deploy, and more: -# https://aka.ms/yaml -# Build and push sonic-slave-[buster|jessie|stretch] images for amd64/armhf/arm64 -resources: - repositories: - - repository: buildimage - type: github - name: sonic-net/sonic-buildimage - ref: master - endpoint: sonic-net - -schedules: -- cron: "0 8 * * *" - branches: - include: - - master - - 202012 - always: true - -trigger: none -pr: - branches: - include: - - master - paths: - include: - - sonic-slave-jessie - - sonic-slave-stretch - - sonic-slave-buster - - sonic-slave-bullseye - - .azure-pipelines - -parameters: -- name: 'dists' - type: object - default: - - bullseye - - buster - - stretch - -stages: -- stage: Build - jobs: - - ${{ each dist in parameters.dists }}: - - ${{ if contains(variables['Build.DefinitionName'], dist) }}: - - template: docker-sonic-slave-template.yml - parameters: - pool: sonicbld-arm64 - arch: arm64 - dist: ${{ dist }} diff --git a/.azure-pipelines/docker-sonic-slave-armhf.yml b/.azure-pipelines/docker-sonic-slave-armhf.yml deleted file mode 100644 index fcdad5f2cd1..00000000000 --- a/.azure-pipelines/docker-sonic-slave-armhf.yml +++ /dev/null @@ -1,52 +0,0 @@ -# Starter pipeline -# Start with a minimal pipeline that you can customize to build and deploy your code. -# Add steps that build, run tests, deploy, and more: -# https://aka.ms/yaml -# Build and push sonic-slave-[buster|jessie|stretch] images for amd64/armhf/arm64 -resources: - repositories: - - repository: buildimage - type: github - name: sonic-net/sonic-buildimage - ref: master - endpoint: sonic-net - -schedules: -- cron: "0 8 * * *" - branches: - include: - - master - - 202012 - always: true - -trigger: none -pr: - branches: - include: - - master - paths: - include: - - sonic-slave-jessie - - sonic-slave-stretch - - sonic-slave-buster - - sonic-slave-bullseye - - .azure-pipelines - -parameters: -- name: 'dists' - type: object - default: - - bullseye - - buster - - stretch - -stages: -- stage: Build - jobs: - - ${{ each dist in parameters.dists }}: - - ${{ if contains(variables['Build.DefinitionName'], dist) }}: - - template: docker-sonic-slave-template.yml - parameters: - pool: sonicbld-armhf - arch: armhf - dist: ${{ dist }} diff --git a/.azure-pipelines/docker-sonic-slave-template.yml b/.azure-pipelines/docker-sonic-slave-template.yml index 2cf06638a4c..31f978fca83 100644 --- a/.azure-pipelines/docker-sonic-slave-template.yml +++ b/.azure-pipelines/docker-sonic-slave-template.yml @@ -10,6 +10,9 @@ parameters: - amd64 - armhf - arm64 +- name: march + type: string + default: '' - name: dist type: string values: @@ -32,89 +35,55 @@ parameters: - sonicbld-armhf jobs: -- job: Build_${{ parameters.dist }}_${{ parameters.arch }} +- job: Build_${{ parameters.dist }}_${{ parameters.march }}${{ parameters.arch }} timeoutInMinutes: 360 + variables: + - template: .azure-pipelines/template-variables.yml@buildimage + - template: .azure-pipelines/azure-pipelines-repd-build-variables.yml@buildimage pool: ${{ parameters.pool }} steps: - template: cleanup.yml - - ${{ if eq(variables['Build.Reason'], 'PullRequest') }}: - - template: template-clean-sonic-slave.yml - - ${{ else }}: - - template: '/.azure-pipelines/template-clean-sonic-slave.yml@buildimage' + - template: .azure-pipelines/template-clean-sonic-slave.yml@buildimage - checkout: self clean: true submodules: recursive + - task: Docker@2 + displayName: Login to ACR + inputs: + command: login + containerRegistry: ${{ parameters.registry_conn }} - bash: | set -ex + case ${{ parameters.dist }} in + bullseye) + args='NOJESSIE=1 NOSTRETCH=1 NOBUSTER=1' + ;; + buster) + args='NOJESSIE=1 NOSTRETCH=1 NOBULLSEYE=1' + ;; + stretch) + args='NOJESSIE=1 NOBUSTER=1 NOBULLSEYE=1' + ;; + jessie) + args='NOSTRETCH=1 NOBUSTER=1 NOBULLSEYE=1' + ;; + esac + image_tag=$(make showtag PLATFORM=generic PLATFORM_ARCH=${{ parameters.arch }} $args | grep sonic-slave | tail -n 1) + image_latest=$(echo $(echo $image_tag | awk -F: '{print$1}'):latest) + docker rmi $image_tag || true - SLAVE_DIR=sonic-slave-${{ parameters.dist }} - if [ x${{ parameters.pool }} == x"sonicbld" ]; then - if [ x${{ parameters.arch }} == x"amd64" ]; then - SLAVE_BASE_IMAGE=${SLAVE_DIR} - SLAVE_BASE_IMAGE_UPLOAD=${SLAVE_DIR} - elif [ x${{ parameters.pool }} == x"sonicbld" ]; then - SLAVE_BASE_IMAGE=${SLAVE_DIR}-march-${{ parameters.arch }} - SLAVE_BASE_IMAGE_UPLOAD=${SLAVE_DIR}-march-${{ parameters.arch }} - fi - elif [[ x${{ parameters.pool }} == x"sonicbld-armhf" && x${{ parameters.arch }} == x"armhf" ]]; then - SLAVE_BASE_IMAGE=${SLAVE_DIR} - SLAVE_BASE_IMAGE_UPLOAD=${SLAVE_DIR}-armhf - elif [[ x${{ parameters.pool }} == x"sonicbld-arm64" && x${{ parameters.arch }} == x"arm64" ]]; then - SLAVE_BASE_IMAGE=${SLAVE_DIR} - SLAVE_BASE_IMAGE_UPLOAD=${SLAVE_DIR}-arm64 - else - echo "do not support build ${{ parameters.arch }} on ${{ parameters.pool }}" - exit 1 + if docker pull ${{ parameters.registry_url }}/${image_tag};then + exit 0 fi - if [ x"$(Build.SourceBranchName)" == x"202012" ]; then - BUILD_OPTIONS = 'SONIC_VERSION_CONTROL_COMPONENTS=deb,py2,py3,web,git,docker' - fi - - tmpfile=$(mktemp) - - echo ${{ parameters.arch }} > .arch + DOCKER_DATA_ROOT_FOR_MULTIARCH=/data/march/docker make configure PLATFORM=generic PLATFORM_ARCH=${{ parameters.arch }} $args || docker image ls $image_tag - DOCKER_DATA_ROOT_FOR_MULTIARCH=/data/march/docker BLDENV=${{ parameters.dist }} $(BUILD_OPTIONS) make -f Makefile.work sonic-slave-build | tee $tmpfile - SLAVE_BASE_TAG=$(grep "^Checking sonic-slave-base image:" $tmpfile | awk -F ':' '{print $3}') - SLAVE_TAG=$(grep "^Checking sonic-slave image:" $tmpfile | awk -F ':' '{print $3}') - - mkdir -p target - - docker tag $SLAVE_BASE_IMAGE:$SLAVE_BASE_TAG $REGISTRY_SERVER/$SLAVE_BASE_IMAGE_UPLOAD:latest - docker tag $SLAVE_BASE_IMAGE:$SLAVE_BASE_TAG $REGISTRY_SERVER/$SLAVE_BASE_IMAGE_UPLOAD:$SLAVE_BASE_TAG - if [ "$SLAVE_BASE_IMAGE_UPLOAD" != "$SLAVE_DIR" ]; then - docker tag $SLAVE_BASE_IMAGE:$SLAVE_BASE_TAG $REGISTRY_SERVER/$SLAVE_DIR:latest-${{ parameters.arch }} - docker tag $SLAVE_BASE_IMAGE:$SLAVE_BASE_TAG $REGISTRY_SERVER/$SLAVE_DIR:$SLAVE_BASE_TAG + docker tag ${image_tag} ${REGISTRY_SERVER}/${image_tag} + docker push ${REGISTRY_SERVER}/${image_tag} + if [[ "${{ parameters.arch }}" == "amd64" ]];then + docker tag ${image_tag} ${REGISTRY_SERVER}/${image_latest} + docker push ${REGISTRY_SERVER}/${image_latest} fi - set +x - echo "##vso[task.setvariable variable=VARIABLE_SLAVE_BASE_IMAGE]$SLAVE_BASE_IMAGE_UPLOAD" - echo "##vso[task.setvariable variable=VARIABLE_SLAVE_BASE_TAG]$SLAVE_BASE_TAG" env: REGISTRY_SERVER: ${{ parameters.registry_url }} displayName: Build sonic-slave-${{ parameters.dist }}-${{ parameters.arch }} - - - task: Docker@2 - condition: ne(variables['Build.Reason'], 'PullRequest') - displayName: Upload image - inputs: - containerRegistry: ${{ parameters.registry_conn }} - repository: $(VARIABLE_SLAVE_BASE_IMAGE) - command: push - ${{ if eq(variables['Build.SourceBranchName'], 'master') }}: - tags: | - $(VARIABLE_SLAVE_BASE_TAG) - latest - ${{ else }}: - tags: | - $(VARIABLE_SLAVE_BASE_TAG) - - ${{ if ne(parameters.arch, 'amd64') }}: - - task: Docker@2 - condition: ne(variables['Build.Reason'], 'PullRequest') - displayName: Upload image ${{ parameters.dist }} - inputs: - containerRegistry: ${{ parameters.registry_conn }} - repository: "sonic-slave-${{ parameters.dist }}" - command: push - tags: | - $(VARIABLE_SLAVE_BASE_TAG) diff --git a/.azure-pipelines/docker-sonic-slave.yml b/.azure-pipelines/docker-sonic-slave.yml index cd8a6df4aff..b9f9e215249 100644 --- a/.azure-pipelines/docker-sonic-slave.yml +++ b/.azure-pipelines/docker-sonic-slave.yml @@ -12,26 +12,25 @@ resources: endpoint: sonic-net schedules: -- cron: "0 8 * * *" +- cron: "0 0 * * 0" + displayName: Weekly build branches: include: - master - - 202012 + - 202??? always: true -trigger: none -pr: +pr: none +trigger: branches: include: - master + - 202??? paths: include: - - sonic-slave-jessie - - sonic-slave-stretch - - sonic-slave-buster - - sonic-slave-bullseye + - sonic-slave-* - src/sonic-build-hooks - - .azure-pipelines + - files/build/versions parameters: - name: 'arches' @@ -60,15 +59,20 @@ stages: - ${{ each dist in parameters.dists }}: - ${{ if endswith(variables['Build.DefinitionName'], dist) }}: - ${{ each arch in parameters.arches }}: - - ${{ if eq(variables['Build.Reason'], 'PullRequest') }}: - - template: docker-sonic-slave-template.yml - parameters: - pool: sonicbld - arch: ${{ arch }} - dist: ${{ dist }} - - ${{ else }}: - - template: '/.azure-pipelines/docker-sonic-slave-template.yml@buildimage' + - template: .azure-pipelines/docker-sonic-slave-template.yml@buildimage + parameters: + pool: sonicbld + arch: ${{ arch }} + dist: ${{ dist }} +- stage: Build_march + jobs: + - ${{ each dist in parameters.dists }}: + - ${{ if endswith(variables['Build.DefinitionName'], dist) }}: + - ${{ each arch in parameters.arches }}: + - ${{ if ne(arch, 'amd64') }}: + - template: .azure-pipelines/docker-sonic-slave-template.yml@buildimage parameters: - pool: sonicbld + pool: sonicbld-${{ arch }} arch: ${{ arch }} dist: ${{ dist }} + march: march_ From 5e20ded25a22e109c092786d48e1cfa1125170c2 Mon Sep 17 00:00:00 2001 From: shilongliu Date: Wed, 31 Aug 2022 14:26:02 +0800 Subject: [PATCH 2/6] fix --- .azure-pipelines/docker-sonic-slave-template.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.azure-pipelines/docker-sonic-slave-template.yml b/.azure-pipelines/docker-sonic-slave-template.yml index 31f978fca83..8bdee896148 100644 --- a/.azure-pipelines/docker-sonic-slave-template.yml +++ b/.azure-pipelines/docker-sonic-slave-template.yml @@ -72,11 +72,14 @@ jobs: image_latest=$(echo $(echo $image_tag | awk -F: '{print$1}'):latest) docker rmi $image_tag || true - if docker pull ${{ parameters.registry_url }}/${image_tag};then + if [[ "$(Build.Reason)" == "IndividualCI" ]] && docker pull ${{ parameters.registry_url }}/${image_tag};then exit 0 fi DOCKER_DATA_ROOT_FOR_MULTIARCH=/data/march/docker make configure PLATFORM=generic PLATFORM_ARCH=${{ parameters.arch }} $args || docker image ls $image_tag + if [[ "$(Build.Reason)" == "PullRequest" ]];then + exit 0 + fi docker tag ${image_tag} ${REGISTRY_SERVER}/${image_tag} docker push ${REGISTRY_SERVER}/${image_tag} From 0f36bd795884c21e9d50dd0a7b1cddf18dcdff10 Mon Sep 17 00:00:00 2001 From: shilongliu Date: Wed, 31 Aug 2022 14:29:30 +0800 Subject: [PATCH 3/6] fix --- .azure-pipelines/docker-sonic-slave.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.azure-pipelines/docker-sonic-slave.yml b/.azure-pipelines/docker-sonic-slave.yml index b9f9e215249..0cc229feb0a 100644 --- a/.azure-pipelines/docker-sonic-slave.yml +++ b/.azure-pipelines/docker-sonic-slave.yml @@ -31,6 +31,8 @@ trigger: - sonic-slave-* - src/sonic-build-hooks - files/build/versions + - Makefile + - Makefile.work parameters: - name: 'arches' From 9c972b2afa5779b909eac5e1e3af31b8cef6b95b Mon Sep 17 00:00:00 2001 From: shilongliu Date: Wed, 31 Aug 2022 14:35:10 +0800 Subject: [PATCH 4/6] fix --- .azure-pipelines/docker-sonic-slave.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.azure-pipelines/docker-sonic-slave.yml b/.azure-pipelines/docker-sonic-slave.yml index 0cc229feb0a..8c2fb952f38 100644 --- a/.azure-pipelines/docker-sonic-slave.yml +++ b/.azure-pipelines/docker-sonic-slave.yml @@ -67,6 +67,7 @@ stages: arch: ${{ arch }} dist: ${{ dist }} - stage: Build_march + dependsOn: [] jobs: - ${{ each dist in parameters.dists }}: - ${{ if endswith(variables['Build.DefinitionName'], dist) }}: From df0f931a4fc793e42b27df70a96f1cf8e2de2d32 Mon Sep 17 00:00:00 2001 From: shilongliu Date: Thu, 1 Sep 2022 13:46:13 +0800 Subject: [PATCH 5/6] fix --- .azure-pipelines/docker-sonic-slave-template.yml | 16 +--------------- .azure-pipelines/docker-sonic-slave.yml | 1 + 2 files changed, 2 insertions(+), 15 deletions(-) diff --git a/.azure-pipelines/docker-sonic-slave-template.yml b/.azure-pipelines/docker-sonic-slave-template.yml index 8bdee896148..0ec1d9ed373 100644 --- a/.azure-pipelines/docker-sonic-slave-template.yml +++ b/.azure-pipelines/docker-sonic-slave-template.yml @@ -54,21 +54,7 @@ jobs: containerRegistry: ${{ parameters.registry_conn }} - bash: | set -ex - case ${{ parameters.dist }} in - bullseye) - args='NOJESSIE=1 NOSTRETCH=1 NOBUSTER=1' - ;; - buster) - args='NOJESSIE=1 NOSTRETCH=1 NOBULLSEYE=1' - ;; - stretch) - args='NOJESSIE=1 NOBUSTER=1 NOBULLSEYE=1' - ;; - jessie) - args='NOSTRETCH=1 NOBUSTER=1 NOBULLSEYE=1' - ;; - esac - image_tag=$(make showtag PLATFORM=generic PLATFORM_ARCH=${{ parameters.arch }} $args | grep sonic-slave | tail -n 1) + image_tag=$(BLDENV=${{ parameters.dist }} make -f Makefile.work showtag PLATFORM=generic PLATFORM_ARCH=${{ parameters.arch }} | grep sonic-slave | tail -n 1) image_latest=$(echo $(echo $image_tag | awk -F: '{print$1}'):latest) docker rmi $image_tag || true diff --git a/.azure-pipelines/docker-sonic-slave.yml b/.azure-pipelines/docker-sonic-slave.yml index 8c2fb952f38..dd7a11d2c53 100644 --- a/.azure-pipelines/docker-sonic-slave.yml +++ b/.azure-pipelines/docker-sonic-slave.yml @@ -22,6 +22,7 @@ schedules: pr: none trigger: + batch: true branches: include: - master From 284f62cb19856ff4556d0a1ba774f342030237df Mon Sep 17 00:00:00 2001 From: shilongliu Date: Fri, 2 Sep 2022 16:02:50 +0800 Subject: [PATCH 6/6] fix --- .azure-pipelines/docker-sonic-slave-template.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.azure-pipelines/docker-sonic-slave-template.yml b/.azure-pipelines/docker-sonic-slave-template.yml index 0ec1d9ed373..1a7b983b5c1 100644 --- a/.azure-pipelines/docker-sonic-slave-template.yml +++ b/.azure-pipelines/docker-sonic-slave-template.yml @@ -58,7 +58,7 @@ jobs: image_latest=$(echo $(echo $image_tag | awk -F: '{print$1}'):latest) docker rmi $image_tag || true - if [[ "$(Build.Reason)" == "IndividualCI" ]] && docker pull ${{ parameters.registry_url }}/${image_tag};then + if [[ "$(Build.Reason)" =~ [a-zA-Z]*CI ]] && docker pull ${{ parameters.registry_url }}/${image_tag};then exit 0 fi