-
Notifications
You must be signed in to change notification settings - Fork 346
Make install_packages resilient to 500 Server Error
#3286
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,34 @@ | ||||||
| #!/bin/sh | ||||||
|
|
||||||
| MAX_ATTEMPTS=5 | ||||||
| WAIT_TIME=10 | ||||||
| RETRY_COUNT=0 | ||||||
|
|
||||||
| # Check if any package names were provided | ||||||
| if [ $# -eq 0 ]; then | ||||||
| echo "Error: install_packages requires at least one package name." >&2 | ||||||
| exit 1 | ||||||
| fi | ||||||
|
|
||||||
| # Loop for retry attempts | ||||||
| while [ $RETRY_COUNT -lt $MAX_ATTEMPTS ]; do | ||||||
| echo "Attempt $((RETRY_COUNT + 1)) of $MAX_ATTEMPTS: Running install_packages $@" | ||||||
|
|
||||||
| # Execute the actual install command | ||||||
| install_packages "$@" | ||||||
|
|
||||||
| # Check the exit status of the previous command | ||||||
| if [ $? -eq 0 ]; then | ||||||
| echo "Packages installed successfully." | ||||||
| exit 0 # Success, exit the function | ||||||
|
||||||
| exit 0 # Success, exit the function | |
| exit 0 # Success, exit the script |
Copilot
AI
Nov 19, 2025
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.
Using $? in a condition is fragile. The exit status should be captured immediately after the command. Consider rewriting as:
if install_packages "$@"; then
echo "Packages installed successfully."
exit 0
else
RETRY_COUNT=$((RETRY_COUNT + 1))
# ... rest of error handling
fiThis ensures the exit status is evaluated correctly without risk of being overwritten by intervening commands.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,17 +15,18 @@ RUN echo "deb http://archive.debian.org/debian/ buster main" > /etc/apt/sources. | |
|
|
||
| # TODO install_packages calls apt-get update and then nukes the list files after. We should avoid multiple calls to apt-get update..... | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @nik9000 I don't fully understand your comment above, but I wonder if the wrapper script that I'm introducing can help in any way. |
||
| # We could probably fix this by running the update and installs ourself with `RUN --mount type=cache` but that is "experimental" | ||
| COPY --chmod=755 .docker/install_packages.sh /usr/local/bin/ | ||
|
|
||
| # Fix for Debian Buster EOL - point to archive repositories | ||
| RUN sed -i 's/deb.debian.org/archive.debian.org/g' /etc/apt/sources.list && \ | ||
| sed -i 's/security.debian.org/archive.debian.org/g' /etc/apt/sources.list && \ | ||
| sed -i '/buster-updates/d' /etc/apt/sources.list | ||
|
|
||
| RUN install_packages apt-transport-https gnupg2 ca-certificates | ||
| RUN install_packages.sh apt-transport-https gnupg2 ca-certificates | ||
| COPY .docker/apt/keys/nodesource.gpg / | ||
| RUN apt-key add /nodesource.gpg | ||
| COPY .docker/apt/sources.list.d/nodesource.list /etc/apt/sources.list.d/ | ||
| RUN install_packages \ | ||
| RUN install_packages.sh \ | ||
| build-essential python2 \ | ||
| # needed for compiling native modules on ARM | ||
| nodejs ruby \ | ||
|
|
@@ -43,7 +44,7 @@ ENV LC_ALL en_US.UTF-8 | |
|
|
||
|
|
||
| FROM base AS ruby_deps | ||
| RUN install_packages \ | ||
| RUN install_packages.sh \ | ||
| bundler \ | ||
| # Fetches ruby dependencies | ||
| ruby-dev make cmake gcc libc-dev patch | ||
|
|
@@ -61,7 +62,7 @@ FROM base AS node_deps | |
| COPY .docker/apt/keys/yarn.gpg / | ||
| RUN apt-key add /yarn.gpg | ||
| COPY .docker/apt/sources.list.d/yarn.list /etc/apt/sources.list.d/ | ||
| RUN install_packages yarn=1.22.19-1 | ||
| RUN install_packages.sh yarn=1.22.19-1 | ||
| COPY package.json / | ||
| COPY yarn.lock / | ||
| ENV YARN_CACHE_FOLDER=/tmp/.yarn-cache | ||
|
|
@@ -74,7 +75,7 @@ RUN yarn install --frozen-lockfile --production | |
| # Dockerfiles to make the images to serve previews and air gapped docs. | ||
| FROM base AS build | ||
| LABEL MAINTAINERS="Nik Everett <nik@elastic.co>" | ||
| RUN install_packages \ | ||
| RUN install_packages.sh \ | ||
| git \ | ||
| # Clone source repositories and commit to destination repositories | ||
| libnss-wrapper \ | ||
|
|
@@ -110,7 +111,7 @@ RUN rm -rf /var/log/nginx && rm -rf /run/nginx | |
| ##### Everything below this run tests | ||
| FROM base AS py_test | ||
| # There's not a published wheel for yamale, so we need setuptools and wheel | ||
| RUN install_packages python3 python3-pip python3-setuptools python3-wheel python3-dev libxml2-dev libxslt-dev zlib1g-dev | ||
| RUN install_packages.sh python3 python3-pip python3-setuptools python3-wheel python3-dev libxml2-dev libxslt-dev zlib1g-dev | ||
| RUN pip3 install \ | ||
| beautifulsoup4==4.8.1 \ | ||
| lxml==4.4.2 \ | ||
|
|
@@ -131,4 +132,4 @@ COPY --from=ruby_test /usr/local/bin/rspec /usr/local/bin/rspec | |
| COPY --from=ruby_test /usr/local/bin/rubocop /usr/local/bin/rubocop | ||
|
|
||
| FROM py_test AS diff_tool | ||
| RUN install_packages git | ||
| RUN install_packages.sh git | ||
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 variable
$@should be quoted as"$@"to properly handle arguments containing spaces or special characters. Without quotes, arguments with spaces will be split into multiple arguments.