Skip to content

Commit e135191

Browse files
[ci] Fix remove sonic-slave-* docker image issue when building sonic-slave* (sonic-net#10296)
1 parent 8d0aea0 commit e135191

File tree

2 files changed

+107
-0
lines changed

2 files changed

+107
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# Starter pipeline
2+
# Start with a minimal pipeline that you can customize to build and deploy your code.
3+
# Add steps that build, run tests, deploy, and more:
4+
# https://aka.ms/yaml
5+
# Build and push sonic-slave-[buster|jessie|stretch] images for amd64/armhf/arm64
6+
7+
parameters:
8+
- name: arch
9+
type: string
10+
values:
11+
- amd64
12+
- armhf
13+
- arm64
14+
- name: dist
15+
type: string
16+
values:
17+
- bullseye
18+
- buster
19+
- stretch
20+
- jessie
21+
- name: registry_url
22+
type: string
23+
default: sonicdev-microsoft.azurecr.io
24+
- name: registry_conn
25+
type: string
26+
default: sonicdev
27+
- name: pool
28+
type: string
29+
default: sonicbld
30+
values:
31+
- sonicbld
32+
- sonicbld-arm64
33+
- sonicbld-armhf
34+
35+
jobs:
36+
- job: Build_${{ parameters.dist }}_${{ parameters.arch }}
37+
timeoutInMinutes: 360
38+
pool: ${{ parameters.pool }}
39+
steps:
40+
- template: cleanup.yml
41+
- template: template-clean-sonic-slave.yml
42+
- checkout: self
43+
clean: true
44+
submodules: recursive
45+
- bash: |
46+
set -ex
47+
48+
SLAVE_DIR=sonic-slave-${{ parameters.dist }}
49+
if [ x${{ parameters.pool }} == x"sonicbld" ]; then
50+
if [ x${{ parameters.arch }} == x"amd64" ]; then
51+
SLAVE_BASE_IMAGE=${SLAVE_DIR}
52+
SLAVE_BASE_IMAGE_UPLOAD=${SLAVE_DIR}
53+
elif [ x${{ parameters.pool }} == x"sonicbld" ]; then
54+
SLAVE_BASE_IMAGE=${SLAVE_DIR}-march-${{ parameters.arch }}
55+
SLAVE_BASE_IMAGE_UPLOAD=${SLAVE_DIR}-march-${{ parameters.arch }}
56+
fi
57+
elif [[ x${{ parameters.pool }} == x"sonicbld-armhf" && x${{ parameters.arch }} == x"armhf" ]]; then
58+
SLAVE_BASE_IMAGE=${SLAVE_DIR}
59+
SLAVE_BASE_IMAGE_UPLOAD=${SLAVE_DIR}-armhf
60+
elif [[ x${{ parameters.pool }} == x"sonicbld-arm64" && x${{ parameters.arch }} == x"arm64" ]]; then
61+
SLAVE_BASE_IMAGE=${SLAVE_DIR}
62+
SLAVE_BASE_IMAGE_UPLOAD=${SLAVE_DIR}-arm64
63+
else
64+
echo "do not support build ${{ parameters.arch }} on ${{ parameters.pool }}"
65+
exit 1
66+
fi
67+
68+
if [ x"$(Build.SourceBranchName)" == x"202012" ]; then
69+
BUILD_OPTIONS = 'SONIC_VERSION_CONTROL_COMPONENTS=deb,py2,py3,web,git,docker'
70+
fi
71+
72+
tmpfile=$(mktemp)
73+
74+
echo ${{ parameters.arch }} > .arch
75+
76+
DOCKER_DATA_ROOT_FOR_MULTIARCH=/data/march/docker BLDENV=${{ parameters.dist }} $(BUILD_OPTIONS) make -f Makefile.work sonic-slave-build | tee $tmpfile
77+
SLAVE_BASE_TAG=$(grep "^Checking sonic-slave-base image:" $tmpfile | awk -F ':' '{print $3}')
78+
SLAVE_TAG=$(grep "^Checking sonic-slave image:" $tmpfile | awk -F ':' '{print $3}')
79+
80+
mkdir -p target
81+
82+
docker tag $SLAVE_BASE_IMAGE:$SLAVE_BASE_TAG $REGISTRY_SERVER/$SLAVE_BASE_IMAGE_UPLOAD:latest
83+
docker tag $SLAVE_BASE_IMAGE:$SLAVE_BASE_TAG $REGISTRY_SERVER/$SLAVE_BASE_IMAGE_UPLOAD:$SLAVE_BASE_TAG
84+
set +x
85+
echo "##vso[task.setvariable variable=VARIABLE_SLAVE_BASE_IMAGE]$SLAVE_BASE_IMAGE_UPLOAD"
86+
echo "##vso[task.setvariable variable=VARIABLE_SLAVE_BASE_TAG]$SLAVE_BASE_TAG"
87+
env:
88+
REGISTRY_SERVER: ${{ parameters.registry_url }}
89+
displayName: Build sonic-slave-${{ parameters.dist }}-${{ parameters.arch }}
90+
91+
- task: Docker@2
92+
displayName: Upload image
93+
inputs:
94+
containerRegistry: ${{ parameters.registry_conn }}
95+
repository: $(VARIABLE_SLAVE_BASE_IMAGE)
96+
command: push
97+
tags: |
98+
$(VARIABLE_SLAVE_BASE_TAG)
99+
latest
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
steps:
2+
- script: |
3+
containers=$(docker container ls -a | grep "sonic-slave" | awk '{ print $1 }')
4+
[ -n "$containers" ] && docker container rm -f containers
5+
docker images | grep "^<none>" | awk '{print$3}' | xargs -i docker rmi {}
6+
images=$(docker images 'sonic-slave-*' -a -q)
7+
[ -n "$images" ] && docker rmi -f $images
8+
displayName: 'Cleanup sonic slave'

0 commit comments

Comments
 (0)