Configuring communication between containers in QM and root partitions
Configuring communication between containers in QM and root partitions¶
Cross-environment communication enables containers in the root partition to communicate with containers in the quality-managed (QM) partition using UNIX domain sockets. This configuration requires mounting a shared volume in both partitions and configuring appropriate SELinux security labels to enable inter-process communication (IPC) between the containers.
About the demo code¶
The demo code uses a pair of
C applications packaged as containers — a server running in the root partition and a client running in the QM
partition — that communicate over a UNIX domain socket at /run/ipc/ipc_server.socket.
To configure the AutoSD OS image build, the Automotive Image Builder (AIB) manifest file specifies:
- The server container image to add to the root partition
- The client container image to add to the QM partition
- The Quadlet unit configurations for both applications
- A shared volume mount at
/run/ipcfor socket communication
When the built AutoSD system starts, the server creates and binds to the UNIX domain socket, and the client connects to it, enabling IPC between the two applications running in separate partitions.
The sample Containerfiles and C source code available in the demo directory illustrate how to create these containerized applications with proper socket handling.
Prerequisites
A custom aib.yml Automotive Image Builder (AIB) manifest file, such as the manifest file that you created in
Configuring communication between containers in the root partition
Procedure
-
Using Podman, create local containerized versions of the server and client applications using the sample code located in the demo code.
Note
The demo code includes C source files (
echo-uds-server.candecho-uds-client.c) and Containerfiles for building the applications. You can use the providedbuild.shscript to build both container images locally. For AIB to find the the built container images during the build process, you must run the build script as a user with elevated privileges:sudo bash build.shbuilds both the application containers and the AutoSD OS image from the AIB manifest, andsudo bash build.sh --noimagebuilds only the application containers. -
To copy the local container images to their respective partitions in the OS image, add the following sections to your manifest file:
-
Add the server container image to the root partition in the
contentsection:console --8<-- "demos/ipc_between_qm_asil_2/ipc_between_qm_asil_2.aib.yml:13:18" -
Add the client container image to the QM partition in the
qmsection:console --8<-- "demos/ipc_between_qm_asil_2/ipc_between_qm_asil_2.aib.yml:52:57"
-
-
Create Quadlet unit files for both the server and client containers:
-
Create an
ipc_server.containerQuadlet unit file for the server running in the root partition:console --8<-- "demos/ipc_between_qm_asil_2/ipc_server.container" -
Create an
ipc_client.containerQuadlet unit file for the client running in the QM partition:console --8<-- "demos/ipc_between_qm_asil_2/ipc_client.container"
Note
Both containers mount the same volume
/run/ipc:/run/ipcbut use different SELinux security label types:- Server (root partition):
SecurityLabelType=ipc_t - Client (QM partition):
SecurityLabelType=qm_container_ipc_t
-
-
Create a Quadlet drop-in configuration file for the QM container to ensure the shared volume is mounted. Create a
10-ipc-demo.conffile:console --8<-- "demos/ipc_between_qm_asil_2/10-ipc-demo.conf"Note
QM configuration is built into the partition and should not be changed. By using drop-in files, you can make additional modifications to the QM partition without overwriting the built-in configuration settings.
-
Configure the manifest file to copy the Quadlet files and create necessary directories:
-
Add the directory creation for the QM container drop-in configuration:
console --8<-- "demos/ipc_between_qm_asil_2/ipc_between_qm_asil_2.aib.yml:20:24" -
Add the file copying configuration for all Quadlet files and configurations:
console --8<-- "demos/ipc_between_qm_asil_2/ipc_between_qm_asil_2.aib.yml:26:32" -
Copy the client Quadlet file to the QM partition:
console --8<-- "demos/ipc_between_qm_asil_2/ipc_between_qm_asil_2.aib.yml:59:61"
-
-
Configure the runtime directory creation by adding a systemd tmpfiles configuration. The demo includes a
qm_ipc.conffile that creates the/run/ipcdirectory:console --8<-- "demos/ipc_between_qm_asil_2/qm_ipc.conf"This file is copied to
/usr/lib/tmpfiles.d/qm_ipc.confas shown in the manifest file above.
Sample code
The following is a fully functioning demo code sample of an AIB manifest so that two containerized C applications will be added to separate partitions and will automatically start communicating via an IPC Unix domain socket.
console title="Sample ipc_between_qm_asil_2.aib.yml file"
--8<-- "demos/ipc_between_qm_asil_2/ipc_between_qm_asil_2.aib.yml"
Next steps
- Now that you have configured the manifest and Quadlet unit files to set up communication between containers in different partitions, you can build your AutoSD OS image. For more information, see Building an image from a custom manifest.
- Alternatively, you can continue customizing your image. For more information, see Containerized applications.
Additional resources