Skip to content

Commit 1ad69aa

Browse files
committed
cidata: automatically upgrade existing containerd/nerdctl
When the timestamp of `/mnt/lima-cidata/nerdctl-full.tgz:bin/nerdctl` is newer than `/usr/local/bin/nerdctl`, containerd/nerdctl is automatically upgraded. Drawback: increases boot time by 4-5 seconds. Fix issue 303 Signed-off-by: Akihiro Suda <[email protected]>
1 parent 66f66e1 commit 1ad69aa

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

pkg/cidata/cidata.TEMPLATE.d/boot/40-install-containerd.sh

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/sh
1+
#!/bin/bash
22
set -eux
33

44
if [ "${LIMA_CIDATA_CONTAINERD_SYSTEM}" != 1 ] && [ "${LIMA_CIDATA_CONTAINERD_USER}" != 1 ]; then
@@ -8,14 +8,31 @@ fi
88
# This script does not work unless systemd is available
99
command -v systemctl >/dev/null 2>&1 || exit 0
1010

11-
if [ ! -x /usr/local/bin/nerdctl ]; then
11+
# Extract bin/nerdctl and compare whether it is newer than the current /usr/local/bin/nerdctl (if already exists).
12+
# Takes 4-5 seconds. (FIXME: optimize)
13+
tmp_extract_nerdctl="$(mktemp -d)"
14+
tar Cxzf "${tmp_extract_nerdctl}" "${LIMA_CIDATA_MNT}"/nerdctl-full.tgz bin/nerdctl
15+
16+
if [ ! -f /usr/local/bin/nerdctl ] || [[ "${tmp_extract_nerdctl}"/bin/nerdctl -nt /usr/local/bin/nerdctl ]]; then
17+
if [ -f /usr/local/bin/nerdctl ]; then
18+
(
19+
set +e
20+
echo "Upgrading existing nerdctl"
21+
echo "- Old: $(/usr/local/bin/nerdctl --version)"
22+
echo "- New: $("${tmp_extract_nerdctl}"/bin/nerdctl --version)"
23+
systemctl disable --now containerd buildkit stargz-snapshotter
24+
sudo -iu "${LIMA_CIDATA_USER}" "XDG_RUNTIME_DIR=/run/user/${LIMA_CIDATA_UID}" "PATH=${PATH}" containerd-rootless-setuptool.sh uninstall
25+
)
26+
fi
1227
tar Cxzf /usr/local "${LIMA_CIDATA_MNT}"/nerdctl-full.tgz
1328

1429
mkdir -p /etc/bash_completion.d
1530
nerdctl completion bash >/etc/bash_completion.d/nerdctl
1631
# TODO: enable zsh completion too
1732
fi
1833

34+
rm -rf "${tmp_extract_nerdctl}"
35+
1936
if [ "${LIMA_CIDATA_CONTAINERD_SYSTEM}" = 1 ]; then
2037
mkdir -p /etc/containerd
2138
cat >"/etc/containerd/config.toml" <<EOF

0 commit comments

Comments
 (0)