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

Add Kconfig option for Supervisor channel #3618

Merged
merged 4 commits into from
Nov 18, 2024

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 configuration option to specify the HASSIO package channel.
    • Added support for passing the channel parameter during data partition creation.
    • Created a JSON file to store the selected channel information for the Supervisor App.
  • Improvements

    • Enhanced version retrieval to dynamically fetch based on the specified HASSIO channel.
    • Updated output filenames to reflect the selected channel in version-related files.

@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

Caution

Review failed

The pull request is closed.

📝 Walkthrough
📝 Walkthrough

Walkthrough

The pull request introduces a new configuration option BR2_PACKAGE_HASSIO_CHANNEL for the Hass.io package in the Buildroot environment, allowing users to specify the default channel for the Supervisor App. 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 utilize the BR2_PACKAGE_HASSIO_CHANNEL variable for dynamic version retrieval.

Changes

File Change Summary
buildroot-external/package/hassio/Config.in Added new configuration options for channel selection: BR2_PACKAGE_HASSIO_CHANNEL_STABLE, BR2_PACKAGE_HASSIO_CHANNEL_BETA, BR2_PACKAGE_HASSIO_CHANNEL_DEV.
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 output filenames from stable.json to version.json in HASSIO_CONFIGURE_CMDS and HASSIO_BUILD_CMDS. Added $(BR2_PACKAGE_HASSIO_CHANNEL) to create-data-partition.sh in HASSIO_INSTALL_IMAGES_CMDS.

Warning

Rate limit exceeded

@agners has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 3 minutes and 27 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 8cfa907 and c21cca3.


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.

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 force-pushed the allow-to-select-hassio-source-channel branch from 503886f to e1f757c Compare November 18, 2024 11:12
@agners agners changed the title RFC: Add Makefile variable for Supervisor channel Add Makefile variable for Supervisor channel Nov 18, 2024
@agners agners requested a review from sairon November 18, 2024 11:12
@agners agners marked this pull request as ready for review November 18, 2024 11:12
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: 3

🧹 Outside diff range and nitpick comments (4)
buildroot-external/package/hassio/Config.in (1)

24-25: Enhance the help text with available channel options

The current help text is minimal. Consider expanding it to list the available channel options (e.g., stable, beta) and their implications. This would help users make informed decisions.

 	help
-	  Channel to use by default.
+	  Channel to use by default for pre-installed Home Assistant components
+	  (Supervisor and add-ons). Available options:
+	    - stable: Production-ready releases
+	    - beta: Pre-release versions for testing
buildroot-external/package/hassio/create-data-partition.sh (1)

28-28: Add error handling for the Docker command

The script should handle potential errors when executing the Docker command.

Add error handling:

-docker exec "${container}" sh /build/dind-import-containers.sh "${channel}"
+if ! docker exec "${container}" sh /build/dind-import-containers.sh "${channel}"; then
+    echo "Error: Failed to import containers for channel '${channel}'"
+    docker stop "${container}" || true
+    sudo umount "${build_dir}/data/" || true
+    exit 1
+fi
buildroot-external/package/hassio/dind-import-containers.sh (1)

Line range hint 1-33: Consider architectural implications of channel configuration.

The addition of channel configuration at the container import stage has important implications:

  1. This setting affects the entire system's update behavior
  2. Consider documenting the supported channel values and their implications
  3. Consider adding logging for the selected channel for debugging purposes
  4. Think about upgrade path and backward compatibility

Consider adding these features:

  1. Logging of the selected channel
  2. Documentation of supported channels
  3. Version compatibility checks
  4. Recovery mechanism if an invalid channel is specified
buildroot-external/package/hassio/hassio.mk (1)

18-18: Add timeout and retry logic to curl command

The curl command should include timeout and retry logic to handle network issues gracefully. Also consider validating the JSON response.

Consider updating the command:

-	curl -s $(HASSIO_VERSION_URL) | jq '.core = "landingpage"' > $(@D)/version.json
+	curl -s --retry 3 --retry-delay 2 --max-time 30 $(HASSIO_VERSION_URL) | jq 'if type=="object" then .core = "landingpage" else error("Invalid JSON") end' > $(@D)/version.json || (echo "Failed to fetch version info" >&2; exit 1)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 503886f and e1f757c.

📒 Files selected for processing (4)
  • buildroot-external/package/hassio/Config.in (1 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 (1 hunks)
🔇 Additional comments (5)
buildroot-external/package/hassio/Config.in (1)

21-26: Verify the intended default channel value

The implementation uses "stable" as the default channel, but the PR comments mentioned "beta" as the intended default. Please confirm which channel should be the default.

buildroot-external/package/hassio/create-data-partition.sh (1)

28-28: Verify the existence and permissions of the import script

Let's verify that the dind-import-containers.sh script exists and has the correct permissions.

✅ Verification successful

Let me check the actual content of the script to verify how it handles the channel parameter.


Script exists and is properly configured

The verification shows that:

  • The script exists at the correct location with executable permissions (755)
  • It properly accepts and uses the channel parameter
  • The script's functionality is well-defined:
    • Waits for Docker daemon
    • Loads container images
    • Tags supervisor image
    • Sets up AppArmor
    • Creates updater configuration with the provided channel
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if the import script exists and has correct permissions

# Find the script
echo "Searching for dind-import-containers.sh..."
fd "dind-import-containers.sh"

# Check script permissions if found
if [ $? -eq 0 ]; then
    echo "Checking script permissions..."
    ls -l $(fd "dind-import-containers.sh")
fi

# Check if the script handles the channel parameter
echo "Checking script content for channel parameter handling..."
if [ -f $(fd "dind-import-containers.sh") ]; then
    grep -A 5 "channel" $(fd "dind-import-containers.sh")
fi

Length of output: 1055


Script:

#!/bin/bash
# Check the full content of the script
cat $(fd "dind-import-containers.sh")

Length of output: 1150

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

26-26: LGTM: Proper handling of container image fetching

The implementation correctly handles variable expansion, quoting, and path variables while fetching container images.


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

The implementation correctly passes the channel parameter to the script.

Let's verify how the script handles the new parameter:

#!/bin/bash
# Description: Check create-data-partition.sh for channel parameter handling

# Search for the script and show its channel parameter handling
echo "Checking create-data-partition.sh for channel parameter usage:"
fd "create-data-partition.sh$" --exec grep -A 5 -B 5 "channel"

12-12: Verify BR2_PACKAGE_HASSIO_CHANNEL configuration

The variable needs to be properly defined in the Buildroot configuration system. Consider adding documentation about the available channel options.

Let's verify the variable definition and documentation:

✅ Verification successful

BR2_PACKAGE_HASSIO_CHANNEL is properly configured

The variable is correctly defined in buildroot-external/package/hassio/Config.in with a default value of "stable" and appropriate help text. It's properly used in the makefile and build scripts:

  • Defined as a config option in Config.in
  • Used in hassio.mk for version URL and data partition creation
  • Passed to build scripts that configure the supervisor
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for BR2_PACKAGE_HASSIO_CHANNEL definition and documentation

# Search for the variable definition in Config.in files
echo "Searching for BR2_PACKAGE_HASSIO_CHANNEL in Config.in files:"
fd "Config.in$" --exec grep -l "BR2_PACKAGE_HASSIO_CHANNEL"

# Check if the variable is documented in README or similar files
echo "\nChecking for documentation:"
rg -l "hassio.*channel|supervisor.*channel" -g "README*" -g "*.md"

Length of output: 735


Script:

#!/bin/bash
# Let's search more thoroughly for the channel configuration

# Search for BR2_PACKAGE_HASSIO_CHANNEL in Config.in files
echo "Searching for BR2_PACKAGE_HASSIO_CHANNEL in Config.in:"
rg "BR2_PACKAGE_HASSIO_CHANNEL" -A 5 -B 5

# Search for channel-related configuration in package/hassio directory
echo -e "\nChecking hassio package configuration:"
fd . "buildroot-external/package/hassio" -t f --exec cat {}

# Search for default channel value in any build scripts
echo -e "\nChecking for channel usage in build scripts:"
rg "channel.*=|CHANNEL.*=" -g "*.sh" -g "*.mk"

Length of output: 8410

@@ -3,6 +3,7 @@ set -e

build_dir=$1
dst_dir=$2
channel=$3
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add parameter validation for the channel argument

The script should validate that the required channel parameter is provided and contains a valid value.

Add this validation after the parameter declaration:

 channel=$3
+
+# Validate channel parameter
+if [ -z "${channel}" ]; then
+    echo "Error: Channel parameter is required"
+    echo "Usage: $0 <build_dir> <dst_dir> <channel>"
+    exit 1
+fi
+
+# Validate channel value
+case "${channel}" in
+    stable|beta|dev) ;;
+    *)
+        echo "Error: Invalid channel '${channel}'. Must be one of: stable, beta, dev"
+        exit 1
+        ;;
+esac
📝 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
channel=$3
channel=$3
# Validate channel parameter
if [ -z "${channel}" ]; then
echo "Error: Channel parameter is required"
echo "Usage: $0 <build_dir> <dst_dir> <channel>"
exit 1
fi
# Validate channel value
case "${channel}" in
stable|beta|dev) ;;
*)
echo "Error: Invalid channel '${channel}'. Must be one of: stable, beta, dev"
exit 1
;;
esac

Comment on lines +4 to +5
channel=$1

Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add parameter validation and documentation.

The script now accepts a channel parameter but lacks validation and documentation. Consider these improvements:

 #!/bin/sh
 set -e
 
+# Usage: dind-import-containers.sh <channel>
+# <channel>: The release channel to use (e.g., "stable", "beta", "dev")
+
+if [ -z "$1" ]; then
+    echo "Error: Channel parameter is required"
+    echo "Usage: $0 <channel>"
+    exit 1
+fi
+
 channel=$1
📝 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
channel=$1
#!/bin/sh
set -e
# Usage: dind-import-containers.sh <channel>
# <channel>: The release channel to use (e.g., "stable", "beta", "dev")
if [ -z "$1" ]; then
echo "Error: Channel parameter is required"
echo "Usage: $0 <channel>"
exit 1
fi
channel=$1

@@ -27,3 +29,5 @@ docker tag "${supervisor}" "ghcr.io/home-assistant/${arch}-hassio-supervisor:lat
# Setup AppArmor
mkdir -p "/data/supervisor/apparmor"
wget -O "/data/supervisor/apparmor/hassio-supervisor" "${APPARMOR_URL}"

echo "{ \"channel\": \"${channel}\" }" > /data/supervisor/updater.json
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Improve JSON file creation robustness and security.

The current implementation has several potential issues:

  1. No directory existence check
  2. No error handling
  3. Potential JSON injection vulnerability
  4. Hard-coded path

Consider this more robust implementation:

-echo "{ \"channel\": \"${channel}\" }" > /data/supervisor/updater.json
+UPDATER_DIR="/data/supervisor"
+UPDATER_FILE="${UPDATER_DIR}/updater.json"
+
+# Ensure directory exists
+mkdir -p "${UPDATER_DIR}" || {
+    echo "Error: Failed to create directory ${UPDATER_DIR}"
+    exit 1
+}
+
+# Create JSON with proper escaping
+printf '{"channel":"%s"}\n' "$(echo "${channel}" | sed 's/[\"]/\\&/g')" > "${UPDATER_FILE}" || {
+    echo "Error: Failed to write to ${UPDATER_FILE}"
+    exit 1
+}
📝 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
echo "{ \"channel\": \"${channel}\" }" > /data/supervisor/updater.json
UPDATER_DIR="/data/supervisor"
UPDATER_FILE="${UPDATER_DIR}/updater.json"
# Ensure directory exists
mkdir -p "${UPDATER_DIR}" || {
echo "Error: Failed to create directory ${UPDATER_DIR}"
exit 1
}
# Create JSON with proper escaping
printf '{"channel":"%s"}\n' "$(echo "${channel}" | sed 's/[\"]/\\&/g')" > "${UPDATER_FILE}" || {
echo "Error: Failed to write to ${UPDATER_FILE}"
exit 1
}

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.

The title/commit message should be updated, as it's not a Makefile variable anymore. Otherwise LGTM.

I'll leave it up to you if you want to go with the suggestion below. It's quite a bit of boilerplate code but IMHO the experience of having the options in menuconfig is better and adds some error-proofing.

buildroot-external/package/hassio/Config.in Outdated Show resolved Hide resolved
@agners agners requested a review from sairon November 18, 2024 12:02
@agners agners changed the title Add Makefile variable for Supervisor channel Add Kconfig option for Supervisor channel Nov 18, 2024
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: 3

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between e1f757c and cf8446c.

📒 Files selected for processing (2)
  • buildroot-external/package/hassio/Config.in (1 hunks)
  • buildroot-external/package/hassio/hassio.mk (1 hunks)
🔇 Additional comments (4)
buildroot-external/package/hassio/Config.in (1)

21-38: Well-structured choice configuration!

The implementation of the channel selection using Kconfig's choice mechanism is clean and follows best practices. The default is appropriately set to stable, and each option has clear help text.

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

33-33: LGTM: Container image fetching looks good.

The script correctly uses the new version.json file and maintains proper parameter passing.


40-40: Verify create-data-partition.sh script updates.

The script now receives the channel parameter. Let's verify that the corresponding changes exist in the script.

✅ Verification successful

Script is properly updated to handle the channel parameter

The verification shows that create-data-partition.sh has been correctly updated to:

  • Accept the channel parameter as $3
  • Pass the channel parameter to dind-import-containers.sh during Docker execution
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if create-data-partition.sh is updated to handle the channel parameter

# Search for channel parameter handling in create-data-partition.sh
echo "Checking create-data-partition.sh for channel parameter handling:"
rg -A 5 "channel" "buildroot-external/package/hassio/create-data-partition.sh"

# Check if the script's usage/help text mentions the channel parameter
echo "\nChecking script usage text:"
head -n 20 "buildroot-external/package/hassio/create-data-partition.sh"

Length of output: 1078


13-18: Verify channel configuration definitions.

Let's ensure that the channel configuration variables are properly defined in Config.in.

✅ Verification successful

Channel configuration is properly defined and structured

The Config.in file correctly defines all the channel variables used in hassio.mk as a choice configuration:

  • BR2_PACKAGE_HASSIO_CHANNEL_STABLE (default)
  • BR2_PACKAGE_HASSIO_CHANNEL_BETA
  • BR2_PACKAGE_HASSIO_CHANNEL_DEV
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify channel configuration definitions

# Search for channel configuration in Config.in
echo "Checking Config.in for channel definitions:"
rg "BR2_PACKAGE_HASSIO_CHANNEL" "buildroot-external/package/hassio/Config.in"

# Check if it's a choice configuration
echo "\nChecking for choice configuration:"
rg -A 10 "choice" "buildroot-external/package/hassio/Config.in"

Length of output: 743

Comment on lines +38 to +39
endchoice

Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Missing string config for channel value mapping

The choice configuration needs to be followed by a string config that maps the selected choice to actual channel values. This string config will be used by other scripts to determine the selected channel.

Add this configuration after the choice block:

 endchoice
+
+config BR2_PACKAGE_HASSIO_CHANNEL
+	string
+	default "stable" if BR2_PACKAGE_HASSIO_CHANNEL_STABLE
+	default "beta" if BR2_PACKAGE_HASSIO_CHANNEL_BETA
+	default "dev" if BR2_PACKAGE_HASSIO_CHANNEL_DEV
📝 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
endchoice
endchoice
config BR2_PACKAGE_HASSIO_CHANNEL
string
default "stable" if BR2_PACKAGE_HASSIO_CHANNEL_STABLE
default "beta" if BR2_PACKAGE_HASSIO_CHANNEL_BETA
default "dev" if BR2_PACKAGE_HASSIO_CHANNEL_DEV


HASSIO_CONTAINER_IMAGES_ARCH = supervisor dns audio cli multicast observer core

define HASSIO_CONFIGURE_CMDS
# Deploy only landing page for "core" by setting version to "landingpage"
curl -s $(HASSIO_VERSION_URL) | jq '.core = "landingpage"' > $(@D)/stable.json
curl -s $(HASSIO_VERSION_URL)$(HASSIO_VERSION_FILE) | jq '.core = "landingpage"' > $(@D)/version.json
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add error handling for curl command.

The curl command should handle potential network failures or invalid responses to prevent silent build failures.

Enhance the command with error handling:

-curl -s $(HASSIO_VERSION_URL)$(HASSIO_VERSION_FILE) | jq '.core = "landingpage"' > $(@D)/version.json
+curl -f -s $(HASSIO_VERSION_URL)$(HASSIO_VERSION_FILE) | jq '.core = "landingpage"' > $(@D)/version.json || \
+  (echo "Error: Failed to fetch version file from $(HASSIO_VERSION_URL)$(HASSIO_VERSION_FILE)" >&2; exit 1)
📝 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
curl -s $(HASSIO_VERSION_URL)$(HASSIO_VERSION_FILE) | jq '.core = "landingpage"' > $(@D)/version.json
curl -f -s $(HASSIO_VERSION_URL)$(HASSIO_VERSION_FILE) | jq '.core = "landingpage"' > $(@D)/version.json || \
(echo "Error: Failed to fetch version file from $(HASSIO_VERSION_URL)$(HASSIO_VERSION_FILE)" >&2; exit 1)

buildroot-external/package/hassio/hassio.mk Outdated Show resolved Hide resolved
@agners agners marked this pull request as draft November 18, 2024 13:09
@agners agners marked this pull request as ready for review November 18, 2024 13:17
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.

Looks good to me now. Just a code style nit in the comment but functionally it's fine!

buildroot-external/package/hassio/Config.in Show resolved Hide resolved
@agners agners added the build Build and CI related issues label Nov 18, 2024
@agners agners merged commit f169f78 into dev Nov 18, 2024
2 of 3 checks passed
@agners agners deleted the allow-to-select-hassio-source-channel branch November 18, 2024 13:39
@sairon sairon mentioned this pull request Nov 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build Build and CI related issues cla-signed hacktoberfest
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants