From 9ed9e9eec580c1adf464fcb15028a677466f7392 Mon Sep 17 00:00:00 2001 From: Gabriel Adrian Samfira Date: Tue, 13 Jun 2023 22:37:20 +0300 Subject: [PATCH] Add retries for curl calls Signed-off-by: Gabriel Adrian Samfira --- cloudconfig/templates.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cloudconfig/templates.go b/cloudconfig/templates.go index bfffe1fc..e7c7e7db 100644 --- a/cloudconfig/templates.go +++ b/cloudconfig/templates.go @@ -36,11 +36,11 @@ if [ -z "$METADATA_URL" ];then echo "no token is available and METADATA_URL is not set" exit 1 fi -GITHUB_TOKEN=$(curl --fail -s -X GET -H 'Accept: application/json' -H "Authorization: Bearer ${BEARER_TOKEN}" "${METADATA_URL}/runner-registration-token/") +GITHUB_TOKEN=$(curl --retry 5 --retry-max-time 5 --fail -s -X GET -H 'Accept: application/json' -H "Authorization: Bearer ${BEARER_TOKEN}" "${METADATA_URL}/runner-registration-token/") function call() { PAYLOAD="$1" - curl --fail -s -X POST -d "${PAYLOAD}" -H 'Accept: application/json' -H "Authorization: Bearer ${BEARER_TOKEN}" "${CALLBACK_URL}" || echo "failed to call home: exit code ($?)" + curl --retry 5 --retry-max-time 5 --retry-all-errors --fail -s -X POST -d "${PAYLOAD}" -H 'Accept: application/json' -H "Authorization: Bearer ${BEARER_TOKEN}" "${CALLBACK_URL}" || echo "failed to call home: exit code ($?)" } function sendStatus() { @@ -93,7 +93,7 @@ function downloadAndExtractRunner() { if [ ! -z "{{ .TempDownloadToken }}" ]; then TEMP_TOKEN="Authorization: Bearer {{ .TempDownloadToken }}" fi - curl -L -H "${TEMP_TOKEN}" -o "/home/{{ .RunnerUsername }}/{{ .FileName }}" "{{ .DownloadURL }}" || fail "failed to download tools" + curl --retry 5 --retry-max-time 5 --retry-all-errors --fail -L -H "${TEMP_TOKEN}" -o "/home/{{ .RunnerUsername }}/{{ .FileName }}" "{{ .DownloadURL }}" || fail "failed to download tools" mkdir -p /home/runner/actions-runner || fail "failed to create actions-runner folder" sendStatus "extracting runner" tar xf "/home/{{ .RunnerUsername }}/{{ .FileName }}" -C /home/{{ .RunnerUsername }}/actions-runner/ || fail "failed to extract runner"