From 7b53de50e3d469e4ffd706160daf6e7e139f1ec3 Mon Sep 17 00:00:00 2001 From: Hunter Presnall Date: Tue, 28 Feb 2023 18:41:54 -0500 Subject: [PATCH 1/3] make apk cache work with chroot --- alpine-make-vm-image | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/alpine-make-vm-image b/alpine-make-vm-image index 90f756e..fd4a121 100755 --- a/alpine-make-vm-image +++ b/alpine-make-vm-image @@ -241,6 +241,10 @@ prepare_chroot() { mount_bind /dev "$dest"/dev mount_bind /sys "$dest"/sys + if [ -n "$apk_cache_dir" ]; then + mount_bind "$apk_cache_dir" "$dest/$apk_cache_dir" + fi + install -D -m 644 /etc/resolv.conf "$dest"/etc/resolv.conf echo "$RESOLVCONF_MARK" >> "$dest"/etc/resolv.conf } @@ -479,8 +483,10 @@ else fi # Use APK cache if available. +apk_cache_dir= if [ -L /etc/apk/cache ]; then - ln -s "$(realpath /etc/apk/cache)" etc/apk/cache + apk_cache_dir="$(realpath /etc/apk/cache)" + ln -s "$apk_cache_dir" etc/apk/cache fi _apk add --root . --update-cache --initdb alpine-base @@ -546,11 +552,6 @@ if [ "$PACKAGES" ]; then _apk add --root . $PACKAGES fi -#----------------------------------------------------------------------- -if [ -L /etc/apk/cache ]; then - rm etc/apk/cache >/dev/null 2>&1 -fi - #----------------------------------------------------------------------- if [ "$FS_SKEL_DIR" ]; then einfo "Copying content of $FS_SKEL_DIR into image" @@ -588,7 +589,11 @@ if grep -qw "$RESOLVCONF_MARK" etc/resolv.conf 2>/dev/null; then EOF fi -rm -Rf var/cache/apk/* ||: +if [ -n "$apk_cache_dir" ]; then + rm etc/apk/cache >/dev/null 2>&1 +else + rm -Rf var/cache/apk/* ||: +fi einfo 'Completed' From 8edee3449de8e8aece78901a11d18572aee43348 Mon Sep 17 00:00:00 2001 From: Hunter Presnall Date: Sun, 17 Mar 2024 11:58:42 -0400 Subject: [PATCH 2/3] remove apk_cache bind mount dir --- alpine-make-vm-image | 1 + 1 file changed, 1 insertion(+) diff --git a/alpine-make-vm-image b/alpine-make-vm-image index c91c57b..b8f9cf5 100755 --- a/alpine-make-vm-image +++ b/alpine-make-vm-image @@ -739,6 +739,7 @@ fi if [ -n "$apk_cache_dir" ]; then rm etc/apk/cache >/dev/null 2>&1 + rm $apk_cache_dir > /dev/null 2>&1 else rm -Rf var/cache/apk/* ||: fi From bd4c88bf04bb9bd3bc77cc46ea40846bb70148be Mon Sep 17 00:00:00 2001 From: Hunter Presnall Date: Sun, 17 Mar 2024 12:32:42 -0400 Subject: [PATCH 3/3] delete vm apk_cache, not host --- alpine-make-vm-image | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/alpine-make-vm-image b/alpine-make-vm-image index 0aca8e7..d8ad4d0 100755 --- a/alpine-make-vm-image +++ b/alpine-make-vm-image @@ -738,8 +738,10 @@ if grep -qw "$RESOLVCONF_MARK" etc/resolv.conf 2>/dev/null; then fi if [ -n "$apk_cache_dir" ]; then - rm etc/apk/cache >/dev/null 2>&1 - rm $apk_cache_dir > /dev/null 2>&1 + # remove symlink and dir created by bind mount + rm etc/apk/cache >/dev/null ||: + umount $mount_dir/$apk_cache_dir ||: + rm $mount_dir/$apk_cache_dir ||: else rm -Rf var/cache/apk/* ||: fi