armbian-next: use retries for downloading ORAS tooling

- `do_with_retries()`: add `IS_A_RETRY` and `RETRY_FMT_MORE_THAN_ONCE` for convenient logging in retried functions
This commit is contained in:
Ricardo Pardini 2023-01-18 00:31:31 +01:00
parent a13fe8d947
commit be49433b41
No known key found for this signature in database
GPG Key ID: 3D38CA12A66C5D02
2 changed files with 26 additions and 11 deletions

View File

@ -42,17 +42,7 @@ function run_tool_oras() {
declare ACTUAL_VERSION
if [[ ! -f "${ORAS_BIN}" ]]; then
display_alert "Cache miss, downloading..."
display_alert "MACHINE: ${MACHINE}" "ORAS" "debug"
display_alert "Down URL: ${DOWN_URL}" "ORAS" "debug"
display_alert "ORAS_BIN: ${ORAS_BIN}" "ORAS" "debug"
display_alert "Downloading required" "ORAS tooling" "info"
run_host_command_logged wget --no-verbose --progress=dot:giga -O "${ORAS_BIN}.tar.gz" "${DOWN_URL}"
run_host_command_logged tar -xf "${ORAS_BIN}.tar.gz" -C "${DIR_ORAS}" "oras"
run_host_command_logged rm -rf "${ORAS_BIN}.tar.gz"
run_host_command_logged mv -v "${DIR_ORAS}/oras" "${ORAS_BIN}"
run_host_command_logged chmod -v +x "${ORAS_BIN}"
do_with_retries 5 try_download_oras_tooling
fi
ACTUAL_VERSION="$("${ORAS_BIN}" version | grep "^Version" | xargs echo -n)"
display_alert "Running ORAS ${ACTUAL_VERSION}" "ORAS" "debug"
@ -62,6 +52,22 @@ function run_tool_oras() {
"${ORAS_BIN}" "$@"
}
function try_download_oras_tooling() {
display_alert "MACHINE: ${MACHINE}" "ORAS" "debug"
display_alert "Down URL: ${DOWN_URL}" "ORAS" "debug"
display_alert "ORAS_BIN: ${ORAS_BIN}" "ORAS" "debug"
display_alert "Downloading required" "ORAS tooling${RETRY_FMT_MORE_THAN_ONCE}" "info"
run_host_command_logged wget --no-verbose --progress=dot:giga -O "${ORAS_BIN}.tar.gz.tmp" "${DOWN_URL}" || {
return 1
}
run_host_command_logged mv "${ORAS_BIN}.tar.gz.tmp" "${ORAS_BIN}.tar.gz"
run_host_command_logged tar -xf "${ORAS_BIN}.tar.gz" -C "${DIR_ORAS}" "oras"
run_host_command_logged rm -rf "${ORAS_BIN}.tar.gz"
run_host_command_logged mv "${DIR_ORAS}/oras" "${ORAS_BIN}"
run_host_command_logged chmod +x "${ORAS_BIN}"
}
function oras_push_artifact_file() {
declare image_full_oci="${1}" # Something like "ghcr.io/rpardini/armbian-git-shallow/kernel-git:latest"
declare upload_file="${2}" # Absolute path to the file to upload including the path and name

View File

@ -10,13 +10,22 @@ function do_with_retries() {
while [[ $counter -lt $retries ]]; do
counter=$((counter + 1))
declare -i RETRY_RUNS=${counter}
declare -i IS_A_RETRY=0
declare RETRY_FMT_MORE_THAN_ONCE=""
if [[ ${RETRY_RUNS} -gt 1 ]]; then
IS_A_RETRY=1
RETRY_FMT_MORE_THAN_ONCE=" (attempt ${RETRY_RUNS})"
fi
"$@" && return 0 # execute and return 0 if success; if not, let it loop;
if [[ "${silent_retry}" == "yes" ]]; then
: # do nothing
else
display_alert "Command failed, retrying in ${sleep_seconds}s" "$*" "warn"
fi
unset IS_A_RETRY
unset RETRY_RUNS
unset RETRY_FMT_MORE_THAN_ONCE
sleep "${sleep_seconds}"
done
display_alert "Command failed ${counter} times, giving up" "$*" "warn"