Skip to content
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

chore(build): move deps buold codes to onghorn/dep-versions #851

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

derekbit
Copy link
Member

@derekbit derekbit commented Feb 5, 2025

Which issue(s) this PR fixes:

Issue longhorn/longhorn#10208

What this PR does / why we need it:

  • move deps buold codes to onghorn/dep-versions
  • update workflows/build.yml

Special notes for your reviewer:

Additional documentation or context

@derekbit derekbit self-assigned this Feb 5, 2025
Copy link

coderabbitai bot commented Feb 5, 2025

Walkthrough

The changes update the CI workflow and associated scripts to dynamically determine a dependency version branch for Docker image builds on both AMD64 and ARM64 architectures. A new step in the GitHub Actions workflow calls a Bash script that retrieves the branch based on a local version file. The Dockerfile and package script now use this branch information to fetch dependency configuration from a remote repository. Additionally, new functions for version conversion and branch retrieval have been added to streamline dependency version management.

Changes

File(s) Change Summary
.github/workflows/build.yml Added new steps in both build-push-amd64-images and build-push-arm64-images jobs to execute a script for retrieving the dependency version branch and passing it via build arguments.
.github/workflows/scripts/build.sh
scripts/package
Introduced and/or modified functions (get_branch and convert_version_to_major_minor_x) to read a local version file, format the version, fetch versions.json from a remote repository, and return the branch name with error handling fallback to "main".
package/Dockerfile Replaced the DEP_VERSION_FILE argument with a BRANCH argument. Updated the build process by cloning the dep-versions repository and retrieving the dependency information from a remote source using the branch value.

Sequence Diagram(s)

sequenceDiagram
  participant CI as GitHub Actions Workflow
  participant Script as Build Script (build.sh / package script)
  participant File as Local "version" File
  participant Remote as Remote Repo (versions.json)
  participant Docker as Docker Build Process

  CI->>Script: Execute "Get Deps-Version Branch" step
  Script->>File: Check for "version" file
  File-->>Script: Return version value
  Script->>Script: Convert version (convert_version_to_major_minor_x)
  Script->>Remote: Attempt to download versions.json using branch value
  alt Download succeeds
    Remote-->>Script: Return versions.json
    Script-->>CI: Echo derived branch value
  else Download fails
    Script-->>CI: Return "main" as branch value
  end
  CI->>Docker: Pass BRANCH in build arguments for Docker image
Loading

Assessment against linked issues

Objective Addressed Explanation
Centrally manage dependent packages' version info via longhorn/dep-versions [#10208]

Possibly related PRs

Suggested reviewers

  • DamiaSan
  • innobead
  • mantissahz
  • shuo-wu
  • c3y1huang

Tip

🌐 Web search-backed reviews and chat
  • We have enabled web search-based reviews and chat for all users. This feature allows CodeRabbit to access the latest documentation and information on the web.
  • You can disable this feature by setting web_search: false in the knowledge_base settings.
  • Please share any feedback in the Discord discussion.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
scripts/package (1)

51-68: Improve error handling and file path in get_branch function.

The function has a few areas for improvement:

  1. The wget command downloads to /versions.json which might require root permissions
  2. The exit code check can be simplified

Apply this diff to improve the implementation:

 function get_branch() {
   local version_file="version"
   if [[ ! -f $version_file ]]; then
     echo "Error: Version file '$version_file' not found."
     exit 1
   fi

   local version=$(cat "$version_file")
   local branch=$(convert_version_to_major_minor_x "$version")

   # Fetch versions.json from the appropriate branch, fallback to main
-  wget -q "https://raw.githubusercontent.com/longhorn/dep-versions/${branch}/versions.json" -O /versions.json
-  if [ $? -eq 0 ]; then
+  if wget -q "https://raw.githubusercontent.com/longhorn/dep-versions/${branch}/versions.json" -O versions.json; then
     echo "${branch}"
   else
     echo "main"
   fi
 }
🧰 Tools
🪛 GitHub Check: CodeFactor

[notice] 63-63: scripts/package#L63
Check exit code directly with e.g. 'if mycmd;', not indirectly with $?. (SC2181)

.github/workflows/scripts/build.sh (1)

12-29: Improve variable declarations and error handling in get_branch function.

The function has a few areas for improvement:

  1. Variable declarations should be separate from assignments to avoid masking return values
  2. The exit code check can be simplified

Apply this diff to improve the implementation:

 function get_branch() {
     local version_file="version"
     if [[ ! -f $version_file ]]; then
         echo "Error: Version file '$version_file' not found."
         exit 1
     fi

-    local version=$(cat "$version_file")
-    local branch=$(convert_version_to_major_minor_x "$version")
+    local version branch
+    version=$(cat "$version_file")
+    branch=$(convert_version_to_major_minor_x "$version")

     # Fetch versions.json from the appropriate branch, fallback to main
-    wget -q "https://raw.githubusercontent.com/longhorn/dep-versions/${branch}/versions.json" -O versions.json
-    if [ $? -eq 0 ]; then
+    if wget -q "https://raw.githubusercontent.com/longhorn/dep-versions/${branch}/versions.json" -O versions.json; then
         echo "${branch}"
     else
         echo "main"
     fi
 }
🧰 Tools
🪛 Shellcheck (0.10.0)

[warning] 19-19: Declare and assign separately to avoid masking return values.

(SC2155)


[warning] 20-20: Declare and assign separately to avoid masking return values.

(SC2155)

🪛 GitHub Check: CodeFactor

[notice] 24-24: .github/workflows/scripts/build.sh#L24
Check exit code directly with e.g. 'if mycmd;', not indirectly with $?. (SC2181)

package/Dockerfile (1)

28-30: Improve wget command in grpc_health_probe installation.

Add progress indicator or use quiet mode for better output control.

Apply this diff:

-RUN export GRPC_HEALTH_PROBE_DOWNLOAD_URL=$(wget -qO- https://api.github.com/repos/grpc-ecosystem/grpc-health-probe/releases/latest | jq -r '.assets[] | select(.name | test("linux.*'"${ARCH}"'"; "i")) | .browser_download_url') && \
+RUN export GRPC_HEALTH_PROBE_DOWNLOAD_URL=$(wget --progress=dot:giga -O- https://api.github.com/repos/grpc-ecosystem/grpc-health-probe/releases/latest | jq -r '.assets[] | select(.name | test("linux.*'"${ARCH}"'"; "i")) | .browser_download_url') && \
     wget ${GRPC_HEALTH_PROBE_DOWNLOAD_URL} -O /usr/local/bin/grpc_health_probe && \
     chmod +x /usr/local/bin/grpc_health_probe
🧰 Tools
🪛 GitHub Check: CodeFactor

[notice] 28-28: package/Dockerfile#L28
Avoid use of wget without progress bar. Use wget --progress=dot:giga <url>. Or consider using -q or -nv (shorthands for --quiet or --no-verbose). (DL3047)

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0a4a540 and 2c2658c.

📒 Files selected for processing (4)
  • .github/workflows/build.yml (6 hunks)
  • .github/workflows/scripts/build.sh (1 hunks)
  • package/Dockerfile (3 hunks)
  • scripts/package (1 hunks)
🧰 Additional context used
🪛 Shellcheck (0.10.0)
.github/workflows/scripts/build.sh

[warning] 19-19: Declare and assign separately to avoid masking return values.

(SC2155)


[warning] 20-20: Declare and assign separately to avoid masking return values.

(SC2155)

🪛 GitHub Check: CodeFactor
.github/workflows/scripts/build.sh

[notice] 24-24: .github/workflows/scripts/build.sh#L24
Check exit code directly with e.g. 'if mycmd;', not indirectly with $?. (SC2181)

package/Dockerfile

[notice] 28-28: package/Dockerfile#L28
Avoid use of wget without progress bar. Use wget --progress=dot:giga <url>. Or consider using -q or -nv (shorthands for --quiet or --no-verbose). (DL3047)

scripts/package

[notice] 63-63: scripts/package#L63
Check exit code directly with e.g. 'if mycmd;', not indirectly with $?. (SC2181)

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Build AMD64 binaries
  • GitHub Check: Build ARM64 binaries
  • GitHub Check: Summary
🔇 Additional comments (4)
scripts/package (1)

42-49: LGTM!

The version conversion function is well-implemented with proper error handling.

.github/workflows/scripts/build.sh (1)

3-10: LGTM!

The version conversion function is well-implemented with proper error handling.

package/Dockerfile (1)

19-20: LGTM!

The dependency version management is properly set up.

.github/workflows/build.yml (1)

65-70: LGTM!

The workflow properly integrates the dependency version management for both AMD64 and ARM64 builds.

Also applies to: 139-144

- move deps buold codes to onghorn/dep-versions
- update workflows/build.yml

Longhorn 10208

Signed-off-by: Derek Su <[email protected]>
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (3)
scripts/package (1)

61-67: Improve error handling in get_branch function.

  1. Use direct command status check instead of $?
  2. Consider using a temporary file or cleaning up the downloaded file
-  wget -q "https://raw.githubusercontent.com/longhorn/dep-versions/${branch}/versions.json" -O /versions.json
-  if [ $? -eq 0 ]; then
+  if wget -q "https://raw.githubusercontent.com/longhorn/dep-versions/${branch}/versions.json" -O versions.json.tmp; then
+    rm -f versions.json.tmp
     echo "${branch}"
   else
+    rm -f versions.json.tmp
     echo "main"
   fi
🧰 Tools
🪛 GitHub Check: CodeFactor

[notice] 63-63: scripts/package#L63
Check exit code directly with e.g. 'if mycmd;', not indirectly with $?. (SC2181)

package/Dockerfile (2)

23-78: Optimize build script execution pattern.

The current implementation:

  1. Uses empty override variables consistently
  2. Repeats the same export pattern multiple times

Consider creating a helper function to reduce repetition:

+RUN echo '#!/bin/bash
+build_component() {
+    local script_name="$1"
+    local arch="$2"
+    export REPO_OVERRIDE=""
+    export COMMIT_ID_OVERRIDE=""
+    if [ -n "$arch" ]; then
+        bash "/usr/src/dep-versions/scripts/$script_name" "$REPO_OVERRIDE" "$COMMIT_ID_OVERRIDE" "$arch"
+    else
+        bash "/usr/src/dep-versions/scripts/$script_name" "$REPO_OVERRIDE" "$COMMIT_ID_OVERRIDE"
+    fi
+}' > /usr/local/bin/build-helper.sh && chmod +x /usr/local/bin/build-helper.sh

-RUN export REPO_OVERRIDE="" && \
-    export COMMIT_ID_OVERRIDE="" && \
-    bash /usr/src/dep-versions/scripts/build-go-spdk-helper.sh "${REPO_OVERRIDE}" "${COMMIT_ID_OVERRIDE}"
+RUN build_component build-go-spdk-helper.sh
🧰 Tools
🪛 GitHub Check: CodeFactor

[notice] 28-28: package/Dockerfile#L28
Avoid use of wget without progress bar. Use wget --progress=dot:giga <url>. Or consider using -q or -nv (shorthands for --quiet or --no-verbose). (DL3047)


52-53: Avoid redundant downloads in multi-stage builds.

The versions.json file and dep-versions repository are downloaded multiple times in different stages.

Consider copying these files between stages:

+FROM gobuilder as deps
+RUN wget -q "https://raw.githubusercontent.com/longhorn/dep-versions/${BRANCH}/versions.json" -O /versions.json && \
+    git clone https://github.com/longhorn/dep-versions.git -b ${BRANCH} /usr/src/dep-versions

 FROM registry.suse.com/bci/bci-base:15.6 AS cbuilder
-RUN wget -q "https://raw.githubusercontent.com/longhorn/dep-versions/${BRANCH}/versions.json" -O /versions.json
-RUN git clone https://github.com/longhorn/dep-versions.git -b ${BRANCH} /usr/src/dep-versions
+COPY --from=deps /versions.json /versions.json
+COPY --from=deps /usr/src/dep-versions /usr/src/dep-versions
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2c2658c and 6bc3731.

📒 Files selected for processing (4)
  • .github/workflows/build.yml (6 hunks)
  • .github/workflows/scripts/build.sh (1 hunks)
  • package/Dockerfile (3 hunks)
  • scripts/package (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • .github/workflows/build.yml
🧰 Additional context used
🪛 GitHub Check: CodeFactor
scripts/package

[notice] 63-63: scripts/package#L63
Check exit code directly with e.g. 'if mycmd;', not indirectly with $?. (SC2181)

package/Dockerfile

[notice] 28-28: package/Dockerfile#L28
Avoid use of wget without progress bar. Use wget --progress=dot:giga <url>. Or consider using -q or -nv (shorthands for --quiet or --no-verbose). (DL3047)

.github/workflows/scripts/build.sh

[notice] 24-24: .github/workflows/scripts/build.sh#L24
Check exit code directly with e.g. 'if mycmd;', not indirectly with $?. (SC2181)

🪛 Shellcheck (0.10.0)
.github/workflows/scripts/build.sh

[warning] 19-19: Declare and assign separately to avoid masking return values.

(SC2155)


[warning] 20-20: Declare and assign separately to avoid masking return values.

(SC2155)

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Build AMD64 binaries
  • GitHub Check: Build ARM64 binaries
  • GitHub Check: Summary
🔇 Additional comments (1)
package/Dockerfile (1)

19-20: Consider security implications of downloading and executing scripts.

The implementation downloads and executes scripts from a remote repository. While this improves maintainability, it introduces security considerations:

  1. No checksum verification for downloaded content
  2. No fallback if the remote repository is unavailable

Consider implementing checksum verification:

.github/workflows/scripts/build.sh Show resolved Hide resolved
@derekbit
Copy link
Member Author

derekbit commented Feb 5, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant