Kokoro: Retry gclient sync

Network IO appears to flake. Try up to 5 times before giving up.

Change-Id: I1c58e2b603495835d2410a1256aa70c0fe10ee98
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/49340
Kokoro: Kokoro <noreply+kokoro@google.com>
Auto-Submit: Ben Clayton <bclayton@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
diff --git a/kokoro/linux/docker.sh b/kokoro/linux/docker.sh
index 3796c9b..6a8358c 100755
--- a/kokoro/linux/docker.sh
+++ b/kokoro/linux/docker.sh
@@ -38,6 +38,21 @@
     echo ""
     task_begin $@
 }
+function with_retry {
+  local MAX_ATTEMPTS=5
+  local RETRY_DELAY_SECS=5
+  local ATTEMPT=1
+  while true; do
+    "$@" && break
+    if [[ $ATTEMPT -ge $MAX_ATTEMPTS ]]; then
+        echo "The command has failed after $ATTEMPT attempts."
+        exit $?
+    fi
+    ((ATTEMPT++))
+    echo "'$@' failed. Attempt ($ATTEMPT/$MAX_ATTEMPTS). Retrying..."
+    sleep $RETRY_DELAY_SECS;
+  done
+}
 
 ORIGINAL_SRC_DIR="$(pwd)"
 
@@ -55,7 +70,7 @@
 
 status "Fetching dependencies"
 cp standalone.gclient .gclient
-gclient sync
+with_retry gclient sync
 
 status "Configuring build system"
 if [ "$BUILD_SYSTEM" == "cmake" ]; then