Skip to content

Commit 4d1b370

Browse files
[build] Add retry when make SONiC image to improve success rate. (sonic-net#12325)
Why I did it Makefile needs some dependencies from the Internet. It will fail for network related issue. Retries will fix most of these issues. How I did it Add retries when running commands which maybe related with networking. How to verify it
1 parent a8376ef commit 4d1b370

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

.azure-pipelines/template-variables.yml

+2
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ variables:
22
DEFAULT_CONTAINER_REGISTRY: 'publicmirror.azurecr.io'
33
COMMON_LIB_BUILD_ENVS: 'bullseye'
44
SONIC_SLAVE_DOCKER_DRIVER: 'overlay2'
5+
SONIC_BUILD_RETRY_COUNT: 3
6+
SONIC_BUILD_RETRY_INTERVAL: 600

Makefile

+5-4
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,21 @@ PLATFORM_PATH := platform/$(if $(PLATFORM),$(PLATFORM),$(CONFIGURED_PLATFORM))
2525
PLATFORM_CHECKOUT := platform/checkout
2626
PLATFORM_CHECKOUT_FILE := $(PLATFORM_CHECKOUT)/$(PLATFORM).ini
2727
PLATFORM_CHECKOUT_CMD := $(shell if [ -f $(PLATFORM_CHECKOUT_FILE) ]; then PLATFORM_PATH=$(PLATFORM_PATH) j2 $(PLATFORM_CHECKOUT)/template.j2 $(PLATFORM_CHECKOUT_FILE); fi)
28+
MAKE_WITH_RETRY := ./scripts/run_with_retry $(MAKE)
2829

2930
%::
3031
@echo "+++ --- Making $@ --- +++"
3132
ifeq ($(NOJESSIE), 0)
32-
EXTRA_DOCKER_TARGETS=$(notdir $@) make -f Makefile.work jessie
33+
$(MAKE_WITH_RETRY) EXTRA_DOCKER_TARGETS=$(notdir $@) -f Makefile.work jessie
3334
endif
3435
ifeq ($(NOSTRETCH), 0)
35-
EXTRA_DOCKER_TARGETS=$(notdir $@) BLDENV=stretch make -f Makefile.work stretch
36+
$(MAKE_WITH_RETRY) EXTRA_DOCKER_TARGETS=$(notdir $@) BLDENV=stretch -f Makefile.work stretch
3637
endif
3738
ifeq ($(NOBUSTER), 0)
38-
EXTRA_DOCKER_TARGETS=$(notdir $@) BLDENV=buster make -f Makefile.work buster
39+
$(MAKE_WITH_RETRY) EXTRA_DOCKER_TARGETS=$(notdir $@) BLDENV=buster -f Makefile.work buster
3940
endif
4041
ifeq ($(NOBULLSEYE), 0)
41-
BLDENV=bullseye make -f Makefile.work $@
42+
$(MAKE_WITH_RETRY) BLDENV=bullseye -f Makefile.work $@
4243
endif
4344
BLDENV=bullseye make -f Makefile.work docker-cleanup
4445

scripts/run_with_retry

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
3+
run_with_retry(){
4+
[ "$SONIC_BUILD_RETRY_COUNT" -gt 0 ] || SONIC_BUILD_RETRY_COUNT=0
5+
[[ "$*" == "" ]] && { echo "run_with_retry: input command can't be empty." 1>&2;exit 1; }
6+
for ((i=0; i<=$SONIC_BUILD_RETRY_COUNT; i++))
7+
do
8+
if [[ $i != 0 ]];then
9+
echo "==============================================================================" 1>&2
10+
echo "Waiting $SONIC_BUILD_RETRY_INTERVAL to run again, $i/$SONIC_BUILD_RETRY_COUNT" 1>&2
11+
echo "==============================================================================" 1>&2
12+
sleep $SONIC_BUILD_RETRY_INTERVAL
13+
fi
14+
"$@" && break
15+
done
16+
}
17+
run_with_retry "$@"

0 commit comments

Comments
 (0)