forked from opendatahub-io/notebooks
-
Notifications
You must be signed in to change notification settings - Fork 26
[rhoai-2.25] RHAIENG-2645: add loop to retry package installation when it fails #1883
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
daniellutz
wants to merge
2
commits into
red-hat-data-services:rhoai-2.25
Choose a base branch
from
daniellutz:dnf-loop-retry
base: rhoai-2.25
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| #!/bin/bash | ||
|
|
||
| # Shared install script with retry logic for dnf, texlive (install_pdf_deps), and npm. | ||
| # Usage: | ||
| # ./install_with_retry.sh dnf-install <package> [package ...] | ||
| # ./install_with_retry.sh texlive-install | ||
| # ./install_with_retry.sh npm-install | ||
|
|
||
| set -Eeuxo pipefail | ||
|
|
||
| readonly MAX_RETRIES="${MAX_RETRIES:-3}" | ||
| readonly RETRY_DELAY="${RETRY_DELAY:-30}" | ||
|
|
||
| # Runs a command with retry logic. | ||
| # Optional: set CLEANUP_CMD to a shell command (e.g. "dnf clean metadata") to run between retries. | ||
| # Returns 0 on success, exits 1 after MAX_RETRIES failures. | ||
| run_with_retry() { | ||
| local retry_count=0 | ||
| while true; do | ||
| if "$@"; then | ||
| return 0 | ||
| fi | ||
| retry_count=$((retry_count + 1)) | ||
| if [ "$retry_count" -ge "$MAX_RETRIES" ]; then | ||
| echo "ERROR: Command failed after $MAX_RETRIES attempts" >&2 | ||
| exit 1 | ||
| fi | ||
| echo "Command failed (attempt $retry_count/$MAX_RETRIES), retrying in ${RETRY_DELAY} seconds..." | ||
| if [ -n "${CLEANUP_CMD:-}" ]; then | ||
| $CLEANUP_CMD || true | ||
| fi | ||
| sleep "$RETRY_DELAY" | ||
| done | ||
| } | ||
|
|
||
| dnf_install() { | ||
| local packages=("$@") | ||
| if [ ${#packages[@]} -eq 0 ]; then | ||
| echo "Usage: $0 dnf-install <package> [package ...]" >&2 | ||
| exit 1 | ||
| fi | ||
| CLEANUP_CMD="dnf clean metadata" run_with_retry dnf install -y ${DNF_EXTRA_OPTS:-} "${packages[@]}" | ||
| dnf clean all | ||
| rm -rf /var/cache/yum | ||
| } | ||
|
|
||
| texlive_install() { | ||
| local script_dir | ||
| script_dir="$(cd "$(dirname "$0")" && pwd)" | ||
| CLEANUP_CMD= run_with_retry "$script_dir/install_pdf_deps.sh" | ||
| } | ||
|
|
||
| npm_install() { | ||
| CLEANUP_CMD="rm -rf node_modules" run_with_retry npm install | ||
| } | ||
|
|
||
| main() { | ||
| case "${1:-}" in | ||
| dnf-install) | ||
| shift | ||
| dnf_install "$@" | ||
| ;; | ||
| texlive-install) | ||
| texlive_install | ||
| ;; | ||
| npm-install) | ||
| npm_install | ||
| ;; | ||
| *) | ||
| echo "Usage: $0 {dnf-install|texlive-install|npm-install} [args...]" >&2 | ||
| echo " dnf-install <package> [package ...] Install RPM packages with retry" >&2 | ||
| echo " texlive-install Run install_pdf_deps.sh with retry" >&2 | ||
| echo " npm-install Run npm install with retry" >&2 | ||
| exit 1 | ||
| ;; | ||
| esac | ||
| } | ||
|
|
||
| # Only run main when this script is executed directly (not when sourced by run-code-server.sh) | ||
| if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then | ||
| main "$@" | ||
| fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On my trials the other time I had timeout issues on
npm installstep, can you wrap that line with the retry script?https://github.com/daniellutz/odh-notebooks/blob/83c426252f148afac76f61b5e221ef823e21efdd/codeserver/ubi9-python-3.12/get_code_server_rpm.sh#L68C2-L68C13
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the idea of the script (thanks Jiri, again) was to improve that as well, npm install, dnf upgrade and anything that could require the retry loop
let me wrap it as well
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added the
npm installretry loop as well for codeserver imageon purpose, I did not add the loop to
npm run build, let's see if onnpm installwill be enough