From 9da8f7a58022ecc9e95cd14618dc8069d253182d Mon Sep 17 00:00:00 2001
From: j1nx
Date: Thu, 30 Nov 2023 18:24:34 +0000
Subject: [PATCH] [ALL] First try-out on pre loading the podman containers at
buildtime
---
buildroot | 2 +-
.../board/ovos/ova/genimage-ova.cfg | 8 --------
buildroot-external/board/ovos/ova/post-build.sh | 15 +++++++++++++++
.../board/ovos/raspberrypi/post-build.sh | 15 +++++++++++++++
.../board/ovos/raspberrypi/rpi3/genimage-rpi3.cfg | 8 --------
.../board/ovos/raspberrypi/rpi4/genimage-rpi4.cfg | 8 --------
buildroot-external/configs/ova_64_defconfig | 3 +++
buildroot-external/configs/rpi3_64_defconfig | 3 +++
buildroot-external/configs/rpi4_64_defconfig | 3 +++
.../ovos-containers/install-container-image.sh | 11 +++++++++++
.../package/ovos-containers/ovos-containers.mk | 12 +++++++++++-
11 files changed, 62 insertions(+), 26 deletions(-)
create mode 100755 buildroot-external/package/ovos-containers/install-container-image.sh
diff --git a/buildroot b/buildroot
index fa179b6a..8d3a8bfd 160000
--- a/buildroot
+++ b/buildroot
@@ -1 +1 @@
-Subproject commit fa179b6a0755fbb8591f1782080c2bcdd5069d40
+Subproject commit 8d3a8bfd1a561f15dae900eb6da81f9718208f46
diff --git a/buildroot-external/board/ovos/ova/genimage-ova.cfg b/buildroot-external/board/ovos/ova/genimage-ova.cfg
index 5e622930..2cccc6dc 100644
--- a/buildroot-external/board/ovos/ova/genimage-ova.cfg
+++ b/buildroot-external/board/ovos/ova/genimage-ova.cfg
@@ -19,14 +19,6 @@ image overlayfs.ext4 {
size = 256M
}
-image homefs.ext4 {
- name = "homefs"
- ext4 {
- use-mke2fs = "true"
- }
- size = 64M
-}
-
image disk.img {
hdimage {
partition-table-type = "gpt"
diff --git a/buildroot-external/board/ovos/ova/post-build.sh b/buildroot-external/board/ovos/ova/post-build.sh
index 7d886ae2..1120a014 100755
--- a/buildroot-external/board/ovos/ova/post-build.sh
+++ b/buildroot-external/board/ovos/ova/post-build.sh
@@ -40,3 +40,18 @@ if [ -f "${TARGET_DIR}/boot/bzImage" ]; then
echo "Found bzImage, renaming to kernel"
mv ${TARGET_DIR}/boot/bzImage ${TARGET_DIR}/boot/kernel
fi
+
+# Prepare home data
+rm -f ${BINARIES_DIR}/homefs.ext4
+truncate --size="5G" ${BINARIES_DIR}/homefs.ext4
+mkfs.ext4 -L "homefs" -E lazy_itable_init=0,lazy_journal_init=0 ${BINARIES_DIR}/homefs.ext4
+
+# Mount home image
+mkdir -p ${BINARIES_DIR}/home
+sudo mount -o loop,discard ${BINARIES_DIR}/homefs.ext4 ${BINARIES_DIR}/home
+
+# sync home folder
+sudo rsync -ah --progress ${TARGET_DIR}/home/* ${BINARIES_DIR}/home/
+
+# Unmount home image
+sudo umount ${BINARIES_DIR}/homefs.ext4
diff --git a/buildroot-external/board/ovos/raspberrypi/post-build.sh b/buildroot-external/board/ovos/raspberrypi/post-build.sh
index 9240ff7b..3c552677 100755
--- a/buildroot-external/board/ovos/raspberrypi/post-build.sh
+++ b/buildroot-external/board/ovos/raspberrypi/post-build.sh
@@ -56,3 +56,18 @@ do
;;
esac
done
+
+# Prepare home data
+rm -f ${BINARIES_DIR}/homefs.ext4
+truncate --size="5G" ${BINARIES_DIR}/homefs.ext4
+mkfs.ext4 -L "homefs" -E lazy_itable_init=0,lazy_journal_init=0 ${BINARIES_DIR}/homefs.ext4
+
+# Mount home image
+mkdir -p ${BINARIES_DIR}/home
+sudo mount -o loop,discard ${BINARIES_DIR}/homefs.ext4 ${BINARIES_DIR}/home
+
+# sync home folder
+sudo rsync -ah --progress ${TARGET_DIR}/home/* ${BINARIES_DIR}/home/
+
+# Unmount home image
+sudo umount ${BINARIES_DIR}/homefs.ext4
diff --git a/buildroot-external/board/ovos/raspberrypi/rpi3/genimage-rpi3.cfg b/buildroot-external/board/ovos/raspberrypi/rpi3/genimage-rpi3.cfg
index 41b1a855..06ba21b6 100644
--- a/buildroot-external/board/ovos/raspberrypi/rpi3/genimage-rpi3.cfg
+++ b/buildroot-external/board/ovos/raspberrypi/rpi3/genimage-rpi3.cfg
@@ -31,14 +31,6 @@ image overlayfs.ext4 {
size = 256M
}
-image homefs.ext4 {
- name = "homefs"
- ext4 {
- use-mke2fs = "true"
- }
- size = 64M
-}
-
image disk.img {
hdimage {
partition-table-type = "hybrid"
diff --git a/buildroot-external/board/ovos/raspberrypi/rpi4/genimage-rpi4.cfg b/buildroot-external/board/ovos/raspberrypi/rpi4/genimage-rpi4.cfg
index 51a1171a..3ea6bcc1 100644
--- a/buildroot-external/board/ovos/raspberrypi/rpi4/genimage-rpi4.cfg
+++ b/buildroot-external/board/ovos/raspberrypi/rpi4/genimage-rpi4.cfg
@@ -28,14 +28,6 @@ image overlayfs.ext4 {
size = 256M
}
-image homefs.ext4 {
- name = "homefs"
- ext4 {
- use-mke2fs = "true"
- }
- size = 64M
-}
-
image disk.img {
hdimage {
partition-table-type = "gpt"
diff --git a/buildroot-external/configs/ova_64_defconfig b/buildroot-external/configs/ova_64_defconfig
index cf707721..05beb708 100644
--- a/buildroot-external/configs/ova_64_defconfig
+++ b/buildroot-external/configs/ova_64_defconfig
@@ -320,4 +320,7 @@ BR2_PACKAGE_HOST_MTOOLS=y
BR2_PACKAGE_HOST_PKGCONF=y
BR2_PACKAGE_HOSTNAME_SERVICE=y
BR2_PACKAGE_NCPAMIXER=y
+BR2_PACKAGE_OVOS_CONTAINERS=y
+BR2_PACKAGE_OVOS_CONTAINERS_ARCH="x86_64"
+BR2_PACKAGE_OVOS_CONTAINERS_IMAGES="ovos-messagebus"
BR2_PACKAGE_OVOS_SPLASH=y
diff --git a/buildroot-external/configs/rpi3_64_defconfig b/buildroot-external/configs/rpi3_64_defconfig
index 25e23e66..6e14a1df 100644
--- a/buildroot-external/configs/rpi3_64_defconfig
+++ b/buildroot-external/configs/rpi3_64_defconfig
@@ -305,6 +305,9 @@ BR2_PACKAGE_HOST_MTOOLS=y
BR2_PACKAGE_HOST_PKGCONF=y
BR2_PACKAGE_HOSTNAME_SERVICE=y
BR2_PACKAGE_NCPAMIXER=y
+BR2_PACKAGE_OVOS_CONTAINERS=y
+BR2_PACKAGE_OVOS_CONTAINERS_ARCH="aarch64"
+BR2_PACKAGE_OVOS_CONTAINERS_IMAGES="ovos-messagebus"
BR2_PACKAGE_OVOS_SPLASH=y
BR2_PACKAGE_RESPEAKER=y
BR2_PACKAGE_RPI_EEPROM=y
diff --git a/buildroot-external/configs/rpi4_64_defconfig b/buildroot-external/configs/rpi4_64_defconfig
index 82afad37..c57d812e 100644
--- a/buildroot-external/configs/rpi4_64_defconfig
+++ b/buildroot-external/configs/rpi4_64_defconfig
@@ -304,6 +304,9 @@ BR2_PACKAGE_HOST_MTOOLS=y
BR2_PACKAGE_HOST_PKGCONF=y
BR2_PACKAGE_HOSTNAME_SERVICE=y
BR2_PACKAGE_NCPAMIXER=y
+BR2_PACKAGE_OVOS_CONTAINERS=y
+BR2_PACKAGE_OVOS_CONTAINERS_ARCH="aarch64"
+BR2_PACKAGE_OVOS_CONTAINERS_IMAGES="ovos-messagebus"
BR2_PACKAGE_OVOS_SPLASH=y
BR2_PACKAGE_RESPEAKER=y
BR2_PACKAGE_RPI_EEPROM=y
diff --git a/buildroot-external/package/ovos-containers/install-container-image.sh b/buildroot-external/package/ovos-containers/install-container-image.sh
new file mode 100755
index 00000000..16970ace
--- /dev/null
+++ b/buildroot-external/package/ovos-containers/install-container-image.sh
@@ -0,0 +1,11 @@
+#!/usr/bin/env bash
+set -e
+
+build_dir=$1
+dst_dir=$2
+
+# shellcheck disable=SC2045
+for image in $(ls -S ${build_dir}/images/*.tar); do
+ podman --root "${dst_dir}" load --input "${image}"
+done
+
diff --git a/buildroot-external/package/ovos-containers/ovos-containers.mk b/buildroot-external/package/ovos-containers/ovos-containers.mk
index f394ed12..dc9a23d4 100644
--- a/buildroot-external/package/ovos-containers/ovos-containers.mk
+++ b/buildroot-external/package/ovos-containers/ovos-containers.mk
@@ -10,7 +10,8 @@ OVOS_CONTAINERS_LICENSE_FILES = $(BR2_EXTERNAL_OPENVOICEOS_PATH)/../LICENSE
OVOS_CONTAINERS_SITE = $(BR2_EXTERNAL_OPENVOICEOS_PATH)/package/ovos-containers
OVOS_CONTAINERS_SITE_METHOD = local
-OVOS_CONTAINERS_IMAGES = $(call qstrip,$(BR2_PACKAGE_OVOS_CONTAINERS))
+#OVOS_CONTAINERS_IMAGES = $(call qstrip, $(BR2_PACKAGE_OVOS_CONTAINERS))
+OVOS_CONTAINERS_IMAGES = ovos-messagebus ovos-phal ovos-phal-admin ovos-listener-dinkum ovos-audio ovos-core ovos-cli ovos-gui-websocket ovos-gui-shell
define OVOS_CONTAINERS_BUILD_CMDS
$(Q)mkdir -p $(@D)/images
@@ -21,4 +22,13 @@ define OVOS_CONTAINERS_BUILD_CMDS
)
endef
+OVOS_CONTAINERS_INSTALL_IMAGES = YES
+
+define OVOS_CONTAINERS_INSTALL_IMAGES_CMDS
+ $(BR2_EXTERNAL_OPENVOICEOS_PATH)/package/ovos-containers/install-container-image.sh "$(@D)" "$(TARGET_DIR)/home/ovos/.local/share/containers/storage"
+ rm -rf $(TARGET_DIR)/home/ovos/.local/share/containers/storage/storage.lock
+ rm -rf $(TARGET_DIR)/home/ovos/.local/share/containers/storage/userns.lock
+ rm -rf $(TARGET_DIR)/home/ovos/.local/share/containers/storage/libpod
+endef
+
$(eval $(generic-package))