diff --git a/.pipeline/e2e-tests.yaml b/.pipeline/e2e-tests.yaml index 2a9bf5e0..eede806b 100644 --- a/.pipeline/e2e-tests.yaml +++ b/.pipeline/e2e-tests.yaml @@ -105,7 +105,7 @@ jobs: helm version --short kubectl version --client yq --version - go mod download + sh ./hack/retry-go.sh mod download df -h / mkdir -p "$LOG_DIR" displayName: Check E2E prerequisites diff --git a/docker/hub-gateway-controller-manager.Dockerfile b/docker/hub-gateway-controller-manager.Dockerfile index f3e50854..76842db0 100644 --- a/docker/hub-gateway-controller-manager.Dockerfile +++ b/docker/hub-gateway-controller-manager.Dockerfile @@ -7,7 +7,9 @@ ARG GOARCH=amd64 WORKDIR /workspace COPY go.mod go.mod COPY go.sum go.sum -RUN --mount=type=cache,target=/go/pkg/mod go mod download +RUN --mount=type=cache,target=/go/pkg/mod \ + --mount=type=bind,source=hack/retry-go.sh,target=/tmp/retry-go.sh \ + sh /tmp/retry-go.sh mod download COPY cmd/hub-gateway-controller-manager/ cmd/hub-gateway-controller-manager/ COPY api/ api/ diff --git a/docker/hub-net-controller-manager.Dockerfile b/docker/hub-net-controller-manager.Dockerfile index ef60b0a0..7b192eeb 100644 --- a/docker/hub-net-controller-manager.Dockerfile +++ b/docker/hub-net-controller-manager.Dockerfile @@ -10,7 +10,9 @@ COPY go.mod go.mod COPY go.sum go.sum # Cache the downloaded dependency modules across different builds to expedite the progress. # This also helps reduce downloading related reliability issues in our build environment. -RUN --mount=type=cache,target=/go/pkg/mod go mod download +RUN --mount=type=cache,target=/go/pkg/mod \ + --mount=type=bind,source=hack/retry-go.sh,target=/tmp/retry-go.sh \ + sh /tmp/retry-go.sh mod download # Copy the go source COPY cmd/hub-net-controller-manager/main.go main.go diff --git a/docker/mcs-controller-manager.Dockerfile b/docker/mcs-controller-manager.Dockerfile index 7d5b79ce..778bf74f 100644 --- a/docker/mcs-controller-manager.Dockerfile +++ b/docker/mcs-controller-manager.Dockerfile @@ -10,7 +10,9 @@ COPY go.mod go.mod COPY go.sum go.sum # Cache the downloaded dependency modules across different builds to expedite the progress. # This also helps reduce downloading related reliability issues in our build environment. -RUN --mount=type=cache,target=/go/pkg/mod go mod download +RUN --mount=type=cache,target=/go/pkg/mod \ + --mount=type=bind,source=hack/retry-go.sh,target=/tmp/retry-go.sh \ + sh /tmp/retry-go.sh mod download # Copy the go source COPY cmd/mcs-controller-manager/main.go main.go diff --git a/docker/member-net-controller-manager.Dockerfile b/docker/member-net-controller-manager.Dockerfile index 0297da2d..165a4738 100644 --- a/docker/member-net-controller-manager.Dockerfile +++ b/docker/member-net-controller-manager.Dockerfile @@ -10,7 +10,9 @@ COPY go.mod go.mod COPY go.sum go.sum # Cache the downloaded dependency modules across different builds to expedite the progress. # This also helps reduce downloading related reliability issues in our build environment. -RUN --mount=type=cache,target=/go/pkg/mod go mod download +RUN --mount=type=cache,target=/go/pkg/mod \ + --mount=type=bind,source=hack/retry-go.sh,target=/tmp/retry-go.sh \ + sh /tmp/retry-go.sh mod download # Copy the go source COPY cmd/member-net-controller-manager/main.go main.go diff --git a/docker/net-crd-installer.Dockerfile b/docker/net-crd-installer.Dockerfile index 146d255c..273f1e09 100644 --- a/docker/net-crd-installer.Dockerfile +++ b/docker/net-crd-installer.Dockerfile @@ -10,7 +10,9 @@ COPY go.mod go.mod COPY go.sum go.sum # Cache the downloaded dependency modules across different builds to expedite the progress. # This also helps reduce downloading related reliability issues in our build environment. -RUN --mount=type=cache,target=/go/pkg/mod go mod download +RUN --mount=type=cache,target=/go/pkg/mod \ + --mount=type=bind,source=hack/retry-go.sh,target=/tmp/retry-go.sh \ + sh /tmp/retry-go.sh mod download # Copy the go source COPY cmd/net-crd-installer/ cmd/net-crd-installer/ diff --git a/hack/go-install.sh b/hack/go-install.sh index 8f035620..cdd092d4 100755 --- a/hack/go-install.sh +++ b/hack/go-install.sh @@ -25,6 +25,7 @@ if [[ -z "${GOBIN}" ]]; then exit 1 fi +retry_go="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/retry-go.sh" tmp_dir=$(mktemp -d -t goinstall_XXXXXXXXXX) function clean { rm -rf "${tmp_dir}" @@ -39,6 +40,6 @@ cd "${tmp_dir}" go mod init fake/mod # install the golang module specified as the first argument -go install "${1}@${3}" +sh "$retry_go" install "${1}@${3}" mv "${GOBIN}/${2}" "${GOBIN}/${2}-${3}" ln -sf "${GOBIN}/${2}-${3}" "${GOBIN}/${2}" diff --git a/hack/retry-go.sh b/hack/retry-go.sh new file mode 100644 index 00000000..cb46d67f --- /dev/null +++ b/hack/retry-go.sh @@ -0,0 +1,20 @@ +#!/bin/sh +set -eu + +if [ "$#" -eq 0 ]; then + echo "error: provide a Go command to retry" >&2 + exit 1 +fi + +for attempt in 1 2 3; do + if go "$@"; then + exit 0 + fi + if [ "$attempt" -eq 3 ]; then + echo "error: go $* failed after 3 attempts" >&2 + exit 1 + fi + delay=$((attempt * 10)) + echo "go $* failed; retrying in $delay seconds..." >&2 + sleep "$delay" +done