kata-containers / tests

Kata Containers tests, CI, and metrics
https://katacontainers.io/
Apache License 2.0
139 stars 196 forks source link

coalesce all packages to install into single transaction #1560

Closed jodh-intel closed 5 years ago

jodh-intel commented 5 years ago

Looking at https://github.com/kata-containers/tests/pull/1559 made me think that we should consider refactoring the .ci/setup_env_${distro}.sh scripts so all packages are installed in a single apt/yum/dnf/zypper transaction. That should be more efficient and quicker:

Something like this:

# Array of packages.
#
# Each element is in the format:
#
#   description:packages
#
pkg_sets=()

# XXX: Put all the packages to install here, one set per line
pkg_sets+=(libsystemd:systemd-devel)
pkg_sets+=(cri-containerd dependencies:libseccomp-devel btrfs-progs-devel)

# space-separated list of packages to install
pkgs_to_install=

info "The following package sets will be installed:\n"

for set in ${pkg_sets[@]}
do
    descr=$(echo "$set"|cut -d: -f1)
    pkgs=$(echo "$set"|cut -d: -f2-)

    info "$descr ($pkgs)"
    pkgs_to_install+=" $pkgs"
done

chronic sudo -E apt -y install $pkgs_to_install

/cc @chavafg, @marcov.

marcov commented 5 years ago

+1, that's giving for sure some speedup. It would also be possible to (ab)use a associative array:

declare -A packages=( \
  [libsystemd]="systemd-devel" \
  [cri-containerd dependencies]="libseccomp-devel btrfs-progs-devel" \
)

pkgs_to_install=${packages[@]}

for description in ${!packages[@]}; do 
...
jodh-intel commented 5 years ago

+1 for using a hash - I keep forgetting that even bash on centos now has that feature! ;)