Skip to content

Commit 364045c

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 b65e06f commit 364045c

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
@@ -33,20 +33,21 @@ PLATFORM_PATH := platform/$(if $(PLATFORM),$(PLATFORM),$(CONFIGURED_PLATFORM))
3333
PLATFORM_CHECKOUT := platform/checkout
3434
PLATFORM_CHECKOUT_FILE := $(PLATFORM_CHECKOUT)/$(PLATFORM).ini
3535
PLATFORM_CHECKOUT_CMD := $(shell if [ -f $(PLATFORM_CHECKOUT_FILE) ]; then PLATFORM_PATH=$(PLATFORM_PATH) j2 $(PLATFORM_CHECKOUT)/template.j2 $(PLATFORM_CHECKOUT_FILE); fi)
36+
MAKE_WITH_RETRY := ./scripts/run_with_retry $(MAKE)
3637

3738
%::
3839
@echo "+++ --- Making $@ --- +++"
3940
ifeq ($(NOJESSIE), 0)
40-
EXTRA_DOCKER_TARGETS=$(notdir $@) $(MAKE) -f Makefile.work jessie
41+
$(MAKE_WITH_RETRY) EXTRA_DOCKER_TARGETS=$(notdir $@) -f Makefile.work jessie
4142
endif
4243
ifeq ($(NOSTRETCH), 0)
43-
EXTRA_DOCKER_TARGETS=$(notdir $@) BLDENV=stretch $(MAKE) -f Makefile.work stretch
44+
$(MAKE_WITH_RETRY) EXTRA_DOCKER_TARGETS=$(notdir $@) BLDENV=stretch -f Makefile.work stretch
4445
endif
4546
ifeq ($(NOBUSTER), 0)
46-
EXTRA_DOCKER_TARGETS=$(notdir $@) BLDENV=buster $(MAKE) -f Makefile.work buster
47+
$(MAKE_WITH_RETRY) EXTRA_DOCKER_TARGETS=$(notdir $@) BLDENV=buster -f Makefile.work buster
4748
endif
4849
ifeq ($(NOBULLSEYE), 0)
49-
BLDENV=bullseye $(MAKE) -f Makefile.work $@
50+
$(MAKE_WITH_RETRY) BLDENV=bullseye -f Makefile.work $@
5051
endif
5152
BLDENV=bullseye $(MAKE) -f Makefile.work docker-cleanup
5253

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)