summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBruce Ashfield <bruce.ashfield@gmail.com>2026-01-15 21:50:17 +0000
committerBruce Ashfield <bruce.ashfield@gmail.com>2026-01-21 18:00:26 -0500
commit1abd778b15ccedd2cfc80d4f44802c1415fbbbde (patch)
tree8c72e448db475533a37f628bd1857078b5b94e12
parent92a34f0187fad2b6ab3dd60b722a53d70a090e16 (diff)
downloadmeta-virtualization-1abd778b15ccedd2cfc80d4f44802c1415fbbbde.tar.gz
container-cross-install: fix image naming and default runtime
Fix extract_container_info() to properly handle multi-part container names and add automatic runtime detection based on CONTAINER_PROFILE. - Fix multi-part name parsing (app-container-multilayer-latest-oci now correctly becomes app-container-multilayer:latest) - Add CONTAINER_DEFAULT_RUNTIME from CONTAINER_PROFILE - Add CONTAINER_IMPORT_TIMEOUT_BASE/PER for dynamic timeout scaling Signed-off-by: Bruce Ashfield <bruce.ashfield@gmail.com>
-rw-r--r--classes/container-cross-install.bbclass73
1 files changed, 56 insertions, 17 deletions
diff --git a/classes/container-cross-install.bbclass b/classes/container-cross-install.bbclass
index 8137a857..d365d7a1 100644
--- a/classes/container-cross-install.bbclass
+++ b/classes/container-cross-install.bbclass
@@ -103,6 +103,17 @@
103# Inherit shared functions for multiconfig/machine/arch mapping 103# Inherit shared functions for multiconfig/machine/arch mapping
104inherit container-common 104inherit container-common
105 105
106# Default runtime based on CONTAINER_PROFILE (same logic as container-bundle.bbclass)
107def get_default_container_runtime(d):
108 """Determine default container runtime from CONTAINER_PROFILE"""
109 profile = d.getVar('CONTAINER_PROFILE') or 'docker'
110 if profile in ['podman']:
111 return 'podman'
112 # docker, containerd, k3s-*, default all use docker storage format
113 return 'docker'
114
115CONTAINER_DEFAULT_RUNTIME ?= "${@get_default_container_runtime(d)}"
116
106# Dependencies on native tools 117# Dependencies on native tools
107# vcontainer-native provides vrunner.sh 118# vcontainer-native provides vrunner.sh
108# Blobs come from multiconfig builds (vdkr-initramfs-create, vpdmn-initramfs-create) 119# Blobs come from multiconfig builds (vdkr-initramfs-create, vpdmn-initramfs-create)
@@ -199,6 +210,11 @@ KERNEL_IMAGETYPE_QEMU = "${@get_kernel_name(d)}"
199# BLOB_ARCH uses get_blob_arch() from container-common.bbclass 210# BLOB_ARCH uses get_blob_arch() from container-common.bbclass
200BLOB_ARCH = "${@get_blob_arch(d)}" 211BLOB_ARCH = "${@get_blob_arch(d)}"
201 212
213# Timeout scaling: base startup + per-container time
214# QEMU boot is ~180s, larger containers (multi-layer with deps) can take ~600s
215CONTAINER_IMPORT_TIMEOUT_BASE ?= "180"
216CONTAINER_IMPORT_TIMEOUT_PER ?= "600"
217
202# ============================================================================ 218# ============================================================================
203# Merge container bundles installed via IMAGE_INSTALL 219# Merge container bundles installed via IMAGE_INSTALL
204# This function processes packages created by container-bundle.bbclass 220# This function processes packages created by container-bundle.bbclass
@@ -260,12 +276,18 @@ merge_installed_bundles() {
260 276
261 local docker_storage="${WORKDIR}/docker-storage-$$.tar" 277 local docker_storage="${WORKDIR}/docker-storage-$$.tar"
262 278
279 # Calculate timeout: base startup + per-container time
280 local num_containers=$(echo "${docker_containers}" | wc -w)
281 local import_timeout=$(expr ${CONTAINER_IMPORT_TIMEOUT_BASE} + $num_containers \* ${CONTAINER_IMPORT_TIMEOUT_PER})
282 bbnote "Docker batch import timeout: ${import_timeout}s (${num_containers} containers)"
283
263 ${VRUNNER_PATH} \ 284 ${VRUNNER_PATH} \
264 --no-daemon \ 285 --no-daemon \
265 --runtime docker \ 286 --runtime docker \
266 --arch ${BLOB_ARCH} \ 287 --arch ${BLOB_ARCH} \
267 --blob-dir ${VDKR_BLOB_DIR} \ 288 --blob-dir ${VDKR_BLOB_DIR} \
268 --batch-import \ 289 --batch-import \
290 --timeout ${import_timeout} \
269 --output "${docker_storage}" \ 291 --output "${docker_storage}" \
270 --verbose \ 292 --verbose \
271 -- ${docker_containers} 293 -- ${docker_containers}
@@ -292,12 +314,18 @@ merge_installed_bundles() {
292 314
293 local podman_storage="${WORKDIR}/podman-storage-$$.tar" 315 local podman_storage="${WORKDIR}/podman-storage-$$.tar"
294 316
317 # Calculate timeout: base startup + per-container time
318 local num_containers=$(echo "${podman_containers}" | wc -w)
319 local import_timeout=$(expr ${CONTAINER_IMPORT_TIMEOUT_BASE} + $num_containers \* ${CONTAINER_IMPORT_TIMEOUT_PER})
320 bbnote "Podman batch import timeout: ${import_timeout}s (${num_containers} containers)"
321
295 ${VRUNNER_PATH} \ 322 ${VRUNNER_PATH} \
296 --no-daemon \ 323 --no-daemon \
297 --runtime podman \ 324 --runtime podman \
298 --arch ${BLOB_ARCH} \ 325 --arch ${BLOB_ARCH} \
299 --blob-dir ${VPDMN_BLOB_DIR} \ 326 --blob-dir ${VPDMN_BLOB_DIR} \
300 --batch-import \ 327 --batch-import \
328 --timeout ${import_timeout} \
301 --output "${podman_storage}" \ 329 --output "${podman_storage}" \
302 --verbose \ 330 --verbose \
303 -- ${podman_containers} 331 -- ${podman_containers}
@@ -489,7 +517,8 @@ bundle_containers() {
489 517
490 # Extract container image name and tag from OCI directory name 518 # Extract container image name and tag from OCI directory name
491 # Sets: CONTAINER_IMAGE_NAME, CONTAINER_IMAGE_TAG 519 # Sets: CONTAINER_IMAGE_NAME, CONTAINER_IMAGE_TAG
492 # Input: /path/to/container-base-latest-oci 520 # Input: /path/to/container-base-latest-oci or /path/to/app-container-multilayer-latest-oci
521 # Output: container-base:latest or app-container-multilayer:latest
493 # Note: Use _cci_ prefix to avoid conflicts with bitbake's environment variables 522 # Note: Use _cci_ prefix to avoid conflicts with bitbake's environment variables
494 extract_container_info() { 523 extract_container_info() {
495 _cci_oci_path="$1" 524 _cci_oci_path="$1"
@@ -498,19 +527,17 @@ bundle_containers() {
498 CONTAINER_IMAGE_NAME="" 527 CONTAINER_IMAGE_NAME=""
499 CONTAINER_IMAGE_TAG="latest" 528 CONTAINER_IMAGE_TAG="latest"
500 529
501 # Three-part pattern: part1-part2-part3 (e.g., container-base-latest) 530 # Check if name ends with -latest or a version tag (-X.Y, -X.Y.Z, -vX.Y, etc.)
502 if echo "$_cci_dir_name" | grep -qE '^[^-]+-[^-]+-[^-]+$'; then 531 # The last hyphen-separated part is the tag if it looks like a version or is "latest"
503 _cci_part1=$(echo "$_cci_dir_name" | cut -d- -f1) 532 _cci_last_part=$(echo "$_cci_dir_name" | rev | cut -d- -f1 | rev)
504 _cci_part2=$(echo "$_cci_dir_name" | cut -d- -f2) 533
505 _cci_part3=$(echo "$_cci_dir_name" | cut -d- -f3) 534 # Check if last part is a tag (latest, or version-like: 1.0, v1.0, 1.0.0, etc.)
506 CONTAINER_IMAGE_NAME="${_cci_part1}-${_cci_part2}" 535 if echo "$_cci_last_part" | grep -qE '^(latest|v?[0-9]+\.[0-9]+(\.[0-9]+)?|[0-9]+)$'; then
507 CONTAINER_IMAGE_TAG="$_cci_part3" 536 # Strip the tag from the end to get the image name
508 # Two-part pattern: name-tag (e.g., myapp-1.0) 537 CONTAINER_IMAGE_TAG="$_cci_last_part"
509 elif echo "$_cci_dir_name" | grep -qE '^[^-]+-[^-]+$'; then 538 CONTAINER_IMAGE_NAME=$(echo "$_cci_dir_name" | sed "s/-${_cci_last_part}$//")
510 CONTAINER_IMAGE_NAME=$(echo "$_cci_dir_name" | cut -d- -f1)
511 CONTAINER_IMAGE_TAG=$(echo "$_cci_dir_name" | cut -d- -f2)
512 # Single name (e.g., myapp)
513 else 539 else
540 # No recognizable tag suffix, use whole name with default tag
514 CONTAINER_IMAGE_NAME="$_cci_dir_name" 541 CONTAINER_IMAGE_NAME="$_cci_dir_name"
515 CONTAINER_IMAGE_TAG="latest" 542 CONTAINER_IMAGE_TAG="latest"
516 fi 543 fi
@@ -635,9 +662,9 @@ EOF
635 local runtime_type="$(echo $bc | cut -d: -f2)" 662 local runtime_type="$(echo $bc | cut -d: -f2)"
636 local autostart_policy="$(echo $bc | cut -d: -f3)" 663 local autostart_policy="$(echo $bc | cut -d: -f3)"
637 664
638 # Default runtime to docker if not specified 665 # Default runtime from CONTAINER_PROFILE if not specified
639 if [ "$container_name" = "$runtime_type" ]; then 666 if [ "$container_name" = "$runtime_type" ]; then
640 runtime_type="docker" 667 runtime_type="${CONTAINER_DEFAULT_RUNTIME}"
641 autostart_policy="" 668 autostart_policy=""
642 fi 669 fi
643 670
@@ -719,9 +746,9 @@ EOF
719 container_name="$(echo $bc_clean | cut -d: -f1)" 746 container_name="$(echo $bc_clean | cut -d: -f1)"
720 runtime_type="$(echo $bc_clean | cut -d: -f2)" 747 runtime_type="$(echo $bc_clean | cut -d: -f2)"
721 748
722 # Default runtime to docker if not specified 749 # Default runtime from CONTAINER_PROFILE if not specified
723 if [ "$container_name" = "$runtime_type" ]; then 750 if [ "$container_name" = "$runtime_type" ]; then
724 runtime_type="docker" 751 runtime_type="${CONTAINER_DEFAULT_RUNTIME}"
725 fi 752 fi
726 753
727 bbnote "Collecting container: $container_name (runtime: $runtime_type)" 754 bbnote "Collecting container: $container_name (runtime: $runtime_type)"
@@ -781,12 +808,18 @@ Or remove it from BUNDLED_CONTAINERS if not needed.
781 tar -cf "${EXISTING_DOCKER_STORAGE}" -C "${IMAGE_ROOTFS}/var/lib" docker 808 tar -cf "${EXISTING_DOCKER_STORAGE}" -C "${IMAGE_ROOTFS}/var/lib" docker
782 fi 809 fi
783 810
811 # Calculate timeout: base startup + per-container time
812 NUM_DOCKER=$(echo "${DOCKER_CONTAINERS}" | wc -w)
813 DOCKER_TIMEOUT=$(expr ${CONTAINER_IMPORT_TIMEOUT_BASE} + $NUM_DOCKER \* ${CONTAINER_IMPORT_TIMEOUT_PER})
814 bbnote "Docker batch import timeout: ${DOCKER_TIMEOUT}s (${NUM_DOCKER} containers)"
815
784 # Build vrunner batch-import command 816 # Build vrunner batch-import command
785 VRUNNER_CMD="${VRUNNER} \ 817 VRUNNER_CMD="${VRUNNER} \
786 --runtime docker \ 818 --runtime docker \
787 --arch ${BLOB_ARCH} \ 819 --arch ${BLOB_ARCH} \
788 --blob-dir ${VDKR_BLOB_DIR} \ 820 --blob-dir ${VDKR_BLOB_DIR} \
789 --batch-import \ 821 --batch-import \
822 --timeout ${DOCKER_TIMEOUT} \
790 --output ${DOCKER_STORAGE_TAR} \ 823 --output ${DOCKER_STORAGE_TAR} \
791 --verbose" 824 --verbose"
792 825
@@ -839,12 +872,18 @@ Or remove it from BUNDLED_CONTAINERS if not needed.
839 tar -cf "${EXISTING_PODMAN_STORAGE}" -C "${IMAGE_ROOTFS}/var/lib/containers" storage 872 tar -cf "${EXISTING_PODMAN_STORAGE}" -C "${IMAGE_ROOTFS}/var/lib/containers" storage
840 fi 873 fi
841 874
875 # Calculate timeout: base startup + per-container time
876 NUM_PODMAN=$(echo "${PODMAN_CONTAINERS}" | wc -w)
877 PODMAN_TIMEOUT=$(expr ${CONTAINER_IMPORT_TIMEOUT_BASE} + $NUM_PODMAN \* ${CONTAINER_IMPORT_TIMEOUT_PER})
878 bbnote "Podman batch import timeout: ${PODMAN_TIMEOUT}s (${NUM_PODMAN} containers)"
879
842 # Build vrunner batch-import command 880 # Build vrunner batch-import command
843 VRUNNER_CMD="${VRUNNER} \ 881 VRUNNER_CMD="${VRUNNER} \
844 --runtime podman \ 882 --runtime podman \
845 --arch ${BLOB_ARCH} \ 883 --arch ${BLOB_ARCH} \
846 --blob-dir ${VPDMN_BLOB_DIR} \ 884 --blob-dir ${VPDMN_BLOB_DIR} \
847 --batch-import \ 885 --batch-import \
886 --timeout ${PODMAN_TIMEOUT} \
848 --output ${PODMAN_STORAGE_TAR} \ 887 --output ${PODMAN_STORAGE_TAR} \
849 --verbose" 888 --verbose"
850 889