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

Optimize containerd/nerdctl upgrader script #699

Open
AkihiroSuda opened this issue Mar 7, 2022 · 0 comments
Open

Optimize containerd/nerdctl upgrader script #699

AkihiroSuda opened this issue Mar 7, 2022 · 0 comments

Comments

@AkihiroSuda
Copy link
Member

AkihiroSuda commented Mar 7, 2022

# Extract bin/nerdctl and compare whether it is newer than the current /usr/local/bin/nerdctl (if already exists).
# Takes 4-5 seconds. (FIXME: optimize)
tmp_extract_nerdctl="$(mktemp -d)"
tar Cxzf "${tmp_extract_nerdctl}" "${LIMA_CIDATA_MNT}"/nerdctl-full.tgz bin/nerdctl
if [ ! -f /usr/local/bin/nerdctl ] || [[ "${tmp_extract_nerdctl}"/bin/nerdctl -nt /usr/local/bin/nerdctl ]]; then
if [ -f /usr/local/bin/nerdctl ]; then
(
set +e
echo "Upgrading existing nerdctl"
echo "- Old: $(/usr/local/bin/nerdctl --version)"
echo "- New: $("${tmp_extract_nerdctl}"/bin/nerdctl --version)"
systemctl disable --now containerd buildkit stargz-snapshotter
sudo -iu "${LIMA_CIDATA_USER}" "XDG_RUNTIME_DIR=/run/user/${LIMA_CIDATA_UID}" "PATH=${PATH}" containerd-rootless-setuptool.sh uninstall
)
fi
tar Cxzf /usr/local "${LIMA_CIDATA_MNT}"/nerdctl-full.tgz
mkdir -p /etc/bash_completion.d
nerdctl completion bash >/etc/bash_completion.d/nerdctl
# TODO: enable zsh completion too
fi
rm -rf "${tmp_extract_nerdctl}"


Idea for optimization:

root@lima-default:/mnt/lima-cidata# gunzip -c nerdctl-full.tgz | head -c 512 | tar tv | awk '/ bin\/$/ {print $4}'
2022-03-03
root@lima-default:/mnt/lima-cidata# date -r /usr/local/bin/nerdctl "+%F"
2022-03-03

Then do simple string comparison on the dates.

This relies on a tar header block being 512 bytes (so tar will not throw an error), and bin/ being the first entry in the tarball. I think these are reasonable assumptions, but am not totally sure. If the first line doesn't return a non-empty string, fall back on the expensive check by extracting the tarball.

Originally posted by @jandubois in #694 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant