Skip to content

Commit 66ee351

Browse files
committed
make apk cache work with chroot
1 parent 75ab553 commit 66ee351

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

alpine-make-vm-image

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,10 @@ prepare_chroot() {
241241
mount_bind /dev "$dest"/dev
242242
mount_bind /sys "$dest"/sys
243243

244+
if [ -n "$apk_cache_dir" ]; then
245+
mount_bind "$apk_cache_dir" "$dest/$apk_cache_dir"
246+
fi
247+
244248
install -D -m 644 /etc/resolv.conf "$dest"/etc/resolv.conf
245249
echo "$RESOLVCONF_MARK" >> "$dest"/etc/resolv.conf
246250
}
@@ -480,7 +484,8 @@ fi
480484

481485
# Use APK cache if available.
482486
if [ -L /etc/apk/cache ]; then
483-
ln -s "$(realpath /etc/apk/cache)" etc/apk/cache
487+
apk_cache_dir="$(realpath /etc/apk/cache)"
488+
ln -s "$apk_cache_dir" etc/apk/cache
484489
fi
485490

486491
_apk add --root . --update-cache --initdb alpine-base
@@ -546,11 +551,6 @@ if [ "$PACKAGES" ]; then
546551
_apk add --root . $PACKAGES
547552
fi
548553

549-
#-----------------------------------------------------------------------
550-
if [ -L /etc/apk/cache ]; then
551-
rm etc/apk/cache >/dev/null 2>&1
552-
fi
553-
554554
#-----------------------------------------------------------------------
555555
if [ "$FS_SKEL_DIR" ]; then
556556
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
588588
EOF
589589
fi
590590

591-
rm -Rf var/cache/apk/* ||:
591+
if [ -n "$apk_cache_dir" ]; then
592+
rm etc/apk/cache >/dev/null 2>&1
593+
else
594+
rm -Rf var/cache/apk/* ||:
595+
fi
592596

593597
einfo 'Completed'
594598

0 commit comments

Comments
 (0)