Skip to content

Commit d3612c1

Browse files
authored
[ci] Update docker sonic slave pipeline to build slave base docker (#11908) (#12340)
1 parent 96c48fa commit d3612c1

File tree

4 files changed

+52
-190
lines changed

4 files changed

+52
-190
lines changed

.azure-pipelines/docker-sonic-slave-arm64.yml

Lines changed: 0 additions & 52 deletions
This file was deleted.

.azure-pipelines/docker-sonic-slave-armhf.yml

Lines changed: 0 additions & 52 deletions
This file was deleted.

.azure-pipelines/docker-sonic-slave-template.yml

Lines changed: 26 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -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

3437
jobs:
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)

.azure-pipelines/docker-sonic-slave.yml

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,28 @@ resources:
1212
endpoint: sonic-net
1313

1414
schedules:
15-
- cron: "0 8 * * *"
15+
- cron: "0 0 * * 0"
16+
displayName: Weekly build
1617
branches:
1718
include:
1819
- master
19-
- 202012
20+
- 202???
2021
always: true
2122

22-
trigger: none
23-
pr:
23+
pr: none
24+
trigger:
25+
batch: true
2426
branches:
2527
include:
2628
- master
29+
- 202???
2730
paths:
2831
include:
29-
- sonic-slave-jessie
30-
- sonic-slave-stretch
31-
- sonic-slave-buster
32-
- sonic-slave-bullseye
32+
- sonic-slave-*
3333
- src/sonic-build-hooks
34-
- .azure-pipelines
34+
- files/build/versions
35+
- Makefile
36+
- Makefile.work
3537

3638
parameters:
3739
- name: 'arches'
@@ -60,15 +62,21 @@ stages:
6062
- ${{ each dist in parameters.dists }}:
6163
- ${{ if endswith(variables['Build.DefinitionName'], dist) }}:
6264
- ${{ each arch in parameters.arches }}:
63-
- ${{ if eq(variables['Build.Reason'], 'PullRequest') }}:
64-
- template: docker-sonic-slave-template.yml
65-
parameters:
66-
pool: sonicbld
67-
arch: ${{ arch }}
68-
dist: ${{ dist }}
69-
- ${{ else }}:
70-
- template: '/.azure-pipelines/docker-sonic-slave-template.yml@buildimage'
65+
- template: .azure-pipelines/docker-sonic-slave-template.yml@buildimage
66+
parameters:
67+
pool: sonicbld
68+
arch: ${{ arch }}
69+
dist: ${{ dist }}
70+
- stage: Build_march
71+
dependsOn: []
72+
jobs:
73+
- ${{ each dist in parameters.dists }}:
74+
- ${{ if endswith(variables['Build.DefinitionName'], dist) }}:
75+
- ${{ each arch in parameters.arches }}:
76+
- ${{ if ne(arch, 'amd64') }}:
77+
- template: .azure-pipelines/docker-sonic-slave-template.yml@buildimage
7178
parameters:
72-
pool: sonicbld
79+
pool: sonicbld-${{ arch }}
7380
arch: ${{ arch }}
7481
dist: ${{ dist }}
82+
march: march_

0 commit comments

Comments
 (0)