Skip to content

Commit 10f12f2

Browse files
committed
refactor: allows for a docker build if the building machine is arm (apple silicon)
1 parent f158e0d commit 10f12f2

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

Makefile

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,28 @@ ${BIN_DIR}/deepcopy-gen:
7676
$(info Compiling deepcopy-gen...)
7777
go build -o ${BIN_DIR}/deepcopy-gen ./cmd/deepcopy-gen/
7878

79+
80+
# Build the docker image and tag it.
7981
images: verify-tag-name generate-code update-deployment-crds
8082
$(info List executable directory)
8183
$(info repo id: ${git_repository_id})
8284
$(info branch: ${GIT_BRANCH})
8385
$(info Build the docker image)
84-
ifeq ($(strip $(GO_BUILD_ARGS)),)
85-
docker build --quiet --no-cache --tag mcad-controller:${TAG} -f ${CURRENT_DIR}/Dockerfile ${CURRENT_DIR}
86-
else
87-
docker build --no-cache --tag mcad-controller:${TAG} --build-arg GO_BUILD_ARGS=$(GO_BUILD_ARGS) -f ${CURRENT_DIR}/Dockerfile ${CURRENT_DIR}
88-
endif
86+
echo "Host architecture: $(shell uname -m)"
87+
@HOST_ARCH=$(shell uname -m); \
88+
if [ "$$HOST_ARCH" = "arm64" ]; then \
89+
if [ "$(strip $(GO_BUILD_ARGS))" = "" ]; then \
90+
docker buildx build --platform linux/amd64 --no-cache --tag mcad-controller:${TAG} -f ${CURRENT_DIR}/Dockerfile ${CURRENT_DIR}; \
91+
else \
92+
docker buildx build --platform linux/amd64 --no-cache --tag mcad-controller:${TAG} --build-arg GO_BUILD_ARGS=$(GO_BUILD_ARGS) -f ${CURRENT_DIR}/Dockerfile ${CURRENT_DIR}; \
93+
fi \
94+
else \
95+
if [ "$(strip $(GO_BUILD_ARGS))" = "" ]; then \
96+
docker build --no-cache --tag mcad-controller:${TAG} -f ${CURRENT_DIR}/Dockerfile ${CURRENT_DIR}; \
97+
else \
98+
docker build --no-cache --tag mcad-controller:${TAG} --build-arg GO_BUILD_ARGS=$(GO_BUILD_ARGS) -f ${CURRENT_DIR}/Dockerfile ${CURRENT_DIR}; \
99+
fi \
100+
fi
89101

90102
images-podman: verify-tag-name generate-code update-deployment-crds
91103
$(info List executable directory)

0 commit comments

Comments
 (0)