Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ RUN JAVA_HOME=/usr/lib/jvm/java-17-openjdk mvn clean install -DskipTests=true
FROM registry.access.redhat.com/ubi9/ubi-minimal AS index-download
RUN microdnf install -y wget zip && microdnf clean all && rm -rf /var/cache/dnf
WORKDIR /maven-index-data
#TODO: get latest release when we get to update them periodically
RUN wget --quiet https://github.com/konveyor/maven-search-index/releases/download/v0.0.1/maven-index-data-v0.0.1.zip -O maven-index-data.zip && unzip maven-index-data.zip && rm maven-index-data.zip
RUN DOWNLOAD_URL=$(wget --quiet -O - https://api.github.com/repos/konveyor/maven-search-index/releases/latest | grep '"browser_download_url".*maven-index-data.*\.zip' | sed -E 's/.*"browser_download_url": "([^"]+)".*/\1/') && \
wget --quiet ${DOWNLOAD_URL} -O maven-index-data.zip && \
unzip maven-index-data.zip && \
rm maven-index-data.zip
Comment on lines +31 to +34
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Add error handling for API query and URL extraction failures.

If the GitHub API call fails, the grep doesn't match, or sed fails to extract a valid URL, DOWNLOAD_URL will be empty. The subsequent wget ${DOWNLOAD_URL} will execute with no argument, leading to silent failures or undefined behavior. Docker RUN instructions do not enable set -e by default, so failures in the grep/sed pipeline won't halt the build—the build will succeed despite a missing download.

Apply this diff to add explicit error handling:

 RUN DOWNLOAD_URL=$(wget --quiet -O - https://api.github.com/repos/konveyor/maven-search-index/releases/latest | grep '"browser_download_url".*maven-index-data.*\.zip' | sed -E 's/.*"browser_download_url": "([^"]+)".*/\1/') && \
+    if [ -z "$DOWNLOAD_URL" ]; then echo "Failed to extract download URL from GitHub API"; exit 1; fi && \
     wget --quiet ${DOWNLOAD_URL} -O maven-index-data.zip && \
     unzip maven-index-data.zip && \
     rm maven-index-data.zip

Alternatively, use a more robust approach:

-RUN DOWNLOAD_URL=$(wget --quiet -O - https://api.github.com/repos/konveyor/maven-search-index/releases/latest | grep '"browser_download_url".*maven-index-data.*\.zip' | sed -E 's/.*"browser_download_url": "([^"]+)".*/\1/') && \
+RUN DOWNLOAD_URL=$(wget --quiet -O - https://api.github.com/repos/konveyor/maven-search-index/releases/latest | grep -o '"browser_download_url":"[^"]*maven-index-data[^"]*\.zip[^"]*"' | head -1 | cut -d'"' -f4) && \
+    test -n "$DOWNLOAD_URL" || (echo "Failed to extract download URL"; exit 1) && \
     wget --quiet ${DOWNLOAD_URL} -O maven-index-data.zip && \
     unzip maven-index-data.zip && \
     rm maven-index-data.zip
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
RUN DOWNLOAD_URL=$(wget --quiet -O - https://api.github.com/repos/konveyor/maven-search-index/releases/latest | grep '"browser_download_url".*maven-index-data.*\.zip' | sed -E 's/.*"browser_download_url": "([^"]+)".*/\1/') && \
wget --quiet ${DOWNLOAD_URL} -O maven-index-data.zip && \
unzip maven-index-data.zip && \
rm maven-index-data.zip
RUN DOWNLOAD_URL=$(wget --quiet -O - https://api.github.com/repos/konveyor/maven-search-index/releases/latest | grep '"browser_download_url".*maven-index-data.*\.zip' | sed -E 's/.*"browser_download_url": "([^"]+)".*/\1/') && \
if [ -z "$DOWNLOAD_URL" ]; then echo "Failed to extract download URL from GitHub API"; exit 1; fi && \
wget --quiet ${DOWNLOAD_URL} -O maven-index-data.zip && \
unzip maven-index-data.zip && \
rm maven-index-data.zip
🤖 Prompt for AI Agents
In Dockerfile around lines 31 to 34, the RUN pipeline that queries the GitHub
API and extracts a download URL can produce an empty DOWNLOAD_URL (if the API
call, grep, or sed fails) which then causes wget to run with no argument and the
build to continue silently; update this block to explicitly fail the build on
any error by enabling errexit for the command (or test the extracted variable),
validate that DOWNLOAD_URL is non-empty before calling wget (exit with a clear
error message if empty), and prefer using a robust API parsing command (e.g.,
curl/wget with non-zero-exit check and jq to extract the browser_download_url)
so that any HTTP or parsing failure stops the Docker build and surfaces a
helpful error.


FROM registry.access.redhat.com/ubi9/ubi-minimal
# Java 1.8 is required for backwards compatibility with older versions of Gradle
Expand Down
Loading