Skip to content

Allow to force rebuild of add-ons #6002

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

Merged
merged 2 commits into from
Jul 7, 2025

Conversation

felipecrs
Copy link
Contributor

@felipecrs felipecrs commented Jul 7, 2025

Proposed change

Allows passing {"force": true} to http://supervisor/addons/<addon>/rebuild to force a rebuild of the add-on, even if the add-on has image set in its config.yml.

This is useful for testing changes to the add-on, avoiding the need for commenting out the image line in the config.yml file.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (which adds functionality to the supervisor)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Disclaimer: tests generated by Claude Sonnet 4.

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • The code has been formatted using Ruff (ruff format supervisor tests)
  • Tests have been added to verify that the new code works.

If API endpoints or add-on configuration are added/changed:

Summary by CodeRabbit

  • New Features

    • Added support for a "force" option when rebuilding add-ons via the API, allowing forced rebuilds even if not normally permitted.
  • Bug Fixes

    • Improved error handling for rebuild requests on image-based add-ons, providing clearer feedback.
  • Tests

    • Introduced new tests to verify correct behavior of the forced rebuild feature for add-ons.

Copy link
Contributor

coderabbitai bot commented Jul 7, 2025

📝 Walkthrough

Walkthrough

The changes introduce a new optional force parameter to the add-on rebuild functionality, allowing forced rebuilds even for image-based add-ons that normally cannot be rebuilt. The API endpoint, internal manager logic, and constants are updated to support this parameter. A new test verifies forced rebuild behavior.

Changes

File(s) Change Summary
supervisor/addons/manager.py Updated AddonManager.rebuild method signature to accept a force boolean parameter and adjusted logic.
supervisor/api/addons.py Added ATTR_FORCE support to the rebuild API, including schema validation and passing force to manager.
supervisor/const.py Added new constant: ATTR_FORCE = "force".
tests/api/test_addons.py Added test test_api_addon_rebuild_force to verify forced rebuilds for image-based add-ons.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant APIAddons
    participant AddonManager

    Client->>APIAddons: POST /addons/{slug}/rebuild (with optional force)
    APIAddons->>APIAddons: Validate request (SCHEMA_REBUILD)
    APIAddons->>AddonManager: rebuild(slug, force=...)
    AddonManager->>AddonManager: Check need_build or force
    AddonManager-->>APIAddons: Return rebuild task or error
    APIAddons-->>Client: Respond with status (success or error)
Loading

Warning

Review ran into problems

🔥 Problems

Check-run timed out after 90 seconds. Some checks/pipelines were still in progress when the timeout was reached. Consider increasing the reviews.tools.github-checks.timeout_ms value in your CodeRabbit configuration to allow more time for checks to complete.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between 5c90a00 and 1f34dfb.

📒 Files selected for processing (4)
  • supervisor/addons/manager.py (2 hunks)
  • supervisor/api/addons.py (3 hunks)
  • supervisor/const.py (1 hunks)
  • tests/api/test_addons.py (1 hunks)
🧰 Additional context used
📓 Path-based instructions (10)
`supervisor/**/*.py`: Use Python 3.13+ and modern Python features: type hints wi...

supervisor/**/*.py: Use Python 3.13+ and modern Python features: type hints with typing module, f-strings, dataclasses, enum classes, async/await, and pattern matching where appropriate
Use Ruff for code formatting
Use PyLint and Ruff for linting
Use MyPy for type checking
Use constants from supervisor/const.py instead of hardcoding values; define new constants following existing patterns and group related constants together
Inherit from CoreSysAttributes for major classes to provide access to centralized system state via self.coresys and convenient sys_* properties
Implement a load() method for components that initialize from external sources (containers, files, D-Bus services)
Use Supervisor's Docker manager (self.sys_docker) for container management instead of direct Docker API usage
All I/O operations must be async: file operations, network calls, subprocess execution
Prefer asyncio.gather() over sequential awaits for concurrent async operations
Use self.sys_run_in_executor() for blocking operations
Use two-phase initialization: __init__ for sync setup, post_init() for async initialization
Use the from clause for exception chaining when propagating errors
Avoid direct Docker API usage; use Supervisor's Docker manager instead
Avoid blocking operations in async context; use asyncio alternatives
Avoid hardcoded values; use constants from const.py

📄 Source: CodeRabbit Inference Engine (.github/copilot-instructions.md)

List of files the instruction was applied to:

  • supervisor/const.py
  • supervisor/addons/manager.py
  • supervisor/api/addons.py
`*/**(html|markdown|md)`: - For instructional content in documentation, use a di...

*/**(html|markdown|md): - For instructional content in documentation, use a direct and authoritative tone. Avoid expressions of politeness such as 'may' or 'please', and ensure the goal of the instruction is fronted.

  • Apply the Microsoft Style Guide to ensure documentation maintains clarity and conciseness.
  • In step-by-step instructions, front the location phrase in the instructional sentence.
  • In step-by-step instructions, front the 'goal' in the instructional sentence.
  • In step-by-step instructions, if in doubt what to front, front the 'goal' before the location phrase in the instructional sentence.
  • do not hyphenate terms like 'top-right' or 'bottom-left' with 'corner'

⚙️ Source: CodeRabbit Configuration File

List of files the instruction was applied to:

  • supervisor/const.py
`*/**(html|markdown|md)`: - Use bold to mark UI strings. - If "" are used to mark UI strings, replace them by bold.

*/**(html|markdown|md): - Use bold to mark UI strings.

  • If "" are used to mark UI strings, replace them by bold.

⚙️ Source: CodeRabbit Configuration File

List of files the instruction was applied to:

  • supervisor/const.py
`*/**(html|markdown|md)`: - Be brief in your replies and don't add fluff like "thank you for..." and "Please let me know if"

*/**(html|markdown|md): - Be brief in your replies and don't add fluff like "thank you for..." and "Please let me know if"

⚙️ Source: CodeRabbit Configuration File

List of files the instruction was applied to:

  • supervisor/const.py
`*/**(html|markdown|md)`: - Use sentence-style capitalization also in headings.

*/**(html|markdown|md): - Use sentence-style capitalization also in headings.

⚙️ Source: CodeRabbit Configuration File

List of files the instruction was applied to:

  • supervisor/const.py
`*/**(html|markdown|md)`: do not comment on HTML used for icons

*/**(html|markdown|md): do not comment on HTML used for icons

⚙️ Source: CodeRabbit Configuration File

List of files the instruction was applied to:

  • supervisor/const.py
`*/**(html|markdown|md)`: Avoid flagging inline HTML for embedding videos in future reviews for this repository.

*/**(html|markdown|md): Avoid flagging inline HTML for embedding videos in future reviews for this repository.

⚙️ Source: CodeRabbit Configuration File

List of files the instruction was applied to:

  • supervisor/const.py
`supervisor/addons/**/*.py`: AppArmor profiles are mandatory for add-ons, with minimal capabilities

supervisor/addons/**/*.py: AppArmor profiles are mandatory for add-ons, with minimal capabilities

📄 Source: CodeRabbit Inference Engine (.github/copilot-instructions.md)

List of files the instruction was applied to:

  • supervisor/addons/manager.py
`supervisor/api/**/*.py`: All REST API endpoints must be under `/api/`, use bear...

supervisor/api/**/*.py: All REST API endpoints must be under /api/, use bearer token authentication, consistent response format, and voluptuous schemas with api_validate()
Use the @api_process decorator for API endpoints to handle standard error handling and response formatting
Use APIError with appropriate HTTP status codes for API errors
Use token-based API authentication with role-based access
Avoid manual error handling in API endpoints; let @api_process handle it

📄 Source: CodeRabbit Inference Engine (.github/copilot-instructions.md)

List of files the instruction was applied to:

  • supervisor/api/addons.py
`tests/**/*.py`: Use pytest with asyncio support for testing Place all tests in ...

tests/**/*.py: Use pytest with asyncio support for testing
Place all tests in the tests/ directory with module mirroring
Use pytest fixtures extensively for CoreSys setup in tests
Mock external dependencies (Docker, D-Bus, network calls) in tests
Maintain minimum 90% test coverage, 100% for security-sensitive code

📄 Source: CodeRabbit Inference Engine (.github/copilot-instructions.md)

List of files the instruction was applied to:

  • tests/api/test_addons.py
🧬 Code Graph Analysis (1)
tests/api/test_addons.py (4)
tests/conftest.py (7)
  • api_client (514-537)
  • coresys (332-415)
  • install_addon_ssh (627-635)
  • container (801-809)
  • tmp_supervisor_data (430-449)
  • path_extern (92-95)
  • docker (106-136)
supervisor/addons/addon.py (5)
  • Addon (132-1606)
  • load (209-242)
  • state (166-168)
  • state (171-202)
  • container_state_changed (1566-1584)
supervisor/const.py (2)
  • AddonState (446-453)
  • CpuArch (511-518)
supervisor/docker/const.py (1)
  • ContainerState (30-38)
🪛 Flake8 (7.2.0)
tests/api/test_addons.py

[error] 285-285: nonlocal state_changes is unused: name is never assigned in scope

(F824)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Build armhf supervisor
  • GitHub Check: Build armv7 supervisor
  • GitHub Check: Build aarch64 supervisor
  • GitHub Check: Run tests Python 3.13.5
🔇 Additional comments (7)
supervisor/const.py (1)

191-191: LGTM! Constant follows established patterns.

The new ATTR_FORCE constant is correctly defined following the existing naming convention and alphabetical placement. This adheres to the coding guidelines of using constants from const.py instead of hardcoding values.

supervisor/addons/manager.py (2)

269-269: LGTM! Method signature correctly implements force parameter.

The addition of the force: bool = False parameter follows Python conventions for optional parameters and maintains backward compatibility.


292-292: LGTM! Logic correctly implements forced rebuild functionality.

The condition change properly allows bypassing the need_build check when force=True, enabling forced rebuilds of image-based add-ons as intended.

supervisor/api/addons.py (3)

39-39: LGTM! Import correctly placed in alphabetical order.

The ATTR_FORCE import follows the established pattern and maintains alphabetical ordering.


144-144: LGTM! Schema properly validates the force parameter.

The SCHEMA_REBUILD schema correctly uses voluptuous validation with an optional boolean parameter defaulting to False, following the API validation patterns in the codebase.


467-471: LGTM! API method correctly implements force parameter handling.

The rebuild method properly validates the request body using the new schema and passes the force parameter to the manager method, following the established API patterns with @api_process and api_validate().

tests/api/test_addons.py (1)

264-354: LGTM! Comprehensive test coverage for forced rebuild functionality.

The test properly covers both scenarios:

  1. Verifies that image-based add-ons fail to rebuild without the force parameter
  2. Confirms that forced rebuilds succeed and trigger proper state transitions

The test follows established patterns in the file and uses appropriate mocking for all dependencies. The static analysis hint about unused nonlocal state_changes is a false positive - the variable is actively used for tracking state changes and assertions.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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.

@felipecrs
Copy link
Contributor Author

Demo:

~ curl --fail-with-body -sSL -H "Authorization: Bearer ${SUPERVISOR_TOKEN}" -X POST http://supervisor/addons/local_example/rebuild 
curl: (22) The requested URL returned error: 400
{"result":"error","message":"Can't rebuild a image based add-on"}#                                                                                                                                     ~ curl --fail-with-body -sSL -H "Authorization: Bearer ${SUPERVISOR_TOKEN}" -X POST http://supervisor/addons/local_example/rebuild -d '{"force": true}' 
{"result":"ok","data":{}}#

Copy link
Member

@agners agners left a comment

Choose a reason for hiding this comment

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

Nice, LGTM, thanks! 👍

@agners agners merged commit 381e719 into home-assistant:main Jul 7, 2025
23 of 24 checks passed
@felipecrs felipecrs deleted the force-rebuild branch July 7, 2025 19:49
@github-actions github-actions bot locked and limited conversation to collaborators Jul 9, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy