Skip to content

Commit 0974c74

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

File tree

1 file changed

+40
-6
lines changed

1 file changed

+40
-6
lines changed

Makefile

+40-6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ CAT_CMD=$(if $(filter $(OS),Windows_NT),type,cat)
33
RELEASE_VER:=
44
CURRENT_DIR=$(shell pwd)
55
GIT_BRANCH:=$(shell git symbolic-ref --short HEAD 2>&1 | grep -v fatal)
6+
ARCH := $(shell uname -m)
67
#define the GO_BUILD_ARGS if you need to pass additional arguments to the go build
78
GO_BUILD_ARGS?=
89

@@ -76,16 +77,49 @@ ${BIN_DIR}/deepcopy-gen:
7677
$(info Compiling deepcopy-gen...)
7778
go build -o ${BIN_DIR}/deepcopy-gen ./cmd/deepcopy-gen/
7879

80+
# Build the docker image and tag it.
81+
# images: verify-tag-name generate-code update-deployment-crds
82+
# $(info List executable directory)
83+
# $(info repo id: ${git_repository_id})
84+
# $(info branch: ${GIT_BRANCH})
85+
# $(info Build the docker image)
86+
# ARCH := $(shell uname -m)
87+
# ifeq ($(ARCH),aarch64)
88+
# ifeq ($(strip $(GO_BUILD_ARGS)),)
89+
# docker buildx build --quiet --no-cache --platform=linux/amd64 --tag mcad-controller:${TAG} -f ${CURRENT_DIR}/Dockerfile ${CURRENT_DIR}
90+
# else
91+
# docker buildx build --no-cache --platform=linux/amd64 --tag mcad-controller:${TAG} --build-arg GO_BUILD_ARGS=$(GO_BUILD_ARGS) -f ${CURRENT_DIR}/Dockerfile ${CURRENT_DIR}
92+
# endif
93+
# else
94+
# ifeq ($(strip $(GO_BUILD_ARGS)),)
95+
# docker build --quiet --no-cache --tag mcad-controller:${TAG} -f ${CURRENT_DIR}/Dockerfile ${CURRENT_DIR}
96+
# else
97+
# docker build --no-cache --tag mcad-controller:${TAG} --build-arg GO_BUILD_ARGS=$(GO_BUILD_ARGS) -f ${CURRENT_DIR}/Dockerfile ${CURRENT_DIR}
98+
# endif
99+
# endif
100+
101+
102+
# Build the docker image and tag it.
79103
images: verify-tag-name generate-code update-deployment-crds
80104
$(info List executable directory)
81105
$(info repo id: ${git_repository_id})
82106
$(info branch: ${GIT_BRANCH})
83107
$(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
108+
@HOST_ARCH=$$(uname -m); \
109+
if [ "$$HOST_ARCH" = "aarch64" ]; then \
110+
if [ "$(strip $(GO_BUILD_ARGS))" = "" ]; then \
111+
docker buildx build --quiet --no-cache --platform=linux/amd64 --tag mcad-controller:${TAG} -f ${CURRENT_DIR}/Dockerfile ${CURRENT_DIR}; \
112+
else \
113+
docker buildx build --no-cache --platform=linux/amd64 --tag mcad-controller:${TAG} --build-arg GO_BUILD_ARGS=$(GO_BUILD_ARGS) -f ${CURRENT_DIR}/Dockerfile ${CURRENT_DIR}; \
114+
fi \
115+
else \
116+
if [ "$(strip $(GO_BUILD_ARGS))" = "" ]; then \
117+
docker build --quiet --no-cache --tag mcad-controller:${TAG} -f ${CURRENT_DIR}/Dockerfile ${CURRENT_DIR}; \
118+
else \
119+
docker build --no-cache --tag mcad-controller:${TAG} --build-arg GO_BUILD_ARGS=$(GO_BUILD_ARGS) -f ${CURRENT_DIR}/Dockerfile ${CURRENT_DIR}; \
120+
fi \
121+
fi
122+
89123

90124
images-podman: verify-tag-name generate-code update-deployment-crds
91125
$(info List executable directory)
@@ -158,4 +192,4 @@ ${DEPLOYMENT_CRD_DIR}/mcad.ibm.com_schedulingspecs.yaml : ${CRD_BASE_DIR}/mcad.i
158192

159193

160194
$(DEPLOYMENT_CRD_DIR)/%: ${CRD_BASE_DIR}/%
161-
cp $< $@
195+
cp $< $@

0 commit comments

Comments
 (0)