Skip to content

Commit

Permalink
make apk cache work with chroot
Browse files Browse the repository at this point in the history
  • Loading branch information
hpresnall committed Feb 28, 2023
1 parent 75ab553 commit 66ee351
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions alpine-make-vm-image
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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'

Expand Down

0 comments on commit 66ee351

Please sign in to comment.