Skip to content

Commit 25cdf2a

Browse files
committed
refactor: allows for a docker build if the building machine is arm (apple silicon)
1 parent ed9bc20 commit 25cdf2a

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

Makefile

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ 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-
76
#define the GO_BUILD_ARGS if you need to pass additional arguments to the go build
87
GO_BUILD_ARGS?=
98

@@ -150,16 +149,26 @@ manifests: controller-gen ## Generate CustomResourceDefinition objects.
150149
generate-code: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
151150
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate/boilerplate.go.txt" paths="./pkg/apis/..."
152151

152+
# Build the docker image and tag it.
153153
images: verify-tag-name generate-code update-deployment-crds
154154
$(info List executable directory)
155155
$(info repo id: ${git_repository_id})
156156
$(info branch: ${GIT_BRANCH})
157157
$(info Build the docker image)
158-
ifeq ($(strip $(GO_BUILD_ARGS)),)
159-
docker build --quiet --no-cache --tag mcad-controller:${TAG} -f ${CURRENT_DIR}/Dockerfile ${CURRENT_DIR}
160-
else
161-
docker build --no-cache --tag mcad-controller:${TAG} --build-arg GO_BUILD_ARGS=$(GO_BUILD_ARGS) -f ${CURRENT_DIR}/Dockerfile ${CURRENT_DIR}
162-
endif
158+
@HOST_ARCH=$$(uname -m); \
159+
if [ "$$HOST_ARCH" = "aarch64" ]; then \
160+
if [ "$(strip $(GO_BUILD_ARGS))" = "" ]; then \
161+
docker buildx build --quiet --no-cache --platform=linux/amd64 --tag mcad-controller:${TAG} -f ${CURRENT_DIR}/Dockerfile ${CURRENT_DIR}; \
162+
else \
163+
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}; \
164+
fi \
165+
else \
166+
if [ "$(strip $(GO_BUILD_ARGS))" = "" ]; then \
167+
docker build --quiet --no-cache --tag mcad-controller:${TAG} -f ${CURRENT_DIR}/Dockerfile ${CURRENT_DIR}; \
168+
else \
169+
docker build --no-cache --tag mcad-controller:${TAG} --build-arg GO_BUILD_ARGS=$(GO_BUILD_ARGS) -f ${CURRENT_DIR}/Dockerfile ${CURRENT_DIR}; \
170+
fi \
171+
fi
163172

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

0 commit comments

Comments
 (0)