Skip to content

Commit 8bb5e19

Browse files
[build] Add retry when make SONiC image to improve success rate. (#12325) (#13132)
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 f4e005a commit 8bb5e19

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
variables:
2+
DEFAULT_CONTAINER_REGISTRY: 'publicmirror.azurecr.io'
3+
COMMON_LIB_BUILD_ENVS: 'bullseye'
4+
SONIC_SLAVE_DOCKER_DRIVER: 'overlay2'
5+
SONIC_BUILD_RETRY_COUNT: 3
6+
SONIC_BUILD_RETRY_INTERVAL: 600

Makefile

+4-3
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,17 @@ PLATFORM_PATH := platform/$(if $(PLATFORM),$(PLATFORM),$(CONFIGURED_PLATFORM))
1515
PLATFORM_CHECKOUT := platform/checkout
1616
PLATFORM_CHECKOUT_FILE := $(PLATFORM_CHECKOUT)/$(PLATFORM).ini
1717
PLATFORM_CHECKOUT_CMD := $(shell if [ -f $(PLATFORM_CHECKOUT_FILE) ]; then PLATFORM_PATH=$(PLATFORM_PATH) j2 $(PLATFORM_CHECKOUT)/template.j2 $(PLATFORM_CHECKOUT_FILE); fi)
18+
MAKE_WITH_RETRY := ./scripts/run_with_retry $(MAKE)
1819

1920
%::
2021
@echo "+++ --- Making $@ --- +++"
2122
ifeq ($(NOJESSIE), 0)
22-
EXTRA_DOCKER_TARGETS=$(notdir $@) make -f Makefile.work jessie
23+
$(MAKE_WITH_RETRY) EXTRA_DOCKER_TARGETS=$(notdir $@) -f Makefile.work jessie
2324
endif
2425
ifeq ($(NOSTRETCH), 0)
25-
EXTRA_DOCKER_TARGETS=$(notdir $@) BLDENV=stretch make -f Makefile.work stretch
26+
$(MAKE_WITH_RETRY) EXTRA_DOCKER_TARGETS=$(notdir $@) BLDENV=stretch -f Makefile.work stretch
2627
endif
27-
BLDENV=buster make -f Makefile.work $@
28+
$(MAKE_WITH_RETRY) BLDENV=buster -f Makefile.work $@
2829

2930
jessie:
3031
@echo "+++ Making $@ +++"

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)