1515
1616if [ " $IS_MACOS " = true ]; then
1717 PID_CMD=" pgrep"
18- SED=gsed
1918else
2019 PID_CMD=" pidof"
21- SED=sed
20+ fi
21+
22+ # Detect the available `sed` tool
23+ if command -v gsed & > /dev/null; then
24+ USE_GSED=true
25+ SED=gsed # Use `gsed` if available
26+ else
27+ USE_GSED=false
28+ SED=sed # Fallback to default `sed`
2229fi
2330
2431for arg in " $@ " ; do
@@ -134,6 +141,42 @@ data:
134141EOF
135142}
136143
144+ # Patching Dockerfile based on the GPU type (rocm or nvidia)
145+ patch_dockerfile () {
146+ gpu_type=" $1 "
147+ echo " Patching Dockerfile for $gpu_type compatibility..."
148+ # Additional GPU-specific changes
149+ if [ " $gpu_type " = " nvidia" ]; then
150+ # Apply NVIDIA-specific patching if needed
151+ echo " Applying NVIDIA-specific patches to the Dockerfile..."
152+ if [ " $IS_MACOS " = true ] && [ " $USE_GSED " = false ]; then
153+ # macOS-specific patching with sed
154+ ${SED} -i ' ' ' s|^FROM redhat/ubi9-minimal|FROM registry.access.redhat.com/ubi9/ubi-minimal|' deployments/container/Dockerfile
155+ ${SED} -i ' ' ' s|^FROM public.ecr.aws/ubi9/ubi-minimal|FROM registry.access.redhat.com/ubi9/ubi-minimal|' deployments/container/Dockerfile
156+ ${SED} -i ' ' ' s|^FROM registry.access.redhat.com/ubi9/ubi9-minimal|FROM registry.access.redhat.com/ubi9/ubi-minimal|' deployments/container/Dockerfile
157+ else
158+ # Linux-specific patching with default sed
159+ ${SED} -i ' s|^FROM redhat/ubi9-minimal|FROM registry.access.redhat.com/ubi9/ubi-minimal|' deployments/container/Dockerfile
160+ ${SED} -i ' s|^FROM public.ecr.aws/ubi9/ubi-minimal|FROM registry.access.redhat.com/ubi9/ubi-minimal|' deployments/container/Dockerfile
161+ ${SED} -i ' s|^FROM registry.access.redhat.com/ubi9/ubi9-minimal|FROM registry.access.redhat.com/ubi9/ubi-minimal|' deployments/container/Dockerfile
162+ fi
163+ elif [ " $gpu_type " = " rocm" ]; then
164+ # Apply ROCm-specific patching if needed
165+ echo " Applying ROCm-specific patches to the Dockerfile..."
166+ if [ " $IS_MACOS " = true ] && [ " $USE_GSED " = false ]; then
167+ # macOS-specific patching with sed
168+ ${SED} -i ' ' " s|^FROM alpine:3.21.3|FROM public.ecr.aws/docker/library/alpine:3.21.3|" Dockerfile
169+ ${SED} -i ' ' " s|^FROM docker.io/golang:1.23.6-alpine3.21|FROM public.ecr.aws/docker/library/golang:1.23.6-alpine3.21|" Dockerfile
170+ ${SED} -i ' ' " s|^FROM golang:1.23.6-alpine3.21|FROM public.ecr.aws/docker/library/golang:1.23.6-alpine3.21|" Dockerfile
171+ else
172+ # Linux-specific patching with default sed
173+ ${SED} -i " s|^FROM alpine:3.21.3|FROM public.ecr.aws/docker/library/alpine:3.21.3|" Dockerfile
174+ ${SED} -i " s|^FROM docker.io/golang:1.23.6-alpine3.21|FROM public.ecr.aws/docker/library/golang:1.23.6-alpine3.21|" Dockerfile
175+ ${SED} -i " s|^FROM golang:1.23.6-alpine3.21|FROM public.ecr.aws/docker/library/golang:1.23.6-alpine3.21|" Dockerfile
176+ fi
177+ fi
178+ }
179+
137180function build_and_push_images() {
138181 gpu_type=" $1 "
139182
@@ -143,11 +186,7 @@ function build_and_push_images() {
143186 cd k8s-device-plugin-nvidia
144187
145188 if [ " $CONTAINER_RUNTIME " = " podman" ]; then
146- echo " Patching NVIDIA Dockerfile for Podman compatibility..."
147- ${SED} -i ' s|^FROM redhat/ubi9-minimal|FROM registry.access.redhat.com/ubi9/ubi-minimal|' deployments/container/Dockerfile
148- ${SED} -i ' s|^FROM public.ecr.aws/ubi9/ubi-minimal|FROM registry.access.redhat.com/ubi9/ubi-minimal|' deployments/container/Dockerfile
149- ${SED} -i ' s|^FROM registry.access.redhat.com/ubi9/ubi9-minimal|FROM registry.access.redhat.com/ubi9/ubi-minimal|' deployments/container/Dockerfile
150-
189+ patch_dockerfile " $gpu_type "
151190 grep FROM deployments/container/Dockerfile
152191 fi
153192
@@ -171,10 +210,7 @@ function build_and_push_images() {
171210 [ ! -d k8s-device-plugin-rocm ] && git clone https://github.com/RadeonOpenCompute/k8s-device-plugin.git k8s-device-plugin-rocm
172211 cd k8s-device-plugin-rocm
173212
174- echo " Patching ROCm Dockerfile for public registry compatibility..."
175- ${SED} -i ' s|FROM alpine:3.21.3|FROM public.ecr.aws/docker/library/alpine:3.21.3|' Dockerfile
176- ${SED} -i ' s|FROM docker.io/golang:1.23.6-alpine3.21|FROM public.ecr.aws/docker/library/golang:1.23.6-alpine3.21|' Dockerfile
177- ${SED} -i ' s|FROM golang:1.23.6-alpine3.21|FROM public.ecr.aws/docker/library/golang:1.23.6-alpine3.21|' Dockerfile
213+ patch_dockerfile " $gpu_type "
178214
179215 cr build -t localhost:${REGISTRY_PORT} /amdgpu-dp:dev -f Dockerfile .
180216
0 commit comments