-
-
Couldn't load subscription status.
- Fork 20
Add container origin sensor #494
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 container origin sensor #494
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @MichelFR, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
Summary of Changes
Hello! Gemini here, providing a summary of this pull request. This PR introduces a new sensor/attribute for Docker containers to identify how they were created, specifically distinguishing between containers started directly with the Docker CLI and those managed by Docker Compose. This is achieved by inspecting the container's labels for common Docker Compose patterns. The new origin information is then exposed via MQTT for Home Assistant discovery and included in the standard container state messages.
Highlights
- New Sensor/Attribute: Adds a new
docker_created_bysensor/attribute to indicate if a container was created by 'Docker' or 'Composer'. - Compose Detection Logic: Implements a static method
DockerService.getCreatedByto check container labels forcom.docker.composeprefixes to determine the origin. - Home Assistant Integration: Adds Home Assistant MQTT discovery configuration for the new
docker_created_bysensor and includes the origin in the main container state MQTT payload. - Unit Tests: Includes new unit tests specifically for the
DockerService.getCreatedBymethod to ensure correct detection logic.
Changelog
- README.md
- Removed an empty line.
- src/services/DockerService.ts
- Added a new static method
getCreatedByto determine if a container was created by Docker Compose or standard Docker based on labels.
- Added a new static method
- src/services/HomeassistantService.ts
- Added Home Assistant discovery configuration for the new
docker_created_bysensor. - Included the container's creation origin (detected by
DockerService.getCreatedBy) in the main container state MQTT payload.
- Added Home Assistant discovery configuration for the new
- tests/DockerServiceCreatedBy.test.ts
- Added a new test file with unit tests for the
DockerService.getCreatedBymethod, covering both 'Composer' and 'Docker' cases.
- Added a new test file with unit tests for the
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Container starts fast,
Compose labels tell its birth,
Docker or Composer?
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This PR effectively introduces the docker_created_by sensor, enhancing container information. The implementation in DockerService.ts for detecting the origin (Composer vs. Docker) is clear and robust, and its integration into HomeassistantService.ts follows existing patterns well. The new unit tests for DockerService.getCreatedBy are also a great addition and cover the primary logic paths.
One point of clarification: The PR description mentions '- remove the README addition that described the new sensor'. However, the diff for README.md only shows the removal of a blank line. Could you clarify if there was other content related to the new sensor in the README that was intended to be removed, or if this description point refers to something else?
Overall, the code changes look good and improve the functionality as intended. The work is high quality.
Summary of Findings
- Use of Magic Strings: In
src/services/DockerService.ts, the strings "Composer" and "Docker" returned bygetCreatedByare used directly. While clear in this context, consider defining them as constants for improved maintainability, especially if these values were to be used elsewhere or become more complex. (Severity: low, not commented directly due to review settings) - Unit Test Explicitness: The unit tests for
DockerService.getCreatedByintests/DockerServiceCreatedBy.test.tscover the main scenarios well. For even greater explicitness, consider adding a test case specifically for whencontainer.Config.Labelsis an empty object or null/undefined, although the current implementation handles this correctly and it's implicitly covered. (Severity: low, not commented directly due to review settings) - README.md Change Clarification: The PR description states a README addition about the new sensor was removed, but the diff only shows a blank line removal. Clarification on this point would be helpful. (Severity: low, addressed in general comments)
Merge Readiness
The code changes are well-implemented and add valuable functionality. After clarifying the README.md change mentioned in the general feedback, this PR appears ready for merging from a technical standpoint. As an AI reviewer, I cannot approve pull requests; please ensure it undergoes further review and approval by the maintainers.
Summary
docker_created_bysensor for each containerDockerService.getCreatedByTesting
npm testhttps://chatgpt.com/codex/tasks/task_e_684034a70f94832994828b7a777a06d4