Skip to content

Commit

Permalink
init: massively speed up apk deps install (#1298)
Browse files Browse the repository at this point in the history
Instead of running "apk info" on each package individually instead just
compare the list of requested packages to an "apk search" of them and
pick the ones that could be found.

On alpine due to the way searching for providers of openssh-client and
exact matching of the found packages (procps is procps-ng) adjust these
both accordingly to keep the end result consistent for alpine and wolfi.

On my end this halves the setup time for the non-toolbox alpine and
wolfi images from ~30 and 40 seconds to ~15 and 20 seconds respectively.
  • Loading branch information
JamiKettunen authored Mar 25, 2024
1 parent 90b1789 commit e5bbb7b
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions distrobox-init
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,7 @@ if [ "${upgrade}" -ne 0 ] ||
gnutar
man-db
mesa
openssh-client
posix-libc-utils
"
elif apk add alpine-base; then
Expand All @@ -433,6 +434,7 @@ if [ "${upgrade}" -ne 0 ] ||
man-pages
mandoc
musl-utils
openssh-client-default
pinentry
sudo
tar
Expand Down Expand Up @@ -463,9 +465,7 @@ if [ "${upgrade}" -ne 0 ] ||
ncurses
ncurses-terminfo
net-tools
openssh-client
pigz
procps
rsync
shadow
su-exec
Expand All @@ -482,12 +482,18 @@ if [ "${upgrade}" -ne 0 ] ||
xauth
xz
zip
$(apk search -qe procps)
"
# shellcheck disable=SC2086
found_deps="$(apk search -qe ${deps} | tr '\n' ' ')"
install_pkg=""
for dep in ${deps}; do
if apk info "${dep}" > /dev/null; then
install_pkg="${install_pkg} ${dep}"
fi
# shellcheck disable=SC2249
case " ${found_deps} " in
*" ${dep} "*)
install_pkg="${install_pkg} ${dep}"
;;
esac
done
# shellcheck disable=SC2086
apk add --force-overwrite ${install_pkg}
Expand Down

0 comments on commit e5bbb7b

Please sign in to comment.