Skip to content

Commit 280e750

Browse files
dimakisopenshift-ci[bot]
authored andcommitted
refactor: allows for a docker build if the building machine is arm (apple silicon)
1 parent f60a1f8 commit 280e750

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

Diff for: Makefile

+15-6
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

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

139+
# Build the docker image and tag it.
140140
images: verify-tag-name generate-code update-deployment-crds
141141
$(info List executable directory)
142142
$(info repo id: ${git_repository_id})
143143
$(info branch: ${GIT_BRANCH})
144144
$(info Build the docker image)
145-
ifeq ($(strip $(GO_BUILD_ARGS)),)
146-
docker build --quiet --no-cache --tag mcad-controller:${TAG} -f ${CURRENT_DIR}/Dockerfile ${CURRENT_DIR}
147-
else
148-
docker build --no-cache --tag mcad-controller:${TAG} --build-arg GO_BUILD_ARGS=$(GO_BUILD_ARGS) -f ${CURRENT_DIR}/Dockerfile ${CURRENT_DIR}
149-
endif
145+
@HOST_ARCH=$$(uname -m); \
146+
if [ "$$HOST_ARCH" = "aarch64" ]; then \
147+
if [ "$(strip $(GO_BUILD_ARGS))" = "" ]; then \
148+
docker buildx build --quiet --no-cache --platform=linux/amd64 --tag mcad-controller:${TAG} -f ${CURRENT_DIR}/Dockerfile ${CURRENT_DIR}; \
149+
else \
150+
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}; \
151+
fi \
152+
else \
153+
if [ "$(strip $(GO_BUILD_ARGS))" = "" ]; then \
154+
docker build --quiet --no-cache --tag mcad-controller:${TAG} -f ${CURRENT_DIR}/Dockerfile ${CURRENT_DIR}; \
155+
else \
156+
docker build --no-cache --tag mcad-controller:${TAG} --build-arg GO_BUILD_ARGS=$(GO_BUILD_ARGS) -f ${CURRENT_DIR}/Dockerfile ${CURRENT_DIR}; \
157+
fi \
158+
fi
150159

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

0 commit comments

Comments
 (0)