-
Notifications
You must be signed in to change notification settings - Fork 272
chore: parameterize BUILD_ARCH/BUILD_PLATFORM in Makefiles #2257
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,13 @@ LDFLAGS=-ldflags "-X=main.commitSHA=$(BUILD)" | |
| AWS_BUCKET_PREFIX ?= $(PREFIX)$(AWS_ACCOUNT_ID)- | ||
| GCP_BUCKET_PREFIX ?= $(GCP_PROJECT_ID)- | ||
|
|
||
| # Architecture for builds. Defaults to local arch; override for cross-compilation | ||
| # (e.g., BUILD_ARCH=amd64 make build from an ARM64 host). | ||
| BUILD_ARCH ?= $(shell go env GOARCH) | ||
| # Docker platform string. Override for cross-platform builds: | ||
| # BUILD_PLATFORM=linux/arm64 make start-docker | ||
| BUILD_PLATFORM ?= linux/$(BUILD_ARCH) | ||
|
|
||
| .PHONY: init | ||
| init: | ||
| brew install protobuf | ||
|
|
@@ -20,17 +27,17 @@ else | |
| endif | ||
|
|
||
| build: | ||
| CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o bin/envd ${LDFLAGS} | ||
| CGO_ENABLED=0 GOOS=linux GOARCH=$(BUILD_ARCH) go build -a -o bin/envd ${LDFLAGS} | ||
|
|
||
| build-debug: | ||
| CGO_ENABLED=1 go build -race -gcflags=all="-N -l" -o bin/debug/envd ${LDFLAGS} | ||
|
|
||
| start-docker: | ||
| make build | ||
| DOCKER_BUILDKIT=1 docker build --platform linux/amd64 -t envd-debug . -f debug.Dockerfile | ||
| DOCKER_BUILDKIT=1 docker build --platform $(BUILD_PLATFORM) -t envd-debug . -f debug.Dockerfile | ||
| docker run \ | ||
| --name envd \ | ||
| --platform linux/amd64 \ | ||
| --platform $(BUILD_PLATFORM) \ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Envd start-docker mixes local binary arch with Docker platformMedium Severity The Additional Locations (1)
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Won't fix — BUILD_ARCH and BUILD_PLATFORM both default to host arch via |
||
| -p 49983:49983 \ | ||
| -p 2345:2345 \ | ||
| -p 9999:9999 \ | ||
|
Comment on lines
35
to
43
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔴 The comment for Extended reasoning...What the bug is and how it manifests The The specific code path that triggers it When a user runs
Why existing code doesn't prevent it Make has no mechanism to validate that a variable is appropriate for a specific Docker subcommand. The same What the impact would be Any developer following the documented example for How to fix it Two options:
Step-by-step proof
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed — comment now shows single-arch example only. |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,13 @@ GCP_BUCKET_PREFIX ?= $(GCP_PROJECT_ID)- | |
| HOSTNAME := $(shell hostname 2> /dev/null || hostnamectl hostname 2> /dev/null) | ||
| $(if $(HOSTNAME),,$(error Failed to determine hostname: both 'hostname' and 'hostnamectl' failed)) | ||
|
|
||
| # Architecture for builds. Defaults to local arch; override for cross-compilation | ||
| # (e.g., BUILD_ARCH=amd64 make build from an ARM64 host). | ||
| BUILD_ARCH ?= $(shell go env GOARCH) | ||
| # Docker platform string. Override for cross-platform builds: | ||
| # BUILD_PLATFORM=linux/arm64 make build | ||
| BUILD_PLATFORM ?= linux/$(BUILD_ARCH) | ||
|
|
||
| .PHONY: init | ||
| init: | ||
| brew install protobuf | ||
|
|
@@ -18,18 +25,18 @@ generate: | |
| .PHONY: build | ||
| build: | ||
| $(eval COMMIT_SHA := $(shell git rev-parse --short HEAD)) | ||
| @docker build --platform linux/amd64 --output=bin --build-arg COMMIT_SHA="$(COMMIT_SHA)" -f ./Dockerfile .. | ||
| @docker build --platform $(BUILD_PLATFORM) --output=bin --build-arg COMMIT_SHA="$(COMMIT_SHA)" -f ./Dockerfile .. | ||
|
|
||
| .PHONY: build-local | ||
| build-local: | ||
| # Allow for passing commit sha directly for docker builds | ||
| $(eval COMMIT_SHA ?= $(shell git rev-parse --short HEAD)) | ||
| CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -o bin/orchestrator -ldflags "-X=main.commitSHA=$(COMMIT_SHA)" . | ||
| CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -o bin/clean-nfs-cache -ldflags "-X=main.commitSHA=$(COMMIT_SHA)" ./cmd/clean-nfs-cache | ||
| CGO_ENABLED=1 GOOS=linux GOARCH=$(BUILD_ARCH) go build -o bin/orchestrator -ldflags "-X=main.commitSHA=$(COMMIT_SHA)" . | ||
| CGO_ENABLED=1 GOOS=linux GOARCH=$(BUILD_ARCH) go build -o bin/clean-nfs-cache -ldflags "-X=main.commitSHA=$(COMMIT_SHA)" ./cmd/clean-nfs-cache | ||
|
|
||
| .PHONY: build-debug | ||
| build-debug: | ||
| CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -race -gcflags=all="-N -l" -o bin/orchestrator . | ||
| CGO_ENABLED=1 GOOS=linux GOARCH=$(BUILD_ARCH) go build -race -gcflags=all="-N -l" -o bin/orchestrator . | ||
|
|
||
| .PHONY: run-debug | ||
| run-debug: | ||
|
|
@@ -100,12 +107,12 @@ test: | |
|
|
||
| .PHONY: test-docker | ||
| test-docker: | ||
| @echo "Running orchestrator tests in Docker (AMD64 Linux)..." | ||
| @echo "Running orchestrator tests in Docker ($(BUILD_PLATFORM))..." | ||
| @rm -rf .shared/ | ||
| @cp -r ../shared .shared/ | ||
| @rm -rf .clickhouse/ | ||
| @cp -r ../clickhouse .clickhouse/ | ||
| @docker build --platform linux/amd64 -f test.Dockerfile --no-cache-filter runner --progress=plain -t orchestrator-test . | ||
cursor[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| @docker build --platform $(BUILD_PLATFORM) -f test.Dockerfile --no-cache-filter runner --progress=plain -t orchestrator-test . | ||
| @rm -rf .shared/ | ||
| @rm -rf .clickhouse/ | ||
| @echo "Done" | ||
|
Comment on lines
112
to
118
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 The Extended reasoning...What the bug is and how it manifests In @echo "Running orchestrator tests in Docker (AMD64 Linux)..."
...
@docker build --platform $(BUILD_PLATFORM) -f test.Dockerfile ...The specific code path that triggers it Any invocation of Why existing code doesn't prevent it The PR correctly updated every functional reference from What the impact would be The impact is cosmetic/informational only — the actual docker build uses the correct How to fix it Change the echo to dynamically include the platform value: @echo "Running orchestrator tests in Docker ($(BUILD_PLATFORM))..."Step-by-step proof
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed — echo now uses $(BUILD_PLATFORM) instead of hardcoded "AMD64 Linux". |
||
|
|
||


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BUILD_PLATFORMsingle-valued forstart-dockerstart-dockernow passes$(BUILD_PLATFORM)todocker run --platform, but this Makefile also documentsBUILD_PLATFORM=linux/amd64,linux/arm64as a supported override.docker run --platformexpects one platform value, so a comma-separated list will makestart-dockerfail beforeenvdstarts. This regression is specific to users following the new multi-arch override pattern.Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed — comment updated to single-arch example.