Skip to content

Commit 0360168

Browse files
blooopclaude
andcommitted
fix(setup_host): make the script work on ubuntu 26.04
The script aborted partway through on a fresh host regardless of Ubuntu version, leaving pixi, uv and the docker group setup uninstalled: - docker run hello-world ran before usermod -aG docker, so it hit a permission denied on the socket and set -e killed the script. The group setup now happens right after the docker install, and the smoke tests run under sudo. - sudo groupadd docker always failed, since docker-ce already creates the group. It is now guarded with getent. - newgrp docker at the end would have spawned an interactive subshell. Ubuntu 26.04 ships neither sg nor newgrp, so this is gone in favour of a "log out and back in" message. Ubuntu 26.04 specifics: - download.docker.com does publish a resolute suite, so $VERSION_CODENAME still resolves, but the script now falls back to noble if the host's codename has not been published yet. - nvidia-docker2 is dropped. It is deprecated, frozen at 2.14.0 and no longer in NVIDIA's docs; nvidia-container-toolkit alone is what nvidia-ctk runtime configure needs. Other fixes: - The NVIDIA half is skipped unless nvidia-smi -L succeeds, with a hint to install a driver first, rather than installing a toolkit that every GPU container then fails against. - The conflicting-package removal is a single apt-get remove -y instead of a loop without -y that prompted mid-script. - gpg --dearmor gains --yes so re-runs do not prompt, and the pixi completion line is only appended to .bashrc once. - Added a GPU smoke test using ubuntu:$VERSION_ID. A plain ubuntu image avoids pinning a CUDA version, since the toolkit injects nvidia-smi and the driver libraries from the host. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 5ff4cb3 commit 0360168

2 files changed

Lines changed: 88 additions & 36 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ There are two methods of using this project.
3232
1. Use github to use this project as a template
3333
2. Clone the project and run, `scripts/update_from_template.sh` and then run the `scripts/rename_project.sh` to rename the project.
3434

35-
If you want to use docker you may want to run the `scripts/setup_host.sh` script. It will set up docker and nvidia-docker (assuming you are on ubuntu22.04).
35+
If you want to use docker you may want to run the `scripts/setup_host.sh` script. It will set up docker and the NVIDIA Container Toolkit (tested on ubuntu 22.04/24.04/26.04).
3636

3737
If you are using pixi, look at the available tasks in pyproject.toml If you are new to pixi follow the instructions on the pixi [website](https://prefix.dev/)
3838

‎scripts/setup_host.sh‎

Lines changed: 87 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,117 @@
11
#! /bin/bash
2-
set -eo pipefail
2+
set -euo pipefail
33

4-
#Sets up docker, nvidia docker git-lfs and rocker which are used to clone and setup docker containers
4+
# Sets up docker, the NVIDIA Container Toolkit, git-lfs, pixi and uv, which are used
5+
# to clone and set up docker containers.
6+
#
7+
# Tested on Ubuntu 22.04 / 24.04 / 26.04.
58

6-
#COPIED FROM OFFICIAL DOCKER INSTALL INSTRUCTIONS
9+
if [ "${EUID}" -eq 0 ]; then
10+
echo "Do not run this script as root / with sudo; it calls sudo itself where needed." >&2
11+
exit 1
12+
fi
13+
14+
# Keep a sudo timestamp alive so the script does not stall halfway through.
15+
sudo -v
16+
17+
# ---------------------------------------------------------------------------
18+
# DOCKER
19+
# Adapted from the official install instructions:
720
# https://docs.docker.com/engine/install/ubuntu/
21+
# ---------------------------------------------------------------------------
822

9-
#remove incorrect docker
10-
for pkg in docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do sudo apt-get remove "$pkg"; done
23+
# Remove distro/podman packages that conflict with docker-ce.
24+
# `apt-get remove` on a package that is not installed is a no-op, so this is safe.
25+
sudo apt-get remove -y docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc
1126

1227
# Add Docker's official GPG key:
13-
sudo apt update
14-
sudo apt install -y ca-certificates curl
28+
sudo apt-get update
29+
sudo apt-get install -y ca-certificates curl
1530
sudo install -m 0755 -d /etc/apt/keyrings
1631
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
1732
sudo chmod a+r /etc/apt/keyrings/docker.asc
1833

1934
# Add the repository to Apt sources:
2035
# shellcheck disable=SC1091
36+
UBUNTU_CODENAME="$(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}")"
37+
38+
# Docker does not always publish a suite on release day. If this release is not
39+
# there yet, fall back to the most recent suite that is.
40+
if ! curl -fsSL -o /dev/null "https://download.docker.com/linux/ubuntu/dists/${UBUNTU_CODENAME}/Release"; then
41+
echo "WARNING: Docker has no apt suite for '${UBUNTU_CODENAME}' yet; falling back to 'noble'." >&2
42+
UBUNTU_CODENAME=noble
43+
fi
44+
2145
echo \
2246
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
23-
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
47+
${UBUNTU_CODENAME} stable" | \
2448
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
25-
sudo apt update
49+
sudo apt-get update
2650

2751
# Install docker
28-
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
29-
#END OFFICIAL DOCKER INSTALL
52+
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
53+
# END OFFICIAL DOCKER INSTALL
3054

55+
# Allow the current user to talk to the docker socket without sudo.
56+
# docker-ce already creates the group, so only create it if it is somehow missing.
57+
getent group docker > /dev/null || sudo groupadd docker
58+
sudo usermod -aG docker "$USER"
3159

60+
# ---------------------------------------------------------------------------
61+
# NVIDIA CONTAINER TOOLKIT
62+
# https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/install-guide.html
63+
# Note: the old `nvidia-docker2` package is deprecated and is NOT needed.
64+
# ---------------------------------------------------------------------------
3265

33-
#INSTALL NVIDIA DOCKER
34-
#https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/install-guide.html
35-
curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg \
36-
&& curl -s -L https://nvidia.github.io/libnvidia-container/stable/deb/nvidia-container-toolkit.list | \
66+
if command -v nvidia-smi > /dev/null && nvidia-smi -L > /dev/null 2>&1; then
67+
curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | \
68+
sudo gpg --yes --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg
69+
curl -fsSL https://nvidia.github.io/libnvidia-container/stable/deb/nvidia-container-toolkit.list | \
3770
sed 's#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://#g' | \
38-
sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list
39-
sudo apt update
40-
sudo apt install -y nvidia-docker2 nvidia-container-toolkit
41-
sudo nvidia-ctk runtime configure --runtime=docker
42-
sudo systemctl restart docker
43-
44-
sudo apt install -y git-lfs
45-
46-
#Install rocker and rocker extensions which are used to launch the devcontainer
71+
sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list > /dev/null
72+
sudo apt-get update
73+
sudo apt-get install -y nvidia-container-toolkit
74+
sudo nvidia-ctk runtime configure --runtime=docker
75+
sudo systemctl restart docker
76+
else
77+
echo "No working NVIDIA driver detected (nvidia-smi failed); skipping NVIDIA Container Toolkit."
78+
echo "Install a driver first, e.g. 'sudo ubuntu-drivers install', reboot, then re-run this script."
79+
fi
80+
81+
sudo apt-get install -y git-lfs
82+
83+
# Install rocker and rocker extensions which are used to launch the devcontainer
4784
# pip install rocker off-your-rocker git+https://github.com/blooop/deps_rocker
4885

49-
echo "testing docker install"
50-
51-
docker run hello-world
86+
# ---------------------------------------------------------------------------
87+
# SMOKE TESTS
88+
# The `docker` group membership added above does not apply to the current shell
89+
# until the user logs out and back in, so run the tests with sudo. (Ubuntu 26.04
90+
# removed `sg` and `newgrp`, so those are not an option.)
91+
# ---------------------------------------------------------------------------
5292

53-
echo "you may need to restart your machine"
54-
55-
#INSTALL PIXI
93+
echo "testing docker install"
94+
sudo docker run --rm hello-world
95+
96+
if command -v nvidia-ctk > /dev/null; then
97+
echo "testing nvidia docker install"
98+
# Plain ubuntu image matching the host release: the toolkit injects nvidia-smi
99+
# and the driver libraries from the host, so this avoids pinning a CUDA version.
100+
# shellcheck disable=SC1091
101+
TEST_IMAGE="ubuntu:$(. /etc/os-release && echo "$VERSION_ID")"
102+
sudo docker run --rm --gpus all "${TEST_IMAGE}" nvidia-smi || \
103+
echo "WARNING: GPU container test failed."
104+
fi
105+
106+
# INSTALL PIXI
56107
curl -fsSL https://pixi.sh/install.sh | bash
57108
# shellcheck disable=SC2016
58-
echo 'eval "$(pixi completion --shell bash)"' >> ~/.bashrc
109+
grep -qF 'pixi completion --shell bash' ~/.bashrc || \
110+
echo 'eval "$(pixi completion --shell bash)"' >> ~/.bashrc
59111

60-
#INSTALL UV
112+
# INSTALL UV
61113
curl -LsSf https://astral.sh/uv/install.sh | sh
62114

63-
sudo groupadd docker
64-
sudo usermod -aG docker "$USER"
65-
newgrp docker || true
115+
echo
116+
echo "Done. Log out and back in (or reboot) so your 'docker' group membership applies"
117+
echo "to every new shell, and so pixi/uv are on your PATH."

0 commit comments

Comments
 (0)