-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
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
Improve is docker env checks #132404
Improve is docker env checks #132404
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.
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |
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.
This is a Docker env check, not Podman.
Additionally, Podman cannot be used to run Home Assistant in a supported way as far as I am aware.
../Frenck
This wouldn't fix detection in |
Home Assistant works inside Podman just fine. It is more or less a drop-in replacement for Docker. However, according to the issue mentioned in the PR, custom integrations are incorrectly installed since other container environments apart from Docker are not detected properly. |
This proposal also checks the |
nowadays, i think the naming i am running HA on Kubernetes using containerd and am testing my integration locally using Podman (macOS). it all works perfectly fine, which is the main point of having a container image. i am pretty sure any runtime/orchestrator is able to run HA nowadays. looking at the container tech landscape and compatibilities between them, i do think it's a reasonable request to include other runtimes in this check and not limit it to one runtime/orchestrator only, especially considering the few lines required to do so, and that there's no requirement of any orchestrator in HA's codebase (e.g. specific runtime function being required or triggered). it could potentially make sense to rename the check to a broader name like if the lack of automated testing for other runtimes/orchestrators causes hesitation regarding this pull request, maybe being more specific about it in the docs can be a solution. probably something along the lines that container runtimes are generally supported, but only Docker is automatically tested for each release. |
While this change would somewhat work, it's a workaround, not a solution. There is no definitive way to assess whether or not one is running in a container and therefore relying on it is risky. For example, the changes wouldn't work on k3s/containerd I've noticed this which could help as well? Again a workaround, but perhaps a more reliable one.
|
Let's not let the desire for perfection block progress. This is a solution that automatically addresses many cases, providing a marked improvement for users, while also providing an "escape hatch" in the form of the "container" environment variable for when the auto-detection doesn't work.
I believe this approach would work on containerd: #132404 (comment)
Instead of a file, how about using this PR and setting the |
Agreed!
Sorry it doesn't root@k3s [04:45:57 PM] [~]
-> # crictl inspect 68677a7693893 | jq -r '.status.image.image'
ghcr.io/home-assistant/home-assistant:2024.12.0
root@k3s [04:46:11 PM] [~]
-> # k exec -it home-assistant-0 -- /bin/sh
/config # ls -l /run/.containerenv
ls: /run/.containerenv: No such file or directory
/config #
As this file is present in the official container image, perhaps worth adding as alternative check to this patch? |
How about adding Line 8 in 46e5136
That approach is preferrable over checking for a file as HA may move that file later inadvertently breaking this check. The environment variable is more or less standard and common (red hat sets it on all of its images, ex https://hub.docker.com/layers/redhat/ubi8/latest/images/sha256-4dd46257b3a8d40b0f4e25c39e3c79696077090e97a71ace4e2c7080ba37fb99?context=explore) so it should be more expected. |
To remove the file, every reference to this function also needs to be cleaned: core/homeassistant/helpers/system_info.py Line 27 in 46e5136
And therefore this use-case will be found as well. Both solutions won't work for non-official images like https://github.com/linuxserver/docker-homeassistant/blob/main/Dockerfile |
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.
The CI is failing, can you please make sure pre-commit passes before marking the PR as ready?
Thanks! 👍
../Frenck
Co-authored-by: Sander Hoentjen <[email protected]>
[> How about adding
Isn't this the best approach? Unofficial images could grab that change also, or use the official image as a base? |
As discussed here, including environment variables in the image is a bad practice. |
This comment was marked as off-topic.
This comment was marked as off-topic.
This is not related to this issue. We actually do not want to persist it, that is by design. ../Frenck |
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.
@candrews I've seen you made a change, but the PR is still in draft?
Are you still working on things or did you forget to mark it ready for review?
Additionally, it would be nice to add some tests, as this hit the core of Home Assistant.
../Frenck
This comment was marked as off-topic.
This comment was marked as off-topic.
Co-authored-by: Paulus Schoutsen <[email protected]>
I will pick it up, so we can include it in 2025.1 |
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.
Co-authored-by: Franck Nijhof <[email protected]> Co-authored-by: Sander Hoentjen <[email protected]> Co-authored-by: Paulus Schoutsen <[email protected]> Co-authored-by: Robert Resch <[email protected]>
Proposed change
Improve is docker env checks
Check for the existence of the /run/.containerenv file. This file is created by podman (https://github.com/containers/podman/blob/v5.3.1/docs/source/markdown/podman-run.1.md.in#L31), cri-o (cri-o/cri-o#5461), and other runtimes.
Check for the "container" environment variable having a value. This environment variable is always set by podman (containers/podman#3586 (comment)) and other runtimes. Users can easily set this environment variable to ensure detection as a container.
Type of change
Additional information
Checklist
ruff format homeassistant tests
)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest
.requirements_all.txt
.Updated by running
python3 -m script.gen_requirements_all
.To help with the load of incoming pull requests: