Skip to content

Commit aee1baf

Browse files
Support building image with dedicated platform by specifying compatible docker flags (#1227)
* support building image with dedicated platform * fix build error by specifying undefined target arch * refactor code to include supported arch and guiding messages Signed-off-by: Luong Vo <[email protected]>
1 parent 3c74a19 commit aee1baf

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ SA?=source activate
1212
ENV:=enterprise-gateway-dev
1313
SHELL:=/bin/bash
1414
MULTIARCH_BUILD?=
15+
TARGET_ARCH?=undefined
1516

1617
VERSION?=3.2.0.dev0
1718
SPARK_VERSION?=3.2.1
@@ -156,10 +157,10 @@ kernel-images: ## Build kernel-based docker images
156157
docker-images: demo-base enterprise-gateway-demo kernel-images enterprise-gateway kernel-py kernel-spark-py kernel-r kernel-spark-r kernel-scala kernel-tf-py kernel-tf-gpu-py kernel-image-puller
157158

158159
enterprise-gateway-demo kernel-images enterprise-gateway kernel-py kernel-spark-py kernel-r kernel-spark-r kernel-scala kernel-tf-py kernel-tf-gpu-py kernel-image-puller:
159-
make WHEEL_FILE=$(WHEEL_FILE) VERSION=$(VERSION) NO_CACHE=$(NO_CACHE) TAG=$(TAG) SPARK_VERSION=$(SPARK_VERSION) MULTIARCH_BUILD=$(MULTIARCH_BUILD) -C etc $@
160+
make WHEEL_FILE=$(WHEEL_FILE) VERSION=$(VERSION) NO_CACHE=$(NO_CACHE) TAG=$(TAG) SPARK_VERSION=$(SPARK_VERSION) MULTIARCH_BUILD=$(MULTIARCH_BUILD) TARGET_ARCH=$(TARGET_ARCH) -C etc $@
160161

161162
demo-base:
162-
make WHEEL_FILE=$(WHEEL_FILE) VERSION=$(VERSION) NO_CACHE=$(NO_CACHE) TAG=$(SPARK_VERSION) SPARK_VERSION=$(SPARK_VERSION) MULTIARCH_BUILD=$(MULTIARCH_BUILD) -C etc $@
163+
make WHEEL_FILE=$(WHEEL_FILE) VERSION=$(VERSION) NO_CACHE=$(NO_CACHE) TAG=$(SPARK_VERSION) SPARK_VERSION=$(SPARK_VERSION) MULTIARCH_BUILD=$(MULTIARCH_BUILD) TARGET_ARCH=$(TARGET_ARCH) -C etc $@
163164

164165
# Here for doc purposes
165166
clean-images: clean-demo-base ## Remove docker images (includes kernel-based images)

etc/Makefile

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
SA?=source activate
99
ENV:=enterprise-gateway-dev
1010
SHELL:=/bin/bash
11+
SUPPORTED_ARCHS=linux/arm64 linux/amd64
12+
PLATFORM_ARCHS=`echo ${SUPPORTED_ARCHS} | sed "s/ /,/g"`
1113

1214
# Docker attributes - hub organization and tag. Modify accordingly
1315
HUB_ORG:=elyra
@@ -43,7 +45,7 @@ TOREE_LAUNCHER_FILES:=$(shell find kernel-launchers/scala/toree-launcher/src -ty
4345
../build/kernelspecs: kernel-launchers/scala/lib $(FILES_kernelspecs_all)
4446
@rm -rf ../build/kernelspecs
4547
@mkdir -p ../build/kernelspecs
46-
# Seed the build tree with initial files
48+
# Seed the build tree with initial files
4749
cp -r kernelspecs ../build
4850
# Distribute language and config-sensitive files.
4951
# On-prem kernelspecs get launcher files in the kernelspec hierarchy
@@ -153,10 +155,15 @@ ifdef MULTIARCH_BUILD
153155
@echo "starting buildx builder for $1"
154156
-@(docker buildx rm $1)
155157
(docker buildx create --use --name $1)
156-
(cd ../build/docker/$1; docker buildx build ${NO_CACHE} --platform linux/arm64,linux/amd64 --build-arg HUB_ORG=${HUB_ORG} --build-arg TAG=${TAG} --build-arg SPARK_VERSION=${SPARK_VERSION} -t $(HUB_ORG)/$1:$(TAG) . --push)
158+
(cd ../build/docker/$1; docker buildx build ${NO_CACHE} --platform $(PLATFORM_ARCHS) --build-arg HUB_ORG=${HUB_ORG} --build-arg TAG=${TAG} --build-arg SPARK_VERSION=${SPARK_VERSION} -t $(HUB_ORG)/$1:$(TAG) . --push)
157159
@echo "remove builder instance $1"
158160
-(docker buildx rm $1)
161+
else ifeq ($(TARGET_ARCH), $(filter $(TARGET_ARCH), $(SUPPORTED_ARCHS)))
162+
@echo "Building docker image for $(TARGET_ARCH)"
163+
(cd ../build/docker/$1; docker build ${NO_CACHE} --platform ${TARGET_ARCH} --build-arg HUB_ORG=${HUB_ORG} --build-arg TAG=${TAG} --build-arg SPARK_VERSION=${SPARK_VERSION} -t $(HUB_ORG)/$1:$(TAG) .)
164+
@-docker images $(HUB_ORG)/$1:$(TAG)
159165
else
166+
@echo "TARGET_ARCH not defined or not in supported platforms: $(PLATFORM_ARCHS). Building docker image for default platform"
160167
(cd ../build/docker/$1; docker build ${NO_CACHE} --build-arg HUB_ORG=${HUB_ORG} --build-arg TAG=${TAG} --build-arg SPARK_VERSION=${SPARK_VERSION} -t $(HUB_ORG)/$1:$(TAG) .)
161168
@-docker images $(HUB_ORG)/$1:$(TAG)
162169
endif

0 commit comments

Comments
 (0)