Skip to content

Commit 40306d9

Browse files
committed
conditionally add in cache to the image, allowing caching in customize image step if using docker build
1 parent c897044 commit 40306d9

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

lib/functions/general/chroot-helpers.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ function mount_chroot() {
1616
local target
1717
target="$(realpath "$1")" # normalize, remove last slash if dir
1818
display_alert "mount_chroot" "$target" "debug"
19+
1920
mkdir -p "${target}/run/user/0"
2021

2122
# tmpfs size=50% is the Linux default, but we need more.
@@ -26,6 +27,27 @@ function mount_chroot() {
2627
mount -t sysfs chsys "${target}"/sys
2728
mount --bind /dev "${target}"/dev
2829
mount -t devpts chpts "${target}"/dev/pts || mount --bind /dev/pts "${target}"/dev/pts
30+
31+
# ─── Cache bind logic ───────────────────────────────────────────────────────
32+
# The build framework relies on a host-side cache at /armbian/cache:
33+
# - In Docker: compile.sh mounts './cache' → /armbian/cache automatically.
34+
# - On bare-metal: /armbian/cache may not exist.
35+
# If /armbian/cache exists on the host:
36+
# • mkdir inside chroot
37+
# • bind-mount host cache → chroot cache
38+
# • touch '/run/user/0/cache_mounted.flag' in tmpfs to signal success.
39+
# The flag auto-expires when /run/user/0 unmounts.
40+
if [[ -d /armbian/cache ]]; then
41+
mkdir -p "${target}/armbian/cache"
42+
if mount --bind /armbian/cache "${target}/armbian/cache"; then
43+
# leave a temporary marker inside the chroot so processes there can detect it
44+
touch "${target}/run/user/0/cache_mounted.flag"
45+
else
46+
display_alert "cache bind failed" "/armbian/cache → ${target}/armbian/cache" "warn"
47+
fi
48+
else
49+
display_alert "Host /armbian/cache not found — skipping cache mount" "" "warn"
50+
fi
2951
}
3052

3153
# umount_chroot <target>
@@ -36,6 +58,15 @@ function umount_chroot() {
3658
local target
3759
target="$(realpath "$1")" # normalize, remove last slash if dir
3860
display_alert "Unmounting" "$target" "info"
61+
62+
# ─── Conditional cache unmount ─────────────────────────────────────────────
63+
# Only unmount cache if we previously mounted it (flag file present)
64+
if [[ -f "${target}/run/user/0/cache_mounted.flag" ]]; then
65+
umount "${target}/armbian/cache" || true
66+
rm -f "${target}/run/user/0/cache_mounted.flag" || true
67+
fi
68+
# ──────────────────────────────────────────────────────────────────────────
69+
3970
while grep -Eq "${target}\/(dev|proc|sys|tmp|var\/tmp|run\/user\/0)" /proc/mounts; do
4071
display_alert "Unmounting..." "target: ${target}" "debug"
4172
umount "${target}"/dev/pts || true

0 commit comments

Comments
 (0)