diff --git a/alpine-make-vm-image b/alpine-make-vm-image index 90f756e..0100e99 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 } @@ -480,7 +484,8 @@ fi # Use APK cache if available. 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 +551,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 +588,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'