Skip to content

Commit fc640db

Browse files
committed
use rootless podman
1 parent 0d4a065 commit fc640db

File tree

2 files changed

+23
-93
lines changed

2 files changed

+23
-93
lines changed

scripts/dev/setup_ibm_container_runtime.sh

Lines changed: 21 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -2,93 +2,37 @@
22

33
set -Eeou pipefail
44

5-
echo "=========================================="
65
echo "Setting up IBM container runtime (rootless)"
7-
echo "=========================================="
86

97
# 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}"
8+
uid=$(id -u)
9+
runtime_dir="/run/user/${uid}"
10+
if [[ ! -d "${runtime_dir}" ]]; then
1811
sudo mkdir -p "${runtime_dir}"
1912
sudo chown "$(whoami):$(whoami)" "${runtime_dir}"
2013
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-
36-
echo "Cleaning DNF cache..."
37-
sudo dnf clean all && sudo rm -rf /var/cache/dnf || true
38-
39-
echo "Installing/upgrading crun..."
40-
sudo dnf upgrade -y crun --disableplugin=subscription-manager || \
41-
sudo dnf install -y crun --disableplugin=subscription-manager || \
42-
sudo yum upgrade -y crun --disableplugin=subscription-manager || \
43-
sudo yum install -y crun --disableplugin=subscription-manager
44-
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
63-
exit 1
6414
fi
15+
export XDG_RUNTIME_DIR="${runtime_dir}"
6516

66-
echo "Found crun at: ${crun_path}"
67-
current_version=$("${crun_path}" --version | head -n1)
68-
echo "✅ Using crun: ${current_version}"
69-
70-
# Clean up any existing conflicting configurations (user-level only for rootless)
71-
echo "Cleaning up existing container configurations..."
72-
rm -f ~/.config/containers/containers.conf 2>/dev/null || true
73-
74-
# Configure for rootless podman with explicit crun path
75-
config="[containers]
76-
cgroup_manager = \"cgroupfs\"
77-
78-
[engine]
79-
runtime = \"${crun_path}\""
17+
# Install crun
18+
echo "Installing crun..."
19+
sudo dnf clean all || true
20+
sudo dnf install -y crun --disableplugin=subscription-manager || \
21+
sudo yum install -y crun --disableplugin=subscription-manager || true
8022

23+
# Configure rootless podman
8124
mkdir -p ~/.config/containers
82-
echo "${config}" > ~/.config/containers/containers.conf
8325

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\""
26+
cat > ~/.config/containers/containers.conf << 'EOF'
27+
[containers]
28+
cgroup_manager = "cgroupfs"
29+
EOF
8930

90-
echo "${storage_config}" > ~/.config/containers/storage.conf
31+
cat > ~/.config/containers/storage.conf << EOF
32+
[storage]
33+
driver = "overlay"
34+
runroot = "${XDG_RUNTIME_DIR}/containers"
35+
graphroot = "${HOME}/.local/share/containers/storage"
36+
EOF
9137

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"
38+
echo "Done"

scripts/funcs/kubernetes

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -101,19 +101,10 @@ create_image_registries_secret() {
101101

102102
# Detect the correct config file path based on container runtime
103103
local config_file
104-
local temp_config_file=""
105-
if command -v podman &> /dev/null && (podman info &> /dev/null || sudo podman info &> /dev/null); then
106-
# For Podman, use root's auth.json since minikube uses sudo podman
107-
config_file="/root/.config/containers/auth.json"
104+
if command -v podman &> /dev/null && podman info &> /dev/null; then
105+
config_file="${HOME}/.config/containers/auth.json"
108106
echo "Using Podman config: ${config_file}"
109-
110-
# Create a temporary copy that the current user can read
111-
temp_config_file=$(mktemp)
112-
sudo cp "${config_file}" "${temp_config_file}"
113-
sudo chown "$(whoami):$(whoami)" "${temp_config_file}"
114-
config_file="${temp_config_file}"
115107
else
116-
# For Docker, use standard docker config
117108
config_file="${HOME}/.docker/config.json"
118109
echo "Using Docker config: ${config_file}"
119110
fi
@@ -127,11 +118,6 @@ create_image_registries_secret() {
127118
else
128119
echo "Skipping creating pull secret in ${context}/${namespace}. The namespace doesn't exist yet."
129120
fi
130-
131-
# Clean up temporary file
132-
if [[ -n "${temp_config_file}" ]] && [[ -f "${temp_config_file}" ]]; then
133-
rm -f "${temp_config_file}"
134-
fi
135121
}
136122

137123
echo "Creating/updating pull secret from docker configured file"

0 commit comments

Comments
 (0)