Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make apk cache work with chroot #34

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions alpine-make-vm-image
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,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 @@ -590,8 +594,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 . ${ARCH:+--arch "$ARCH"} --update-cache --initdb alpine-base
Expand Down Expand Up @@ -694,11 +700,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 @@ -736,7 +737,14 @@ 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
# 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

einfo 'Completed'

Expand Down
Loading