consul-k8s icon indicating copy to clipboard operation
consul-k8s copied to clipboard

`make control-plane-dev-docker GOARCH=amd64` on M1 laptop does not work as expected

Open komapa opened this issue 1 year ago • 2 comments

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request. Searching for pre-existing feature requests helps us consolidate datapoints for identical requirements into a single place, thank you!
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request.
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment.

Overview of the Issue

The Makefile logic for building for different architectures is not correct because it sets TARGETARCH as build-arg instead of using the --platform parameter.

  • https://github.com/hashicorp/consul-k8s/blob/main/Makefile#L47
  • https://github.com/hashicorp/consul-k8s/blob/main/Makefile#L84

Reproduction Steps

When you run an amd64 build on an arm64 machine (M1/2/3), you end up with the container layers being arm64 while the golang executable is amd64, which then does not work and you get a runtime error.

make control-plane-dev-docker GOARCH=amd64

Expected behavior

Index: Makefile
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/Makefile b/Makefile
--- a/Makefile	(revision d3a596ea121396f8296019107494222e0bfbadb5)
+++ b/Makefile	(date 1703004820940)
@@ -44,7 +44,7 @@
 	@$(SHELL) $(CURDIR)/control-plane/build-support/scripts/build-local.sh -o linux -a $(GOARCH)
 	@docker build -t '$(DEV_IMAGE)' \
        --target=dev \
-       --build-arg 'TARGETARCH=$(GOARCH)' \
+       --platform "linux/$(GOARCH)" \
        --build-arg 'GIT_COMMIT=$(GIT_COMMIT)' \
        --build-arg 'GIT_DIRTY=$(GIT_DIRTY)' \
        --build-arg 'GIT_DESCRIBE=$(GIT_DESCRIBE)' \
@@ -55,7 +55,7 @@
 control-plane-dev-skaffold: ## Build consul-k8s-control-plane dev Docker image for use with skaffold or local development.
 	@$(SHELL) $(CURDIR)/control-plane/build-support/scripts/build-local.sh -o linux -a $(GOARCH)
 	@docker build -t '$(DEV_IMAGE)' \
-       --build-arg 'TARGETARCH=$(GOARCH)' \
+       --platform "linux/$(GOARCH)" \
        -f $(CURDIR)/control-plane/Dockerfile.dev $(CURDIR)/control-plane
 
 .PHONY: check-remote-dev-image-env
@@ -247,7 +247,7 @@
 	@echo "Installing copywrite"
 	@go install github.com/hashicorp/copywrite@latest
 endif
-	@copywrite headers --spdx "MPL-2.0" 
+	@copywrite headers --spdx "MPL-2.0"
 
 ##@ CI Targets
 

Environment details

M1 laptop

komapa avatar Dec 19 '23 16:12 komapa

Hi @komapa

This is probably an artifact of our old build/release system that used to use the make targets for building multiple architectures.

These days, I use control-plane-dev-docker-multi-arch on my M1. I am often running a local Kind and it seems to need both linux/amd64 and linux/arm64 images. Unfortunately this requires pushing to a docker registry to get both architectures uploaded.

curtbushko avatar Dec 19 '23 17:12 curtbushko

Thank you, I did end up using control-plane-dev-docker-multi-arch but thought it will be good to report the initial problem I had with make control-plane-dev-docker GOARCH=amd64. Thank you for confirming that control-plane-dev-docker-multi-arch is what you use primarily.

komapa avatar Dec 19 '23 19:12 komapa