From 67ae105a4f5b0b1e810ebd86ace16a606725e3a4 Mon Sep 17 00:00:00 2001 From: Carmine Vassallo Date: Tue, 26 Sep 2023 18:20:24 +0200 Subject: [PATCH] SONAR-20383 Add retry mechanism for multi-architecture docker build --- .cirrus.yml | 4 ++-- .cirrus/multi-arch-build.sh | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) create mode 100755 .cirrus/multi-arch-build.sh diff --git a/.cirrus.yml b/.cirrus.yml index 88c8f97f..7a404b75 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -54,12 +54,12 @@ multi_arch_build_task: - docker login --username $DOCKER_USERNAME --password $DOCKER_PASSWORD setup_script: - docker run -t --rm --privileged tonistiigi/binfmt --install all - - docker buildx create --name multibuilder + - docker buildx create --name multibuilder --driver docker-container - docker buildx use multibuilder - docker buildx inspect --bootstrap build_script: - echo "Build the ${STAGING_IMAGE_NAME}:${tag} image supporting two architectures, linux/amd64 and linux/arm64" - - docker buildx build --platform linux/amd64,linux/arm64 --tag "${STAGING_IMAGE_NAME}:${tag}" --push ${version} + - .cirrus/multi-arch-build.sh ${STAGING_IMAGE_NAME} ${tag} ${version} private_scan_task: env: diff --git a/.cirrus/multi-arch-build.sh b/.cirrus/multi-arch-build.sh new file mode 100755 index 00000000..61a9ccde --- /dev/null +++ b/.cirrus/multi-arch-build.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +export DOCKER_BUILDKIT=1 +for i in $(seq 1 3); do + if docker buildx build --platform linux/amd64,linux/arm64 --tag "$1:$2" --push $3; then + echo "[Success]: Buildx, attempt ${i}" + break + fi + sleep 3 + if [[ "${i}" == "3" ]]; then + echo "[Error]: Context Deadline Exceeded - Buildx" + exit 1 + fi +done \ No newline at end of file