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

RFC: Add Makefile variable for Supervisor channel #3618

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

agners
Copy link
Member

@agners agners commented Oct 10, 2024

Allow to set the release channel pre-installed Home Assistant components like Supervisor and add-on are fetched from. This channel is then also used at runtime.

Summary by CodeRabbit

  • New Features

    • Introduced a new variable to specify the HASSIO package channel during the build process.
    • Added support for dynamic channel selection in the installation scripts.
    • Created a JSON file to store the selected channel information.
  • Improvements

    • Updated URLs to fetch HASSIO version dynamically based on the selected channel.

Allow to set the release channel pre-installed Home Assistant components
like Supervisor and add-on are fetched from. This channel is then also
used at runtime.
@agners agners changed the title Add Makefile variable for Supervisor channel RFC: Add Makefile variable for Supervisor channel Oct 10, 2024
@agners agners marked this pull request as draft October 10, 2024 07:32
@agners
Copy link
Member Author

agners commented Oct 10, 2024

I was considering making this a package config, like so:

--- a/buildroot-external/package/hassio/Config.in
+++ b/buildroot-external/package/hassio/Config.in
@@ -18,4 +18,10 @@ config BR2_PACKAGE_HASSIO_MACHINE
        help
          Machine to pull containers for (used for landing page).
 
+config BR2_PACKAGE_HASSIO_CHANNEL
+       string "Default Channel"
+       default "beta"
+       help
+         Channel to use by default.
+
 endif

But then it can't be overriden from Makefile (at least it didn't work for me 🤔 ).

I think we should rename the variable to BR2_EXTERNAL_HASSIO_CHANNEL or something if we want to go with the overrideable variant.

Copy link

coderabbitai bot commented Oct 10, 2024

📝 Walkthrough

Walkthrough

The pull request introduces a new variable CHANNEL in the Makefile, defaulting to stable, which can be overridden during the build process. The create-data-partition.sh script is updated to accept a channel parameter, which is passed to the dind-import-containers.sh script. This script now creates a JSON file containing the channel information. Additionally, the HASSIO_VERSION_URL in the hassio.mk file is modified to use the BR2_PACKAGE_HASSIO_CHANNEL variable, and the command for installing images is updated to include this channel variable.

Changes

File Change Summary
Makefile Added variable CHANNEL ?= stable. Updated build command to include BR2_PACKAGE_HASSIO_CHANNEL=$(CHANNEL).
buildroot-external/package/hassio/create-data-partition.sh Modified to accept channel as the third argument.
buildroot-external/package/hassio/dind-import-containers.sh Introduced variable channel from the first argument. Created JSON file at /data/supervisor/updater.json with channel information.
buildroot-external/package/hassio/hassio.mk Updated HASSIO_VERSION_URL to use $(BR2_PACKAGE_HASSIO_CHANNEL). Updated HASSIO_INSTALL_IMAGES_CMDS to pass $(BR2_PACKAGE_HASSIO_CHANNEL) to create-data-partition.sh.

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 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 or @coderabbitai title anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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

🧹 Outside diff range and nitpick comments (6)
buildroot-external/package/hassio/create-data-partition.sh (2)

6-6: LGTM! Consider adding parameter validation.

The addition of the channel parameter aligns with the PR objectives. However, to improve robustness, consider adding parameter validation and a default value.

You could modify the script to include validation and a default value like this:

 channel=$3
+
+# Set default channel if not provided
+channel=${channel:-stable}
+
+# Validate channel
+if [[ ! "$channel" =~ ^(stable|beta|dev)$ ]]; then
+    echo "Error: Invalid channel. Must be 'stable', 'beta', or 'dev'."
+    exit 1
+fi

This ensures that the script always has a valid channel value, even if it's not explicitly provided.


28-28: LGTM! Consider adding a comment for clarity.

The modification correctly passes the channel parameter to the dind-import-containers.sh script, aligning with the PR objectives.

For improved readability, consider adding a comment explaining the purpose of this line:

+# Execute container import script with specified channel
 docker exec "${container}" sh /build/dind-import-containers.sh "${channel}"

This addition would make the script's intention clearer to future maintainers.

buildroot-external/package/hassio/dind-import-containers.sh (3)

4-4: LGTM! Consider adding input validation.

The addition of the channel variable aligns well with the PR objectives, allowing users to set the release channel. This change enhances the script's flexibility.

Consider adding input validation or a default value for the channel variable. This would prevent potential issues if the script is called without an argument. For example:

channel=${1:-stable}

This sets 'stable' as the default if no argument is provided.


33-33: LGTM! Consider adding a directory check.

The creation of the JSON file with the channel information is a good addition. It provides a structured way to store and access the channel information, which aligns with the PR objectives.

Consider adding a check to ensure the /data/supervisor directory exists before creating the file. This would prevent potential errors if the directory structure is not as expected. For example:

mkdir -p /data/supervisor
echo "{ \"channel\": \"${channel}\" }" > /data/supervisor/updater.json

This ensures the directory exists before attempting to create the file.


Line range hint 1-33: Overall, the changes look good and align with the PR objectives.

The addition of the channel variable and the creation of the JSON file with channel information successfully implement the feature to set and store the release channel. The changes are well-integrated into the existing script structure.

To further improve the script's robustness and maintainability, consider:

  1. Implementing error handling for the channel parameter.
  2. Adding comments to explain the purpose of the new additions, especially the JSON file creation.
  3. If this channel information is used elsewhere in the system, ensure consistent naming and structure across different components.
Makefile (1)

34-35: LGTM: Effective integration of channel variable into build process.

The modification to include BR2_PACKAGE_HASSIO_CHANNEL=$(CHANNEL) in the make command effectively integrates the new channel variable into the build process. This change ensures that the specified channel is used during the build, aligning with the PR objectives.

For improved readability, consider adding a comment explaining the purpose of the new parameter:

 $(MAKE) -C $(BUILDROOT) O=$(O) BR2_EXTERNAL=$(BUILDROOT_EXTERNAL) \
+		# Pass the channel information to Buildroot
 		BR2_PACKAGE_HASSIO_CHANNEL=$(CHANNEL)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 1b6b40e and 503886f.

📒 Files selected for processing (4)
  • Makefile (2 hunks)
  • buildroot-external/package/hassio/create-data-partition.sh (2 hunks)
  • buildroot-external/package/hassio/dind-import-containers.sh (2 hunks)
  • buildroot-external/package/hassio/hassio.mk (2 hunks)
🧰 Additional context used
🔇 Additional comments (5)
buildroot-external/package/hassio/create-data-partition.sh (1)

Line range hint 1-32: Overall, the changes effectively implement the channel selection feature.

The modifications to this script successfully incorporate the new channel parameter, allowing for flexible release channel selection as per the PR objectives. The changes are minimal yet impactful, maintaining the overall structure and readability of the script.

To further enhance the script:

  1. Consider adding parameter validation and a default value for the channel variable.
  2. A brief comment explaining the purpose of the dind-import-containers.sh call would improve clarity.

These suggestions would make the script more robust and easier to maintain in the future.

buildroot-external/package/hassio/hassio.mk (2)

Line range hint 1-33: Overall assessment: Changes align well with PR objectives

The modifications to this Makefile effectively implement the feature allowing users to set the release channel for pre-installed Home Assistant components. The changes are consistent and well-integrated into the existing structure.

Key points:

  1. The HASSIO_VERSION_URL now dynamically uses the specified channel.
  2. The channel information is passed to the create-data-partition.sh script during installation.

These changes provide the desired flexibility in component sourcing, both during installation and at runtime. The verification tasks will help ensure the completeness of the implementation across the codebase.


33-33: LGTM: Channel information passed to create-data-partition.sh

The update to pass $(BR2_PACKAGE_HASSIO_CHANNEL) as an argument to the create-data-partition.sh script is consistent with the PR objective and the previous change. This allows the script to use the specified channel during the installation process.

Let's verify if the create-data-partition.sh script has been updated to handle this new argument:

#!/bin/bash
# Description: Verify the create-data-partition.sh script for the new channel argument

# Find the create-data-partition.sh script
script_path=$(fd -t f "create-data-partition.sh")

if [ -n "$script_path" ]; then
    echo "Found create-data-partition.sh at: $script_path"
    echo "\nChecking for channel argument handling:"
    rg -n "channel" "$script_path"
else
    echo "create-data-partition.sh not found. Please verify the script location."
fi
Makefile (2)

6-6: LGTM: Well-implemented channel variable.

The addition of the CHANNEL variable with a default value of "stable" is a good implementation. Using the ?= operator allows for easy overriding during the build process, providing flexibility for users to specify different channels as needed. This change aligns well with the PR objective of allowing users to set the release channel for pre-installed Home Assistant components.


Line range hint 1-53: Overall: Well-implemented feature for channel specification.

The changes to the Makefile effectively implement the desired feature of allowing channel specification for pre-installed Home Assistant components. The addition of the CHANNEL variable and its integration into the build process are minimal, focused, and maintain the existing structure and style of the Makefile.

These modifications align well with the PR objectives and provide the flexibility for users to specify different channels during the build process. The implementation is clean and doesn't introduce any apparent issues or conflicts with the existing code.

@@ -9,7 +9,7 @@ HASSIO_LICENSE = Apache License 2.0
# HASSIO_LICENSE_FILES = $(BR2_EXTERNAL_HASSOS_PATH)/../LICENSE
HASSIO_SITE = $(BR2_EXTERNAL_HASSOS_PATH)/package/hassio
HASSIO_SITE_METHOD = local
HASSIO_VERSION_URL = "https://version.home-assistant.io/stable.json"
HASSIO_VERSION_URL = "https://version.home-assistant.io/$(BR2_PACKAGE_HASSIO_CHANNEL).json"
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

Issue Found: BR2_PACKAGE_HASSIO_CHANNEL is used but not defined.

  • The variable BR2_PACKAGE_HASSIO_CHANNEL is utilized in buildroot-external/package/hassio/create-data-partition.sh but its definition is missing in the Makefiles.
  • Ensure that BR2_PACKAGE_HASSIO_CHANNEL is properly defined and set within the appropriate configuration files to avoid potential build or runtime issues.
🔗 Analysis chain

LGTM: Dynamic channel selection implemented.

The change to use $(BR2_PACKAGE_HASSIO_CHANNEL) in the HASSIO_VERSION_URL allows for dynamic selection of the version URL based on the specified channel. This aligns well with the PR objective of allowing users to set the release channel for pre-installed Home Assistant components.

Let's verify the existence and setting of the BR2_PACKAGE_HASSIO_CHANNEL variable:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the existence and setting of BR2_PACKAGE_HASSIO_CHANNEL

# Search for the definition of BR2_PACKAGE_HASSIO_CHANNEL
echo "Searching for BR2_PACKAGE_HASSIO_CHANNEL definition:"
rg -n "BR2_PACKAGE_HASSIO_CHANNEL" --type make

# Check if it's used in other places
echo "\nChecking usage of BR2_PACKAGE_HASSIO_CHANNEL in other files:"
rg -n "BR2_PACKAGE_HASSIO_CHANNEL" --type-not make

Length of output: 637

Copy link
Member

@sairon sairon left a comment

Choose a reason for hiding this comment

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

Since this only affects the hassio package, I'll prefer having it as a (choice) config option there, so instead of passing a variable when running make, changing it would either mean to set it in the menuconfig or replace it in the .config (or just simply append it to the end). It's a little bit more complicated but IMO more appropriate.

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

Successfully merging this pull request may close these issues.

2 participants