Skip to content

Commit 0d4a065

Browse files
committed
use rootless podman
1 parent 2bf57af commit 0d4a065

File tree

4 files changed

+155
-102
lines changed

4 files changed

+155
-102
lines changed

scripts/dev/configure_container_auth.sh

Lines changed: 14 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,14 @@ setup_validate_container_runtime() {
2222
echo "Error: Podman is not available but was specified"
2323
exit 1
2424
fi
25-
USE_SUDO=true
26-
CONFIG_PATH="/root/.config/containers/auth.json"
27-
echo "Using Podman for container authentication (sudo mode)"
25+
CONFIG_PATH="${HOME}/.config/containers/auth.json"
26+
echo "Using Podman for container authentication (rootless mode)"
2827
;;
2928
"docker")
3029
if ! command -v docker &> /dev/null; then
3130
echo "Error: Docker is not available but was specified"
3231
exit 1
3332
fi
34-
USE_SUDO=false
3533
CONFIG_PATH="${HOME}/.docker/config.json"
3634
echo "Using Docker for container authentication"
3735
;;
@@ -41,41 +39,7 @@ setup_validate_container_runtime() {
4139
;;
4240
esac
4341

44-
if [[ "${USE_SUDO}" == "true" ]]; then
45-
sudo mkdir -p "$(dirname "${CONFIG_PATH}")"
46-
else
47-
mkdir -p "$(dirname "${CONFIG_PATH}")"
48-
fi
49-
}
50-
51-
# Wrapper function to execute commands with or without sudo
52-
exec_cmd() {
53-
if [[ "${USE_SUDO}" == "true" ]]; then
54-
sudo env PATH="${PATH}" "$@"
55-
else
56-
"$@"
57-
fi
58-
}
59-
60-
# Wrapper function to read files with or without sudo
61-
read_file() {
62-
local file="$1"
63-
if [[ "${USE_SUDO}" == "true" ]]; then
64-
sudo cat "${file}"
65-
else
66-
cat "${file}"
67-
fi
68-
}
69-
70-
# Wrapper function to write files with or without sudo
71-
write_file() {
72-
local content="$1"
73-
local file="$2"
74-
if [[ "${USE_SUDO}" == "true" ]]; then
75-
echo "${content}" | sudo tee "${file}" > /dev/null
76-
else
77-
echo "${content}" > "${file}"
78-
fi
42+
mkdir -p "$(dirname "${CONFIG_PATH}")"
7943
}
8044

8145
remove_element() {
@@ -84,11 +48,11 @@ remove_element() {
8448
tmpfile=$(mktemp)
8549

8650
if [[ ! -f "${CONFIG_PATH}" ]]; then
87-
write_file '{}' "${CONFIG_PATH}"
51+
echo '{}' > "${CONFIG_PATH}"
8852
fi
8953

90-
exec_cmd jq 'del(.'"${config_option}"')' "${CONFIG_PATH}" > "${tmpfile}"
91-
exec_cmd cp "${tmpfile}" "${CONFIG_PATH}"
54+
jq 'del(.'"${config_option}"')' "${CONFIG_PATH}" > "${tmpfile}"
55+
cp "${tmpfile}" "${CONFIG_PATH}"
9256
rm "${tmpfile}"
9357
}
9458

@@ -97,7 +61,7 @@ registry_login() {
9761
local registry="$2"
9862

9963
if [[ "${CONTAINER_RUNTIME}" == "podman" ]]; then
100-
exec_cmd podman login --authfile "${CONFIG_PATH}" --username "${username}" --password-stdin "${registry}"
64+
podman login --authfile "${CONFIG_PATH}" --username "${username}" --password-stdin "${registry}"
10165
else
10266
docker login --username "${username}" --password-stdin "${registry}"
10367
fi
@@ -106,13 +70,13 @@ registry_login() {
10670
setup_validate_container_runtime
10771

10872
if [[ ! -f "${CONFIG_PATH}" ]]; then
109-
write_file '{}' "${CONFIG_PATH}"
73+
echo '{}' > "${CONFIG_PATH}"
11074
fi
11175

11276
if [[ -f "${CONFIG_PATH}" ]]; then
11377
if [[ "${RUNNING_IN_EVG:-"false"}" != "true" ]]; then
11478
echo "Checking if container registry credentials are valid..."
115-
ecr_auth=$(exec_cmd jq -r '.auths."268558157000.dkr.ecr.us-east-1.amazonaws.com".auth // empty' "${CONFIG_PATH}")
79+
ecr_auth=$(jq -r '.auths."268558157000.dkr.ecr.us-east-1.amazonaws.com".auth // empty' "${CONFIG_PATH}")
11680

11781
if [[ -n "${ecr_auth}" ]]; then
11882
http_status=$(curl --head -s -o /dev/null -w "%{http_code}" --max-time 3 "https://268558157000.dkr.ecr.us-east-1.amazonaws.com/v2/dev/mongodb-kubernetes/manifests/latest" \
@@ -132,10 +96,10 @@ if [[ -f "${CONFIG_PATH}" ]]; then
13296

13397
# There could be some leftovers on Evergreen (Docker-specific, skip for Podman)
13498
if [[ "${CONTAINER_RUNTIME}" == "docker" ]]; then
135-
if exec_cmd grep -q "credsStore" "${CONFIG_PATH}"; then
99+
if grep -q "credsStore" "${CONFIG_PATH}"; then
136100
remove_element "credsStore"
137101
fi
138-
if exec_cmd grep -q "credHelpers" "${CONFIG_PATH}"; then
102+
if grep -q "credHelpers" "${CONFIG_PATH}"; then
139103
remove_element "credHelpers"
140104
fi
141105
fi
@@ -149,7 +113,7 @@ aws ecr get-login-password --region "us-east-1" | registry_login "AWS" "26855815
149113
# by default docker tries to store credentials in an external storage (e.g. OS keychain) - not in the config.json
150114
# We need to store it as base64 string in config.json instead so we need to remove the "credsStore" element
151115
# This is Docker-specific behavior, Podman stores credentials directly in auth.json
152-
if [[ "${CONTAINER_RUNTIME}" == "docker" ]] && exec_cmd grep -q "credsStore" "${CONFIG_PATH}"; then
116+
if [[ "${CONTAINER_RUNTIME}" == "docker" ]] && grep -q "credsStore" "${CONFIG_PATH}"; then
153117
remove_element "credsStore"
154118

155119
# login again to store the credentials into the config.json
@@ -164,8 +128,8 @@ if [[ -n "${PRERELEASE_PULLSECRET_DOCKERCONFIGJSON:-}" ]]; then
164128
quay_io_auth_file=$(mktemp)
165129
config_tmp=$(mktemp)
166130
echo "${PRERELEASE_PULLSECRET_DOCKERCONFIGJSON}" | base64 -d > "${quay_io_auth_file}"
167-
exec_cmd jq -s '.[0] * .[1]' "${quay_io_auth_file}" "${CONFIG_PATH}" > "${config_tmp}"
168-
exec_cmd mv "${config_tmp}" "${CONFIG_PATH}"
131+
jq -s '.[0] * .[1]' "${quay_io_auth_file}" "${CONFIG_PATH}" > "${config_tmp}"
132+
mv "${config_tmp}" "${CONFIG_PATH}"
169133
rm "${quay_io_auth_file}"
170134
fi
171135

scripts/dev/setup_ibm_container_runtime.sh

Lines changed: 65 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,93 @@
22

33
set -Eeou pipefail
44

5+
echo "=========================================="
6+
echo "Setting up IBM container runtime (rootless)"
7+
echo "=========================================="
8+
9+
# Setup XDG_RUNTIME_DIR for rootless podman
10+
# This directory must exist and be writable for rootless containers
11+
setup_runtime_dir() {
12+
local uid
13+
uid=$(id -u)
14+
local runtime_dir="/run/user/${uid}"
15+
16+
if [[ ! -d "${runtime_dir}" ]]; then
17+
echo "Creating XDG_RUNTIME_DIR: ${runtime_dir}"
18+
sudo mkdir -p "${runtime_dir}"
19+
sudo chown "$(whoami):$(whoami)" "${runtime_dir}"
20+
sudo chmod 700 "${runtime_dir}"
21+
elif [[ ! -w "${runtime_dir}" ]]; then
22+
echo "Fixing permissions on XDG_RUNTIME_DIR: ${runtime_dir}"
23+
sudo chown "$(whoami):$(whoami)" "${runtime_dir}"
24+
sudo chmod 700 "${runtime_dir}"
25+
fi
26+
27+
export XDG_RUNTIME_DIR="${runtime_dir}"
28+
echo "XDG_RUNTIME_DIR=${XDG_RUNTIME_DIR}"
29+
30+
# Create containers subdirectory
31+
mkdir -p "${runtime_dir}/containers" 2>/dev/null || true
32+
}
33+
34+
setup_runtime_dir
35+
536
echo "Cleaning DNF cache..."
6-
sudo dnf clean all && sudo rm -r /var/cache/dnf
37+
sudo dnf clean all && sudo rm -rf /var/cache/dnf || true
738

839
echo "Installing/upgrading crun..."
940
sudo dnf upgrade -y crun --disableplugin=subscription-manager || \
1041
sudo dnf install -y crun --disableplugin=subscription-manager || \
1142
sudo yum upgrade -y crun --disableplugin=subscription-manager || \
1243
sudo yum install -y crun --disableplugin=subscription-manager
1344

14-
if ! crun --version &>/dev/null; then
15-
echo "❌ crun installation failed"
45+
# Find crun path - it might be in different locations
46+
crun_path=""
47+
for path in /usr/bin/crun /usr/local/bin/crun /bin/crun; do
48+
if [[ -x "${path}" ]]; then
49+
crun_path="${path}"
50+
break
51+
fi
52+
done
53+
54+
if [[ -z "${crun_path}" ]]; then
55+
# Try to find it
56+
crun_path=$(command -v crun 2>/dev/null || true)
57+
fi
58+
59+
if [[ -z "${crun_path}" || ! -x "${crun_path}" ]]; then
60+
echo "❌ crun not found after installation"
61+
echo "Searching for crun..."
62+
find /usr -name "crun" -type f 2>/dev/null || true
1663
exit 1
1764
fi
1865

19-
current_version=$(crun --version | head -n1)
66+
echo "Found crun at: ${crun_path}"
67+
current_version=$("${crun_path}" --version | head -n1)
2068
echo "✅ Using crun: ${current_version}"
2169

22-
# Clean up any existing conflicting configurations
70+
# Clean up any existing conflicting configurations (user-level only for rootless)
2371
echo "Cleaning up existing container configurations..."
2472
rm -f ~/.config/containers/containers.conf 2>/dev/null || true
25-
sudo rm -f /root/.config/containers/containers.conf 2>/dev/null || true
26-
sudo rm -f /etc/containers/containers.conf 2>/dev/null || true
27-
28-
crun_path=$(which crun)
29-
echo "Using crun path: ${crun_path}"
3073

74+
# Configure for rootless podman with explicit crun path
3175
config="[containers]
3276
cgroup_manager = \"cgroupfs\"
3377
3478
[engine]
35-
runtime = \"crun\""
79+
runtime = \"${crun_path}\""
3680

3781
mkdir -p ~/.config/containers
3882
echo "${config}" > ~/.config/containers/containers.conf
3983

40-
sudo mkdir -p /root/.config/containers
41-
echo "${config}" | sudo tee /root/.config/containers/containers.conf >/dev/null
84+
# Also set storage driver explicitly for rootless
85+
storage_config="[storage]
86+
driver = \"overlay\"
87+
runroot = \"${XDG_RUNTIME_DIR}/containers\"
88+
graphroot = \"${HOME}/.local/share/containers/storage\""
89+
90+
echo "${storage_config}" > ~/.config/containers/storage.conf
4291

43-
echo "✅ Configured crun"
92+
echo "✅ Configured crun for rootless podman"
93+
echo "Config written to ~/.config/containers/containers.conf"
94+
echo "Storage config written to ~/.config/containers/storage.conf"

0 commit comments

Comments
 (0)