Fix sonic slave pipeline to set correct tag on sonic slave image. (#13177) (#13385)

This commit is contained in:
Liu Shilong 2023-01-18 11:33:11 +08:00 committed by GitHub
parent 82f4a2628b
commit 5db68009ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,26 +3,36 @@
# Add steps that build, run tests, deploy, and more: # Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml # https://aka.ms/yaml
# Build and push sonic-slave-[buster|jessie|stretch] images for amd64/armhf/arm64 # 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: schedules:
- cron: "0 8 * * *" - cron: "0 0 * * 0"
displayName: Weekly build
branches: branches:
include: include:
- master - master
- 202012 - 202???
always: true always: true
trigger: none pr: none
pr: trigger:
batch: true
branches: branches:
include: include:
- master - master
- 202???
paths: paths:
include: include:
- sonic-slave-jessie - sonic-slave-*
- sonic-slave-stretch - files/build/versions
- sonic-slave-buster - Makefile
- src/sonic-build-hooks - Makefile.work
parameters: parameters:
- name: 'arches' - name: 'arches'
@ -34,6 +44,7 @@ parameters:
- name: 'dists' - name: 'dists'
type: object type: object
default: default:
- bullseye
- buster - buster
- stretch - stretch
- jessie - jessie
@ -44,70 +55,29 @@ parameters:
type: string type: string
default: sonicdev default: sonicdev
variables:
- ${{ if eq(variables['Build.SourceBranchName'], '202012') }}:
- name: BUILD_OPTIONS
value: 'SONIC_VERSION_CONTROL_COMPONENTS=deb,py2,py3,web,git,docker'
stages: stages:
- stage: Build - stage: Build_in_amd64
jobs: jobs:
- ${{ each dist in parameters.dists }}: - ${{ each dist in parameters.dists }}:
- ${{ if endswith(variables['Build.DefinitionName'], dist) }}: - ${{ if endswith(variables['Build.DefinitionName'], dist) }}:
- ${{ each arch in parameters.arches }}: - ${{ each arch in parameters.arches }}:
- job: Build_${{ dist }}_${{ arch }} - template: .azure-pipelines/docker-sonic-slave-template.yml@buildimage
timeoutInMinutes: 360 parameters:
pool: sonicbld pool: sonicbld
steps: arch: ${{ arch }}
- template: cleanup.yml dist: ${{ dist }}
- checkout: self ${{ if ne(arch, 'amd64') }}:
clean: true march: _march_${{ arch }}
submodules: recursive - stage: Build_native_arm
- bash: | dependsOn: []
set -ex jobs:
- ${{ each dist in parameters.dists }}:
containers=$(docker container ls | grep "sonic-slave" | awk '{ print $1 }') - ${{ if endswith(variables['Build.DefinitionName'], dist) }}:
if [ ! -z "$containers" ]; then - ${{ each arch in parameters.arches }}:
docker container kill $containers || true - ${{ if ne(arch, 'amd64') }}:
sleep 5 - template: .azure-pipelines/docker-sonic-slave-template.yml@buildimage
fi parameters:
images=$(docker images 'sonic-slave-*' -a -q) pool: sonicbld-${{ arch }}
if [ ! -z "$images" ]; then arch: ${{ arch }}
docker rmi -f $images dist: ${{ dist }}
fi march: _${{ arch }}
SLAVE_DIR=sonic-slave-${{ dist }}
if [ x${{ arch }} == x"amd64" ]; then
SLAVE_BASE_IMAGE=${SLAVE_DIR}
else
SLAVE_BASE_IMAGE=${SLAVE_DIR}-march-${{ arch }}
fi
tmpfile=$(mktemp)
echo ${{ arch }} > .arch
DOCKER_DATA_ROOT_FOR_MULTIARCH=/data/march/docker BLDENV=${{ 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:latest
docker tag $SLAVE_BASE_IMAGE:$SLAVE_BASE_TAG $REGISTRY_SERVER/$SLAVE_BASE_IMAGE:$SLAVE_BASE_TAG
set +x
echo "##vso[task.setvariable variable=VARIABLE_SLAVE_BASE_IMAGE]$SLAVE_BASE_IMAGE"
echo "##vso[task.setvariable variable=VARIABLE_SLAVE_BASE_TAG]$SLAVE_BASE_TAG"
env:
REGISTRY_SERVER: ${{ parameters.registry_url }}
displayName: Build sonic-slave-${{ dist }}-${{ arch }}
- task: Docker@2
displayName: Upload image
inputs:
containerRegistry: ${{ parameters.registry_conn }}
repository: $(VARIABLE_SLAVE_BASE_IMAGE)
command: push
tags: |
$(VARIABLE_SLAVE_BASE_TAG)
latest