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: versions of dependent packages are centrally managed in longhorn/dep-versions #831

Merged
merged 1 commit into from
Feb 5, 2025

Conversation

derekbit
Copy link
Member

Which issue(s) this PR fixes:

Issue longhorn/longhorn#10208

What this PR does / why we need it:

Special notes for your reviewer:

Additional documentation or context

@derekbit derekbit self-assigned this Jan 14, 2025
Copy link

coderabbitai bot commented Jan 14, 2025

Walkthrough

This pull request updates the dependency management process by modifying both the Dockerfile and the packaging script. The Dockerfile now accepts a build argument (DEP_VERSION_FILE) and uses the JSON file to set dependency commit IDs instead of hardcoded values. Additionally, the Dockerfile installs jq for JSON parsing and copies the versions.json file into the image. The packaging script adds functions to convert version strings and deduce branch names, fetching the versions.json file from a GitHub repository with error handling. Overall, the changes enable dynamic retrieval of dependency details during the build process.

Changes

Files Change Summary
package/Dockerfile Added ARG DEP_VERSION_FILE=versions.json, installed jq, added a COPY command for versions.json, and removed hardcoded ENV variables for dependency commits.
scripts/package Added functions convert_version_to_major_minor_x and get_branch for processing version strings and determining branch names, and updated the Docker build command with error handling for fetching versions.json.

Assessment against linked issues

Objective Addressed Explanation
Update Dockerfile to retrieve dependency info from versions.json (Issue #10208)
Create longhorn/dep-versions repo and versions.json for centralized dependency management (Issue #10208) Repo creation is not implemented in this PR.

Possibly related PRs

  • chore: update nvme-cli to v2.10.2 #701: The changes in the main PR focus on removing hardcoded commit IDs and introducing dynamic retrieval for multiple components, while the retrieved PR specifically updates the commit ID for NVME_CLI, indicating a direct modification to the same variable in the Dockerfile. Therefore, the changes are related.

Suggested reviewers

  • innobead
  • DamiaSan
  • shuo-wu

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: 1

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

61-72: Add input validation for version content.

While the function handles missing file errors, it doesn't validate the content of the version file. Consider adding validation to ensure the version string is not empty and matches the expected format.

Apply this diff to add input validation:

 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")
+  if [[ -z "$version" ]]; then
+    echo "Error: Version file is empty."
+    exit 1
+  fi
+
   local branch=$(convert_version_to_major_minor_x "$version")
+  if [[ "$branch" == "Invalid version format: $version" ]]; then
+    echo "Error: Invalid version format in version file."
+    exit 1
+  fi

   echo "${branch}"
 }

76-82: Document the version file fallback strategy.

The code implements a smart fallback strategy for fetching versions.json, but it would benefit from a comment explaining this behavior to future maintainers.

Add a comment before the wget commands:

+# First attempt to fetch versions.json from the branch matching the current version.
+# If that fails, fall back to the main branch which should contain the latest versions.
 wget -q "https://raw.githubusercontent.com/longhorn/dep-versions/refs/heads/${BRANCH}/versions.json" -O package/versions.json || {
   echo "Failed to fetch from branch $BRANCH, trying main branch..."
   wget -q "https://raw.githubusercontent.com/longhorn/dep-versions/refs/heads/main/versions.json" -O package/versions.json || {
     echo "Failed to fetch from main branch. Exiting."
     exit 1
   }
 }
package/Dockerfile (1)

89-89: Optimize pip installation by disabling cache.

To reduce the image size and follow best practices, disable pip cache when installing requirements.

Apply this diff:

-    pip3 install -r ./scripts/pkgdep/requirements.txt && \
+    pip3 install --no-cache-dir -r ./scripts/pkgdep/requirements.txt && \
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 21d560e and f52335e.

📒 Files selected for processing (2)
  • package/Dockerfile (5 hunks)
  • scripts/package (1 hunks)
🧰 Additional context used
🪛 GitHub Check: CodeFactor
package/Dockerfile

[warning] 79-79: package/Dockerfile#L79
Avoid use of cache directory with pip. Use pip install --no-cache-dir <package>. (DL3042)

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

85-89: LGTM!

The Docker build command is well-structured and correctly passes the DEP_VERSION_FILE argument.

package/Dockerfile (3)

5-5: LGTM!

The changes to the gobuilder stage correctly implement the centralized version management approach:

  1. Added DEP_VERSION_FILE argument
  2. Installed jq for JSON parsing
  3. Copies and uses versions.json for dependency information

Also applies to: 13-13, 19-19, 22-23


40-40: LGTM!

The changes to the cbuilder stage consistently implement the centralized version management approach across all dependencies.

Also applies to: 54-55, 56-56, 59-60, 69-70, 79-80, 104-105, 117-118


128-192: LGTM!

The release stage correctly uses the binaries built in previous stages and is not directly affected by the version management changes.

scripts/package Show resolved Hide resolved
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 (2)
scripts/package (1)

66-72: Consider enhancing error handling and file validation.

While the fallback logic is good, consider these improvements:

  1. Remove -q flag from wget to see error details
  2. Validate JSON file structure after download

Apply this diff:

-wget -q "https://raw.githubusercontent.com/longhorn/dep-versions/refs/heads/${BRANCH}/versions.json" -O package/versions.json || {
+wget "https://raw.githubusercontent.com/longhorn/dep-versions/refs/heads/${BRANCH}/versions.json" -O package/versions.json || {
   echo "Failed to fetch from branch $BRANCH, trying main branch..."
-  wget -q "https://raw.githubusercontent.com/longhorn/dep-versions/refs/heads/main/versions.json" -O package/versions.json || {
+  wget "https://raw.githubusercontent.com/longhorn/dep-versions/refs/heads/main/versions.json" -O package/versions.json || {
     echo "Failed to fetch from main branch. Exiting."
     exit 1
   }
 }
+
+# Validate JSON file
+if ! jq empty package/versions.json 2>/dev/null; then
+  echo "Error: Invalid JSON file"
+  exit 1
+fi
package/Dockerfile (1)

89-89: Add --no-cache-dir to pip install.

Using pip's cache directory in container builds is unnecessary and increases image size.

Apply this diff:

-    pip3 install -r ./scripts/pkgdep/requirements.txt && \
+    pip3 install --no-cache-dir -r ./scripts/pkgdep/requirements.txt && \
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f52335e and c01aabd.

📒 Files selected for processing (2)
  • package/Dockerfile (5 hunks)
  • scripts/package (1 hunks)
🧰 Additional context used
🪛 GitHub Check: CodeFactor
package/Dockerfile

[warning] 79-79: package/Dockerfile#L79
Avoid use of cache directory with pip. Use pip install --no-cache-dir <package>. (DL3042)

⏰ 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 (3)
scripts/package (1)

51-62: LGTM! Well-structured error handling.

The function includes proper error handling for missing version file and clearly communicates errors.

package/Dockerfile (2)

5-5: LGTM! Clean implementation of centralized version management.

The changes effectively integrate the new version management system in the Go build stage.

Also applies to: 13-13, 19-19, 22-29


40-40: LGTM! Consistent implementation across dependencies.

The changes maintain consistency in version management across all dependencies.

Also applies to: 54-56, 59-122

Copy link
Member

@innobead innobead left a comment

Choose a reason for hiding this comment

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

Have we considered building a versioned lib image when updating the dep version file (that should be release version based) and the image includes all necessary dependent libraries (source code or prebuilt), so it can be just used here and it's not required to repeat the process of pulling and building code?

package/Dockerfile Outdated Show resolved Hide resolved
@derekbit
Copy link
Member Author

derekbit commented Feb 4, 2025

Have we considered building a versioned lib image when updating the dep version file (that should be release version based) and the image includes all necessary dependent libraries (source code or prebuilt), so it can be just used here and it's not required to repeat the process of pulling and building code?

Yes, we can design the flow. One concern is the versioned lib image might make the development more time-consuming.
For example, RD updates longhorn-spdk-engine and longhorn-instance-manager, then it needs to build a full lib image and a IM image.

…rn/dep-versions

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: 0

🔭 Outside diff range comments (1)
package/Dockerfile (1)

89-90: Optimize pip Installation Command
The command pip3 install -r ./scripts/pkgdep/requirements.txt should consider disabling caching to avoid potential issues, as noted by static analysis (DL3042). A suggested update is:

-    pip3 install -r ./scripts/pkgdep/requirements.txt && \
+    pip3 install --no-cache-dir -r ./scripts/pkgdep/requirements.txt && \
🧹 Nitpick comments (1)
package/Dockerfile (1)

22-29: Dynamic Checkout for go-spdk-helper via Dependency File
Extracting GO_SPDK_HELPER_REPO and GO_SPDK_HELPER_COMMIT_ID from /versions.json using jq is a robust move toward dynamic dependency management. Consider adding error handling if the expected keys are absent or if JSON parsing fails, to provide clearer build-time diagnostics.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c01aabd and 1939b4a.

📒 Files selected for processing (2)
  • package/Dockerfile (5 hunks)
  • scripts/package (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • scripts/package
🧰 Additional context used
🪛 GitHub Check: CodeFactor
package/Dockerfile

[warning] 79-79: package/Dockerfile#L79
Avoid use of cache directory with pip. Use pip install --no-cache-dir <package>. (DL3042)

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

5-6: Centralized Version File Argument Added
The addition of ARG DEP_VERSION_FILE=versions.json ensures that the Docker build can flexibly use a custom dependency version file, which is key to the centralized management of dependency versions.


19-20: Copying Dependency Version File into Image
Using COPY ${DEP_VERSION_FILE} /versions.json makes the dependency version file available at build time and runtime. Ensure that the file is always present in the build context.


40-41: Consistent Dependency File Argument in Second Stage
Re-declaring ARG DEP_VERSION_FILE=versions.json in the second build stage maintains consistency across stages. This is essential since build stages are isolated from one another.


54-55: Ensuring Availability of jq for JSON Parsing
Including jq in the installation command (along with other necessary packages) guarantees that subsequent JSON parsing commands will execute correctly.


56-57: Copying Dependency File in Second Stage
The COPY ${DEP_VERSION_FILE} /versions.json step in this stage mirrors the first stage and confirms that the dependency version file is available where needed.


59-65: Dynamic Retrieval of liblonghorn Version Info
Extracting LIBLONGHORN_REPO and LIBLONGHORN_COMMIT_ID from the version file removes hardcoded commit IDs and improves maintainability. Ensure that the JSON file consistently uses the expected key names.


69-76: Dynamic Version Extraction for TGT Build
As with other components, using jq to fetch TGT_REPO and TGT_COMMIT_ID centralizes dependency details. It may be beneficial to validate the JSON file structure beforehand to avoid silent failures.


79-88: Robust SPDK Build Process with Dynamic Version Extraction
The SPDK build section effectively uses jq to extract repository details and includes necessary adjustments with sed. This flexible approach is well-aligned with the new dependency management strategy.

🧰 Tools
🪛 GitHub Check: CodeFactor

[warning] 79-79: package/Dockerfile#L79
Avoid use of cache directory with pip. Use pip install --no-cache-dir <package>. (DL3042)


104-114: Dynamic Checkout for libjson-c-devel
Using jq to extract LIBJSONC_REPO and LIBJSONC_COMMIT_ID is consistent with the overall strategy. The multi-step build using CMake is clear and easy to maintain.


117-125: Dynamic Retrieval and Build of nvme-cli
The extraction of repository and commit information for nvme-cli via jq continues the pattern of centralized dependency management. Monitor that the JSON file remains accurate to avoid build failures.


1-193: Overall Centralization of Dependency Versions
The Dockerfile modifications across all build stages effectively centralize dependency version management by leveraging a JSON file (versions.json). This reduces duplication and improves maintainability. Ensure that the JSON file is validated and regularly updated to reflect the required versions for all dependent components.

🧰 Tools
🪛 GitHub Check: CodeFactor

[warning] 79-79: package/Dockerfile#L79
Avoid use of cache directory with pip. Use pip install --no-cache-dir <package>. (DL3042)

@derekbit
Copy link
Member Author

derekbit commented Feb 4, 2025

Have we considered building a versioned lib image when updating the dep version file (that should be release version based) and the image includes all necessary dependent libraries (source code or prebuilt), so it can be just used here and it's not required to repeat the process of pulling and building code?

My original plan is to build an RPM package for each library and install them into a BCI-micro image while building the Longhorn component image as AppCo. However, there are some challenges:

  • When to build the RPM packages
  • Where to store the RPM packages
  • Don't make the development and debugging complicated

@innobead
Copy link
Member

innobead commented Feb 4, 2025

Yes, we can design the flow. One concern is the versioned lib image might make the development more time-consuming.

For example, RD updates longhorn-spdk-engine and longhorn-instance-manager, then it needs to build a full lib image and a IM image.

I thought each should be independent, because the libs defined in https://github.com/longhorn/dep-versions/blob/main/versions.json are all shared library based? Which parts are missing?

Btw, I am also fine with this implementation.

@derekbit
Copy link
Member Author

derekbit commented Feb 4, 2025

Yes, we can design the flow. One concern is the versioned lib image might make the development more time-consuming.
For example, RD updates longhorn-spdk-engine and longhorn-instance-manager, then it needs to build a full lib image and a IM image.

Got it. What you mentioned is like #831 (comment).

Copy link
Contributor

@james-munson james-munson left a comment

Choose a reason for hiding this comment

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

Yes, that looks good. Just one question.

@mergify mergify bot merged commit 1a1da46 into longhorn:master Feb 5, 2025
12 checks passed
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.

4 participants