-
Notifications
You must be signed in to change notification settings - Fork 734
Write cidfiles of Docker containers and mount them individually to /run/cid #6154
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
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.
Neat, I like it. LGTM 👍
supervisor/docker/manager.py
Outdated
# Bind mount to /run/cid in container | ||
if "volumes" not in kwargs: | ||
kwargs["volumes"] = {} | ||
kwargs["volumes"]["/run/cid"] = {"bind": str(cidfile_path), "mode": "ro"} |
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.
It seems not intuitive, but key/bind target is the other way around, from docker-py docs:
The key is either the host path or a volume name, [...]
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.
Huh, I had it the opposite way before and then changed it because I was somehow convinced should be like this but you're right 🤦 It'll need a few more changes.
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |
…un/cid There is no standard way to get the container ID in the container itself, which can be needed for instance for #6006. The usual pattern is to use the --cidfile argument of Docker CLI and mount the generated file to the container. However, this is feature of Docker CLI and we can't use it when creating the containers via API. To get container ID to implement native logging in e.g. Core as well, we need the help of the Supervisor. This change implements similar feature fully in Supervisor's DockerAPI class that orchestrates lifetime of all containers managed by Supervisor. The files are created in the SUPERVISOR_DATA directory, as it needs to be persisted between reboots, just as the instances of Docker containers are. Supervisor's cidfile must be created when starting the Supervisor itself, for that see home-assistant/operating-system#4276.
0db04ca
to
04c5628
Compare
Fixed, there were a few more changes necessary because we need to distinguish between path in the Supervisor container when creating the files and path on the host for mounting. Tested to work correctly now:
|
IMO just a cidfile sounds too restrictive for me. Maybe more flexible mechanism similiar to k8s podinfo would be better idea? Addons can get some use for other information, like HA Core version, addon version itself, installation date, etc. Overall having a single extendable file would be easier to maintain in the future than a number of different injected datasources. |
It resembles what is often done in vanilla Docker with
For add-ons we wire in Other information we usually fetch via the Supervisor API. The Supervisor API is not an option for this information for the Supervisor container itself (making something initial creation of the Supervisor script via the OS script in home-assistant/operating-system#4276). I guess we could use the Supervisor API approach for all the other containers which get started by the Supervisor, but fetching via Superviser API is more complex, and we usually want to do learn the container ID early in container starts to have logging setup. So this defends the current file approach. Looking at the k8s podinfo implementation it seems that a complete directory gets bind mounted, with a couple of key/value files. I guess nothing would prevent us from wiring in more files. As for the cidfile, we could make it a key value thing too, but the simplicity of it and the fact that it aligns with what Docker offers via |
Exactly, this provides simple way of exposing the container ID, which can be easily achieved using Docker CLI too. No special tooling is needed to get it in the container either and the simplicity makes testing or running in different environments easier as well.
The goal of this PR is to expose the container ID - which is a Docker runtime thing. Having other data in |
There is no standard way to get the container ID in the container itself, which can be needed for instance for #6006. The usual pattern is to use the --cidfile argument of Docker CLI and mount the generated file to the container. However, this is feature of Docker CLI and we can't use it when creating the containers via API. To get container ID to implement native logging in e.g. Core as well, we need the help of the Supervisor.
This change implements similar feature fully in Supervisor's DockerAPI class that orchestrates lifetime of all containers managed by Supervisor. The files are created in the SUPERVISOR_DATA directory, as it needs to be persisted between reboots, just as the instances of Docker containers are.
Supervisor's cidfile must be created when starting the Supervisor itself, for that see home-assistant/operating-system#4276.
Proposed change
Type of change
Additional information
Checklist
ruff format supervisor tests
)If API endpoints or add-on configuration are added/changed: