diff --git a/CHANGELOG_PENDING.md b/CHANGELOG_PENDING.md index f32ea198319a..86359c2567d5 100644 --- a/CHANGELOG_PENDING.md +++ b/CHANGELOG_PENDING.md @@ -28,3 +28,5 @@ Friendly reminder, we have a [bug bounty program](https://hackerone.com/tendermi ### IMPROVEMENTS ### BUG FIXES + +[docker] \#9073 enable cross platform build using docker buildx \ No newline at end of file diff --git a/DOCKER/Dockerfile b/DOCKER/Dockerfile index 1d8878bff3f1..c5869f1a3596 100644 --- a/DOCKER/Dockerfile +++ b/DOCKER/Dockerfile @@ -1,11 +1,11 @@ # stage 1 Generate Tendermint Binary -FROM golang:1.15-alpine as builder +FROM --platform=$BUILDPLATFORM golang:1.15-alpine as builder RUN apk update && \ apk upgrade && \ apk --no-cache add make COPY / /tendermint WORKDIR /tendermint -RUN make build-linux +RUN TARGETPLATFORM=$TARGETPLATFORM make build-linux # stage 2 FROM golang:1.15-alpine diff --git a/Makefile b/Makefile index ac0f9085126d..f45bebe8d489 100644 --- a/Makefile +++ b/Makefile @@ -53,6 +53,67 @@ endif # allow users to pass additional flags via the conventional LDFLAGS variable LD_FLAGS += $(LDFLAGS) +# Process Docker environment varible TARGETPLATFORM +# in order to build binary with correspondent ARCH +# by default will always build for linux/amd64 +TARGETPLATFORM ?= +GOOS ?= linux +GOARCH ?= amd64 +GOARM ?= + +ifeq (linux/arm,$(findstring linux/arm,$(TARGETPLATFORM))) + GOOS=linux + GOARCH=arm + GOARM=7 +endif + +ifeq (linux/arm/v6,$(findstring linux/arm/v6,$(TARGETPLATFORM))) + GOOS=linux + GOARCH=arm + GOARM=6 +endif + +ifeq (linux/arm64,$(findstring linux/arm64,$(TARGETPLATFORM))) + GOOS=linux + GOARCH=arm64 + GOARM=7 +endif + +ifeq (linux/386,$(findstring linux/386,$(TARGETPLATFORM))) + GOOS=linux + GOARCH=386 +endif + +ifeq (linux/amd64,$(findstring linux/amd64,$(TARGETPLATFORM))) + GOOS=linux + GOARCH=amd64 +endif + +ifeq (linux/mips,$(findstring linux/mips,$(TARGETPLATFORM))) + GOOS=linux + GOARCH=mips +endif + +ifeq (linux/mipsle,$(findstring linux/mipsle,$(TARGETPLATFORM))) + GOOS=linux + GOARCH=mipsle +endif + +ifeq (linux/mips64,$(findstring linux/mips64,$(TARGETPLATFORM))) + GOOS=linux + GOARCH=mips64 +endif + +ifeq (linux/mips64le,$(findstring linux/mips64le,$(TARGETPLATFORM))) + GOOS=linux + GOARCH=mips64le +endif + +ifeq (linux/riscv64,$(findstring linux/riscv64,$(TARGETPLATFORM))) + GOOS=linux + GOARCH=riscv64 +endif + all: check build test install .PHONY: all @@ -244,7 +305,7 @@ build-docker: build-linux # Build linux binary on other platforms build-linux: - GOOS=linux GOARCH=amd64 $(MAKE) build + GOOS=$(GOOS) GOARCH=$(GOARCH) GOARM=$(GOARM) $(MAKE) build .PHONY: build-linux build-docker-localnode: