I have a simple if condition in my Makefile that I use for building a Docker image based on the platform (if on arm64 use docker buildx), however it is not evaluating and I am confused why it is not. Any suggestions? Thanks!
...
OS_ARCH := $(shell /usr/bin/arch)
build:
@echo "Building for ${OS_ARCH}"
ifeq ($(OS_ARCH),"arm64")
@echo "Building for ARM64"
@docker buildx build -t $(NAMESPACE)/$(IMAGE_NAME):$(VERSION) --platform $(PLATFORM) -f ./$(DOCKERFILE) --no-cache=$(NO_CACHE) --label "git-revison=$(git rev-parse HEAD)" --label "version=$(VERSION)" .
else
@echo "Building for x86_64"
@docker build -t $(NAMESPACE)/$(IMAGE_NAME):$(VERSION) -f ./$(DOCKERFILE) --no-cache=$(NO_CACHE) --label "git-revison=$(git rev-parse HEAD)" --label "version=$(VERSION)" .
endif
@echo 'Done building.'
@docker images --format '{{.Repository}}:{{.Tag}}\t\t Built: {{.CreatedSince}}\t\tSize: {{.Size}}' | grep $(IMAGE_NAME):$(VERSION)
@echo "Finished building $(IMAGE_NAME):$(VERSION)"
CodePudding user response:
You have:
ifeq ($(OS_ARCH),"arm64")
If OS_ARCH is set to arm64 this evaluates to:
ifeq (arm64,"arm64")
and the string arm64 is not the same as the string "arm64" because the latter has quotes and the former doesn't.
Use:
ifeq ($(OS_ARCH),arm64)
