From 6e6dcd0c924d60261944cacf213606ba257fcb2b Mon Sep 17 00:00:00 2001 From: CrazyMax <1951866+crazy-max@users.noreply.github.com> Date: Tue, 19 Dec 2023 10:21:10 +0100 Subject: [PATCH] dockerfile: mitigate flaky smoke test with timeout "buildkitd --version" might hang when using emulation during smoke test. Add a timeout to mitigate this issue and avoid blocking CI. This is currently tracked in https://github.com/moby/buildkit/pull/4491 Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com> --- Dockerfile | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index d83374d2e2fe8..4614844bba9f8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -122,7 +122,30 @@ RUN --mount=target=. --mount=target=/root/.cache,type=cache \ set -ex xx-go build ${GOBUILDFLAGS} -gcflags="${GOGCFLAGS}" -ldflags "$(cat /tmp/.ldflags) -extldflags '-static'" -tags "osusergo netgo static_build seccomp ${BUILDKITD_TAGS}" -o /usr/bin/buildkitd ./cmd/buildkitd xx-verify ${VERIFYFLAGS} /usr/bin/buildkitd - if [ "$(xx-info os)" = "linux" ]; then /usr/bin/buildkitd --version; fi + + # buildkitd --version can be flaky when running through emulation related to + # https://github.com/moby/buildkit/pull/4491. Retry a few times as a workaround. + set +ex + if [ "$(xx-info os)" = "linux" ]; then + max_retries=5 + for attempt in $(seq "$max_retries"); do + timeout 3 /usr/bin/buildkitd --version + exitcode=$? + if ! xx-info is-cross; then + exit $exitcode + elif [ $exitcode -eq 0 ]; then + break + elif [ $exitcode -eq 124 ] || [ $exitcode -eq 143 ]; then + echo "WARN: buildkitd --version timed out ($attempt/$max_retries)" + else + echo "ERROR: buildkitd --version failed with exit code $exitcode ($attempt/$max_retries)" + if [ "$attempt" -eq "$max_retries" ]; then + exit $exitcode + fi + fi + sleep 1 + done + fi EOT FROM scratch AS binaries-linux