@@ -10,6 +10,9 @@ parameters:
1010 - amd64
1111 - armhf
1212 - arm64
13+ - name : march
14+ type : string
15+ default : ' '
1316- name : dist
1417 type : string
1518 values :
@@ -32,89 +35,44 @@ parameters:
3235 - sonicbld-armhf
3336
3437jobs :
35- - job : Build_${{ parameters.dist }}_${{ parameters.arch }}
38+ - job : Build_${{ parameters.dist }}_${{ parameters.march }}${{ parameters. arch }}
3639 timeoutInMinutes : 360
40+ variables :
41+ - template : .azure-pipelines/template-variables.yml@buildimage
42+ - template : .azure-pipelines/azure-pipelines-repd-build-variables.yml@buildimage
3743 pool : ${{ parameters.pool }}
3844 steps :
3945 - template : cleanup.yml
40- - ${{ if eq(variables['Build.Reason'], 'PullRequest') }} :
41- - template : template-clean-sonic-slave.yml
42- - ${{ else }} :
43- - template : ' /.azure-pipelines/template-clean-sonic-slave.yml@buildimage'
46+ - template : .azure-pipelines/template-clean-sonic-slave.yml@buildimage
4447 - checkout : self
4548 clean : true
4649 submodules : recursive
50+ - task : Docker@2
51+ displayName : Login to ACR
52+ inputs :
53+ command : login
54+ containerRegistry : ${{ parameters.registry_conn }}
4755 - bash : |
4856 set -ex
57+ image_tag=$(BLDENV=${{ parameters.dist }} make -f Makefile.work showtag PLATFORM=generic PLATFORM_ARCH=${{ parameters.arch }} | grep sonic-slave | tail -n 1)
58+ image_latest=$(echo $(echo $image_tag | awk -F: '{print$1}'):latest)
59+ docker rmi $image_tag || true
4960
50- SLAVE_DIR=sonic-slave-${{ parameters.dist }}
51- if [ x${{ parameters.pool }} == x"sonicbld" ]; then
52- if [ x${{ parameters.arch }} == x"amd64" ]; then
53- SLAVE_BASE_IMAGE=${SLAVE_DIR}
54- SLAVE_BASE_IMAGE_UPLOAD=${SLAVE_DIR}
55- elif [ x${{ parameters.pool }} == x"sonicbld" ]; then
56- SLAVE_BASE_IMAGE=${SLAVE_DIR}-march-${{ parameters.arch }}
57- SLAVE_BASE_IMAGE_UPLOAD=${SLAVE_DIR}-march-${{ parameters.arch }}
58- fi
59- elif [[ x${{ parameters.pool }} == x"sonicbld-armhf" && x${{ parameters.arch }} == x"armhf" ]]; then
60- SLAVE_BASE_IMAGE=${SLAVE_DIR}
61- SLAVE_BASE_IMAGE_UPLOAD=${SLAVE_DIR}-armhf
62- elif [[ x${{ parameters.pool }} == x"sonicbld-arm64" && x${{ parameters.arch }} == x"arm64" ]]; then
63- SLAVE_BASE_IMAGE=${SLAVE_DIR}
64- SLAVE_BASE_IMAGE_UPLOAD=${SLAVE_DIR}-arm64
65- else
66- echo "do not support build ${{ parameters.arch }} on ${{ parameters.pool }}"
67- exit 1
61+ if [[ "$(Build.Reason)" =~ [a-zA-Z]*CI ]] && docker pull ${{ parameters.registry_url }}/${image_tag};then
62+ exit 0
6863 fi
6964
70- if [ x"$(Build.SourceBranchName)" == x"202012" ]; then
71- BUILD_OPTIONS = 'SONIC_VERSION_CONTROL_COMPONENTS=deb,py2,py3,web,git,docker'
65+ DOCKER_DATA_ROOT_FOR_MULTIARCH=/data/march/docker make configure PLATFORM=generic PLATFORM_ARCH=${{ parameters.arch }} $args || docker image ls $image_tag
66+ if [[ "$(Build.Reason)" == "PullRequest" ]];then
67+ exit 0
7268 fi
7369
74- tmpfile=$(mktemp)
75-
76- echo ${{ parameters.arch }} > .arch
77-
78- DOCKER_DATA_ROOT_FOR_MULTIARCH=/data/march/docker BLDENV=${{ parameters.dist }} $(BUILD_OPTIONS) make -f Makefile.work sonic-slave-build | tee $tmpfile
79- SLAVE_BASE_TAG=$(grep "^Checking sonic-slave-base image:" $tmpfile | awk -F ':' '{print $3}')
80- SLAVE_TAG=$(grep "^Checking sonic-slave image:" $tmpfile | awk -F ':' '{print $3}')
81-
82- mkdir -p target
83-
84- docker tag $SLAVE_BASE_IMAGE:$SLAVE_BASE_TAG $REGISTRY_SERVER/$SLAVE_BASE_IMAGE_UPLOAD:latest
85- docker tag $SLAVE_BASE_IMAGE:$SLAVE_BASE_TAG $REGISTRY_SERVER/$SLAVE_BASE_IMAGE_UPLOAD:$SLAVE_BASE_TAG
86- if [ "$SLAVE_BASE_IMAGE_UPLOAD" != "$SLAVE_DIR" ]; then
87- docker tag $SLAVE_BASE_IMAGE:$SLAVE_BASE_TAG $REGISTRY_SERVER/$SLAVE_DIR:latest-${{ parameters.arch }}
88- docker tag $SLAVE_BASE_IMAGE:$SLAVE_BASE_TAG $REGISTRY_SERVER/$SLAVE_DIR:$SLAVE_BASE_TAG
70+ docker tag ${image_tag} ${REGISTRY_SERVER}/${image_tag}
71+ docker push ${REGISTRY_SERVER}/${image_tag}
72+ if [[ "${{ parameters.arch }}" == "amd64" ]];then
73+ docker tag ${image_tag} ${REGISTRY_SERVER}/${image_latest}
74+ docker push ${REGISTRY_SERVER}/${image_latest}
8975 fi
90- set +x
91- echo "##vso[task.setvariable variable=VARIABLE_SLAVE_BASE_IMAGE]$SLAVE_BASE_IMAGE_UPLOAD"
92- echo "##vso[task.setvariable variable=VARIABLE_SLAVE_BASE_TAG]$SLAVE_BASE_TAG"
9376 env:
9477 REGISTRY_SERVER: ${{ parameters.registry_url }}
9578 displayName: Build sonic-slave-${{ parameters.dist }}-${{ parameters.arch }}
96-
97- - task : Docker@2
98- condition : ne(variables['Build.Reason'], 'PullRequest')
99- displayName : Upload image
100- inputs :
101- containerRegistry : ${{ parameters.registry_conn }}
102- repository : $(VARIABLE_SLAVE_BASE_IMAGE)
103- command : push
104- ${{ if eq(variables['Build.SourceBranchName'], 'master') }} :
105- tags : |
106- $(VARIABLE_SLAVE_BASE_TAG)
107- latest
108- ${{ else }} :
109- tags : |
110- $(VARIABLE_SLAVE_BASE_TAG)
111- - ${{ if ne(parameters.arch, 'amd64') }} :
112- - task : Docker@2
113- condition : ne(variables['Build.Reason'], 'PullRequest')
114- displayName : Upload image ${{ parameters.dist }}
115- inputs :
116- containerRegistry : ${{ parameters.registry_conn }}
117- repository : " sonic-slave-${{ parameters.dist }}"
118- command : push
119- tags : |
120- $(VARIABLE_SLAVE_BASE_TAG)
0 commit comments