diff options
| author | Bruce Ashfield <bruce.ashfield@gmail.com> | 2026-02-06 03:54:31 +0000 |
|---|---|---|
| committer | Bruce Ashfield <bruce.ashfield@gmail.com> | 2026-02-06 03:54:31 +0000 |
| commit | 5aab0f92f1e774305c23802566d75922f65e0862 (patch) | |
| tree | 11193654c643a39e768c267435d562e8e04e8794 /docs/container-bundling.md | |
| parent | 8c31b451c6f5a9d0bb526ee77f467e5b48846bb4 (diff) | |
| download | meta-virtualization-container-cross-install.tar.gz | |
container-cross-install: add tests and documentation for custom service filescontainer-cross-install
Add pytest tests to verify CONTAINER_SERVICE_FILE varflag support:
TestCustomServiceFileSupport (unit tests, no build required):
- test_bbclass_has_service_file_support
- test_bundle_class_has_service_file_support
- test_service_file_map_syntax
- test_install_custom_service_function
TestCustomServiceFileBoot (boot tests, require built image):
- test_systemd_services_directory_exists
- test_container_services_present
- test_container_service_enabled
- test_custom_service_content
- test_podman_quadlet_directory
Documentation updates:
- docs/container-bundling.md: Add "Custom Service Files" section with
variable format, usage examples for both BUNDLED_CONTAINERS and
container-bundle packages, and example .service/.container files
- tests/README.md: Add test class entries to structure diagram and
"What the Tests Check" table
Signed-off-by: Bruce Ashfield <bruce.ashfield@gmail.com>
Diffstat (limited to 'docs/container-bundling.md')
| -rw-r--r-- | docs/container-bundling.md | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/docs/container-bundling.md b/docs/container-bundling.md index 745622b5..f4587a99 100644 --- a/docs/container-bundling.md +++ b/docs/container-bundling.md | |||
| @@ -360,6 +360,101 @@ Containers can be configured to start automatically on boot: | |||
| 360 | - Podman: `/etc/containers/systemd/<name>.container` (Quadlet format) | 360 | - Podman: `/etc/containers/systemd/<name>.container` (Quadlet format) |
| 361 | 361 | ||
| 362 | 362 | ||
| 363 | Custom Service Files | ||
| 364 | -------------------- | ||
| 365 | |||
| 366 | For containers that require specific startup configuration (ports, volumes, | ||
| 367 | capabilities, dependencies), you can provide custom service files instead of | ||
| 368 | using the auto-generated ones. | ||
| 369 | |||
| 370 | ### Variable Format | ||
| 371 | |||
| 372 | Use the `CONTAINER_SERVICE_FILE` varflag to specify custom service files: | ||
| 373 | |||
| 374 | CONTAINER_SERVICE_FILE[container-name] = "${UNPACKDIR}/myservice.service" | ||
| 375 | CONTAINER_SERVICE_FILE[other-container] = "${UNPACKDIR}/other.container" | ||
| 376 | |||
| 377 | ### For BUNDLED_CONTAINERS (in image recipe) | ||
| 378 | |||
| 379 | # host-image.bb or local.conf | ||
| 380 | inherit container-cross-install | ||
| 381 | |||
| 382 | SRC_URI += "\ | ||
| 383 | file://myapp.service \ | ||
| 384 | file://mydb.container \ | ||
| 385 | " | ||
| 386 | |||
| 387 | BUNDLED_CONTAINERS = "\ | ||
| 388 | myapp-container:docker:autostart \ | ||
| 389 | mydb-container:podman:autostart \ | ||
| 390 | " | ||
| 391 | |||
| 392 | # Map containers to custom service files | ||
| 393 | CONTAINER_SERVICE_FILE[myapp-container] = "${UNPACKDIR}/myapp.service" | ||
| 394 | CONTAINER_SERVICE_FILE[mydb-container] = "${UNPACKDIR}/mydb.container" | ||
| 395 | |||
| 396 | ### For container-bundle Packages | ||
| 397 | |||
| 398 | # my-bundle_1.0.bb | ||
| 399 | inherit container-bundle | ||
| 400 | |||
| 401 | SRC_URI = "\ | ||
| 402 | file://myapp.service \ | ||
| 403 | file://mydb.container \ | ||
| 404 | " | ||
| 405 | |||
| 406 | CONTAINER_BUNDLES = "\ | ||
| 407 | myapp-container:autostart \ | ||
| 408 | mydb-container:autostart \ | ||
| 409 | " | ||
| 410 | |||
| 411 | CONTAINER_SERVICE_FILE[myapp-container] = "${UNPACKDIR}/myapp.service" | ||
| 412 | CONTAINER_SERVICE_FILE[mydb-container] = "${UNPACKDIR}/mydb.container" | ||
| 413 | |||
| 414 | ### Docker .service Example | ||
| 415 | |||
| 416 | # myapp.service | ||
| 417 | [Unit] | ||
| 418 | Description=MyApp Container | ||
| 419 | After=docker.service | ||
| 420 | Requires=docker.service | ||
| 421 | |||
| 422 | [Service] | ||
| 423 | Type=simple | ||
| 424 | Restart=unless-stopped | ||
| 425 | RestartSec=5s | ||
| 426 | ExecStartPre=-/usr/bin/docker rm -f myapp | ||
| 427 | ExecStart=/usr/bin/docker run --rm --name myapp \ | ||
| 428 | -p 8080:80 \ | ||
| 429 | -v /data/myapp:/var/lib/myapp:rw \ | ||
| 430 | --cap-add NET_ADMIN \ | ||
| 431 | myapp:latest | ||
| 432 | ExecStop=/usr/bin/docker stop myapp | ||
| 433 | |||
| 434 | [Install] | ||
| 435 | WantedBy=multi-user.target | ||
| 436 | |||
| 437 | ### Podman .container (Quadlet) Example | ||
| 438 | |||
| 439 | # mydb.container | ||
| 440 | [Unit] | ||
| 441 | Description=MyDB Container | ||
| 442 | |||
| 443 | [Container] | ||
| 444 | Image=mydb:latest | ||
| 445 | ContainerName=mydb | ||
| 446 | PublishPort=5432:5432 | ||
| 447 | Volume=/data/db:/var/lib/postgresql/data:Z | ||
| 448 | Environment=POSTGRES_PASSWORD=secret | ||
| 449 | |||
| 450 | [Service] | ||
| 451 | Restart=unless-stopped | ||
| 452 | RestartSec=5s | ||
| 453 | |||
| 454 | [Install] | ||
| 455 | WantedBy=multi-user.target | ||
| 456 | |||
| 457 | |||
| 363 | vdkr and vpdmn - Virtual Container Runtimes | 458 | vdkr and vpdmn - Virtual Container Runtimes |
| 364 | =========================================== | 459 | =========================================== |
| 365 | 460 | ||
